def get_broker_navigator(self): # TODO: remove the manipulation of the URL to allow broker URLs with path components at the root # (this manipulation is here as an interim measure for older usages which specified a more complex # pact broker URL pointing to a different resource) url_parts = urllib.parse.urlparse(self.pact_broker_url) url = f'{url_parts.scheme}://{url_parts.netloc}/' return Navigator.hal(url, default_curie='pb')
def get_broker_navigator(self): # TODO: remove the manipulation of the URL to allow broker URLs with path components at the root # (this manipulation is here as an interim measure for older usages which specified a more complex # pact broker URL pointing to a different resource) url_parts = urllib.parse.urlparse(self.pact_broker_url) url = f'{url_parts.scheme}://{url_parts.netloc}/' nav = Navigator.hal(url, default_curie='pb') if self.pact_broker_username is not None: if self.pact_broker_password is None: raise ValueError('pact broker password must be specified') nav.authenticate( (self.pact_broker_username, self.pact_broker_password)) return nav
def get_broker_navigator(self): return Navigator.hal(self.url, default_curie="pb", auth=self.auth, headers=self.headers)
def __init__(self,aep,api_token=None): self.rn= Navigator.hal(aep) if api_token: self.rn.headers['OSDI-API-Token']=api_token
def __init__(self, api_key, location): self._api_key = api_key self._url_base = self._location_base + location + '/' self._headers={'Api-Key': self._api_key} self._navigator = Navigator.hal(self._url_base, headers=self._headers)
# pip install restnavigator from restnavigator import Navigator # The OSDI API entry point, listing the collections available # View it in a browser: http://demo.osdi.io/hb2/browser.html#/api/v1 aep = 'http://demo.osdi.io/api/v1' # Security is important. The OSDI example server doesn't require a token. # Others do so here's how to do it api_token = 'foobar' # Initialize the navigator with the AEP rn = Navigator.hal(aep) # Set the token rn.headers['OSDI-API-Token'] = api_token # Navigate to the osdi:people collection from the AEP # Then drill in to the osdi:people embedded in the response to the collection # Stick the set of people that came back into a variable people = rn['osdi:people']['osdi:people'] # Loop through the people, grab each persons state for person in people: state = person.state # People have more than one email, grab them all emails = '' for email in state['email_addresses']: emails += email['address']