Class: RunSignupApi::Client
- Inherits:
-
Object
- Object
- RunSignupApi::Client
- Includes:
- HTTParty, RunSignup::DataCoercion
- Defined in:
- lib/run_signup_api/client.rb
Constant Summary collapse
- BASE_URL =
"https://runsignup.com/rest"
Instance Method Summary collapse
-
#default_params ⇒ Object
Params used by all API calls.
-
#get_race(race_id, **opts) ⇒ Object
RunSignup::Client.new.get_race(1, only_future_events: true, something_else: ‘234’).
- #get_races(**opts) ⇒ Object
-
#initialize(api_key: ENV['RUN_SIGNUP_API_KEY'], api_secret: ENV['RUN_SIGNUP_API_SECRET'], response_format: :json) ⇒ Client
constructor
A new instance of Client.
Methods included from RunSignup::DataCoercion
#coerce_for_api, #coerce_from_api, #coerce_value_for_api, #coerce_value_from_api
Constructor Details
#initialize(api_key: ENV['RUN_SIGNUP_API_KEY'], api_secret: ENV['RUN_SIGNUP_API_SECRET'], response_format: :json) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/run_signup_api/client.rb', line 10 def initialize api_key: ENV['RUN_SIGNUP_API_KEY'], api_secret: ENV['RUN_SIGNUP_API_SECRET'], response_format: :json @api_key, @api_secret, @response_format = api_key, api_secret, response_format end |
Instance Method Details
#default_params ⇒ Object
Params used by all API calls
15 16 17 18 19 20 21 |
# File 'lib/run_signup_api/client.rb', line 15 def default_params { api_key: @api_key, api_secret: @api_secret, format: @response_format } end |
#get_race(race_id, **opts) ⇒ Object
RunSignup::Client.new.get_race(1, only_future_events: true, something_else: ‘234’)
48 49 50 51 52 53 54 55 56 |
# File 'lib/run_signup_api/client.rb', line 48 def get_race race_id, **opts # Response in format # { # "race": { # "race_id": 33675, # "name": "\"ASL Run Series: 5K Walk\/Run\" ASL Deaf", # "last_date": "09\/29\/2018", RunSignup::Race.new(call_api('/race', opts.merge(race_id: race_id))['race']) end |
#get_races(**opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/run_signup_api/client.rb', line 23 def get_races **opts # Response in format # { # "races": [{ # "race": { # "race_id": 67504, # "name": "124th Boston Marathon: Fundraising for The Angel Fund, Supported by the Sharon Timlin Race to Cure ALS", # "last_date": "04\/15\/2019", # ... # } # }, # "race": { # "race_id": 67505, # "name": "Another race", # "last_date": "04\/16\/2019", # ... # } # }] # } call_api('/races', opts)['races'].map do |race| RunSignup::Race.new(race['race']) end end |