dblock / strava-ruby-client

A complete Ruby client for the Strava API v3.
https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html
MIT License
97 stars 22 forks source link

athlete_activities should return [Strava::Models::SummaryActivity] and not [Strava::Models::Activity] #24

Open ccoffey opened 4 years ago

ccoffey commented 4 years ago

This is easiest to explain by example:

activity = client.athlete_activities.last

activity.class
=> Strava::Models::Activity

activity.id
=> 2957731094

activity.name
=> "Morning Run"

# This is actually a SummaryActivity (see here https://developers.strava.com/docs/reference/#api-models-SummaryActivity) and so its missing certain fields like description
activity.description
=> nil
activity = client.activity(2957731094)

activity.class
=> Strava::Models::Activity

activity.id
=> 2957731094

activity.name
=> "Morning Run"

# This is actually a DetailedActivity (see here https://developers.strava.com/docs/reference/#api-models-DetailedActivity) and so it contains data for fields like description
=> "What a beautiful day for a run"

My work around for this API weirdness is:

client.athlete_activities(per_page: 30) do |activity_summary|
  activity = client.activity(activity_summary.id)
end

But I think it would be much clearer if client.athlete_activities returned [Strava::Models::SummaryActivity] and client.activity returned a Strava::Models::DetailedActivity.

What do you think?

dblock commented 4 years ago

There's a lot of summary/detail situations in Strava API and for whatever reason I had chosen not to rebuild that hierarchy in this client. I would be open to refactoring that, possibly inheriting DetailedActivity from SummaryActivity or including it and delegating. Give it a shot.