Module: SpiffyStoresAPI::Limits::ClassMethods

Defined in:
lib/spiffy_stores_api/limits.rb

Constant Summary collapse

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”

{
  :store => 'http_x_ratelimit'
}

Instance Method Summary collapse

Instance Method Details

#credit_leftInteger Also known as: available_calls

How many more API calls can I make?

Returns:

  • (Integer)


27
28
29
# File 'lib/spiffy_stores_api/limits.rb', line 27

def credit_left
  credit_limit(:store) - credit_used(:store)
end

#credit_limit(scope = :store) ⇒ Integer Also known as: call_limit

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.

Parameters:

  • scope (Symbol) (defaults to: :store)
    :store

Returns:

  • (Integer)


47
48
49
50
# 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

#credit_maxed?Boolean Also known as: maxed?

Have I reached my API call limit?

Returns:

  • (Boolean)


36
37
38
# File 'lib/spiffy_stores_api/limits.rb', line 36

def credit_maxed?
  credit_left <= 0
end

#credit_used(scope = :store) ⇒ Integer Also known as: call_count

How many API calls have I made?

Parameters:

  • scope (Symbol) (defaults to: :store)
    :store

Returns:

  • (Integer)


58
59
60
# File 'lib/spiffy_stores_api/limits.rb', line 58

def credit_used(scope=:store)
  api_credit_limit_param(scope).shift.to_i
end

#responseHTTPResonse

Returns:

  • (HTTPResonse)


66
67
68
69
# File 'lib/spiffy_stores_api/limits.rb', line 66

def response
  Store.current unless SpiffyStoresAPI::Base.connection.response
  SpiffyStoresAPI::Base.connection.response
end