module Strava
Constants
- STRAVA_API_DATE
- VERSION
Attributes
client_id[W]
@return [Integer, String] Strava
Application ID
client_secret[W]
@return [String] Strava
Application secret
Public Class Methods
client_id()
click to toggle source
@return [Integer, String] Strava
Application ID
# File lib/strava.rb, line 71 def client_id @client_id ||= ENV['STRAVA_CLIENT_ID'] end
client_secret()
click to toggle source
@return [String] Strava
Application secret
# File lib/strava.rb, line 75 def client_secret @client_secret ||= ENV['STRAVA_CLIENT_SECRET'] end
model(as: :strava_athlete, via: :access_token, id: nil)
click to toggle source
Helper for model classes. Allows for convenient instantiation of current athlete. This is completely agnostic to class type, it can be a DB model, a PORO, etc.
Usage:
class Account < ApplicationRecord include Strava.model as: :athlete, via: :token, id: :strava_id end ca = Account.find(1).athlete # => Strava::Athlete
Can also perform lookup through another method:
class User < ApplicationRecord has_one :account include Strava.model as: :athlete, via: 'account.token', id: 'account.strava_id' end
@param as [Symbol] method to define to return current athlete @param via [Symbol, String] method to lookup access token @param id [Symbol, String] method to lookup Strava
ID @return [Module] module to be included in the calling class
# File lib/strava.rb, line 54 def model(as: :strava_athlete, via: :access_token, id: nil) Module.new.tap do |mod| str = <<~EOF def self.included(base) base.send(:define_method, :#{as}) { ::Strava::Athlete.new(#{id ? "{'id' => #{id}}" : '{}' }, token: #{via}, current: true) } end EOF mod.class_eval str end end