Gem for accessing the InSales REST web services
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
CHANGELOG.md
Gemfile
README.md
Rakefile
insales_api.gemspec

README.md

InsalesApi gem

Build Status

Insales api client based on ActiveResource.

Rails application example is here.

Install

Add to Gemfile:

gem 'insales_api'

Initialize

class MyApp < InsalesApi::App
  self.api_key = 'api_key'
end

MyApp.configure_api('domain', 'password')

Use

order = InsalesApi::Order.find 123

# singleton resources
account = InsalesApi::Account.find

Handling Insales API request limit

There is a 500 requests per 5 minutes limit for Insales API. To handle this limitation gracefully, use InsalesApi.wait_retry method:

# prepare a handler for request limit case
notify_user = Proc.new do |wait_for, attempt, max_attempts, ex|
  puts "API limit reached. Waiting for #{wait_for} seconds. Attempt #{attempt}/#{max_attempts}"
end

# perform 10 attempts to get products
InsalesApi.wait_retry(10, notify_user) do |x|
  puts "Attempt ##{x}."
  products = InsalesApi::Products.all
end

If you don't need to cap the attempts number or you don't want to do any special processing, simply drop the arguments:

InsalesApi.wait_retry do
  products = InsalesApi::Products.all # will try to get products until the limit resets
end