recurly v0.0.1 Recurly.Resource
Summary
Functions
Returns an action on a resource given the action name
Returns an map of actions keyed by action name
Gives us the attributes of a resource without all the metadata
Creates a resource on the server and returns a resource struct
Finds and parses a resource given an association
Finds and parses a resource given a path
Returns a list of resources at the given endpoint
Gives us fully qualified location of the persisted resource
Performs and action on a resource. Actions can be found in the <a> tags of the xml.
It follows the same response pattern as Recurly.API.make_request/5
Functions
Returns an action on a resource given the action name
Parameters
resource
Recurly.Resource structaction_name
Atom of the action name
Examples
Recurly.Resource.action(subscription, :cancel)
#=> [:put, "https://your-subsdomain.recurly.com/v2/subscriptions/36d81d1e79995b0b4c7df3419aa1c2f5/cancel"]
Returns an map of actions keyed by action name
Parameters
resource
Recurly.Resource struct
Gives us the attributes of a resource without all the metadata.
Parameters
resource
Resource struct with some attributes
Creates a resource on the server and returns a resource struct.
Parameters
resource
empty resource struct with the type of the expected return resourcechangset
Keyword list changeset representing the creation datapath
String path to the creation endpoint
Examples
changeset = [
account_code: "myaccountcode"
]
case Recurly.Resource.create(%Recurly.Account{}, changeset, "/accounts/") do
{:ok, account} ->
# successfully created
{:error, error} ->
# There was an error
end
Finds and parses a resource given an association
Parameters
association
Recurly.Association
struct where paginate == false
Examples
{:ok, account} = Recurly.Account.find("myaccountcode")
# Suppose we have an account and want to fetch the billing info association
case Recurly.Resource.find(account.billing_info) do
{:ok, billing_info} ->
# successfully found the billing_info
{:error, error} ->
# There was an error
end
# It will explode if we try to use a pageable association
Recurly.Resource.find(account.transactions)
#=> crashes with argument error because paginate == true
Finds and parses a resource given a path
Parameters
Recurly.Resource.find/2
takes a resource and a path:
resource
Recurly.Resource struct to parse result intopath
String path to the resource
Recurly.Resource.find/1
takes an association:
association
Recurly.Association
struct with paginate: false
Examples
case Recurly.Resource.find(%Recurly.Account{}, "/accounts/account123") do
{:ok, account} ->
# successfully found account
{:error, error} ->
# There was an error
end
Returns a list of resources at the given endpoint
Parameters
resource
Recurly.Resource struct to parse result intopath
String path to the resourceoptions
Keyword list of GET params
Examples
case Recurly.Resource.list(%Recurly.Account{}, "/accounts", state: "subscriber") do
{:ok, accounts} ->
# list of accounts
{:error, error} ->
# There was an error
end
Gives us fully qualified location of the persisted resource.
Parameters
resource
Resource struct representing a persisted resource
Performs and action on a resource. Actions can be found in the <a> tags of the xml.
It follows the same response pattern as Recurly.API.make_request/5
Parameters
resource
Resource struct representing a persisted resourceaction_name
Atom of the action name
Examples
case Recurly.Resource.perform_action(subscription, :cancel) do
{:ok, subscription} ->
# sucessfully canceled the subscription
{:error, error} ->
# error happened
end