class Quickdraw::ShopifyConnectorPool

Public Class Methods

new() click to toggle source
# File lib/quickdraw/shopify_connector_pool.rb, line 11
def initialize
        @config = Quickdraw.config
        @auth = {:username => @config[:api_key], :password => @config[:password]}
end

Public Instance Methods

request(call_type, path, options) click to toggle source
# File lib/quickdraw/shopify_connector_pool.rb, line 16
def request(call_type, path, options)
        options.merge!({:basic_auth => @auth})

        begin
                tries ||= 3

                response = HTTParty.send(call_type, path, options)

                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