Skip to content

Commit

Permalink
Add property and methods to expose JSON data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmlccie committed Nov 5, 2017
1 parent 43ea991 commit 5d511d2
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 108 deletions.
8 changes: 4 additions & 4 deletions ciscosparkapi/api/access_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ def __init__(self, json):
@property
def access_token(self):
"""Cisco Spark access token."""
return self._json.get('access_token')
return self._json_data.get('access_token')

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

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

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


class AccessTokensAPI(object):
Expand Down
8 changes: 4 additions & 4 deletions ciscosparkapi/api/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ def __init__(self, json):
@property
def id(self):
"""The unique ID for the License."""
return self._json.get('id')
return self._json_data.get('id')

@property
def name(self):
"""The name of the License."""
return self._json.get('name')
return self._json_data.get('name')

@property
def totalUnits(self):
"""The total number of license units."""
return self._json.get('totalUnits')
return self._json_data.get('totalUnits')

@property
def consumedUnits(self):
"""The total number of license units consumed."""
return self._json.get('consumedUnits')
return self._json_data.get('consumedUnits')


class LicensesAPI(object):
Expand Down
18 changes: 9 additions & 9 deletions ciscosparkapi/api/memberships.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,47 +53,47 @@ def __init__(self, json):
@property
def id(self):
"""The membership's unique ID."""
return self._json.get('id')
return self._json_data.get('id')

@property
def roomId(self):
"""The ID of the room."""
return self._json.get('roomId')
return self._json_data.get('roomId')

@property
def personId(self):
"""The ID of the person."""
return self._json.get('personId')
return self._json_data.get('personId')

@property
def personEmail(self):
"""The email address of the person."""
return self._json.get('personEmail')
return self._json_data.get('personEmail')

@property
def personDisplayName(self):
"""The display name of the person."""
return self._json.get('personDisplayName')
return self._json_data.get('personDisplayName')

@property
def personOrgId(self):
"""The ID of the organization that the person is associated with."""
return self._json.get('personOrgId')
return self._json_data.get('personOrgId')

@property
def isModerator(self):
"""Person is a moderator for the room."""
return self._json.get('isModerator')
return self._json_data.get('isModerator')

@property
def isMonitor(self):
"""Person is a monitor for the room."""
return self._json.get('isMonitor')
return self._json_data.get('isMonitor')

@property
def created(self):
"""The date and time the membership was created."""
return self._json.get('created')
return self._json_data.get('created')


class MembershipsAPI(object):
Expand Down
22 changes: 11 additions & 11 deletions ciscosparkapi/api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,57 +57,57 @@ def __init__(self, json):
@property
def id(self):
"""The message's unique ID."""
return self._json.get('id')
return self._json_data.get('id')

@property
def roomId(self):
"""The ID of the room."""
return self._json.get('roomId')
return self._json_data.get('roomId')

@property
def roomType(self):
"""The type of room (i.e. 'group', 'direct' etc.)."""
return self._json.get('roomType')
return self._json_data.get('roomType')

@property
def text(self):
"""The message, in plain text."""
return self._json.get('text')
return self._json_data.get('text')

@property
def files(self):
"""Files attached to the the message (list of URLs)."""
return self._json.get('files')
return self._json_data.get('files')

@property
def personId(self):
"""The person ID of the sender."""
return self._json.get('personId')
return self._json_data.get('personId')

@property
def personEmail(self):
"""The email address of the sender."""
return self._json.get('personEmail')
return self._json_data.get('personEmail')

@property
def markdown(self):
"""The message, in markdown format."""
return self._json.get('markdown')
return self._json_data.get('markdown')

@property
def html(self):
"""The message, in HTML format."""
return self._json.get('html')
return self._json_data.get('html')

@property
def mentionedPeople(self):
"""The list of IDs of people mentioned in the message."""
return self._json.get('mentionedPeople')
return self._json_data.get('mentionedPeople')

@property
def created(self):
"""The date and time the message was created."""
return self._json.get('created')
return self._json_data.get('created')


class MessagesAPI(object):
Expand Down
6 changes: 3 additions & 3 deletions ciscosparkapi/api/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def __init__(self, json):
@property
def id(self):
"""The unique ID for the Organization."""
return self._json.get('id')
return self._json_data.get('id')

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

