예제 #1
0
 def all(self):
     """Return a CollectionProxy for the resource."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/%s" % (collection)
     return CollectionProxy(
         self.client, self.collection_class, collection, finder_url)
예제 #2
0
 def scroll(self, **params):
     """Find all instances of the resource based on the supplied parameters."""
     collection_name = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/{}/scroll".format(collection_name)
     return ScrollCollectionProxy(self.client, self.collection_class,
                                  collection_name, finder_url)
예제 #3
0
 def reply(self, **reply_data):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(self.__class__)
     url = "/%s/%s/reply" % (collection, self.id)
     reply_data['conversation_id'] = self.id
     response = Intercom.post(url, **reply_data)
     return self.from_response(response)
예제 #4
0
 def reply(self, **reply_data):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(self.__class__)
     url = "/%s/%s/reply" % (collection, self.id)
     reply_data['conversation_id'] = self.id
     response = Intercom.post(url, **reply_data)
     return self.from_response(response)
예제 #5
0
    def submit_bulk_job(self, create_items=[], delete_items=[], job_id=None):
        """Submit a Bulk API job."""
        from intercom import event
        from intercom.errors import HttpError
        from intercom.job import Job

        if self.collection_class == event.Event and delete_items:
            raise Exception("Events do not support bulk delete operations.")
        data_type = utils.resource_class_to_name(self.collection_class)
        collection_name = utils.resource_class_to_collection_name(
            self.collection_class)
        create_items = [
            item_for_api('post', data_type, item) for item in create_items
        ]
        delete_items = [
            item_for_api('delete', data_type, item) for item in delete_items
        ]

        bulk_request = {'items': create_items + delete_items}
        if job_id:
            bulk_request['job'] = {'id': job_id}

        response = self.client.post('/bulk/%s' % (collection_name),
                                    bulk_request)
        if not response:
            raise HttpError('HTTP Error - No response entity returned.')
        return Job().from_response(response)
예제 #6
0
    def create(cls, **params):
        from intercom import Intercom

        collection = utils.resource_class_to_collection_name(cls)
        response = Intercom.post("/%s/" % (collection), **params)
        if response:  # may be empty if we received a 202
            return cls(**response)
 def by_tag(self, _id):
     """Return a CollectionProxy to all the tagged resources."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/%s?tag_id=%s" % (collection, _id)
     return CollectionProxy(self.client, self.collection_class, collection,
                            finder_url)
예제 #8
0
 def users(self, id):
     """Return a CollectionProxy to all the users for the specified Company."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/%s/%s/users" % (collection, id)
     return CollectionProxy(self.client, self.collection_class, "users",
                            finder_url)
    def __init__(self,
                 client,
                 collection_cls,
                 collection,
                 finder_url,
                 finder_params={}):

        self.client = client

        # resource name
        self.resource_name = utils.resource_class_to_collection_name(
            collection_cls)

        # resource class
        self.resource_class = collection_cls

        # needed to create class instances of the resource
        self.collection_cls = collection_cls

        # needed to reference the collection in the response
        self.collection = collection

        # the original URL to retrieve the resources
        self.finder_url = finder_url

        # the params to filter the resources
        self.finder_params = finder_params

        # an iterator over the resources found in the response
        self.resources = None

        # a link to the next page of results
        self.next_page = None
예제 #10
0
 def scroll(self, **params):
     """Find all instances of the resource based on the supplied parameters."""
     collection_name = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/{}/scroll".format(collection_name)
     return ScrollCollectionProxy(
         self.client, self.collection_class, collection_name, finder_url)
예제 #11
0
 def create(self, **params):
     """Create an instance of the resource from the supplied parameters."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     response = self.client.post("/%s/" % (collection), params)
     if response:  # may be empty if we received a 202
         return self.collection_class(**response)
예제 #12
0
 def create(self, **params):
     """Create an instance of the resource from the supplied parameters."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     response = self.client.post("/%s/" % (collection), params)
     if response:  # may be empty if we received a 202
         return self.collection_class(**response)
예제 #13
0
 def users(self, id):
     """Return a CollectionProxy to all the users for the specified Company."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/%s/%s/users" % (collection, id)
     return CollectionProxy(
         self.client, user.User, "users", finder_url)
예제 #14
0
 def find_all(cls, **params):
     collection = utils.resource_class_to_collection_name(cls)
     if 'id' in params and 'type' not in params:
         finder_url = "/%s/%s" % (collection, params['id'])
     else:
         finder_url = "/%s" % (collection)
     finder_params = params
     return CollectionProxy(cls, collection, finder_url, finder_params)
