Skip to content

Commit

Permalink
fix agency, bump dev version
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Nov 7, 2015
1 parent b06d28d commit b1d2186
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
22 changes: 22 additions & 0 deletions habanero/agency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Agency(object):
'''
Habanero: agency class
'''
def __init__(self, result):
self.result = result

def status(self):
return self.result['status']

def message_type(self):
return self.result['message-type']

def message_version(self):
return self.result['message-version']

def message(self):
return self.result['message']

def agency(self):
tmp = self.result['message'].get("agency")
return tmp
3 changes: 1 addition & 2 deletions habanero/habanero.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def works(self, ids = None, query = None, filter = None, offset = None,
>>>
>>> # Get full text links
>>> x = hb.works(filter = {'has_full_text': True})
>>> x.links()
>>> x
>>>
>>> # Parse output to various data pieces
>>> x = hb.works(filter = {'has_full_text': True})
Expand Down Expand Up @@ -351,4 +351,3 @@ def agency(self, ids, **kwargs):
None, None, None, None, None, None,
None, None, None, True, **kwargs)
return res

12 changes: 8 additions & 4 deletions habanero/habanero_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .response import Works
from .noworks import NoWorks
from .agency import Agency

# helpers ----------
def converter(x):
Expand All @@ -16,8 +17,11 @@ def sub_str(x, n = 3):
else:
return str(x[:n]) + '***'

def switch_classes(x, path, works):
if works or re.sub("/", "", path) == "works" and re.sub("/", "", path) != "licenses":
return Works(result = x)
def switch_classes(x, path, works, agency):
if agency:
return Agency(result = x)
else:
return NoWorks(result = x)
if works or re.sub("/", "", path) == "works" and re.sub("/", "", path) != "licenses":
return Works(result = x)
else:
return NoWorks(result = x)
4 changes: 2 additions & 2 deletions habanero/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def request(url, path, ids = None, query = None, filter = None,
url = url.strip("/")
tt = requests.get(url, params = payload, **kwargs)
js = tt.json()
coll = switch_classes(js, path, works)
coll = switch_classes(js, path, works, agency)
else:
if(ids.__class__.__name__ == "str"):
ids = ids.split()
Expand All @@ -40,7 +40,7 @@ def request(url, path, ids = None, query = None, filter = None,
endpt = endpt.strip("/")
tt = requests.get(endpt, params = payload, **kwargs)
js = tt.json()
tt_out = switch_classes(js, path, works)
tt_out = switch_classes(js, path, works, agency)
coll.append(tt_out)

if len(coll) == 1:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name = 'habanero',
version = '0.0.3.9399',
version = '0.0.3.9500',
description = 'Low Level Client for Crossref Search API',
author = 'Scott Chamberlain',
author_email = 'myrmecocystus@gmail.com',
Expand Down

0 comments on commit b1d2186

Please sign in to comment.