Skip to content

Commit 733269b

Browse files
committed
Move data models to ciscosparkapi.models
Separate the data models from the API modules by moving them into their own modules and package.
1 parent abd095f commit 733269b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1154
-1013
lines changed

ciscosparkapi/__init__.py

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,59 @@
22
"""Python API wrapper for the Cisco Spark APIs."""
33

44

5-
# Use future for Python v2 and v3 compatibility
65
from __future__ import (
76
absolute_import,
87
division,
98
print_function,
109
unicode_literals,
1110
)
12-
from builtins import *
13-
from past.builtins import basestring
14-
15-
16-
__author__ = "Chris Lunsford"
17-
__author_email__ = "[email protected]"
18-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
19-
__license__ = "MIT"
20-
__all__ = [
21-
"CiscoSparkAPI", "ciscosparkapiException", "SparkApiError",
22-
"SparkRateLimitError", "Person", "Room", "Membership", "Message", "Team",
23-
"TeamMembership", "Webhook", "WebhookEvent", "Organization", "License",
24-
"Role", "AccessToken"
25-
]
26-
2711

12+
from builtins import *
2813
import logging
2914
import os
3015

31-
from .api.people import Person
32-
from .api.rooms import Room
33-
from .api.memberships import Membership
34-
from .api.messages import Message
35-
from .api.teams import Team
36-
from .api.team_memberships import TeamMembership
37-
from .api.webhooks import Webhook, WebhookEvent
38-
from .api.organizations import Organization
39-
from .api.licenses import License
40-
from .api.roles import Role
41-
from .api.access_tokens import AccessToken
16+
from past.builtins import basestring
4217

43-
from .api.people import PeopleAPI as _PeopleAPI
44-
from .api.rooms import RoomsAPI as _RoomsAPI
18+
from .api.access_tokens import AccessTokensAPI as _AccessTokensAPI
19+
from .api.licenses import LicensesAPI as _LicensesAPI
4520
from .api.memberships import MembershipsAPI as _MembershipsAPI
4621
from .api.messages import MessagesAPI as _MessagesAPI
47-
from .api.teams import TeamsAPI as _TeamsAPI
48-
from .api.team_memberships import TeamMembershipsAPI as _TeamMembershipsAPI
49-
from .api.webhooks import WebhooksAPI as _WebhooksAPI
5022
from .api.organizations import OrganizationsAPI as _OrganizationsAPI
51-
from .api.licenses import LicensesAPI as _LicensesAPI
23+
from .api.people import PeopleAPI as _PeopleAPI
5224
from .api.roles import RolesAPI as _RolesAPI
53-
from .api.access_tokens import AccessTokensAPI as _AccessTokensAPI
54-
25+
from .api.rooms import RoomsAPI as _RoomsAPI
26+
from .api.team_memberships import TeamMembershipsAPI as _TeamMembershipsAPI
27+
from .api.teams import TeamsAPI as _TeamsAPI
28+
from .api.webhooks import WebhooksAPI as _WebhooksAPI
5529
from .exceptions import (
56-
ciscosparkapiException,
57-
SparkApiError,
58-
SparkRateLimitError,
30+
SparkApiError, SparkRateLimitError, ciscosparkapiException,
5931
)
60-
32+
from .models.access_token import AccessToken
33+
from .models.license import License
34+
from .models.membership import Membership
35+
from .models.message import Message
36+
from .models.organization import Organization
37+
from .models.person import Person
38+
from .models.role import Role
39+
from .models.room import Room
40+
from .models.team import Team
41+
from .models.team_membership import TeamMembership
42+
from .models.webhook import Webhook
43+
from .models.webhook_event import WebhookEvent
6144
from .restsession import (
6245
DEFAULT_SINGLE_REQUEST_TIMEOUT,
6346
DEFAULT_WAIT_ON_RATE_LIMIT,
6447
RestSession as _RestSession,
6548
)
66-
6749
from .utils import check_type
6850

6951

52+
__author__ = "Chris Lunsford"
53+
__author_email__ = "[email protected]"
54+
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
55+
__license__ = "MIT"
56+
57+
7058
# Versioneer version control
7159
from ._version import get_versions
7260
__version__ = get_versions()['version']

ciscosparkapi/api/access_tokens.py

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,23 @@
11
# -*- coding: utf-8 -*-
2-
"""Cisco Spark Access-Tokens API wrapper.
2+
"""Cisco Spark Access-Tokens API."""
33

4-
Classes:
5-
AccessToken: Models a Spark 'access token' JSON object as a native Python
6-
object.
7-
AccessTokensAPI: Wraps the Cisco Spark Access-Tokens API and exposes the
8-
API as native Python methods that return native Python objects.
94

10-
"""
11-
12-
13-
# Use future for Python v2 and v3 compatibility
145
from __future__ import (
156
absolute_import,
167
division,
178
print_function,
189
unicode_literals,
1910
)
20-
from builtins import *
21-
from past.builtins import basestring
22-
from future import standard_library
23-
standard_library.install_aliases()
24-
25-
26-
__author__ = "Chris Lunsford"
27-
__author_email__ = "[email protected]"
28-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
29-
__license__ = "MIT"
30-
3111

