Class: Quickdraw::ShopifyConnectorPool
- Inherits:
-
Object
- Object
- Quickdraw::ShopifyConnectorPool
- Includes:
- Celluloid, HTTParty
- Defined in:
- lib/quickdraw/shopify_connector_pool.rb
Instance Method Summary collapse
-
#initialize ⇒ ShopifyConnectorPool
constructor
A new instance of ShopifyConnectorPool.
- #request(call_type, path, options) ⇒ Object
Constructor Details
#initialize ⇒ ShopifyConnectorPool
Returns a new instance of ShopifyConnectorPool.
11 12 13 14 |
# File 'lib/quickdraw/shopify_connector_pool.rb', line 11 def initialize @config = Quickdraw.config @auth = {:username => @config[:api_key], :password => @config[:password]} end |
Instance Method Details
#request(call_type, path, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/quickdraw/shopify_connector_pool.rb', line 16 def request(call_type, path, ) .merge!({:basic_auth => @auth}) begin tries ||= 3 response = HTTParty.send(call_type, path, ) if response.code == 429 tries += 1 puts "Too fast for Shopify! Retrying..." raise "Slow down!" end if response.code == 403 tries == 0 raise "Forbidden" end if response.code != 200 puts response.inspect raise "Request Failed" end rescue => e tries -= 1 if tries > 0 sleep 1 retry end end return response end |