@property
def created(self):
"""Creation date and time in ISO8601 format."""
return self._json.get('created')
return self._json_data.get('created')


class OrganizationsAPI(object):
Expand Down
32 changes: 16 additions & 16 deletions ciscosparkapi/api/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,82 +52,82 @@ def __init__(self, json):
@property
def type(self):
"""The type of object returned by Cisco Spark (should be `person`)."""
return self._json.get('type')
return self._json_data.get('type')

@property
def id(self):
"""The person's unique ID."""
return self._json.get('id')
return self._json_data.get('id')

@property
def emails(self):
"""Email address(es) of the person."""
return self._json['emails']
return self._json_data['emails']

@property
def displayName(self):
"""Full name of the person."""
return self._json.get('displayName')
return self._json_data.get('displayName')

@property
def nickName(self):
"""'Nick name' or preferred short name of the person."""
return self._json.get('nickName')
return self._json_data.get('nickName')

@property
def firstName(self):
"""First name of the person."""
return self._json.get('firstName')
return self._json_data.get('firstName')

@property
def lastName(self):
"""Last name of the person."""
return self._json.get('lastName')
return self._json_data.get('lastName')

@property
def avatar(self):
"""URL to the person's avatar in PNG format."""
return self._json.get('avatar')
return self._json_data.get('avatar')

@property
def orgId(self):
"""ID of the organization to which this person belongs."""
return self._json.get('orgId')
return self._json_data.get('orgId')

@property
def roles(self):
"""Roles of the person."""
return self._json.get('roles')
return self._json_data.get('roles')

@property
def licenses(self):
"""Licenses allocated to the person."""
return self._json.get('licenses')
return self._json_data.get('licenses')

@property
def created(self):
"""The date and time the person was created."""
return self._json.get('created')
return self._json_data.get('created')

@property
def status(self):
"""The person's current status."""
return self._json.get('status')
return self._json_data.get('status')

@property
def lastActivity(self):
"""The date and time of the person's last activity."""
return self._json.get('lastActivity')
return self._json_data.get('lastActivity')

@property
def invitePending(self):
"""Person has been sent an invite, but hasn't responded."""
return self._json.get('invitePending')
return self._json_data.get('invitePending')

@property
def loginEnabled(self):
"""Person is allowed to login."""
return self._json.get('loginEnabled')
return self._json_data.get('loginEnabled')


class PeopleAPI(object):
Expand Down
4 changes: 2 additions & 2 deletions ciscosparkapi/api/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def __init__(self, json):
@property
def id(self):
"""The unique ID for the Role."""
return self._json.get('id')
return self._json_data.get('id')

@property
def name(self):
"""The name of the Role."""
return self._json.get('name')
return self._json_data.get('name')


class RolesAPI(object):
Expand Down
16 changes: 8 additions & 8 deletions ciscosparkapi/api/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,42 @@ def __init__(self, json):
@property
def id(self):
"""The rooms's unique ID."""
return self._json.get('id')
return self._json_data.get('id')

@property
def title(self):
"""A user-friendly name for the room."""
return self._json.get('title')
return self._json_data.get('title')

@property
def type(self):
"""The type of room (i.e. 'group', 'direct' etc.)."""
return self._json.get('type')
return self._json_data.get('type')

@property
def isLocked(self):
"""Whether or not the room is locked and controled by moderator(s)."""
return self._json.get('isLocked')
return self._json_data.get('isLocked')

@property
def lastActivity(self):
"""The date and time when the room was last active."""
return self._json.get('lastActivity')
return self._json_data.get('lastActivity')

@property
def created(self):
"""The date and time when the room was created."""
return self._json.get('created')
return self._json_data.get('created')

@property
def creatorId(self):
"""The ID of the person who created the room."""
return self._json.get('creatorId')
return self._json_data.get('creatorId')

@property
def teamId(self):
"""The ID for the team with which this room is associated."""
return self._json.get('teamId')
return self._json_data.get('teamId')


class RoomsAPI(object):
Expand Down
Loading

0 comments on commit 5d511d2

Please sign in to comment.