Sha256: cdb51d4427ddde90c9969a228b1fcf5c1dd2e3817158429fda114cdf73c4c2cd
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
# InsalesApi gem [![Build Status](https://secure.travis-ci.org/insales/insales_api.png?branch=master)](http://travis-ci.org/insales/insales_api) Insales api client based on [ActiveResource](https://github.com/rails/activeresource). Rails application example is [here](https://github.com/insales/insales_app). ## Install Add to Gemfile: ```ruby gem 'insales_api' ``` ## Initialize ```ruby class MyApp < InsalesApi::App self.api_key = 'api_key' end MyApp.configure_api('domain', 'password') ``` ## Use ```ruby 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: ```ruby # 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: ```ruby InsalesApi.wait_retry do products = InsalesApi::Products.all # will try to get products until the limit resets end ```
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
insales_api-0.2.0 | README.md |
insales_api-0.1.3 | README.md |
insales_api-0.1.2 | README.md |
insales_api-0.1.1 | README.md |
insales_api-0.1.0 | README.md |