Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f5eb7f8
Include orgId parameter for people list method
jbogarin Sep 18, 2017
92445c1
Include the id param to the people list method.
jbogarin Sep 21, 2017
6547533
Update people list method to include **query_params
jbogarin Sep 21, 2017
fac6308
Change how the id parameter is being handled and include the related …
jbogarin Sep 21, 2017
3b66234
Add new attributes to `Person` class & Update some DocStrings
cmlccie Sep 21, 2017
1630ce1
Update docstrings
cmlccie Oct 5, 2017
eaafb62
Update the PeopleAPI
cmlccie Oct 5, 2017
0e753ed
Correct comment typo
cmlccie Oct 5, 2017
3fe19f6
Merge branch 'master' into issue-44
cmlccie Oct 13, 2017
b5e7776
Update Room data model and module docstrings
cmlccie Oct 13, 2017
13c27b4
Refactor future-proofing request_parameters
cmlccie Oct 13, 2017
3a479e5
Update docstrings
cmlccie Oct 13, 2017
6b26d1b
Refactor RoomsAPI
cmlccie Oct 13, 2017
a3e28e3
Patch bug in new dict_from_items_with_values
cmlccie Oct 22, 2017
f89b6f4
Refactor Memberships
cmlccie Oct 22, 2017
d90c6f9
Consistency Update - rooms.py
cmlccie Oct 22, 2017
6a748e4
Consistency Update - people.py
cmlccie Oct 22, 2017
2544be0
Refactor Messages
cmlccie Oct 29, 2017
d294c0d
Correct Indentation and Docstring Typo
cmlccie Oct 29, 2017
fd70b4a
Refactor Teams
cmlccie Oct 29, 2017
b841f30
Update indentation and docstrings
cmlccie Oct 29, 2017
ab85067
Refactor TeamMemberships
cmlccie Oct 29, 2017
f300825
Add WebhookEvent class and Refator Webhooks
cmlccie Oct 29, 2017
bff6a86
Refactor Organizations
cmlccie Oct 29, 2017
b4cf840
Refactor Licenses
cmlccie Oct 29, 2017
968eb9a
Refactor Roles
cmlccie Oct 29, 2017
717aef0
Refactor Access Tokens
cmlccie Oct 29, 2017
3f8a9e0
Update Docstrings
cmlccie Oct 29, 2017
60a5dcc
Update Response Codes
cmlccie Oct 29, 2017
e3f0113
Update Docs
cmlccie Oct 29, 2017
d91b27e
Update mentionedPeople test to use type string
cmlccie Oct 29, 2017
6fa7215
PEP8
cmlccie Oct 29, 2017
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = E402,F401,F403
ignore = E402,F401,F403,F405,W503
exclude =
.git,
__pycache__,
Expand Down
2 changes: 1 addition & 1 deletion ciscosparkapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
TeamMembership,
TeamMembershipsAPI
)
from ciscosparkapi.api.webhooks import Webhook, WebhooksAPI
from ciscosparkapi.api.webhooks import Webhook, WebhookEvent, WebhooksAPI
from ciscosparkapi.api.organizations import Organization, OrganizationsAPI
from ciscosparkapi.api.licenses import License, LicensesAPI
from ciscosparkapi.api.roles import Role, RolesAPI
Expand Down
109 changes: 58 additions & 51 deletions ciscosparkapi/api/accesstokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Classes:
AccessToken: Models a Spark 'access token' JSON object as a native Python
object.
AccessTokensAPI: Wrappers the Cisco Spark AccessTokens-API and exposes the
API calls as Python method calls that return native Python objects.
AccessTokensAPI: Wraps the Cisco Spark Access-Tokens-API and exposes the
APIs as native Python methods that return native Python objects.

"""

Expand All @@ -26,13 +26,15 @@

import requests

from ciscosparkapi.responsecodes import EXPECTED_RESPONSE_CODE
from ciscosparkapi.sparkdata import SparkData
from ciscosparkapi.utils import (
validate_base_url,
check_response_code,
check_type,
dict_from_items_with_values,
extract_and_parse_json,
validate_base_url,
)
from ciscosparkapi.responsecodes import EXPECTED_RESPONSE_CODE


__author__ = "Chris Lunsford"
Expand All @@ -48,10 +50,10 @@ class AccessToken(SparkData):
"""Model a Spark 'access token' JSON object as a native Python object."""

def __init__(self, json):
"""Init a new AccessToken data object from a JSON dictionary or string.
"""Init a new AccessToken data object from a dictionary or JSON string.

Args:
json(dict, basestring): Input JSON object.
json(dict, basestring): Input dictionary or JSON string.

Raises:
TypeError: If the input object is not a dictionary or string.
Expand All @@ -61,59 +63,62 @@ def __init__(self, json):

@property
def access_token(self):
"""Cisco Spark access_token."""
"""Cisco Spark access token."""
return self._json.get('access_token')

@property
def expires_in(self):
"""Access token expires_in number of seconds."""
"""Access token expiry time (in seconds)."""
return self._json.get('expires_in')

@property
def refresh_token(self):
"""refresh_token used to request a new/refreshed access_token."""
"""Refresh token used to request a new/refreshed access token."""
return self._json.get('refresh_token')

@property
def refresh_token_expires_in(self):
"""refresh_token_expires_in number of seconds."""
"""Refresh token expiry time (in seconds)."""
return self._json.get('refresh_token_expires_in')


class AccessTokensAPI(object):
"""Cisco Spark Access-Tokens-API wrapper class.

