Skip to content

Commit

Permalink
added activity photos back
Browse files Browse the repository at this point in the history
  • Loading branch information
dillon-co authored and simonneutert committed Sep 16, 2024
1 parent 3d27bad commit 3b667cb
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### 2.1.1 (Next)

* [#84](https://github.com/dblock/strava-ruby-client/pull/84): Adds back activity photos (finished PR #83) - [@simonneutert](https://github.com/simonneutert)
* [#83](https://github.com/dblock/strava-ruby-client/pull/83): Adds back activity photos - [@dillon-co](https://github.com/dillon-co)
* Your contribution here.

### 2.1.0 (2024/3/20)
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gemspec

group :development, :test do
gem 'dotenv'
gem 'faraday-retry'
gem 'gpx'
gem 'multi_xml'
gem 'polylines'
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
- [Activities](#activities)
- [Create an Activity](#create-an-activity)
- [Get Activity](#get-activity)
- [List Activity Photos](#list-activity-photos)
- [List Activity Comments](#list-activity-comments)
- [List Activity Kudoers](#list-activity-kudoers)
- [List Activity Laps](#list-activity-laps)
Expand Down Expand Up @@ -149,6 +150,31 @@ google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadm

See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.

#### List Activity Photos

Returns the photos on the given activity. This API is undocumented in Strava's docs. But there is a discussion in the [strava community hub](https://communityhub.strava.com/t5/developer-discussions/download-all-photos-of-my-own-activities/m-p/11262).

```ruby
photos = client.activity_photos(1982980795) # => Array[Strava::Models::Photo]
# in order to request a certain size (by default it will return the biggest size possible):
# photos = client.activity_photos(1982980795, {size: 1920}) # => Array[Strava::Models::Photo]

photo = photos.first # => Strava::Models::Photo

photo.id # => nil
photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
photo.athlete_id # => 26_462_176
photo.activity_id # => 1_946_417_534
photo.activity_name # => 'TCS NYC Marathon 2018'
photo.created_at # => Time
photo.uploaded_at # => Time
photo.sizes # => { '0' => [29, 64] }
photo.default_photo # => false
```

See [Strava::Models::Photo](lib/strava/models/photo.rb) for all available properties.

#### List Activity Comments

Returns the comments on the given activity.
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ client = Strava::Api::Client.new(ca_file: OpenSSL::X509::DEFAULT_CERT_FILE, ca_p
- Uploading a file using `create_upload` requires you to check its process, using `client.updload('your-unique-upload-id')`. A successful upload does just mean, that the file was accepted. The Processing of the file is an independent process on Strava's side. From now on, `client.updload('your-unique-upload-id')` will raise `Strava::Errors::UploadError`, if Strava failed processing the file, e.g. it being a duplicate.
- Exceeded Ratelimits (HTTP Status: 429) do now raise a customized Error `Strava::Errors::RatelimitError`. You can use the `Strava::Api::Ratelimit` object coming with the error, for further inspection of your current ratelimits.
- The method `Client#activity_photos` to retrieve an activity's photos has been removed. The Strava API offers no official support for this. See [#76](https://github.com/dblock/strava-ruby-client/issues/76) for details.
- The method `Client#activity_photos` to retrieve an activity's photos has been added back. The Strava API does actually offer undocumented support for this. It's just finicky. See [this discussion](https://communityhub.strava.com/t5/developer-discussions/download-all-photos-of-my-own-activities/m-p/11262) for details.


### Upgrading to >= 1.0.0

Expand Down
16 changes: 16 additions & 0 deletions lib/strava/api/endpoints/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ def activity_comments(id_or_options, options = {}, &block)
paginate "activities/#{id}/comments", options, Strava::Models::Comment, &block
end

#
# List activity photos.
#
# @option options [String] :id
# Activity id.
# @option options [Integer] :page
# Page number.
# @option options [Integer] :per_page
# Number of items per page. Defaults to 30.
#
def activity_photos(id_or_options, options = {}, &block)
id, options = parse_args(id_or_options, options)
options[:size] = 5000 unless options[:size] # to retrieve full size photos
paginate "activities/#{id}/photos", options, Strava::Models::Photo, &block
end

#
# List activity kudoers.
#
Expand Down
109 changes: 95 additions & 14 deletions spec/fixtures/strava/client/activity_photos.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Strava::Api::Client#activity_photos', vcr: { cassette_name: 'client/activity_photos' } do
include_context 'API client'
it 'returns activity photos' do
activity_photos = client.activity_photos(id: 7_287_327_028)
expect(activity_photos).to be_a Enumerable
expect(activity_photos.count).to eq 2
activity_photo = activity_photos.first
expect(activity_photo.id).to eq nil
expect(activity_photo.unique_id).to eq 'f5ebd6e7-8c87-4478-86ce-ce5cf31cf519'
expect(activity_photo.urls).to eq('5000' => 'https://dgtzuqphqg23d.cloudfront.net/3wt2DyGHKHX6gJSXzpAcVdEI1QE2luP9xoDLD0CX2w4-2048x1536.jpg')
expect(activity_photo.source).to eq 1
expect(activity_photo.athlete_id).to eq 24_776_507
expect(activity_photo.activity_id).to eq 7_287_327_028
expect(activity_photo.activity_name).to eq 'Die Rückkehr der Cornichons! 🥒'
expect(activity_photo.resource_state).to eq 2
expect(activity_photo.caption).to eq ''
expect(activity_photo.created_at).to be_a Time
expect(activity_photo.created_at_local).to be_a Time
expect(activity_photo.uploaded_at).to be_a Time
expect(activity_photo.sizes).to eq('5000' => [2048, 1536])
expect(activity_photo.default_photo).to be true
end
it 'returns activity photos by id' do
activity_photos = client.activity_photos(3_958_491_750)
expect(activity_photos).to be_a Enumerable
expect(activity_photos.count).to eq 1
end
end

0 comments on commit 3b667cb

Please sign in to comment.