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.saveproduct = Airbrite::Product.fetch :_id => "foo"
# or
product = Airbrite::Product.new :_id => "foo"
product.refreshproduct = # ... obtain a product
product.name = "Pebble V9"
product.saveAccepts Filters.
result = Airbrite::Product.list
products = result.data
paging = result.pagingparams = {...}
order = Airbrite::Order.create params
# or
order = Airbrite::Order.new params
order.saveorder = Airbrite::Order.fetch :_id => "foo"
# or
order = Airbrite::Order.new :_id => "foo"
order.refreshorder = # ... obtain a order
order.metadata = {...}
order.saveAccepts Filters.
result = Airbrite::Order.list
orders = result.data
paging = result.pagingparams = {:order_id => "o_id", ...}
payment = Airbrite::Payment.create params
# or
payment = Airbrite::Payment.new params
payment.savepayment = Airbrite::Payment.fetch :order_id => "o_id", :_id => "foo"
# or
payment = Airbrite::Payment.new :order_id => "o_id", :_id => "foo"
payment.refreshpayment = # ... obtain a payment
payment.metadata = {...}
payment.saveAccepts Filters.
result = Airbrite::Payment.list :order_id => "o_id"
payments = result.data
paging = result.pagingpayment = # ... obtain a payment
payment.chargepayment = # ... obtain a payment
payment.authorizepayment = # ... obtain a payment
payment.capturepayment = # ... obtain a payment
payment.refund amountparams = {:order_id => "o_id", ...}
shipment = Airbrite::Shipment.create params
# or
shipment = Airbrite::Shipment.new params
shipment.saveshipment = Airbrite::Shipment.fetch :order_id => "o_id", :_id => "foo"
# or
shipment = Airbrite::Shipment.new :order_id => "o_id", :_id => "foo"
shipment.refreshshipment = # ... obtain a shipment
shipment.metadata = {...}
shipment.saveAccepts Filters.
result = Airbrite::Shipment.list :order_id => "o_id"
shipments = result.data
paging = result.pagingparams = {...}
customer = Airbrite::Customer.create params
# or
customer = Airbrite::Customer.new params
customer.savecustomer = Airbrite::Customer.fetch :_id => "foo"
# or
customer = Airbrite::Customer.new :_id => "foo"
customer.refreshcustomer = # ... obtain a customer
customer.metadata = {...}
customer.saveAccepts Filters.
result = Airbrite::Customer.list
customers = result.data
paging = result.pagingtax = Airbrite::Tax.calculate :zip => "94301", :amount => 12345, :nexus_zips => "12345,67890"account = Airbrite::Account.fetchevent = Airbrite::Event.fetch :_id => "foo"
# or
event = Airbrite::Event.new :_id => "foo"
event.refreshAccepts Filters.
result = Airbrite::Event.list
events = result.data
paging = result.pagingAll 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::ClientErrorAll 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