Permalink
Browse files

fixes #4 also bumping version 0.2.0, not backwards-compatible

  • Loading branch information...
1 parent c9c4845 commit 28e851515ae9d4423be7e3f14031f134d5b881b0 @maxcountryman maxcountryman committed Mar 16, 2012
View
BIN docs/_build/doctrees/environment.pickle
Binary file not shown.
View
BIN docs/_build/doctrees/index.doctree
Binary file not shown.
View
2 docs/_build/html/searchindex.js
@@ -1 +1 @@
-Search.setIndex({objects:{"":{webauth:[0,0,1,""]},"webauth.service.OflyService":{request:[0,2,1,""],get_authorize_url:[0,2,1,""]},"webauth.service.OAuth2Service":{get_access_token:[0,2,1,""],request:[0,2,1,""],get_authorize_url:[0,2,1,""]},"webauth.service.OAuth1Service":{get_authenticated_session:[0,2,1,""],get_request_token:[0,2,1,""],get_access_token:[0,2,1,""],request:[0,2,1,""],get_authorize_url:[0,2,1,""]},"webauth.service":{OflyService:[0,1,1,""],OAuth2Service:[0,1,1,""],OAuth1Service:[0,1,1,""]},"webauth.hook":{OAuth1Hook:[0,1,1,""]},"webauth.hook.OAuth1Hook":{generate_authorization_header:[0,2,1,""],generate_oauth_params:[0,2,1,""]}},terms:{represent:0,all:[],code:0,authorization_cod:0,excel:0,auth_head:0,random:[],obtain:0,addit:0,top:0,session:0,through:0,follow:0,assign:[],ofli:0,token_kei:0,paramet:0,redirect:0,whose:[],onli:0,get_authenticated_sess:0,acquir:0,field:[],flask:[],endpoint:0,activ:[],param:0,should:0,reinit:0,response_typ:0,mai:0,foobar:0,input:[],hidden:[],main:[],might:0,app:[],split:0,applic:0,global:[],"return":0,oauth1hook:0,thei:[],get:0,python:0,initi:[],defaul:0,util:0,webauth:0,oauth_request:0,csrf:[],request_token:0,now:0,you:0,string:0,like:0,document:0,name:0,specif:0,hook:0,"_construct_sess":0,html:[],authent:0,"default":0,achiev:[],necessari:0,contain:0,cooki:[],querystr:0,setup:0,deault:0,view:[],oflyservic:0,www:0,set:0,intial:0,client:0,natur:0,some:0,prehook:0,sign:0,consum:0,wrap:0,see:0,http_method:0,design:[],expect:0,authorize_url:0,pass:0,fail:[],unless:[],servic:0,append:0,variabl:0,oflycallsignatur:0,flaskext:[],influenc:[],miss:[],someth:0,token:0,superb:0,content:0,enough:0,run:[],oauth1:0,header_auth:0,"import":0,method:0,attribut:0,altern:0,signatur:0,object:0,hash:[],kei:0,gener:0,usag:0,given:0,here:0,standard:0,consumer_secret:0,extens:0,step:0,base:[],whereupon:0,dictionari:0,pair:0,ask:0,post:[],handl:0,valu:[],jinja:[],both:[],seasurf:[],your:[],wai:0,most:0,access_token_secret:0,could:0,current:0,http:0,oauth2servic:0,get_access_token:0,turn:0,redirect_uri:0,oauth_token:0,logic:[],fals:0,implement:0,reli:0,com:0,produc:0,commonli:0,first:0,request_token_secret:0,pleas:0,rang:[],via:0,simpli:0,although:0,directli:0,point:0,onc:0,modul:0,easy_instal:0,pre_request:0,header:0,api:0,oauth_kei:0,send:0,exclud:[],ensur:0,instal:0,hmacsha1signatur:0,assum:0,primari:[],middlewar:[],backend:[],quit:0,accordingli:0,from:0,oflycallbackurl:0,would:0,attach:0,addition:0,interact:0,support:0,visit:0,two:0,been:0,avail:0,start:0,secret:0,call:0,includ:0,easiest:0,save:0,some_view:[],render_templ:[],type:0,"final":0,more:0,"function":0,head:[],wrapper:0,option:0,form:[],conveni:0,exempt:[],rsa:0,oauth1servic:0,instanc:[],made:0,bodi:0,indic:[],oauth:0,request_token_url:0,reponse_typ:0,"true":0,than:0,access_token_url:0,remote_us:0,none:0,subsequ:0,retriev:0,look:[],keyword:0,possibl:0,provid:0,wish:[],secret_kei:[],access:0,spec:0,can:0,abov:0,oauth_param:0,inform:0,other:[],similar:0,def:[],pre:0,oauth2:0,want:0,generate_oauth_param:0,process:0,well:0,csrf_token:[],respons:0,shutterfli:0,argument:0,templat:[],get_authorize_url:0,direct:0,packag:0,properli:0,have:0,deliv:0,pip:0,doe:0,check:[],"__init__":0,around:0,access_token:0,readi:0,oauth_sess:0,variou:0,authen:0,author:0,receiv:0,oauthhook:0,make:0,format:0,when:[],init_app:[],consumer_kei:0,note:0,also:0,need:0,valid:0,"_csrf_token":[],futur:0,which:0,relav:0,before_request:[],instead:0,presum:0,generate_authorization_head:0,simpl:0,updat:0,oflyremoteus:0,simplifi:0,begin:0,sure:0,resourc:0,allow:0,trace:[],normal:0,our:0,proper:0,after:0,upon:0,decor:[],sfly:0,rout:[],capabl:0,render:[],specifi:[],establish:0,streamlin:0,csrftoken:[],realm:0,construct:0,data:0,"class":0,built:0,get_request_token:0,simplic:0,sha1:0,off:[],url:0,bind:0,grant:0,request:0,uri:0,django:[],rather:0,exampl:0,command:0,thi:0,time:0,grant_typ:0,salt:[],get_authorization_url:0,usual:0},objtypes:{"0":"py:module","1":"py:class","2":"py:method"},titles:["Webauth"],objnames:{"0":["py","module","Python module"],"1":["py","class","Python class"],"2":["py","method","Python method"]},filenames:["index"]})
+Search.setIndex({objects:{"":{webauth:[0,0,1,""]},"webauth.service.OflyService":{request:[0,2,1,""],get_authorize_url:[0,2,1,""]},"webauth.service.OAuth2Service":{get_access_token:[0,2,1,""],request:[0,2,1,""],get_authorize_url:[0,2,1,""]},"webauth.service.OAuth1Service":{get_authenticated_session:[0,2,1,""],get_request_token:[0,2,1,""],get_access_token:[0,2,1,""],request:[0,2,1,""],get_authorize_url:[0,2,1,""]},"webauth.service":{OflyService:[0,1,1,""],OAuth2Service:[0,1,1,""],OAuth1Service:[0,1,1,""]},"webauth.hook":{OAuth1Hook:[0,1,1,""]},"webauth.hook.OAuth1Hook":{generate_authorization_header:[0,2,1,""],generate_oauth_params:[0,2,1,""]}},terms:{represent:0,all:[],code:0,valid:0,authorization_cod:0,when:[],auth_head:0,random:[],obtain:0,session:0,through:0,follow:0,token_kei:0,paramet:0,redirect:0,whose:[],onli:0,get_authenticated_sess:0,acquir:0,field:[],flask:[],"_csrf_token":[],activ:[],param:0,should:0,reinit:0,response_typ:0,onc:0,input:[],hidden:[],main:[],might:0,modul:0,futur:0,applic:0,global:[],"return":0,oauth1hook:0,thei:[],get:0,python:0,than:0,initi:[],defaul:0,util:0,webauth:0,pre_request:0,csrf:[],request_token:0,resourc:0,now:0,presum:0,like:0,receiv:0,name:0,specif:0,header:0,possibl:0,"_construct_sess":0,secret:0,authent:0,provid:0,achiev:[],exampl:0,necessari:0,contain:0,cooki:[],querystr:0,setup:0,deault:0,view:[],oflyservic:0,www:0,set:0,primari:[],signatur:0,natur:0,interact:0,some:0,prehook:0,around:0,sign:0,consum:0,ensur:0,see:0,http_method:0,design:[],expect:0,pass:0,fail:[],hash:[],generate_authorization_head:0,append:0,variabl:0,subsequ:0,oflycallsignatur:0,flaskext:[],influenc:[],assum:0,someth:0,unless:[],token:0,superb:0,content:0,enough:0,header_auth:0,django:[],"import":0,get_authorization_url:0,method:0,attribut:0,altern:0,intial:0,simplifi:0,after:0,run:[],kei:0,gener:0,usag:0,accordingli:0,here:0,standard:0,consumer_secret:0,extens:0,step:0,base:[],whereupon:0,dictionari:0,ask:0,post:[],secret_kei:[],valu:[],addit:0,csrftoken:[],both:[],seasurf:[],would:0,rsa:0,capabl:0,similar:0,could:0,current:0,oauth2servic:0,get_access_token:0,turn:0,redirect_uri:0,oauth_token:0,logic:[],fals:0,implement:0,com:0,produc:0,commonli:0,first:0,request_token_secret:0,pleas:0,rang:[],via:0,simpli:0,although:0,directli:0,point:0,foobar:0,app:[],easy_instal:0,oauth_request:0,hook:0,api:0,oauth_kei:0,send:0,wrap:0,instal:0,hmacsha1signatur:0,miss:[],your:[],middlewar:[],backend:[],quit:0,given:0,doe:0,from:0,wai:0,start:0,addition:0,top:0,support:0,visit:0,two:0,been:0,avail:0,attach:0,reli:0,call:0,includ:0,save:0,some_view:[],render_templ:[],type:0,"final":0,more:0,"function":0,head:[],wrapper:0,option:0,form:[],conveni:0,exempt:[],jinja:[],oauth1servic:0,oflycallbackurl:0,made:0,bodi:0,templat:[],oauth:0,request_token_url:0,reponse_typ:0,"true":0,easiest:0,access_token_url:0,remote_us:0,also:0,none:0,endpoint:0,retriev:0,look:[],keyword:0,instanc:[],"default":0,wish:[],servic:0,access:0,spec:0,can:0,abov:0,oauth_param:0,other:[],access_token_secret:0,def:[],pre:0,oauth2:0,have:0,generate_oauth_param:0,process:0,request:0,csrf_token:[],respons:0,shutterfli:0,argument:0,indic:[],get_authorize_url:0,direct:0,packag:0,properli:0,want:0,deliv:0,pip:0,exclud:[],check:[],"__init__":0,string:0,access_token:0,readi:0,realm:0,variou:0,authen:0,author:0,rather:0,oauthhook:0,authorize_url:0,format:0,excel:0,init_app:[],consumer_kei:0,note:0,handl:0,need:0,html:[],pair:0,split:0,which:0,relav:0,before_request:[],instead:0,you:0,document:0,simpl:0,updat:0,oflyremoteus:0,oauth1:0,begin:0,sure:0,http:0,thi:0,trace:[],normal:0,our:0,proper:0,object:0,upon:0,decor:[],sfly:0,rout:[],most:0,render:[],specifi:[],establish:0,streamlin:0,mai:0,oauth_sess:0,construct:0,data:0,"class":0,built:0,get_request_token:0,simplic:0,sha1:0,off:[],uri:0,url:0,bind:0,grant:0,well:0,ofli:0,assign:[],inform:0,client:0,command:0,allow:0,time:0,grant_typ:0,salt:[],make:0,usual:0},objtypes:{"0":"py:module","1":"py:class","2":"py:method"},titles:["Webauth"],objnames:{"0":["py","module","Python module"],"1":["py","class","Python class"],"2":["py","method","Python method"]},filenames:["index"]})
View
23 tests/test_service.py
@@ -55,7 +55,7 @@ def test_request(self, mock_request):
self.response.content = json.dumps({'status': 'ok'})
mock_request.return_value = self.response
response = self.service.request('GET',
- 'http://example.com/endpoint')
+ 'http://example.com/endpoint').content
self.assertEqual(response['status'], 'ok')
@patch.object(requests.Session, 'request')
@@ -64,7 +64,7 @@ def test_request_header_auth(self, mock_request):
mock_request.return_value = self.response
response = self.service.request('GET',
'http://example.com/endpoint',
- header_auth=True)
+ header_auth=True).content
self.assertEqual(response['status'], 'ok')
@patch.object(requests.Session, 'request')
@@ -130,7 +130,7 @@ def test_get_authorize_url_response_type(self):
@patch.object(requests.Session, 'request')
def test_get_access_token(self, mock_request):
mock_request.return_value = self.response
- response = self.service.get_access_token(code='4242')
+ response = self.service.get_access_token(code='4242').content
self.assertEqual(response['access_token'], '321')
@patch.object(requests.Session, 'request')
@@ -146,8 +146,9 @@ def test_get_access_token_bad_response(self, mock_request):
@patch.object(requests.Session, 'request')
def test_get_access_token_grant_type(self, mock_request):
mock_request.return_value = self.response
- response = self.service.get_access_token(code='4242',
- grant_type='refresh_token')
+ response = \
+ self.service.get_access_token(code='4242',
+ grant_type='refresh_token').content
self.assertEqual(response['access_token'], '321')
@patch.object(requests.Session, 'request')
@@ -156,12 +157,12 @@ def test_request(self, mock_request):
mock_request.return_value = self.response
response = self.service.request('GET',
'http://example.com/endpoint',
- access_token='321')
+ access_token='321').content
self.assertEqual(response['status'], 'ok')
# test here again to make sure the access token was set
response = self.service.request('GET',
- 'http://example.com/endpoint')
+ 'http://example.com/endpoint').content
self.assertEqual(response['status'], 'ok')
@patch.object(requests.Session, 'request')
@@ -272,7 +273,7 @@ def test_get_access_token(self, mock_request):
access_resp = self.service.get_access_token(request_token='123',
request_token_secret='456',
- http_method='GET')
+ http_method='GET').content
self.assertEqual(access_resp['oauth_token'], '123')
self.assertEqual(access_resp['oauth_token_secret'], '456')
@@ -317,7 +318,7 @@ def test_request_get(self, mock_request):
self.service.request('GET',
'http://example.com/some/method',
access_token='123',
- access_token_secret='456')
+ access_token_secret='456').content
self.assertTrue(response is not None)
self.assertEqual('123', response['oauth_token'])
self.assertEqual('456', response['oauth_token_secret'])
@@ -328,12 +329,12 @@ def test_json_response(self, mock_request):
self.response.content = json.dumps({'a': 'b'})
access_resp = self.service.get_access_token('123', '456', 'GET')
- self.assertEqual({'a': 'b'}, access_resp)
+ self.assertEqual({'a': 'b'}, access_resp.content)
@patch.object(requests.Session, 'request')
def test_other_response(self, mock_request):
mock_request.return_value = self.response
self.response.content = {'a': 'b'}
access_resp = self.service.get_access_token('123', '456', 'GET')
- self.assertEqual({'a': 'b'}, access_resp)
+ self.assertEqual({'a': 'b'}, access_resp.content)
View
2 webauth/__init__.py
@@ -6,4 +6,4 @@
'''
-__version__ = '0.1.10'
+__version__ = '0.2.0'
View
28 webauth/service.py
@@ -17,7 +17,7 @@
def _parse_response(response):
- '''Attempts to coerce response.content into a dictionary.
+ '''Attempts to parse response.content. Returns a `Response` object.
:param response: A Requests response object.
'''
@@ -26,10 +26,16 @@ def _parse_response(response):
content = json.loads(response.content)
except ValueError:
content = dict(parse_qsl(response.content))
- return content
- # TODO: rather than returning the content in the case of receiving
- # something we can't parse we should probably raise an error
- return response.content
+ else:
+ content = response.content
+ return Response(content=content, response=response)
+
+
+class Response(object):
+ '''A service response container.'''
+ def __init__(self, content, response):
+ self.content = content
+ self.response = response
class OflyService(object):
@@ -161,9 +167,7 @@ def request(self, http_method, url, header_auth=False, params=None,
response.raise_for_status()
- _response = _parse_response(response)
- _response['_unparsed_response'] = response
- return _response
+ return _parse_response(response)
class OAuth2Service(object):
@@ -279,9 +283,7 @@ def request(self, http_method, url, access_token=None, params=None,
response.raise_for_status()
- _response = _parse_response(response)
- _response['_unparsed_response'] = response
- return _response
+ return _parse_response(response)
class OAuth1Service(object):
@@ -462,6 +464,4 @@ def request(self, http_method, url, access_token, access_token_secret,
response.raise_for_status()
- _response = _parse_response(response)
- _response['_unparsed_response'] = response
- return _response
+ return _parse_response(response)

0 comments on commit 28e8515

Please sign in to comment.