class MangoPay::Environment
Holds environment-specific configuration and data. Allows for multiple client handling and configuration from within the same application.
Constants
- LOG
Attributes
configuration[RW]
Configuration
-
Its
MangoPay
configuration details
id[R]
- Symbol
-
Its identification symbol
rate_limit_count[RW]
- Hash
-
Counts of the requests sent to the API per time interval
rate_limit_remaining[RW]
- Hash
-
Number of remaining possible calls to be made per time interval
rate_limit_reset[RW]
- Hash
-
UNIX times at which counts will be reset per time interval
Public Class Methods
new(id)
click to toggle source
# File lib/mangopay/environment.rb, line 27 def initialize(id) @id = id @rate_limit_count = {} @rate_limit_remaining = {} @rate_limit_reset = {} end
Public Instance Methods
time_interval(index)
click to toggle source
Asserts the time interval corresponding to each index of the values returned in API headers.
# File lib/mangopay/environment.rb, line 51 def time_interval(index) case index when 0 RateLimitInterval::FIFTEEN_MIN when 1 RateLimitInterval::THIRTY_MIN when 2 RateLimitInterval::HOUR when 3 RateLimitInterval::DAY else LOG.warn 'Unexpected rate limit time interval count' end end
update_rate_limits(rate_limits)
click to toggle source
Updates the rate limit data based on headers from API.
noinspection RubyResolve
# File lib/mangopay/environment.rb, line 37 def update_rate_limits(rate_limits) rate_limits['x-ratelimit'].each.with_index do |count, index| @rate_limit_count[time_interval(index)] = count end rate_limits['x-ratelimit-remaining'].each.with_index do |remain, index| @rate_limit_remaining[time_interval(index)] = remain end rate_limits['x-ratelimit-reset'].each.with_index do |reset, index| @rate_limit_reset[time_interval(index)] = reset end end