Class: Strava::Usage

Inherits:
Object
  • Object
show all
Defined in:
lib/strava/usage.rb

Overview

Provides data on Strava API limits and usage.

Usage:

ca = Strava::Athlete.current_athlete
usage = ca.client.usage
usage.recent_usage  # => 254
usage.daily_usage   # => 12536
usage.recent_pct    # => 0.423
usage.daily_pct     # => 0.417

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit_str, usage_str) ⇒ Usage

Returns a new instance of Usage.



17
18
19
20
# File 'lib/strava/usage.rb', line 17

def initialize(limit_str, usage_str)
  @recent_limit, @daily_limit = limit_str.to_s.split(',').map(&:to_i)
  @recent_usage, @daily_usage = usage_str.to_s.split(',').map(&:to_i)
end

Instance Attribute Details

#daily_limitObject (readonly)

Returns the value of attribute daily_limit.



15
16
17
# File 'lib/strava/usage.rb', line 15

def daily_limit
  @daily_limit
end

#daily_usageObject (readonly)

Returns the value of attribute daily_usage.



15
16
17
# File 'lib/strava/usage.rb', line 15

def daily_usage
  @daily_usage
end

#recent_limitObject (readonly)

Returns the value of attribute recent_limit.



15
16
17
# File 'lib/strava/usage.rb', line 15

def recent_limit
  @recent_limit
end

#recent_usageObject (readonly)

Returns the value of attribute recent_usage.



15
16
17
# File 'lib/strava/usage.rb', line 15

def recent_usage
  @recent_usage
end

Instance Method Details

#daily_pctFloat

Percentage of daily limit used.

Returns:

  • (Float)

    Between 0.0 and 1.0



32
33
34
# File 'lib/strava/usage.rb', line 32

def daily_pct
  @daily_usage.fdiv(@daily_limit)
end

#recent_pctFloat

Percentage of recent limit used.

Returns:

  • (Float)

    Between 0.0 and 1.0



25
26
27
# File 'lib/strava/usage.rb', line 25

def recent_pct
  @recent_usage.fdiv(@recent_limit)
end