class Object
Public Class Methods
auto_paging_each(opts = {}) { |record| ... }
click to toggle source
# File lib/shopify_api_extensions/pagination.rb, line 6 def self.auto_paging_each(opts = {}) opts[:limit] ||= 50 current_page = opts[:page] || 1 records = [] record_found = true while record_found record_found = false self.list(opts.merge(page: current_page)).each do |record| record_found = true records << record yield(record) if block_given? end current_page += 1 end records end
list(params = {})
click to toggle source
# File lib/shopify_api_extensions/pagination.rb, line 2 def self.list(params = {}) find(:all, params: params) end
Public Instance Methods
request(*args)
click to toggle source
# File lib/shopify_api_extensions/backoff.rb, line 4 def request(*args) network_retry = 0 network_limit = 10 rate_limit_retry = 0 rate_limit_limit = 30 begin shopify_request(*args) rescue Exception => e exceptions_to_retry = [ ActiveResource::ClientError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EHOSTUNREACH, EOFError, Zlib::BufError, SocketError, ActiveResource::SSLError, ActiveResource::TimeoutError, # NOTE represents only 500x errors ActiveResource::ServerError ] if !exceptions_to_retry.include?(e.class) raise end if e.class == ActiveResource::ClientError && e.message =~ /429/ && e.message =~ /Too Many Requests/ if rate_limit_retry > 0 && rate_limit_retry % 10 == 0 puts "Shopify Rate Limit Error Encountered" end if rate_limit_retry >= rate_limit_limit raise else rate_limit_retry += 1 sleep(rate_limit_retry) retry end elsif e.class == ActiveResource::ClientError raise end if network_retry >= network_limit raise else network_retry += 1 sleep(network_retry) retry end end end