module DuodealerAPI::Limits::ClassMethods
Constants
- CREDIT_LIMIT_HEADER_PARAM
Takes form <call count>/<bucket size> See help.duodealer.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/duodealer_api/limits.rb, line 21 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 DuodealerAPI
cuts off at 299 or shop limits. @param {Symbol} scope [:shop] @return {Integer}
# File lib/duodealer_api/limits.rb, line 41 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/duodealer_api/limits.rb, line 30 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/duodealer_api/limits.rb, line 51 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/duodealer_api/limits.rb, line 59 def response Shop.current unless DuodealerAPI::Base.connection.response DuodealerAPI::Base.connection.response end
Private Instance Methods
api_credit_limit_param(scope)
click to toggle source
@return {Array}
# File lib/duodealer_api/limits.rb, line 69 def api_credit_limit_param(scope) header = response[CREDIT_LIMIT_HEADER_PARAM[scope]] raise LimitUnavailable unless header header.split('/') end