Skip to content

Commit 5d511d2

Browse files
committed
Add property and methods to expose JSON data
Ensure the SparkData object's JSON data is stored as an `OrderedDict` (and not a `dict`) to preserve the attribute ordering from the Spark responses. Add a `json_data` property and `to_dict()` and `to_json()` methods to the SparkData base class to enable access to the data object's JSON data. Note: The json_data should return a copy of the object's data to prevent the object data from being mutated.
1 parent 43ea991 commit 5d511d2

File tree

15 files changed

+141
-108
lines changed

15 files changed

+141
-108
lines changed

ciscosparkapi/api/access_tokens.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ def __init__(self, json):
6464
@property
6565
def access_token(self):
6666
"""Cisco Spark access token."""
67-
return self._json.get('access_token')
67+
return self._json_data.get('access_token')
6868

6969
@property
7070
def expires_in(self):
7171
"""Access token expiry time (in seconds)."""
72-
return self._json.get('expires_in')
72+
return self._json_data.get('expires_in')
7373

7474
@property
7575
def refresh_token(self):
7676
"""Refresh token used to request a new/refreshed access token."""
77-
return self._json.get('refresh_token')
77+
return self._json_data.get('refresh_token')
7878

7979
@property
8080
def refresh_token_expires_in(self):
8181
"""Refresh token expiry time (in seconds)."""
82-
return self._json.get('refresh_token_expires_in')
82+
return self._json_data.get('refresh_token_expires_in')
8383

8484

8585
class AccessTokensAPI(object):

ciscosparkapi/api/licenses.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ def __init__(self, json):
5252
@property
5353
def id(self):
5454
"""The unique ID for the License."""
55-
return self._json.get('id')
55+
return self._json_data.get('id')
5656

5757
@property
5858
def name(self):
5959
"""The name of the License."""
60-
return self._json.get('name')
60+
return self._json_data.get('name')
6161

6262
@property
6363
def totalUnits(self):
6464
"""The total number of license units."""
65-
return self._json.get('totalUnits')
65+
return self._json_data.get('totalUnits')
6666

6767
@property
6868
def consumedUnits(self):
6969
"""The total number of license units consumed."""
70-
return self._json.get('consumedUnits')
70+
return self._json_data.get('consumedUnits')
7171

7272

7373
class LicensesAPI(object):

ciscosparkapi/api/memberships.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,47 +53,47 @@ def __init__(self, json):
5353
@property
5454
def id(self):
5555
"""The membership's unique ID."""
56-
return self._json.get('id')
56+
return self._json_data.get('id')
5757

5858
@property
5959
def roomId(self):
6060
"""The ID of the room."""
61-
return self._json.get('roomId')
61+
return self._json_data.get('roomId')
6262

6363
@property
6464
def personId(self):
6565
"""The ID of the person."""
66-
return self._json.get('personId')
66+
return self._json_data.get('personId')
6767

6868
@property
6969
def personEmail(self):
7070
"""The email address of the person."""
71-
return self._json.get('personEmail')
71+
return self._json_data.get('personEmail')
7272

7373
@property
7474
def personDisplayName(self):
7575
"""The display name of the person."""
76-
return self._json.get('personDisplayName')
76+
return self._json_data.get('personDisplayName')
7777

7878
@property
7979
def personOrgId(self):
8080
"""The ID of the organization that the person is associated with."""
81-
return self._json.get('personOrgId')
81+
return self._json_data.get('personOrgId')
8282

8383
@property
8484
def isModerator(self):
8585
"""Person is a moderator for the room."""
86-
return self._json.get('isModerator')
86+
return self._json_data.get('isModerator')
8787

8888
@property
8989
def isMonitor(self):
9090
"""Person is a monitor for the room."""
91-
return self._json.get('isMonitor')
91+
return self._json_data.get('isMonitor')
9292

