How to use the easypost.__init__.EasyPostObject function in easypost

To help you get started, we’ve selected a few easypost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EasyPost / easypost-python / easypost / __init__.py View on Github external
'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
github EasyPost / easypost-python / easypost / __init__.py View on Github external
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)
github EasyPost / easypost-python / easypost / __init__.py View on Github external
'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
github EasyPost / easypost-python / easypost / __init__.py View on Github external
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
github EasyPost / easypost-python / easypost / __init__.py View on Github external
'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
github EasyPost / easypost-python / easypost / __init__.py View on Github external
def _serialize(o):
            if isinstance(o, EasyPostObject):
                return o.to_dict()
            if isinstance(o, list):
                return [_serialize(r) for r in o]
            return o