recurly v0.2.2 Recurly.XML.Builder
Module responsible for building XML documents. Mostly for internal use. API unstable.
Summary
Functions
Given an attribute tuple from a changeset and a resource type, find and append the field from the schema
Generates an xml document representing a changeset
Takes a tuple from changeset data and returns an xml element
Turns a changeset and associated resource type into a nested
tuple which can be turned into xml by XmlBuilder
Functions
Given an attribute tuple from a changeset and a resource type, find and append the field from the schema
Parameters
attr_tuple
{attr_name, attr_value} from the changsetresource_type
Module which is responsible for the changset data
Examples
alias Recurly.XML.Field
Recurly.XML.Builder.find_field({:account_code, "xyz"}, Recurly.Account)
#=> {:account_code, "xyz", %Field{name: :account_code, type: :string, opts: []}}
Generates an xml document representing a changeset.
Parameters
changeset
Keyword list changesetresource_type
Module representing the resource type
Examples
changeset = [account_code: "my_account", first_name: nil]
Recurly.XML.Builder.generate(changeset, Recurly.Account)
# <account>
# <account_code>my_account</account_code>
# <first_name nil="nil"></first_name>
# </account>
# if you give it a field that is not in the
# resource's field, it will throw an ArgumentError
# let's assume you misspell account `acount`
changeset = [acount_code: "my_account", first_name: nil]
Recurly.XML.Builder.generate(changeset, Recurly.Account)
#=> raises ArgumentError "Invalid changeset data {:acount, "my_account"} for resource Recurly.Account"
Takes a tuple from changeset data and returns an xml element
Parameters
changset_tuple
- contains the attribute name, the attribute value, and theRecurly.XML.Field
.
Examples
alias Recurly.XML.Field
field = %Field{name: :account_code, type: :string, opts: []}
Recurly.XML.Builder.to_element({:account_code, "xyz", field})
#=> {:account_code, nil, "xyz"}