예제 #15
0
 def find_all(self, **params):
     """Find all instances of the resource based on the supplied parameters."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     if 'id' in params and 'type' not in params:
         finder_url = "/%s/%s" % (collection, params['id'])
     else:
         finder_url = "/%s" % (collection)
     finder_params = params
     return self.proxy_class(
         self.client, self.collection_class, collection,
         finder_url, finder_params)
예제 #16
0
파일: find.py 프로젝트: buremba/rakam-tasks
    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)
예제 #17
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)
예제 #18
0
 def save(self):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(self.__class__)
     params = self.attributes
     if self.id_present and not self.posted_updates:
         # update
         response = Intercom.put('/%s/%s' % (collection, self.id), **params)
     else:
         # create
         params.update(self.identity_hash)
         response = Intercom.post('/%s' % (collection), **params)
     if response:
         return self.from_response(response)
예제 #19
0
 def save(self, obj):
     collection = utils.resource_class_to_collection_name(
         obj.__class__)
     params = obj.attributes
     if self.id_present(obj) and not self.posted_updates(obj):
         # update
         response = self.client.put('/%s/%s' % (collection, obj.id), params)
     else:
         # create
         params.update(self.identity_hash(obj))
         response = self.client.post('/%s' % (collection), params)
     if response:
         return obj.from_response(response)
예제 #20
0
파일: save.py 프로젝트: buremba/rakam-tasks
 def save(self):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(self.__class__)
     params = self.attributes
     if self.id_present and not self.posted_updates:
         # update
         response = Intercom.put('/%s/%s' % (collection, self.id), **params)
     else:
         # create
         params.update(self.identity_hash)
         response = Intercom.post('/%s' % (collection), **params)
     if response:
         return self.from_response(response)
예제 #21
0
    def find(self, **params):
        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)
예제 #22
0
 def save(self, obj):
     """Save the instance of the resource."""
     collection = utils.resource_class_to_collection_name(obj.__class__)
     params = obj.attributes
     if self.id_present(obj) and not self.posted_updates(obj):
         # update
         response = self.client.put('/%s/%s' % (collection, obj.id), params)
     else:
         # create
         params.update(self.identity_hash(obj))
         response = self.client.post('/%s' % (collection), params)
     if response:
         return obj.from_response(response)
예제 #23
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)
예제 #24
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)
예제 #25
0
파일: load.py 프로젝트: buremba/rakam-tasks
    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)
예제 #26
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)
예제 #27
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)
예제 #28
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)
예제 #29
0
파일: tag.py 프로젝트: buremba/rakam-tasks
    def _tag_collection(cls, collection_name, name, objects, untag=False):
        from intercom import Intercom
        collection = utils.resource_class_to_collection_name(cls)
        object_ids = []
        for obj in objects:
            if not hasattr(obj, 'keys'):
                obj = {'id': obj}
            if untag:
                obj['untag'] = True
            object_ids.append(obj)

        params = {
            'name': name,
            collection_name: object_ids,
        }
        response = Intercom.post("/%s" % (collection), **params)
        return cls(**response)
예제 #30
0
    def _tag_collection(
            cls, collection_name, name, objects, untag=False):
        from intercom import Intercom
        collection = utils.resource_class_to_collection_name(cls)
        object_ids = []
        for obj in objects:
            if not hasattr(obj, 'keys'):
                obj = {'id': obj}
            if untag:
                obj['untag'] = True
            object_ids.append(obj)

        params = {
            'name': name,
            collection_name: object_ids,
        }
        response = Intercom.post("/%s" % (collection), **params)
        return cls(**response)
예제 #31
0
    def submit_bulk_job(self, create_items=[], delete_items=[], job_id=None):
        """Submit a Bulk API job."""
        from intercom import event
        from intercom.errors import HttpError
        from intercom.job import Job

        if self.collection_class == event.Event and delete_items:
            raise Exception("Events do not support bulk delete operations.")
        data_type = utils.resource_class_to_name(self.collection_class)
        collection_name = utils.resource_class_to_collection_name(self.collection_class)
        create_items = [item_for_api('post', data_type, item) for item in create_items]
        delete_items = [item_for_api('delete', data_type, item) for item in delete_items]

        bulk_request = {
            'items': create_items + delete_items
        }
        if job_id:
            bulk_request['job'] = {'id': job_id}

        response = self.client.post('/bulk/%s' % (collection_name), bulk_request)
        if not response:
            raise HttpError('HTTP Error - No response entity returned.')
        return Job().from_response(response)
예제 #32
0
파일: save.py 프로젝트: buremba/rakam-tasks
 def create(cls, **params):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(cls)
     response = Intercom.post("/%s/" % (collection), **params)
     if response:  # may be empty if we received a 202
         return cls(**response)
예제 #33
0
 def delete(self, obj):
     """Delete the specified instance of this resource."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     self.client.delete("/%s/%s" % (collection, obj.id), {})
     return obj
예제 #34
0
 def all(cls):
     collection = utils.resource_class_to_collection_name(cls)
     finder_url = "/%s" % (collection)
     return CollectionProxy(cls, collection, finder_url)
예제 #35
0
 def users(self, id):
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     finder_url = "/%s/%s/users" % (collection, id)
     return CollectionProxy(
         self.client, self.collection_class, "users", finder_url)
예제 #36
0
 def delete(self, obj):
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     self.client.delete("/%s/%s" % (collection, obj.id), {})
     return obj
예제 #37
0
 def create(self, **params):
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     response = self.client.post("/%s/" % (collection), params)
     if response:  # may be empty if we received a 202
         return self.collection_class(**response)
예제 #38
0
 def users(self):
     collection = utils.resource_class_to_collection_name(self.__class__)
     finder_url = "/%s/%s/users" % (collection, self.id)
     return CollectionProxy(User, "users", finder_url)
예제 #39
0
 def delete(self):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(self.__class__)
     Intercom.delete("/%s/%s/" % (collection, self.id))
     return self
예제 #40
0
 def collection(self):
     """Return the name of the collection."""
     return utils.resource_class_to_collection_name(self.collection_class)
예제 #41
0
 def users(self):
     collection = utils.resource_class_to_collection_name(self.__class__)
     finder_url = "/%s/%s/users" % (collection, self.id)
     return CollectionProxy(User, "users", finder_url)
예제 #42
0
 def delete(self):
     from intercom import Intercom
     collection = utils.resource_class_to_collection_name(self.__class__)
     Intercom.delete("/%s/%s/" % (collection, self.id))
     return self
예제 #43
0
 def collection(self):
     """Return the name of the collection."""
     return utils.resource_class_to_collection_name(self.collection_class)
 def delete(self, obj):
     """Delete the specified instance of this resource."""
     collection = utils.resource_class_to_collection_name(
         self.collection_class)
     self.client.delete("/%s/%s" % (collection, obj.id), {})
     return obj