Skip to content

feat: Add support for error_code and error_message fields in FaxInstance #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion signalwire/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from twilio.rest.fax import Fax as TwilioFax
from twilio.rest.fax.v1 import V1 as TwilioV1
from twilio.rest.fax.v1.fax import FaxList

from signalwire.rest.fax import SWFaxContext

import sys
from six import u
Expand Down Expand Up @@ -311,6 +314,9 @@ def patched_fax_init(self, twilio):
# Versions
self._v1 = None

def patched_faxlist_call(self, sid):
return SWFaxContext(self._version, sid)

def patched_fax_v1_init(self, domain):
"""
Initialize the V1 version of Fax
Expand All @@ -319,7 +325,8 @@ def patched_fax_v1_init(self, domain):
"""
super(TwilioV1, self).__init__(domain)
self.version = "2010-04-01/Accounts/" + domain.account_sid
self._faxes = None
FaxList.__call__ = patched_faxlist_call
self._faxes = FaxList(self)


class Client(TwilioClient):
Expand Down
73 changes: 73 additions & 0 deletions signalwire/rest/fax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from twilio.base import values, deserialize
from twilio.rest.fax.v1.fax import FaxContext, FaxInstance

class SWFaxContext(FaxContext):
def fetch(self):
"""
Fetch the SWFaxInstance

:returns: The fetched SWFaxInstance
:rtype: signalwire.rest.fax.SWFaxInstance
"""
payload = self._version.fetch(method='GET', uri=self._uri, )

return SWFaxInstance(self._version, payload, sid=self._solution['sid'], )

def update(self, status=values.unset):
"""
Update the SWFaxInstance

:param FaxInstance.UpdateStatus status: The new status of the resource

:returns: The updated SWFaxInstance
:rtype: signalwire.rest.fax.SWFaxInstance
"""
data = values.of({'Status': status, })

payload = self._version.update(method='POST', uri=self._uri, data=data, )

return SWFaxInstance(self._version, payload, sid=self._solution['sid'], )

def __repr__(self):
"""
Provide a friendly representation

:returns: Machine friendly representation
:rtype: str
"""
context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
return '<Signalwire.Rest.Fax.SWFaxContext {}>'.format(context)


class SWFaxInstance(FaxInstance):
def __init__(self, version, payload, sid=None):
super().__init__(version, payload, sid)
self._properties.update({
"error_code": deserialize.integer(payload.get("error_code")),
"error_message": payload.get("error_message"),
})

@property
def error_code(self):
"""
:returns: Returns the error code of the fax
:rtype: int
"""
return self._properties['error_code']

@property
def error_message(self):
"""
The error message of the fax
"""
return self._properties['error_message']

def __repr__(self):
"""
Provide a friendly representation

:returns: Machine friendly representation
:rtype: str
"""
context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
return '<Signalwire.Rest.Fax.SWFaxInstance {}>'.format(context)