module ShopifyAPI::Limits::ClassMethods
Constants
- CREDIT_LIMIT_HEADER_PARAM
Takes form <call count>/<bucket size> See help.shopify.com/en/api/getting-started/api-call-limit Eg: 2/40
Public Instance Methods
credit_left()
click to toggle source
How many more API calls can I make? @return {Integer}
# File lib/shopify_api/limits.rb, line 22 def credit_left credit_limit(:shop) - credit_used(:shop) end
Also aliased as: available_calls
credit_limit(scope = :shop)
click to toggle source
How many total API calls can I make? NOTE: subtracting 1 from credit_limit
because I think ShopifyAPI
cuts off at 299 or shop limits. @param {Symbol} scope [:shop] @return {Integer}
# File lib/shopify_api/limits.rb, line 42 def credit_limit(scope = :shop) api_credit_limit_param(scope).pop.to_i - 1 end
Also aliased as: call_limit
credit_maxed?()
click to toggle source
Have I reached my API call limit? @return {Boolean}
# File lib/shopify_api/limits.rb, line 31 def credit_maxed? credit_left <= 0 end
Also aliased as: maxed?
credit_used(scope = :shop)
click to toggle source
How many API calls have I made? @param {Symbol} scope [:shop] @return {Integer}
# File lib/shopify_api/limits.rb, line 52 def credit_used(scope = :shop) api_credit_limit_param(scope).shift.to_i end
Also aliased as: call_count
response()
click to toggle source
@return {HTTPResonse}
# File lib/shopify_api/limits.rb, line 60 def response Shop.current unless ShopifyAPI::Base.connection.response ShopifyAPI::Base.connection.response end
Private Instance Methods
api_credit_limit_param(scope)
click to toggle source
@return {Array}
# File lib/shopify_api/limits.rb, line 70 def api_credit_limit_param(scope) header = response[CREDIT_LIMIT_HEADER_PARAM[scope]] raise LimitUnavailable unless header header.split('/') end