How to use the recurly.resource.Resource.cast function in recurly

To help you get started, we’ve selected a few recurly 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 recurly / recurly-client-python / recurly / base_client.py View on Github external
}
            if body:
                body = json.dumps(body)

            if params:
                path += "?" + urllib.parse.urlencode(params)

            self.__conn.request(method, path, body, headers=headers)
            request = Request(method, path, body)
            resp = Response(self.__conn.getresponse(), request)

            if resp.status >= 400:
                if resp.body:
                    resp_json = resp.body["error"]
                    resp_json["object"] = "error"
                    error = Resource.cast(resp_json, response=resp)
                    typ = error.type
                    name_parts = typ.split("_")
                    class_name = "".join(x.title() for x in name_parts)
                    # gets around inconsistencies in error naming
                    if not class_name.endswith("Error"):
                        class_name += "Error"
                    klass = locate("recurly.errors.%s" % class_name)
                    raise klass(
                        error.message + ". Recurly Request Id: " + resp.request_id,
                        error,
                    )
                else:
                    raise ApiError(
                        "Unknown Error. Recurly Request Id: " + resp.request_id, None
                    )
github recurly / recurly-client-python / recurly / base_client.py View on Github external
if not class_name.endswith("Error"):
                        class_name += "Error"
                    klass = locate("recurly.errors.%s" % class_name)
                    raise klass(
                        error.message + ". Recurly Request Id: " + resp.request_id,
                        error,
                    )
                else:
                    raise ApiError(
                        "Unknown Error. Recurly Request Id: " + resp.request_id, None
                    )

            if resp.body:
                return Resource.cast(resp.body, response=resp)
            else:
                return Resource.cast({}, Empty, resp)

        except socket.error as e:
            raise NetworkError(e)
github recurly / recurly-client-python / recurly / base_client.py View on Github external
class_name = "".join(x.title() for x in name_parts)
                    # gets around inconsistencies in error naming
                    if not class_name.endswith("Error"):
                        class_name += "Error"
                    klass = locate("recurly.errors.%s" % class_name)
                    raise klass(
                        error.message + ". Recurly Request Id: " + resp.request_id,
                        error,
                    )
                else:
                    raise ApiError(
                        "Unknown Error. Recurly Request Id: " + resp.request_id, None
                    )

            if resp.body:
                return Resource.cast(resp.body, response=resp)
            else:
                return Resource.cast({}, Empty, resp)

        except socket.error as e:
            raise NetworkError(e)