Skip to content

Parse path from full url in extract_next_link #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion intercom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MultipleMatchingUsersError, RateLimitExceeded, ResourceNotFound,
ServerError, ServiceUnavailableError, UnexpectedError)

__version__ = '3.0b2'
__version__ = '3.0b2.2'


RELATED_DOCS_TEXT = "See https://github.com/jkeyes/python-intercom \
Expand Down
4 changes: 4 additions & 0 deletions intercom/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
import logging

logger = logging.getLogger('intercom.request')


class Client(object):
Expand Down Expand Up @@ -85,6 +88,7 @@ def _execute_request(self, request, params):

def get(self, path, params):
from intercom import request
logger.info("CLIENT: GETTING PATH %s AND PARAMS %s" % (path, params))
req = request.Request('GET', path)
return self._execute_request(req, params)

Expand Down
14 changes: 12 additions & 2 deletions intercom/collection_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from intercom import HttpError
from intercom import utils

import logging

logger = logging.getLogger('intercom.request')


class CollectionProxy(six.Iterator):

Expand Down Expand Up @@ -92,10 +96,16 @@ def get_page(self, url, params={}):
# grab the next page URL if one exists
self.next_page = self.extract_next_link(response)

logger.info("COLLECTION_PROXY: NEXT PAGE = %s" % self.next_page)

def paging_info_present(self, response):
return 'pages' in response and 'type' in response['pages']

def extract_next_link(self, response):
from urlparse import urlparse
if self.paging_info_present(response):
paging_info = response["pages"]
return paging_info["next"]
paging_info = response['pages']
if 'next' in paging_info and paging_info['next'] != None:
url = urlparse(paging_info['next'])
return "%s?%s" % (url.path, url.query)

4 changes: 4 additions & 0 deletions intercom/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class Request(object):
def __init__(self, http_method, path):
self.http_method = http_method
self.path = path
logger.debug("REQUEST: INIT WITH METHOD %s AND PATH %s" % (http_method, path))

def execute(self, base_url, auth, params):
logger.debug("REQUEST: EXECUTE WITH BASE_URL %s AUTH %s PARAMS %s" % (base_url, auth, params))
return self.send_request_to_path(base_url, auth, params)

def send_request_to_path(self, base_url, auth, params=None):
Expand Down Expand Up @@ -52,6 +54,8 @@ def send_request_to_path(self, base_url, auth, params=None):
else:
logger.debug(" params: %s", req_params['data'])

logger.info("REQUEST: ACTUALLY MAKING REQUEST WITH URL %s, AUTH %s, AND PARAMS %s" % (url, auth, req_params))

resp = requests.request(
self.http_method, url, timeout=self.timeout,
auth=auth, verify=certifi.where(), **req_params)
Expand Down