Module: Strava
- Defined in:
- lib/strava.rb,
lib/strava/lap.rb,
lib/strava/base.rb,
lib/strava/club.rb,
lib/strava/gear.rb,
lib/strava/error.rb,
lib/strava/photo.rb,
lib/strava/route.rb,
lib/strava/usage.rb,
lib/strava/client.rb,
lib/strava/stream.rb,
lib/strava/athlete.rb,
lib/strava/comment.rb,
lib/strava/segment.rb,
lib/strava/version.rb,
lib/strava/activity.rb,
lib/strava/stream_set.rb,
lib/strava/group_event.rb,
lib/strava/leaderboard.rb,
lib/strava/running_race.rb,
lib/strava/segment_effort.rb,
lib/strava/club_announcement.rb,
lib/strava/leaderboard_entry.rb,
lib/strava/adapters/httparty_adapter.rb
Defined Under Namespace
Modules: Adapters Classes: AccessError, Activity, Athlete, Base, Client, Club, ClubAnnouncement, Comment, Error, Gear, GroupEvent, Lap, Leaderboard, LeaderboardEntry, Photo, Route, RunningRace, Segment, SegmentEffort, Stream, StreamSet, Usage
Constant Summary collapse
- VERSION =
"0.1.0"
- STRAVA_API_DATE =
latest supported update to Strava API
'April 10th, 2017'
Class Attribute Summary collapse
-
.client_id ⇒ Integer, String
Strava Application ID.
-
.client_secret ⇒ String
Strava Application secret.
Class Method Summary collapse
-
.model(as: :strava_athlete, via: :access_token, id: nil) ⇒ Module
Helper for model classes.
Class Attribute Details
.client_id ⇒ Integer, String
Returns Strava Application ID.
71 72 73 |
# File 'lib/strava.rb', line 71 def client_id @client_id ||= ENV['STRAVA_CLIENT_ID'] end |
.client_secret ⇒ String
Returns Strava Application secret.
75 76 77 |
# File 'lib/strava.rb', line 75 def client_secret @client_secret ||= ENV['STRAVA_CLIENT_SECRET'] end |
Class Method Details
.model(as: :strava_athlete, via: :access_token, id: nil) ⇒ Module
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
54 55 56 57 58 59 60 61 62 63 |
# 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 |