def get_page(self, url, params={}):
        # get a page of results
        # from intercom import Intercom

        # if there is no url stop iterating
        if url is None:
            raise StopIteration

        response = self.client.get(url, params)

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        # HACK: dealing with the fact that in unstable /tags is returning
        # {'type': 'list', 'data': []} instead of
        # {'type': 'tags.list', 'tags': []}
        if response['type'] == 'list':
            collection = response['data']
        else:
            collection = response[self.collection]
        # if there are no resources in the response stop iterating
        if collection is None:
            raise StopIteration

        # create the resource iterator
        self.resources = iter(collection)
        # grab the next page URL if one exists
        self.next_page = self.extract_next_link(response)
Beispiel #2
0
    def find(cls, **params):
        from intercom import Intercom
        collection = utils.resource_class_to_collection_name(cls)
        if 'id' in params:
            response = Intercom.get("/%s/%s" % (collection, params['id']))
        else:
            response = Intercom.get("/%s" % (collection), **params)

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        return cls(**response)
Beispiel #3
0
    def load(self):
        from intercom import Intercom
        cls = self.__class__
        collection = utils.resource_class_to_collection_name(cls)
        if hasattr(self, 'id'):
            response = Intercom.get("/%s/%s" % (collection, self.id))
        else:
            raise Exception("Cannot load %s as it does not have a valid id." %
                            (cls))

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        return cls(**response)
Beispiel #4
0
    def find(self, **params):
        """Find the instance of the resource based on the supplied parameters."""
        collection = utils.resource_class_to_collection_name(
            self.collection_class)
        if 'id' in params:
            response = self.client.get("/%s/%s" % (collection, params['id']),
                                       {})
        else:
            response = self.client.get("/%s" % (collection), params)

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        return self.collection_class(**response)
Beispiel #5
0
    def load(self, resource):
        """Load the resource from the latest data in Intercom."""
        collection = utils.resource_class_to_collection_name(
            self.collection_class)
        if hasattr(resource, 'id'):
            response = self.client.get("/%s/%s" % (collection, resource.id),
                                       {})  # noqa
        else:
            raise Exception("Cannot load %s as it does not have a valid id." %
                            (self.collection_class))

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        return resource.from_response(response)
Beispiel #6
0
    def get_page(self, scroll_param=None):
        """Retrieve a page of results from the Scroll API."""
        if scroll_param is None:
            response = self.client.get(self.scroll_url, {})
        else:
            response = self.client.get(self.scroll_url,
                                       {'scroll_param': scroll_param})

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        # create the resource iterator
        collection = response[self.resource_name]
        self.resources = iter(collection)
        # grab the next page URL if one exists
        self.scroll_param = self.extract_scroll_param(response)
    def get_page(self, url, params={}):
        # get a page of results
        from intercom import Intercom

        # if there is no url stop iterating
        if url is None:
            raise StopIteration

        response = Intercom.get(url, **params)
        if response is None:
            raise HttpError('Http Error - No response entity returned')

        collection = response[self.collection]
        # if there are no resources in the response stop iterating
        if collection is None:
            raise StopIteration

        # create the resource iterator
        self.resources = iter(collection)
        # grab the next page URL if one exists
        self.next_page = self.extract_next_link(response)
    def get_page(self, url, params={}):
        # get a page of results
        # from intercom import Intercom

        # if there is no url stop iterating
        if url is None:
            raise StopIteration

        if "sort" in params or "query" in params:
            url = f"{url}/search"
            if self.paging_info and "next" in self.paging_info:
                params["pagination"] = {
                    "per_page": self.paging_info["per_page"],
                    "starting_after":
                    self.paging_info["next"]["starting_after"]
                }
            response = self.client.post(url, params)
        else:
            response = self.client.get(url, params)

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        # HACK: dealing with the fact that in unstable /tags is returning
        # {'type': 'list', 'data': []} instead of
        # {'type': 'tags.list', 'tags': []}
        if response['type'] == 'list':
            collection = response['data']
        else:
            collection = response[self.collection]
        # if there are no resources in the response stop iterating
        if collection is None:
            raise StopIteration

        # create the resource iterator
        self.resources = iter(collection)
        # grab the next page URL if one exists
        self.next_page = self.extract_next_link(response)
    def get_page(self, scroll_param=None):
        """Retrieve a page of results from the Scroll API."""
        if scroll_param is None:
            response = self.client.get(self.scroll_url, {})
        else:
            response = self.client.get(self.scroll_url,
                                       {'scroll_param': scroll_param})

        if response is None:
            raise HttpError('Http Error - No response entity returned')

        # create the resource iterator

        # HACK: dealing with the fact that in unstable /tags is returning
        # {'type': 'list', 'data': []} instead of
        # {'type': 'tags.list', 'tags': []}
        if response['type'] == 'list':
            collection = response['data']
        else:
            collection = response[self.resource_name]

        self.resources = iter(collection)
        # grab the next page URL if one exists
        self.scroll_param = self.extract_scroll_param(response)