9393
@property
9494
def created(self):
9595
"""The date and time the membership was created."""
96-
return self._json.get('created')
96+
return self._json_data.get('created')
9797

9898

9999
class MembershipsAPI(object):

ciscosparkapi/api/messages.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,57 +57,57 @@ def __init__(self, json):
5757
@property
5858
def id(self):
5959
"""The message's unique ID."""
60-
return self._json.get('id')
60+
return self._json_data.get('id')
6161

6262
@property
6363
def roomId(self):
6464
"""The ID of the room."""
65-
return self._json.get('roomId')
65+
return self._json_data.get('roomId')
6666

6767
@property
6868
def roomType(self):
6969
"""The type of room (i.e. 'group', 'direct' etc.)."""
70-
return self._json.get('roomType')
70+
return self._json_data.get('roomType')
7171

7272
@property
7373
def text(self):
7474
"""The message, in plain text."""
75-
return self._json.get('text')
75+
return self._json_data.get('text')
7676

7777
@property
7878
def files(self):
7979
"""Files attached to the the message (list of URLs)."""
80-
return self._json.get('files')
80+
return self._json_data.get('files')
8181

8282
@property
8383
def personId(self):
8484
"""The person ID of the sender."""
85-
return self._json.get('personId')
85+
return self._json_data.get('personId')
8686

8787
@property
8888
def personEmail(self):
8989
"""The email address of the sender."""
90-
return self._json.get('personEmail')
90+
return self._json_data.get('personEmail')
9191

9292
@property
9393
def markdown(self):
9494
"""The message, in markdown format."""
95-
return self._json.get('markdown')
95+
return self._json_data.get('markdown')
9696

9797
@property
9898
def html(self):
9999
"""The message, in HTML format."""
100-
return self._json.get('html')
100+
return self._json_data.get('html')
101101

102102
@property
103103
def mentionedPeople(self):
104104
"""The list of IDs of people mentioned in the message."""
105-
return self._json.get('mentionedPeople')
105+
return self._json_data.get('mentionedPeople')
106106

107107
@property
108108
def created(self):
109109
"""The date and time the message was created."""
110-
return self._json.get('created')
110+
return self._json_data.get('created')
111111

112112

113113
class MessagesAPI(object):

ciscosparkapi/api/organizations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ def __init__(self, json):
5353
@property
5454
def id(self):
5555
"""The unique ID for the Organization."""
56-
return self._json.get('id')
56+
return self._json_data.get('id')
5757

5858
@property
5959
def displayName(self):
6060
"""The human-friendly display name of the Organization."""
61-
return self._json.get('displayName')
61+
return self._json_data.get('displayName')
6262

6363
@property
6464
def created(self):
6565
"""Creation date and time in ISO8601 format."""
66-
return self._json.get('created')
66+
return self._json_data.get('created')
6767

6868

6969
class OrganizationsAPI(object):

ciscosparkapi/api/people.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,82 +52,82 @@ def __init__(self, json):
5252
@property
5353
def type(self):
5454
"""The type of object returned by Cisco Spark (should be `person`)."""
55-
return self._json.get('type')
55+
return self._json_data.get('type')
5656

5757
@property
5858
def id(self):
5959
"""The person's unique ID."""
60-
return self._json.get('id')
60+
return self._json_data.get('id')
6161

6262
@property
6363
def emails(self):
6464
"""Email address(es) of the person."""
65-
return self._json['emails']
65+
return self._json_data['emails']
6666

6767
@property
6868
def displayName(self):
6969
"""Full name of the person."""
70-
return self._json.get('displayName')
70+
return self._json_data.get('displayName')
7171

7272
@property
7373
def nickName(self):
7474
"""'Nick name' or preferred short name of the person."""
75-
return self._json.get('nickName')
75+
return self._json_data.get('nickName')
7676

7777
@property
7878
def firstName(self):
7979
"""First name of the person."""
80-
return self._json.get('firstName')
80+
return self._json_data.get('firstName')
8181

