Skip to content

Commit

Permalink
Merge pull request #39 from Capitains/issue-38
Browse files Browse the repository at this point in the history
Added support for default inventory
  • Loading branch information
PonteIneptique committed Oct 1, 2015
2 parents 158d5d7 + 9f3f4c7 commit e32110d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
19 changes: 19 additions & 0 deletions MyCapytain/endpoints/cts5.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ class CTS(MyCapytain.endpoints.proto.CTS):
Basic integration of the MyCapytain.endpoints.proto.CTS abstraction
"""

def __init__(self, endpoint, inventory=None):
""" API Prototype object
:param self: Object
:type self: API
:param endpoint: URL of the API
:type endpoint: str
:param inventory: Inventory to use
:type inventory: str
:ivar endpoint: Url of the endpoint
:ivar inventory: Default Inventory
"""
super(CTS, self).__init__(endpoint)
self.inventory = inventory

def call(self, parameters):
""" Call an endpoint given the parameters
Expand All @@ -28,6 +44,9 @@ def call(self, parameters):
parameters = {
key: str(parameters[key]) for key in parameters if parameters[key] is not None
}
if self.inventory is not None and "inv" not in parameters:
parameters["inv"] = self.inventory

request = requests.get(self.endpoint, params=parameters)
return request.text

Expand Down
26 changes: 13 additions & 13 deletions MyCapytain/resources/texts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def __init__(self, urn, resource, *args, **kwargs):
self.urn = urn

# Could be set during parsing
self.__next = None
self.__prev = None
self._next = None
self._prev = None
self.__first = None
self.__last = None

Expand All @@ -196,8 +196,8 @@ def next(self):
:rtype: Passage
:returns: Following passage at same level
"""
if self.__next is not None:
_next = self.__next
if self._next is not None:
_next = self._next
else:
# Request the next urn
_prev, _next = Passage.prevnext(
Expand All @@ -213,8 +213,8 @@ def prev(self):
:rtype: Passage
:returns: Previous passage at same level
"""
if self.__prev is not None:
_prev = self.__prev
if self._prev is not None:
_prev = self._prev
else:
# Request the next urn
_prev, _next = Passage.prevnext(
Expand All @@ -230,7 +230,7 @@ def __parse(self):
"""
self.resource = self.resource.xpath("//ti:passage/tei:TEI", namespaces=MyCapytain.common.utils.NS)[0]

self.__prev, self.__next = Passage.prevnext(self.resource)
self._prev, self._next = Passage.prevnext(self.resource)

@staticmethod
def prevnext(resource):
Expand All @@ -247,14 +247,14 @@ def prevnext(resource):

if len(prevnext) > 0:
prevnext = prevnext[0]
_next = prevnext.xpath("ti:next/ti:urn/text()", namespaces=MyCapytain.common.utils.NS)
_prev = prevnext.xpath("ti:prev/ti:urn/text()", namespaces=MyCapytain.common.utils.NS)
_next_xpath = prevnext.xpath("ti:next/ti:urn/text()", namespaces=MyCapytain.common.utils.NS)
_prev_xpath = prevnext.xpath("ti:prev/ti:urn/text()", namespaces=MyCapytain.common.utils.NS)

if len(_next):
_next = _next[0]
if len(_next_xpath):
_next = _next_xpath[0]

if len(_prev):
_prev = _prev[0]
if len(_prev_xpath):
_prev = _prev_xpath[0]

return _prev, _next

1 change: 0 additions & 1 deletion doc/MyCapytain.resources.texts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ MyCapytain.resources.texts package
:members:
:undoc-members:
:show-inheritance:

0 comments on commit e32110d

Please sign in to comment.