Skip to content

Fix Bug #7 and #8 #10

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

Merged
merged 3 commits into from
Sep 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ciscosparkapi/api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
if markdown:
post_data[u'markdown'] = utf8(markdown)
if files:
post_data[u'files'] = utf8(files)
files = map(utf8, files)
post_data[u'files'] = files
# API request
json_obj = self.session.post('messages', json=post_data)
# Return a Message object created from the response JSON data
Expand Down
39 changes: 39 additions & 0 deletions ciscosparkapi/restsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@
raise_if_extra_kwargs, check_response_code, extract_and_parse_json


def _fix_next_url(next_url):
"""Remove max=null parameter from URL.

Patch for Cisco Spark Defect: 'next' URL returned in the Link headers of
the responses contain an errant 'max=null' parameter, which causes the
next request (to this URL) to fail if the URL is requested as-is.

This patch parses the next_url to remove the max=null parameter.

Args:
next_url(unicode, str): The 'next' URL to be parsed and cleaned.

Returns:
str: The clean URL to be used for the 'next' request.

Raises:
AssertionError: If the parameter types are incorrect.
ciscosparkapiException: If 'next_url' does not contain a valid API
endpoint URL (scheme, netloc and path).

"""
assert isinstance(next_url, basestring)
parsed_url = urlparse.urlparse(next_url)
if not parsed_url.scheme or not parsed_url.netloc or not parsed_url.path:
error_message = "'next_url' must be a valid API endpoint URL, " \
"minimally containing a scheme, netloc and path."
raise ciscosparkapiException(error_message)
if parsed_url.query:
query_list = parsed_url.query.split('&')
if 'max=null' in query_list:
query_list.remove('max=null')
new_query = '&'.join(query_list)
parsed_url = list(parsed_url)
parsed_url[4] = new_query
return urlparse.urlunparse(parsed_url)


class RestSession(object):
def __init__(self, access_token, base_url, timeout=None):
super(RestSession, self).__init__()
Expand Down Expand Up @@ -83,6 +120,8 @@ def get_pages(self, url, params=None, **kwargs):
# Get next page
if response.links.get('next'):
next_url = response.links.get('next').get('url')
# Patch for Cisco Spark 'max=null' in next URL bug.
next_url = _fix_next_url(next_url)
# API request - get next page
response = self._req_session.get(next_url, timeout=timeout)
else:
Expand Down