Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'ca': CarrierAccount,
'user': User,
'shprep': Report,
'plrep': Report,
'trkrep': Report,
'hook': Webhook
}
if isinstance(response, list):
return [convert_to_easypost_object(r, api_key, parent) for r in response]
elif isinstance(response, dict):
response = response.copy()
cls_name = response.get('object', EasyPostObject)
cls_id = response.get('id', None)
if isinstance(cls_name, six.string_types):
cls = types.get(cls_name, EasyPostObject)
elif cls_id is not None:
cls = prefixes.get(cls_id[0:cls_id.find('_')], EasyPostObject)
else:
cls = EasyPostObject
return cls.construct_from(response, api_key, parent, name)
else:
return response
for k in sorted(self._values):
v = getattr(self, k)
v = _serialize(v)
d[k] = v
return d
class EasyPostObjectEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, EasyPostObject):
return obj.to_dict()
else:
return json.JSONEncoder.default(self, obj)
class Resource(EasyPostObject):
def _ident(self):
return [self.get('id')]
@classmethod
def retrieve(cls, easypost_id, api_key=None, **params):
try:
easypost_id = easypost_id['id']
except (KeyError, TypeError):
pass
instance = cls(easypost_id, api_key, **params)
instance.refresh()
return instance
def refresh(self):
requestor = Requestor(self._api_key)
'trkrep': Report,
'hook': Webhook
}
if isinstance(response, list):
return [convert_to_easypost_object(r, api_key, parent) for r in response]
elif isinstance(response, dict):
response = response.copy()
cls_name = response.get('object', EasyPostObject)
cls_id = response.get('id', None)
if isinstance(cls_name, six.string_types):
cls = types.get(cls_name, EasyPostObject)
elif cls_id is not None:
cls = prefixes.get(cls_id[0:cls_id.find('_')], EasyPostObject)
else:
cls = EasyPostObject
return cls.construct_from(response, api_key, parent, name)
else:
return response
def flatten_unsaved(self):
values = {}
for key in self._unsaved_values:
value = self.get(key)
values[key] = value
if type(value) is EasyPostObject:
values[key] = value.flatten_unsaved()
return values
'pickup': Pickup,
'pickuprate': PickupRate,
'pl': PostageLabel,
'ca': CarrierAccount,
'user': User,
'shprep': Report,
'plrep': Report,
'trkrep': Report,
'hook': Webhook
}
if isinstance(response, list):
return [convert_to_easypost_object(r, api_key, parent) for r in response]
elif isinstance(response, dict):
response = response.copy()
cls_name = response.get('object', EasyPostObject)
cls_id = response.get('id', None)
if isinstance(cls_name, six.string_types):
cls = types.get(cls_name, EasyPostObject)
elif cls_id is not None:
cls = prefixes.get(cls_id[0:cls_id.find('_')], EasyPostObject)
else:
cls = EasyPostObject
return cls.construct_from(response, api_key, parent, name)
else:
return response
def _serialize(o):
if isinstance(o, EasyPostObject):
return o.to_dict()
if isinstance(o, list):
return [_serialize(r) for r in o]
return o