recurly v0.2.2 Recurly.Account
Module for handling accounts in Recurly. See the developer docs on accounts for more details
Summary
Functions
Gives the count of accounts on the server given options
Creates an account from a changeset. Supports nesting the billing_info
Finds an account given an account code. Returns the account or an error
Gives the first account returned given options
Generates the path to an account given the account code
Creates a stream of accounts given some options
Updates an account from a changeset
Functions
Gives the count of accounts on the server given options
Parameters
options
Keyword list of the request options. See options in the account list section of the docs.
Examples
# suppose we want to count all accounts
case Recurly.Account.count() do
{:ok, count} ->
# count => 176 (or some integer)
{:error, err} ->
# error occurred
end
# or maybe we wan to count just past due accounts
case Recurly.Account.count(state: :past_due) do
{:ok, count} ->
# count => 83 (or some integer)
{:error, err} ->
# error occurred
end
Creates an account from a changeset. Supports nesting the billing_info
Parameters
changeset
Keyword list changeset
Examples
alias Recurly.ValidationError
case Recurly.Account.create(account_code: "myaccountcode") do
{:ok, account} ->
# created the account
{:error, %ValidationError{errors: errors}} ->
# will give you a list of validation errors
end
Finds an account given an account code. Returns the account or an error.
Parameters
account_code
String account code
Examples
alias Recurly.NotFoundError
case Recurly.Account.find("myaccountcode") do
{:ok, account} ->
# Found the account
{:error, %NotFoundError{}} ->
# 404 account was not found
end
Gives the first account returned given options
Parameters
options
Keyword list of the request options. See options in the account list section of the docs.
Examples
# suppose we want the latest, active account
case Recurly.Account.first(state: :active) do
{:ok, account} ->
# account => the newest active account
{:error, err} ->
# error occurred
end
# or maybe want the oldest, active account
case Recurly.Account.first(state: :active, order: :asc) do
{:ok, account} ->
# account => the oldest active account
{:error, err} ->
# error occurred
end
Generates the path to an account given the account code
Parameters
account_code
String account code
Creates a stream of accounts given some options.
Parameters
options
Keyword list of the request options. See options in the account list section of the docs.
Examples
See Recurly.Resource.stream/3
for more detailed examples of
working with resource streams.
# stream of past due accounts sorted from most recently
# updated to least recently updated
stream = Recurly.Account.stream(state: :past_due, sort: :updated_at)
Updates an account from a changeset
Parameters
account
account resource structchangeset
Keyword list changeset representing the updates
Examples
alias Recurly.ValidationError
changeset = [
first_name: "Benjamin",
last_name: nil
]
case Recurly.Account.update(account, changeset) do
{:ok, account} ->
# the updated account
{:error, %ValidationError{errors: errors}} ->
# will give you a list of validation errors
end