Skip to content

Commit 67c724b

Browse files
dillon-cosimonneutert
authored andcommitted
added activity photos back
1 parent 3d27bad commit 67c724b

File tree

7 files changed

+174
-14
lines changed

7 files changed

+174
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### 2.1.1 (Next)
22

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

57
### 2.1.0 (2024/3/20)

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gemspec
66

77
group :development, :test do
88
gem 'dotenv'
9+
gem 'faraday-retry'
910
gem 'gpx'
1011
gem 'multi_xml'
1112
gem 'polylines'

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
1414
- [Activities](#activities)
1515
- [Create an Activity](#create-an-activity)
1616
- [Get Activity](#get-activity)
17+
- [List Activity Photos](#list-activity-photos)
1718
- [List Activity Comments](#list-activity-comments)
1819
- [List Activity Kudoers](#list-activity-kudoers)
1920
- [List Activity Laps](#list-activity-laps)
@@ -149,6 +150,31 @@ google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadm
149150

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

153+
#### List Activity Photos
154+
155+
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).
156+
157+
```ruby
158+
photos = client.activity_photos(1982980795) # => Array[Strava::Models::Photo]
159+
# in order to request a certain size (by default it will return the biggest size possible):
160+
# photos = client.activity_photos(1982980795, {size: 1920}) # => Array[Strava::Models::Photo]
161+
162+
photo = photos.first # => Strava::Models::Photo
163+
164+
photo.id # => nil
165+
photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
166+
photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
167+
photo.athlete_id # => 26_462_176
168+
photo.activity_id # => 1_946_417_534
169+
photo.activity_name # => 'TCS NYC Marathon 2018'
170+
photo.created_at # => Time
171+
photo.uploaded_at # => Time
172+
photo.sizes # => { '0' => [29, 64] }
173+
photo.default_photo # => false
174+
```
175+
176+
See [Strava::Models::Photo](lib/strava/models/photo.rb) for all available properties.
177+
152178
#### List Activity Comments
153179

154180
Returns the comments on the given activity.

UPGRADING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ client = Strava::Api::Client.new(ca_file: OpenSSL::X509::DEFAULT_CERT_FILE, ca_p
2525
- 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.
2626
- 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.
2727
- 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.
28+
- 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.
29+
2830

2931
### Upgrading to >= 1.0.0
3032

lib/strava/api/endpoints/activities.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ def activity_comments(id_or_options, options = {}, &block)
3737
paginate "activities/#{id}/comments", options, Strava::Models::Comment, &block
3838
end
3939

40+
#
41+
# List activity photos.
42+
#
43+
# @option options [String] :id
44+
# Activity id.
45+
# @option options [Integer] :page
46+
# Page number.
47+
# @option options [Integer] :per_page
48+
# Number of items per page. Defaults to 30.
49+
#
50+
def activity_photos(id_or_options, options = {}, &block)
51+
id, options = parse_args(id_or_options, options)
52+
options[:size] = 5000 unless options[:size] # to retrieve full size photos
53+
paginate "activities/#{id}/photos", options, Strava::Models::Photo, &block
54+
end
55+
4056
#
4157
# List activity kudoers.
4258
#

spec/fixtures/strava/client/activity_photos.yml

Lines changed: 95 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Strava::Api::Client#activity_photos', vcr: { cassette_name: 'client/activity_photos' } do
6+
include_context 'API client'
7+
it 'returns activity photos' do
8+
activity_photos = client.activity_photos(id: 7_287_327_028)
9+
expect(activity_photos).to be_a Enumerable
10+
expect(activity_photos.count).to eq 2
11+
activity_photo = activity_photos.first
12+
expect(activity_photo.id).to eq nil
13+
expect(activity_photo.unique_id).to eq 'f5ebd6e7-8c87-4478-86ce-ce5cf31cf519'
14+
expect(activity_photo.urls).to eq('5000' => 'https://dgtzuqphqg23d.cloudfront.net/3wt2DyGHKHX6gJSXzpAcVdEI1QE2luP9xoDLD0CX2w4-2048x1536.jpg')
15+
expect(activity_photo.source).to eq 1
16+
expect(activity_photo.athlete_id).to eq 24_776_507
17+
expect(activity_photo.activity_id).to eq 7_287_327_028
18+
expect(activity_photo.activity_name).to eq 'Die Rückkehr der Cornichons! 🥒'
19+
expect(activity_photo.resource_state).to eq 2
20+
expect(activity_photo.caption).to eq ''
21+
expect(activity_photo.created_at).to be_a Time
22+
expect(activity_photo.created_at_local).to be_a Time
23+
expect(activity_photo.uploaded_at).to be_a Time
24+
expect(activity_photo.sizes).to eq('5000' => [2048, 1536])
25+
expect(activity_photo.default_photo).to be true
26+
end
27+
it 'returns activity photos by id' do
28+
activity_photos = client.activity_photos(3_958_491_750)
29+
expect(activity_photos).to be_a Enumerable
30+
expect(activity_photos.count).to eq 1
31+
end
32+
end

0 commit comments

Comments
 (0)