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

action(resource, action_name)

Returns an action on a resource given the action name

Parameters

  • resource Recurly.Resource struct
  • action_name Atom of the action name

Examples

Recurly.Resource.action(subscription, :cancel)
#=> [:put, "https://your-subsdomain.recurly.com/v2/subscriptions/36d81d1e79995b0b4c7df3419aa1c2f5/cancel"]
actions(resource)

Returns an map of actions keyed by action name

Parameters

  • resource Recurly.Resource struct
attributes(resource)

Gives us the attributes of a resource without all the metadata.

Parameters

  • resource Resource struct with some attributes
create(resource, changeset, path)

Creates a resource on the server and returns a resource struct.

Parameters

  • resource empty resource struct with the type of the expected return resource
  • changset Keyword list changeset representing the creation data
  • path 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
find(association)

Finds and parses a resource given an association

Parameters

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
find(resource, path)

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 into
  • path String path to the resource

Recurly.Resource.find/1 takes an association:

Examples

case Recurly.Resource.find(%Recurly.Account{}, "/accounts/account123") do
  {:ok, account} ->
    # successfully found account
  {:error, error} ->
    # There was an error
end
list(resource, path, options)

Returns a list of resources at the given endpoint

Parameters

  • resource Recurly.Resource struct to parse result into
  • path String path to the resource
  • options 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
location(resource)

Gives us fully qualified location of the persisted resource.

Parameters

  • resource Resource struct representing a persisted resource
perform_action(resource, action_name)

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 resource
  • action_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
update(resource, changeset, path \\ nil)