Ruby bindings for the Airbrite API.
Add this line to your application's Gemfile:
gem 'airbrite'
And then execute:
$ bundle
Or install it yourself as:
$ gem install airbrite
Airbrite.api_key = "my_secret_key"
params = {
:sku => "foo",
:price => 12345,
:name => "Pebble",
:description => "An awesome watch",
:metadata => {...}
}
product = Airbrite::Product.create params
# or
product = Airbrite::Product.new params
product.save
product = Airbrite::Product.fetch :_id => "foo"
# or
product = Airbrite::Product.new :_id => "foo"
product.refresh
product = # ... obtain a product
product.name = "Pebble V9"
product.save
Accepts Filters.
result = Airbrite::Product.list
products = result.data
paging = result.paging
params = {...}
order = Airbrite::Order.create params
# or
order = Airbrite::Order.new params
order.save
order = Airbrite::Order.fetch :_id => "foo"
# or
order = Airbrite::Order.new :_id => "foo"
order.refresh
order = # ... obtain a order
order.metadata = {...}
order.save
Accepts Filters.
result = Airbrite::Order.list
orders = result.data
paging = result.paging
params = {:order_id => "o_id", ...}
payment = Airbrite::Payment.create params
# or
payment = Airbrite::Payment.new params
payment.save
payment = Airbrite::Payment.fetch :order_id => "o_id", :_id => "foo"
# or
payment = Airbrite::Payment.new :order_id => "o_id", :_id => "foo"
payment.refresh
payment = # ... obtain a payment
payment.metadata = {...}
payment.save
Accepts Filters.
result = Airbrite::Payment.list :order_id => "o_id"
payments = result.data
paging = result.paging
payment = # ... obtain a payment
payment.charge
payment = # ... obtain a payment
payment.authorize
payment = # ... obtain a payment
payment.capture
payment = # ... obtain a payment
payment.refund amount
params = {:order_id => "o_id", ...}
shipment = Airbrite::Shipment.create params
# or
shipment = Airbrite::Shipment.new params
shipment.save
shipment = Airbrite::Shipment.fetch :order_id => "o_id", :_id => "foo"
# or
shipment = Airbrite::Shipment.new :order_id => "o_id", :_id => "foo"
shipment.refresh
shipment = # ... obtain a shipment
shipment.metadata = {...}
shipment.save
Accepts Filters.
result = Airbrite::Shipment.list :order_id => "o_id"
shipments = result.data
paging = result.paging
params = {...}
customer = Airbrite::Customer.create params
# or
customer = Airbrite::Customer.new params
customer.save
customer = Airbrite::Customer.fetch :_id => "foo"
# or
customer = Airbrite::Customer.new :_id => "foo"
customer.refresh
customer = # ... obtain a customer
customer.metadata = {...}
customer.save
Accepts Filters.
result = Airbrite::Customer.list
customers = result.data
paging = result.paging
tax = Airbrite::Tax.calculate :zip => "94301", :amount => 12345, :nexus_zips => "12345,67890"
account = Airbrite::Account.fetch
event = Airbrite::Event.fetch :_id => "foo"
# or
event = Airbrite::Event.new :_id => "foo"
event.refresh
Accepts Filters.
result = Airbrite::Event.list
events = result.data
paging = result.paging
All list operations accept filters. These are:
[:limit, :skip, :sort, :order, :since, :until]
They work like so:
events = Airbrite::Event.list(
:limit => 50,
:skip => 20,
:sort => :created,
:order => 1,
:since => 24.hours.ago,
:until => 12.hours.ago
)
Anything you pass to [:limit, :skip, :since, :until]
should play nicely with to_i
(Time objects do). Anything passed to :sort
should play nicely with to_s
(symbols do).
You can mix and match them as you please.
You can find out if an entity is persisted by asking it, e.g., order.persisted?
.
Calling refresh
on any "fetchable" entity causes it to fetch itself and replace its contents with the response data from Airbrite. Note that any local changes will be lost. The _id
property must be set in order to refresh properly.
There are 4 exception types that can be raised from all API operations described above. These are:
# Missing api key:
Airbrite::MissingApiKey
# 50* http status codes returned from Airbrite:
Airbrite::ApiError
# 40* http status codes returned from Airbrite:
Airbrite::BadRequestError
# Misc. HTTP client errors such as timeouts and response parse failures:
Airbrite::ClientError
All exceptions above inherit from Airbrite::AirbriteError
and best attempts are made to record useful messages.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request