12+
from builtins import *
3213
import urllib.parse
3314

15+
from future import standard_library
16+
from past.builtins import basestring
3417
import requests
3518

19+
from ..models.access_token import AccessToken
3620
from ..response_codes import EXPECTED_RESPONSE_CODE
37-
from ..sparkdata import SparkData
3821
from ..utils import (
3922
check_response_code,
4023
check_type,
@@ -44,47 +27,20 @@
4427
)
4528

4629

47-
API_ENDPOINT = "access_token"
48-
49-
50-
class AccessToken(SparkData):
51-
"""Model a Spark 'access token' JSON object as a native Python object."""
52-
53-
def __init__(self, json):
54-
"""Init a new AccessToken data object from a dictionary or JSON string.
55-
56-
Args:
57-
json(dict, basestring): Input dictionary or JSON string.
58-
59-
Raises:
60-
TypeError: If the input object is not a dictionary or string.
61-
62-
"""
63-
super(AccessToken, self).__init__(json)
30+
__author__ = "Chris Lunsford"
31+
__author_email__ = "[email protected]"
32+
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
33+
__license__ = "MIT"
6434

65-
@property
66-
def access_token(self):
67-
"""Cisco Spark access token."""
68-
return self._json_data.get('access_token')
6935

70-
@property
71-
def expires_in(self):
72-
"""Access token expiry time (in seconds)."""
73-
return self._json_data.get('expires_in')
36+
standard_library.install_aliases()
7437

75-
@property
76-
def refresh_token(self):
77-
"""Refresh token used to request a new/refreshed access token."""
78-
return self._json_data.get('refresh_token')
7938

80-
@property
81-
def refresh_token_expires_in(self):
82-
"""Refresh token expiry time (in seconds)."""
83-
return self._json_data.get('refresh_token_expires_in')
39+
API_ENDPOINT = "access_token"
8440

8541

8642
class AccessTokensAPI(object):
87-
"""Cisco Spark Access-Tokens API wrapper.
43+
"""Cisco Spark Access-Tokens API.
8844
8945
Wraps the Cisco Spark Access-Tokens API and exposes the API as native
9046
Python methods that return native Python objects.
@@ -138,7 +94,7 @@ def get(self, client_id, client_secret, code, redirect_uri):
13894
process.
13995
14096
Returns:
141-
AccessToken: An AccessToken object with the access token provided
97+
ciscosparkapi.AccessToken: An AccessToken object with the access token provided
14298
by the Cisco Spark cloud.
14399
144100
Raises:

ciscosparkapi/api/licenses.py

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,35 @@
11
# -*- coding: utf-8 -*-
2-
"""Cisco Spark Licenses API wrapper.
2+
"""Cisco Spark Licenses API."""
33

4-
Classes:
5-
License: Models a Spark License JSON object as a native Python object.
6-
LicensesAPI: Wraps the Cisco Spark Licenses API and exposes the API as
7-
native Python methods that return native Python objects.
84

9-
"""
10-
11-
12-
# Use future for Python v2 and v3 compatibility
135
from __future__ import (
146
absolute_import,
157
division,
168
print_function,
179
unicode_literals,
1810
)
19-
from builtins import *
20-
from past.builtins import basestring
2111

12+
from builtins import *
2213

23-
__author__ = "Chris Lunsford"
24-
__author_email__ = "[email protected]"
25-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
26-
__license__ = "MIT"
27-
14+
from past.builtins import basestring
2815

2916
from ..generator_containers import generator_container
17+
from ..models.license import License
3018
from ..restsession import RestSession
31-
from ..sparkdata import SparkData
3219
from ..utils import (
3320
check_type,
3421
dict_from_items_with_values,
3522
)
3623

3724

38-
class License(SparkData):
39-
"""Model a Spark License JSON object as a native Python object."""
40-
41-
def __init__(self, json):
42-
"""Initialize a License data object from a dictionary or JSON string.
43-
44-
Args:
45-
json(dict, basestring): Input dictionary or JSON string.
46-
47-
Raises:
48-
TypeError: If the input object is not a dictionary or string.
49-
50-
"""
51-
super(License, self).__init__(json)
52-
53-
@property
54-
def id(self):
55-
"""The unique ID for the License."""
56-
return self._json_data.get('id')
57-
58-
@property
59-
def name(self):
60-
"""The name of the License."""
61-
return self._json_data.get('name')
62-
63-
@property
64-
def totalUnits(self):
65-
"""The total number of license units."""
66-
return self._json_data.get('totalUnits')
67-
68-
@property
69-
def consumedUnits(self):
70-
"""The total number of license units consumed."""
71-
return self._json_data.get('consumedUnits')
25+
__author__ = "Chris Lunsford"
26+
__author_email__ = "[email protected]"
27+
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
28+
__license__ = "MIT"
7229

7330

7431
class LicensesAPI(object):
75-
"""Cisco Spark Licenses API wrapper.
32+
"""Cisco Spark Licenses API.
7633
7734
Wraps the Cisco Spark Licenses API and exposes the API as native Python
7835
methods that return native Python objects.

0 commit comments

Comments
 (0)