def post(self, data, on_behalf_of=None): onb = on_behalf_of or self._on_behalf_of if onb is None: raise InvalidAPICallError('on_behalf_of must either be passed or set on the Harvest instance') if self._object_id: raise InvalidAPICallError('Cannot POST with an object id') if not self._list: raise InvalidAPICallError('Cannot POST without a list url') url = self._list return self._post(url, data, onb)
def get(self, object_id=None, **params): oid = object_id or self._object_id if oid is not None: url = self._retrieve or self._list url = url.format(id=oid) elif self._list is not None: url = self._list else: raise InvalidAPICallError('Must provide object id') self._set_params(**params) return self._get(url)
def __getattr__(self, key): endpoint = str(key) uris = self._related.get(endpoint, None) if uris is not None: if self._object_id is None: raise InvalidAPICallError( 'Cannot query related object {} without selecting an object id first' .format(endpoint)) list_uri = (uris['list'].format( rel_id=self._object_id) if uris.get('list') else None) retrieve_uri = (uris['retrieve'].format( rel_id=self._object_id) if uris.get('retrieve') else None) return HarvestObject(endpoint, self._api_key, self._base_url, list_uri, retrieve_uri) else: raise EndpointNotFound(endpoint)