Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
nylas-python Changelog
======================

Unreleased
----------------
* Add `enforce_read_only` parameter to overriding `as_json` functions

v5.9.1
----------------
* Add option to include read only params in `as_json`
Expand Down
14 changes: 10 additions & 4 deletions nylas/client/authentication_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ def create(cls, api, **kwargs):

return obj

def as_json(self):
dct = super(Integration, self).as_json()
def as_json(self, enforce_read_only=True):
dct = super(Integration, self).as_json(enforce_read_only)
if enforce_read_only is False:
return dct

if not self.id:
if isinstance(self.provider, Authentication.Provider):
dct["provider"] = self.provider.value
Expand Down Expand Up @@ -108,8 +111,11 @@ def create(cls, api, **kwargs):
obj = super(Grant, cls).create(api, **kwargs)
return obj

def as_json(self):
dct = super(Grant, self).as_json()
def as_json(self, enforce_read_only=True):
dct = super(Grant, self).as_json(enforce_read_only)
if enforce_read_only is False:
return dct

# provider and state can not be updated
if self.id:
del dct["provider"]
Expand Down
32 changes: 18 additions & 14 deletions nylas/client/restful_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,11 @@ def __init__(self, api):
}
)

def as_json(self):
dct = NylasAPIObject.as_json(self)
def as_json(self, enforce_read_only=True):
dct = NylasAPIObject.as_json(self, enforce_read_only)
if enforce_read_only is False:
return dct

# Filter some parameters we got from the API
if dct.get("when"):
# Currently, the event (self) and the dict (dct) share the same
Expand Down Expand Up @@ -920,8 +923,11 @@ def __init__(self, api):
}
)

def as_json(self):
dct = NylasAPIObject.as_json(self)
def as_json(self, enforce_read_only=True):
dct = NylasAPIObject.as_json(self, enforce_read_only)
if enforce_read_only is False:
return dct

# "type" cannot be modified after created
if self.id:
dct.pop("type")
Expand All @@ -945,13 +951,13 @@ def __init__(self, api):
NylasAPIObject.__init__(self, Webhook, api)
self.read_only_attrs.update({"application_id", "version"})

def as_json(self):
def as_json(self, enforce_read_only=True):
dct = {}
# Only 'state' can get updated
if self.id:
if self.id and enforce_read_only is True:
dct["state"] = self.state
else:
dct = NylasAPIObject.as_json(self)
dct = NylasAPIObject.as_json(self, enforce_read_only)
return dct

class Trigger(str, Enum):
Expand Down Expand Up @@ -1035,9 +1041,11 @@ class Account(NylasAPIObject):
def __init__(self, api):
NylasAPIObject.__init__(self, Account, api)

def as_json(self):
dct = {"metadata": self.metadata}
return dct
def as_json(self, enforce_read_only=True):
if enforce_read_only is False:
return NylasAPIObject.as_json(self, enforce_read_only)
else:
return {"metadata": self.metadata}

def upgrade(self):
return self.api._call_resource_method(self, self.account_id, "upgrade", None)
Expand All @@ -1064,10 +1072,6 @@ class APIAccount(NylasAPIObject):
def __init__(self, api):
NylasAPIObject.__init__(self, APIAccount, api)

def as_json(self):
dct = NylasAPIObject.as_json(self)
return dct


class SingletonAccount(APIAccount):
# This is an APIAccount that lives under /account.
Expand Down
2 changes: 1 addition & 1 deletion nylas/client/scheduler_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SchedulerBookingRequest(RestfulModel):
def __init__(self, api):
RestfulModel.__init__(self, SchedulerBookingRequest, api)

def as_json(self):
def as_json(self, enforce_read_only=True):
dct = RestfulModel.as_json(self)
if "additional_values" not in dct or dct["additional_values"] is None:
dct["additional_values"] = {}
Expand Down