Wrappers the Cisco Spark Access-Tokens-API and exposes the API calls as
Python method calls that return native Python objects.
Wraps the Cisco Spark Access-Tokens-API and exposes the APIs as native
Python methods that return native Python objects.

"""

def __init__(self, base_url, timeout=None):
"""Init a new AccessTokensAPI object with the provided RestSession.
"""Initialize an AccessTokensAPI object with the provided RestSession.

Args:
base_url(basestring): The base URL the API endpoints.
timeout(int): Timeout in seconds for the API requests.

Raises:
AssertionError: If the parameter types are incorrect.
TypeError: If the parameter types are incorrect.

"""
assert isinstance(base_url, basestring)
assert timeout is None or isinstance(timeout, int)
check_type(base_url, basestring, may_be_none=False)
check_type(timeout, int)

super(AccessTokensAPI, self).__init__()

self._base_url = str(validate_base_url(base_url))
self._timeout = timeout
self._endpoint_url = urllib.parse.urljoin(self.base_url, API_ENDPOINT)
self._request_kwargs = {}
self._request_kwargs["timeout"] = timeout
self._request_kwargs = {"timeout": timeout}

@property
def base_url(self):
"""The base URL the API endpoints."""
return self._base_url

@property
def timeout(self):
"""Timeout in seconds for the API requests."""
return self._timeout

def get(self, client_id, client_secret, code, redirect_uri):
Expand All @@ -123,8 +128,7 @@ def get(self, client_id, client_secret, code, redirect_uri):
invoke the APIs.

Args:
client_id(basestring): Provided when you created your
integration.
client_id(basestring): Provided when you created your integration.
client_secret(basestring): Provided when you created your
integration.
code(basestring): The Authorization Code provided by the user
Expand All @@ -133,40 +137,41 @@ def get(self, client_id, client_secret, code, redirect_uri):
process.

Returns:
AccessToken: With the access token provided by the Cisco Spark
cloud.
AccessToken: An AccessToken object with the access token provided
by the Cisco Spark cloud.

Raises:
AssertionError: If the parameter types are incorrect.
TypeError: If the parameter types are incorrect.
SparkApiError: If the Cisco Spark cloud returns an error.

"""
# Process args
assert isinstance(client_id, basestring)
assert isinstance(client_secret, basestring)
assert isinstance(code, basestring)
assert isinstance(redirect_uri, basestring)
# Build request parameters
data = {}
data["grant_type"] = "authorization_code"
data["client_id"] = client_id
data["client_secret"] = client_secret
data["code"] = code
data["redirect_uri"] = redirect_uri
check_type(client_id, basestring, may_be_none=False)
check_type(client_secret, basestring, may_be_none=False)
check_type(code, basestring, may_be_none=False)
check_type(redirect_uri, basestring, may_be_none=False)

post_data = dict_from_items_with_values(
grant_type="authorization_code",
client_id=client_id,
client_secret=client_secret,
code=code,
redirect_uri=redirect_uri,
)

# API request
response = requests.post(self._endpoint_url, data=data,
response = requests.post(self._endpoint_url, data=post_data,
**self._request_kwargs)
check_response_code(response, EXPECTED_RESPONSE_CODE['POST'])
json_data = extract_and_parse_json(response)

# Return a AccessToken object created from the response JSON data
return AccessToken(json_data)

def refresh(self, client_id, client_secret, refresh_token):
"""Return a refreshed Access Token via the provided refresh_token.
"""Return a refreshed Access Token from the provided refresh_token.

Args:
client_id(basestring): Provided when you created your
integration.
client_id(basestring): Provided when you created your integration.
client_secret(basestring): Provided when you created your
integration.
refresh_token(basestring): Provided when you requested the Access
Expand All @@ -177,24 +182,26 @@ def refresh(self, client_id, client_secret, refresh_token):
cloud.

Raises:
AssertionError: If the parameter types are incorrect.
TypeError: If the parameter types are incorrect.
SparkApiError: If the Cisco Spark cloud returns an error.

"""
# Process args
assert isinstance(client_id, basestring)
assert isinstance(client_secret, basestring)
assert isinstance(refresh_token, basestring)
# Build request parameters
data = {}
data["grant_type"] = "refresh_token"
data["client_id"] = client_id
data["client_secret"] = client_secret
data["refresh_token"] = refresh_token
check_type(client_id, basestring, may_be_none=False)
check_type(client_secret, basestring, may_be_none=False)
check_type(refresh_token, basestring, may_be_none=False)

post_data = dict_from_items_with_values(
grant_type="refresh_token",
client_id=client_id,
client_secret=client_secret,
refresh_token=refresh_token,
)

# API request
response = requests.post(self._endpoint_url, data=data,
response = requests.post(self._endpoint_url, data=post_data,
**self._request_kwargs)
check_response_code(response, EXPECTED_RESPONSE_CODE['POST'])
json_data = extract_and_parse_json(response)

# Return a AccessToken object created from the response JSON data
return AccessToken(json_data)
Loading