8282
@property
8383
def lastName(self):
8484
"""Last name of the person."""
85-
return self._json.get('lastName')
85+
return self._json_data.get('lastName')
8686

8787
@property
8888
def avatar(self):
8989
"""URL to the person's avatar in PNG format."""
90-
return self._json.get('avatar')
90+
return self._json_data.get('avatar')
9191

9292
@property
9393
def orgId(self):
9494
"""ID of the organization to which this person belongs."""
95-
return self._json.get('orgId')
95+
return self._json_data.get('orgId')
9696

9797
@property
9898
def roles(self):
9999
"""Roles of the person."""
100-
return self._json.get('roles')
100+
return self._json_data.get('roles')
101101

102102
@property
103103
def licenses(self):
104104
"""Licenses allocated to the person."""
105-
return self._json.get('licenses')
105+
return self._json_data.get('licenses')
106106

107107
@property
108108
def created(self):
109109
"""The date and time the person was created."""
110-
return self._json.get('created')
110+
return self._json_data.get('created')
111111

112112
@property
113113
def status(self):
114114
"""The person's current status."""
115-
return self._json.get('status')
115+
return self._json_data.get('status')
116116

117117
@property
118118
def lastActivity(self):
119119
"""The date and time of the person's last activity."""
120-
return self._json.get('lastActivity')
120+
return self._json_data.get('lastActivity')
121121

122122
@property
123123
def invitePending(self):
124124
"""Person has been sent an invite, but hasn't responded."""
125-
return self._json.get('invitePending')
125+
return self._json_data.get('invitePending')
126126

127127
@property
128128
def loginEnabled(self):
129129
"""Person is allowed to login."""
130-
return self._json.get('loginEnabled')
130+
return self._json_data.get('loginEnabled')
131131

132132

133133
class PeopleAPI(object):

ciscosparkapi/api/roles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ def __init__(self, json):
5252
@property
5353
def id(self):
5454
"""The unique ID for the Role."""
55-
return self._json.get('id')
55+
return self._json_data.get('id')
5656

5757
@property
5858
def name(self):
5959
"""The name of the Role."""
60-
return self._json.get('name')
60+
return self._json_data.get('name')
6161

6262

6363
class RolesAPI(object):

ciscosparkapi/api/rooms.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,42 +52,42 @@ def __init__(self, json):
5252
@property
5353
def id(self):
5454
"""The rooms's unique ID."""
55-
return self._json.get('id')
55+
return self._json_data.get('id')
5656

5757
@property
5858
def title(self):
5959
"""A user-friendly name for the room."""
60-
return self._json.get('title')
60+
return self._json_data.get('title')
6161

6262
@property
6363
def type(self):
6464
"""The type of room (i.e. 'group', 'direct' etc.)."""
65-
return self._json.get('type')
65+
return self._json_data.get('type')
6666

6767
@property
6868
def isLocked(self):
6969
"""Whether or not the room is locked and controled by moderator(s)."""
70-
return self._json.get('isLocked')
70+
return self._json_data.get('isLocked')
7171

7272
@property
7373
def lastActivity(self):
7474
"""The date and time when the room was last active."""
75-
return self._json.get('lastActivity')
75+
return self._json_data.get('lastActivity')
7676

7777
@property
7878
def created(self):
7979
"""The date and time when the room was created."""
80-
return self._json.get('created')
80+
return self._json_data.get('created')
8181

8282
@property
8383
def creatorId(self):
8484
"""The ID of the person who created the room."""
85-
return self._json.get('creatorId')
85+
return self._json_data.get('creatorId')
8686

8787
@property
8888
def teamId(self):
8989
"""The ID for the team with which this room is associated."""
90-
return self._json.get('teamId')
90+
return self._json_data.get('teamId')
9191

9292

9393
class RoomsAPI(object):

0 commit comments

Comments
 (0)