def get_library(self): url = self.LIBRARY_ENDPOINT % dict(library_id=self.library_id) representation, cached = Representation.get( self._db, url, self.get, exception_handler=Representation.reraise_exception, ) return json.loads(representation.content)
def request(self, path, body=None, method="GET", identifier=None, max_age=None): path = self.full_path(path) url = self.full_url(path) if method == 'GET': headers = {"Accept": "application/xml"} else: headers = {"Content-Type": "application/xml"} self.sign(method, headers, path) # print headers # self.log.debug("3M request: %s %s", method, url) if max_age and method == 'GET': representation, cached = Representation.get( self._db, url, extra_request_headers=headers, do_get=self._simple_http_get, max_age=max_age, exception_handler=Representation.reraise_exception, ) content = representation.content return content else: return self._request_with_timeout(method, url, data=body, headers=headers, allow_redirects=False)
def get_library(self): """Get basic information about the collection, including a link to the titles in the collection. """ url = self._library_endpoint representation, cached = Representation.get( self._db, url, self.get, exception_handler=Representation.reraise_exception, ) return json.loads(representation.content)
def request(self, path, identifier=None, max_age=LIST_MAX_AGE): if not path.startswith(self.BASE_URL): if not path.startswith("/"): path = "/" + path url = self.BASE_URL + path else: url = path joiner = '?' if '?' in url: joiner = '&' url += joiner + "api-key=" + self.api_key representation, cached = Representation.get(self._db, url, do_get=self.do_get, max_age=max_age, debug=True, pause_before=0.1) content = json.loads(representation.content) return content
def get_advantage_accounts(self): """Find all the Overdrive Advantage accounts managed by this library. :yield: A sequence of OverdriveAdvantageAccount objects. """ library = self.get_library() links = library.get('links', {}) advantage = links.get('advantageAccounts') if not advantage: return [] if advantage: # This library has Overdrive Advantage accounts, or at # least a link where some may be found. advantage_url = advantage.get('href') if not advantage_url: return representation, cached = Representation.get( self._db, advantage_url, self.get, exception_handler=Representation.reraise_exception, ) return OverdriveAdvantageAccount.from_representation( representation.content )