module SpiffyStoresAPI::Limits::ClassMethods
Constants
- CREDIT_LIMIT_HEADER_PARAM
The ratelimit header comes from rack-ratelimit The parameters provided are name period limit remaining until {“name”:“API”,“period”:300,“limit”:500,“remaining”:496,“until”:“2014-11-28T03:45:00Z”}
Public Instance Methods
credit_left()
click to toggle source
How many more API calls can I make? @return {Integer}
# File lib/spiffy_stores_api/limits.rb, line 27 def credit_left credit_limit(:store) - credit_used(:store) end
Also aliased as: available_calls
credit_limit(scope=:store)
click to toggle source
How many total API calls can I make? NOTE: subtracting 1 from credit_limit
because I think SpiffyStoresAPI
cuts off at 299 or store limits. @param {Symbol} scope [:store] @return {Integer}
# File lib/spiffy_stores_api/limits.rb, line 47 def credit_limit(scope=:store) @api_credit_limit ||= {} @api_credit_limit[scope] ||= 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/spiffy_stores_api/limits.rb, line 36 def credit_maxed? credit_left <= 0 end
Also aliased as: maxed?
credit_used(scope=:store)
click to toggle source
How many API calls have I made? @param {Symbol} scope [:store] @return {Integer}
# File lib/spiffy_stores_api/limits.rb, line 58 def credit_used(scope=:store) api_credit_limit_param(scope).shift.to_i end
Also aliased as: call_count
response()
click to toggle source
@return {HTTPResonse}
# File lib/spiffy_stores_api/limits.rb, line 66 def response Store.current unless SpiffyStoresAPI::Base.connection.response SpiffyStoresAPI::Base.connection.response end
Private Instance Methods
api_credit_limit_param(scope)
click to toggle source
@return {Array}
# File lib/spiffy_stores_api/limits.rb, line 76 def api_credit_limit_param(scope) header = response[CREDIT_LIMIT_HEADER_PARAM[scope]] raise LimitUnavailable unless header p = JSON.parse(header) p_limit = p['limit'].to_i p_used = p_limit - p['remaining'].to_i [p_used, p_limit] end