Skip to content

Commit

Permalink
Merge pull request #38 from jaredhobbs/master
Browse files Browse the repository at this point in the history
Synchronize repo with PyPI package v2.1
  • Loading branch information
gene1wood authored Apr 14, 2018
2 parents dbf7014 + d78b731 commit 82cbfb8
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
tags
*.py[co]
.*
MANIFEST
dist/*
agithub.egg-info/
agithub.egg-info/
build/
Expand Down
20 changes: 11 additions & 9 deletions agithub/DigitalOcean.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from agithub.base import *
from agithub.base import API, ConnectionProperties, Client


class DigitalOcean(API):
'''
"""
Digital Ocean API
'''
"""
def __init__(self, token=None, *args, **kwargs):
props = ConnectionProperties(
api_url = 'api.digitalocean.com',
url_prefix = '/v2',
secure_http = True,
extra_headers = {
'authorization' : self.generateAuthHeader(token)
})
api_url='api.digitalocean.com',
url_prefix='/v2',
secure_http=True,
extra_headers={
'authorization': self.generateAuthHeader(token)
},
)
self.setClient(Client(*args, **kwargs))
self.setConnectionProperties(props)

Expand Down
16 changes: 9 additions & 7 deletions agithub/Facebook.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from agithub.base import *
from agithub.base import API, ConnectionProperties, Client


class Facebook(API):
'''
"""
Facebook Graph API
The following example taken from
Expand All @@ -13,12 +14,13 @@ class Facebook(API):
>>> fb.facebook.picture.get(redirect='false')
{u'data': {u'is_silhouette': False,
u'url':
u'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/t1.0-1/p50x50/1377580_10152203108461729_809245696_n.png'}})
'''
u'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/
t1.0-1/p50x50/1377580_10152203108461729_809245696_n.png'}})
"""
def __init__(self, *args, **kwargs):
props = ConnectionProperties(
api_url = 'graph.facebook.com'
, secure_http = True
)
api_url='graph.facebook.com',
secure_http=True,
)
self.setClient(Client(*args, **kwargs))
self.setConnectionProperties(props)
33 changes: 21 additions & 12 deletions agithub/GitHub.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from agithub.base import *
import base64

from agithub.base import API, ConnectionProperties, Client


class GitHub(API):
'''
"""
The agnostic GitHub API. It doesn't know, and you don't care.
>>> from agithub import GitHub
>>> g = GitHub('user', 'pass')
Expand All @@ -28,29 +31,35 @@ class GitHub(API):
NOTE: It is up to you to spell things correctly. A GitHub object
doesn't even try to validate the url you feed it. On the other hand,
it automatically supports the full API--so why should you care?
'''
def __init__(self, username=None, password=None, token=None, *args, **kwargs):
extraHeaders = {'accept' : 'application/vnd.github.v3+json'}
"""
def __init__(self, username=None, password=None, token=None,
*args, **kwargs):
extraHeaders = {'accept': 'application/vnd.github.v3+json'}
auth = self.generateAuthHeader(username, password, token)
if auth != None:
if auth is not None:
extraHeaders['authorization'] = auth
props = ConnectionProperties(
api_url = kwargs.pop('api_url', 'api.github.com'),
secure_http = True,
extra_headers = extraHeaders
)
api_url=kwargs.pop('api_url', 'api.github.com'),
secure_http=True,
extra_headers=extraHeaders
)

self.setClient(Client(*args, **kwargs))
self.setConnectionProperties(props)

def generateAuthHeader(self, username=None, password=None, token=None):
if token is not None:
if password is not None:
raise TypeError("You cannot use both password and oauth token authenication")
raise TypeError(
"You cannot use both password and oauth token "
"authenication"
)
return 'Token %s' % token
elif username is not None:
if password is None:
raise TypeError("You need a password to authenticate as " + username)
raise TypeError(
"You need a password to authenticate as " + username
)
self.username = username
return self.hash_pass(password)

Expand Down
15 changes: 8 additions & 7 deletions agithub/Maven.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from agithub.base import *
from agithub.base import API, Client, ConnectionProperties


class Maven(API):
'''
"""
Maven Search API
'''
"""
def __init__(self, *args, **kwargs):
props = ConnectionProperties(
api_url = 'search.maven.org'
, url_prefix = '/solrsearch'
, secure_http = True
)
api_url='search.maven.org',
url_prefix='/solrsearch',
secure_http=True,
)
self.setClient(Client(*args, **kwargs))
self.setConnectionProperties(props)
11 changes: 6 additions & 5 deletions agithub/OpenWeatherMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# See COPYING for license details
from agithub.base import API, ConnectionProperties, Client


class OpenWeatherMap(API):
'''
"""
Open Weather Map API
'''
"""
def __init__(self, *args, **kwargs):
props = ConnectionProperties(
api_url = 'api.openweathermap.org'
, secure_http = False
)
api_url='api.openweathermap.org',
secure_http=False,
)
self.setClient(Client(*args, **kwargs))
self.setConnectionProperties(props)
15 changes: 9 additions & 6 deletions agithub/SalesForce.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
# See COPYING for license details
from agithub.base import API, ConnectionProperties, Client


class SalesForce(API):
'''
"""
SalesForce.com REST API
Example taken from
http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#CSHID=quickstart_code.htm|StartTopic=Content%2Fquickstart_code.htm|SkinName=webhelp
http://www.salesforce.com/us/developer/docs/api_rest/
index_Left.htm#CSHID=quickstart_code.htm|
StartTopic=Content%2Fquickstart_code.htm|SkinName=webhelp
>>> from SalesForce import SalesForce
>>> sf = SalesForce()
Expand All @@ -29,11 +32,11 @@ class SalesForce(API):
NB: XML is not automically decoded or de-serialized. Patch the
ResponseBody class to fix this.
'''
"""
def __init__(self, *args, **kwargs):
props = ConnectionProperties(
api_url = 'na1.salesforce.com'
, secure_http = True
)
api_url='na1.salesforce.com',
secure_http=True,
)
self.setClient(Client(*args, **kwargs))
self.setConnectionProperties(props)
3 changes: 1 addition & 2 deletions agithub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from functools import partial, update_wrapper
from agithub.base import VERSION, STR_VERSION

__all__ = [ "VERSION", "STR_VERSION" ]
__all__ = ["VERSION", "STR_VERSION"]
39 changes: 19 additions & 20 deletions agithub/agithub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mock
import unittest


class TestGitHubObjectCreation(unittest.TestCase):
def test_user_pw(self):
gh = GitHub('korfuri', '1234')
Expand All @@ -23,8 +24,7 @@ def test_token(self):

def test_token_password(self):
with self.assertRaises(TypeError):
gh = GitHub(
username='korfuri', password='1234', token='deadbeef')
GitHub(username='korfuri', password='1234', token='deadbeef')


class TestIncompleteRequest(unittest.TestCase):
Expand All @@ -39,31 +39,30 @@ def test_pathByGetAttr(self):

def test_callMethodDemo(self):
rb = self.newIncompleteRequest()
self.assertEqual(rb.path.demo(),
{ "methodName" : "demo"
, "args" : ()
, "params" : { "url" : "/path" }
})
self.assertEqual(
rb.path.demo(),
{
"methodName": "demo",
"args": (),
"params": {"url": "/path"}
}
)

def test_pathByGetItem(self):
rb = self.newIncompleteRequest()
rb["hug"][1]["octocat"]
self.assertEqual(rb.url, "/hug/1/octocat")

def test_callMethodDemo(self):
rb = self.newIncompleteRequest()
self.assertEqual(rb.path.demo(),
{ "methodName" : "demo"
, "args" : ()
, "params" : { "url" : "/path" }
})

def test_callMethodTest(self):
rb = self.newIncompleteRequest()
self.assertEqual(rb.path.test(),
{ "methodName" : "test"
, "args" : ()
, "params" : { "url" : "/path" }
})
self.assertEqual(
rb.path.demo(),
{
"methodName": "demo",
"args": (),
"params": {"url": "/path"}
}
)

if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 82cbfb8

Please sign in to comment.