From ef4c89f4857b12a7edaea305c94be9494d3f2373 Mon Sep 17 00:00:00 2001 From: Shahar Evron Date: Sat, 24 Dec 2016 08:41:02 +0200 Subject: [PATCH] Adding FindAll capability to event resources - Added the ability to override the default CollectionProxy class in the FindAll mixin - Created a dedicated Proxy class for Events which handles paging differently, based on the current Event API --- intercom/api_operations/find_all.py | 4 +++- intercom/service/event.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/intercom/api_operations/find_all.py b/intercom/api_operations/find_all.py index cd8b251e..8538f57a 100644 --- a/intercom/api_operations/find_all.py +++ b/intercom/api_operations/find_all.py @@ -8,6 +8,8 @@ class FindAll(object): """A mixin that provides `find_all` functionality.""" + proxy_class = CollectionProxy + def find_all(self, **params): """Find all instances of the resource based on the supplied parameters.""" collection = utils.resource_class_to_collection_name( @@ -17,6 +19,6 @@ def find_all(self, **params): else: finder_url = "/%s" % (collection) finder_params = params - return CollectionProxy( + return self.proxy_class( self.client, self.collection_class, collection, finder_url, finder_params) diff --git a/intercom/service/event.py b/intercom/service/event.py index 2243e6fe..2ae1492c 100644 --- a/intercom/service/event.py +++ b/intercom/service/event.py @@ -3,10 +3,20 @@ from intercom import event from intercom.api_operations.bulk import Submit from intercom.api_operations.save import Save +from intercom.api_operations.find_all import FindAll from intercom.service.base_service import BaseService +from intercom.collection_proxy import CollectionProxy -class Event(BaseService, Save, Submit): +class EventCollectionProxy(CollectionProxy): + + def paging_info_present(self, response): + return 'pages' in response and 'next' in response['pages'] + + +class Event(BaseService, Save, Submit, FindAll): + + proxy_class = EventCollectionProxy @property def collection_class(self):