strava-ruby-client 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +1 -1
  4. data/bin/strava-oauth-token +2 -1
  5. data/bin/strava-webhooks +5 -4
  6. data/lib/strava/api/client.rb +2 -0
  7. data/lib/strava/api/config.rb +2 -0
  8. data/lib/strava/api/cursor.rb +3 -3
  9. data/lib/strava/api/endpoints/activities.rb +2 -0
  10. data/lib/strava/api/endpoints/athletes.rb +2 -0
  11. data/lib/strava/api/endpoints/clubs.rb +2 -0
  12. data/lib/strava/api/endpoints/gears.rb +2 -0
  13. data/lib/strava/api/endpoints/oauth.rb +2 -0
  14. data/lib/strava/api/endpoints/routes.rb +2 -0
  15. data/lib/strava/api/endpoints/running_races.rb +2 -0
  16. data/lib/strava/api/endpoints/segment_efforts.rb +2 -0
  17. data/lib/strava/api/endpoints/segments.rb +2 -0
  18. data/lib/strava/api/endpoints/streams.rb +5 -3
  19. data/lib/strava/api/endpoints/uploads.rb +2 -0
  20. data/lib/strava/errors/fault.rb +2 -0
  21. data/lib/strava/logger.rb +3 -1
  22. data/lib/strava/models/achievement.rb +2 -0
  23. data/lib/strava/models/activity.rb +6 -7
  24. data/lib/strava/models/activity_stats.rb +2 -0
  25. data/lib/strava/models/activity_total.rb +2 -0
  26. data/lib/strava/models/activity_zone.rb +2 -0
  27. data/lib/strava/models/athlete.rb +2 -0
  28. data/lib/strava/models/authorization.rb +2 -0
  29. data/lib/strava/models/club.rb +2 -0
  30. data/lib/strava/models/club_admin.rb +2 -0
  31. data/lib/strava/models/club_event.rb +2 -0
  32. data/lib/strava/models/club_member.rb +2 -0
  33. data/lib/strava/models/comment.rb +2 -0
  34. data/lib/strava/models/explorer_segment.rb +2 -0
  35. data/lib/strava/models/gear.rb +2 -0
  36. data/lib/strava/models/heart_rate_zone_ranges.rb +2 -0
  37. data/lib/strava/models/kudoser.rb +2 -0
  38. data/lib/strava/models/lap.rb +3 -1
  39. data/lib/strava/models/map.rb +2 -0
  40. data/lib/strava/models/mixins/distance.rb +6 -4
  41. data/lib/strava/models/mixins/elevation.rb +2 -0
  42. data/lib/strava/models/mixins/start_date_local.rb +70 -0
  43. data/lib/strava/models/mixins/time.rb +9 -7
  44. data/lib/strava/models/model.rb +2 -0
  45. data/lib/strava/models/photo.rb +2 -0
  46. data/lib/strava/models/photos.rb +2 -0
  47. data/lib/strava/models/power_zone_ranges.rb +2 -0
  48. data/lib/strava/models/route.rb +2 -0
  49. data/lib/strava/models/running_race.rb +2 -0
  50. data/lib/strava/models/segment.rb +2 -0
  51. data/lib/strava/models/segment_effort.rb +3 -1
  52. data/lib/strava/models/segment_leaderboard.rb +2 -0
  53. data/lib/strava/models/segment_leaderboard_entry.rb +3 -1
  54. data/lib/strava/models/segment_stats.rb +2 -0
  55. data/lib/strava/models/similar_activities.rb +2 -0
  56. data/lib/strava/models/split.rb +2 -0
  57. data/lib/strava/models/stream.rb +2 -0
  58. data/lib/strava/models/stream_set.rb +2 -0
  59. data/lib/strava/models/timed_zone_range.rb +2 -0
  60. data/lib/strava/models/token.rb +2 -0
  61. data/lib/strava/models/trend.rb +2 -0
  62. data/lib/strava/models/upload.rb +2 -0
  63. data/lib/strava/models/zone_range.rb +2 -0
  64. data/lib/strava/models/zones.rb +2 -0
  65. data/lib/strava/oauth/client.rb +2 -0
  66. data/lib/strava/oauth/config.rb +2 -0
  67. data/lib/strava/version.rb +3 -1
  68. data/lib/strava/web/client.rb +2 -0
  69. data/lib/strava/web/config.rb +2 -0
  70. data/lib/strava/web/connection.rb +2 -0
  71. data/lib/strava/web/raise_error.rb +4 -2
  72. data/lib/strava/web/request.rb +2 -0
  73. data/lib/strava/webhooks/client.rb +2 -0
  74. data/lib/strava/webhooks/config.rb +2 -0
  75. data/lib/strava/webhooks/models/challenge.rb +2 -0
  76. data/lib/strava/webhooks/models/event.rb +2 -0
  77. data/lib/strava/webhooks/models/subscription.rb +2 -0
  78. data/lib/strava-ruby-client.rb +4 -0
  79. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c405363163b2332c696362fcaecc55b27ebcc9cc36dc78bfff54059d4433a580
4
- data.tar.gz: a555beb0bf2072cf7cfe40a8178e72d0d4bc846963446704a642e344d46f780e
3
+ metadata.gz: f1fd53d322d249bebc5d46c0edaaf9fd6d8831ba2c23134c0450203e078965d6
4
+ data.tar.gz: fa26523a8f6d1987700b414131bd0a754154f734cdf7f21be6988de2fd1a1271
5
5
  SHA512:
6
- metadata.gz: ca090cb5fc5553cbf275f36e797e90cbede14cbe8c400520b79a4ddd061719878e3f1b38e13efbf948bab884f5ab62f8d5b5e49812cc154af155e78bd3601dfc
7
- data.tar.gz: 662f42daf772d75c032a2f228f4d0a2f268c8de68a9ea91b95cae9840d0a185c3a159df5023b182026fd47deaa5909494b06d3b03e91cd85ac74bed66a249239
6
+ metadata.gz: 65e071fafa80e86f019290774a902a53837bc9a6f4aa15f50306bdf0807fdd929a509638832109cfe2e4380dfa921a4e205623252b4651ab780d6109dfd1f3a7
7
+ data.tar.gz: d0cada36caa3cd5beac43605a3efc55ea79f4603184fdfa1df614418a6b9a59e6b8cff7365b0e6f9bc59ddf036d288480d18d81e5165f35f69b2c912502759b7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.4.3 (2022/03/21)
2
+
3
+ * [#51](https://github.com/dblock/strava-ruby-client/pull/51): Ensure support for large Integer IDs - [@simonneutert](https://github.com/simonneutert).
4
+ * [#53](https://github.com/dblock/strava-ruby-client/pull/53): Upgraded to RuboCop 1.26.0 - [@dblock](https://github.com/dblock).
5
+ * [#46](https://github.com/dblock/strava-ruby-client/pull/46): Add missing `activity:read` scope from `strava-oauth-token` - [@xaviershay](https://github.com/xaviershay).
6
+
1
7
  ### 0.4.2 (2021/10/03)
2
8
 
3
9
  * [#45](https://github.com/dblock/strava-ruby-client/pull/45): Added `Gear#frame_type` `#retired` `#weight` - [@deuber](https://github.com/deuber).
data/README.md CHANGED
@@ -2,7 +2,7 @@ Strava Ruby Client
2
2
  ==================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/strava-ruby-client.svg)](https://badge.fury.io/rb/strava-ruby-client)
5
- [![Build Status](https://travis-ci.org/dblock/strava-ruby-client.svg?branch=master)](https://travis-ci.org/dblock/strava-ruby-client)
5
+ [![Test](https://github.com/dblock/strava-ruby-client/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/dblock/strava-ruby-client/actions/workflows/test.yml)
6
6
 
7
7
  A complete Ruby client for the [Strava API v3](https://developers.strava.com).
8
8
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'dotenv/load'
4
5
  require 'strava-ruby-client'
@@ -38,7 +39,7 @@ end
38
39
  redirect_url = client.authorize_url(
39
40
  redirect_uri: 'http://localhost:4242/',
40
41
  response_type: 'code',
41
- scope: 'read_all,activity:read_all,profile:read_all,profile:write,activity:write'
42
+ scope: 'read_all,activity:read,activity:read_all,profile:read_all,profile:write,activity:write'
42
43
  )
43
44
 
44
45
  server.logger.info "opening browser at #{redirect_url}\n"
data/bin/strava-webhooks CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'dotenv/load'
4
5
  require 'strava-ruby-client'
5
6
  require 'webrick'
6
7
 
7
- logger = ::Logger.new(STDOUT)
8
+ logger = ::Logger.new($stdout)
8
9
  logger.level = Logger::INFO
9
10
 
10
11
  client = Strava::Webhooks::Client.new(
@@ -14,7 +15,7 @@ client = Strava::Webhooks::Client.new(
14
15
  )
15
16
 
16
17
  case ARGV[0]
17
- when 'create' then
18
+ when 'create'
18
19
  callback_url = ARGV[1]
19
20
  raise 'Missing callback_url.' unless callback_url
20
21
 
@@ -37,11 +38,11 @@ when 'handle'
37
38
 
38
39
  server.mount_proc '/' do |req, res|
39
40
  case req.request_method
40
- when 'GET' then
41
+ when 'GET'
41
42
  challenge = Strava::Webhooks::Models::Challenge.new(req.query)
42
43
  res.content_type = 'application/json'
43
44
  res.body = challenge.response.to_json
44
- when 'POST' then
45
+ when 'POST'
45
46
  event = Strava::Webhooks::Models::Event.new(JSON.parse(req.body))
46
47
  server.logger.info event
47
48
  res.content_type = 'application/json'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  class Client < Strava::Web::Client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Config
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  class Cursor
4
6
  include Enumerable
5
7
 
6
- attr_reader :client
7
- attr_reader :path
8
- attr_reader :params
8
+ attr_reader :client, :path, :params
9
9
 
10
10
  def initialize(client, path, params = {})
11
11
  @client = client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -16,7 +18,7 @@ module Strava
16
18
  id, options = parse_args(id_or_options, options)
17
19
  query = options.dup
18
20
  query[:key_by_type] = true unless options.key?(:key_by_type)
19
- query[:keys] = options[:keys].join(',') if options[:keys] && options[:keys].is_a?(Array)
21
+ query[:keys] = options[:keys].join(',') if options[:keys].is_a?(Array)
20
22
  Strava::Models::StreamSet.new(get("activities/#{id}/streams", query))
21
23
  end
22
24
 
@@ -34,7 +36,7 @@ module Strava
34
36
  id, options = parse_args(id_or_options, options)
35
37
  query = options.dup
36
38
  query[:key_by_type] = true unless options.key?(:key_by_type)
37
- query[:keys] = options[:keys].join(',') if options[:keys] && options[:keys].is_a?(Array)
39
+ query[:keys] = options[:keys].join(',') if options[:keys].is_a?(Array)
38
40
  Strava::Models::StreamSet.new(get("segment_efforts/#{id}/streams", query))
39
41
  end
40
42
 
@@ -52,7 +54,7 @@ module Strava
52
54
  id, options = parse_args(id_or_options, options)
53
55
  query = options.dup
54
56
  query[:key_by_type] = true unless options.key?(:key_by_type)
55
- query[:keys] = options[:keys].join(',') if options[:keys] && options[:keys].is_a?(Array)
57
+ query[:keys] = options[:keys].join(',') if options[:keys].is_a?(Array)
56
58
  Strava::Models::StreamSet.new(get("segments/#{id}/streams", query))
57
59
  end
58
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Api
3
5
  module Endpoints
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Errors
3
5
  class Fault < ::Faraday::ClientError
data/lib/strava/logger.rb CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
 
3
5
  module Strava
4
6
  class Logger < ::Logger
5
7
  def self.logger
6
8
  @logger ||= begin
7
- logger = new STDOUT
9
+ logger = new $stdout
8
10
  logger.level = Logger::WARN
9
11
  logger
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Achievement < Model
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Activity < Model
4
- include Mixins::Distance
5
6
  include Mixins::Time
7
+ include Mixins::Distance
6
8
  include Mixins::Elevation
9
+ include Mixins::StartDateLocal
7
10
 
8
11
  property 'id'
9
12
  property 'resource_state'
@@ -16,7 +19,6 @@ module Strava
16
19
  property 'external_id'
17
20
  property 'upload_id'
18
21
  property 'start_date', transform_with: ->(v) { Time.parse(v) }
19
- property 'start_date_local', transform_with: ->(v) { Time.parse(v) }
20
22
  property 'timezone'
21
23
  property 'utc_offset'
22
24
  property 'start_latlng'
@@ -99,15 +101,14 @@ module Strava
99
101
 
100
102
  def type_emoji
101
103
  case type
102
- when 'Run' then '🏃'
103
- when 'Ride' then '🚴'
104
+ when 'Run', 'VirtualRun' then '🏃'
105
+ when 'Ride', 'EBikeRide', 'VirtualRide' then '🚴'
104
106
  when 'Swim' then '🏊'
105
107
  when 'Walk' then '🚶'
106
108
  when 'AlpineSki' then '⛷️'
107
109
  when 'BackcountrySki' then '🎿️'
108
110
  # when 'Canoeing' then ''
109
111
  # when 'Crossfit' then ''
110
- when 'EBikeRide' then '🚴'
111
112
  # when 'Elliptical' then ''
112
113
  # when 'Hike' then ''
113
114
  when 'IceSkate' then '⛸️'
@@ -123,8 +124,6 @@ module Strava
123
124
  # when 'StairStepper' then ''
124
125
  # when 'StandUpPaddling' then ''
125
126
  when 'Surfing' then '🏄'
126
- when 'VirtualRide' then '🚴'
127
- when 'VirtualRun' then '🏃'
128
127
  when 'WeightTraining' then '🏋️'
129
128
  # when 'Windsurf' then ''
130
129
  when 'Wheelchair' then '♿'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ActivityStats < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ActivityTotal < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ActivityZone < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Athlete < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Authorization < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Club < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ClubAdmin < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ClubEvent < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ClubMember < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Comment < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ExplorerSegment < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Gear < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class HeartRateZoneRanges < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Kudoser < Model
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Lap < Model
4
6
  include Mixins::Time
5
7
  include Mixins::Distance
6
8
  include Mixins::Elevation
9
+ include Mixins::StartDateLocal
7
10
 
8
11
  property 'id'
9
12
  property 'resource_state'
@@ -11,7 +14,6 @@ module Strava
11
14
  property 'activity', transform_with: ->(v) { Strava::Models::Activity.new(v) }
12
15
  property 'athlete', transform_with: ->(v) { Strava::Models::Athlete.new(v) }
13
16
  property 'start_date', transform_with: ->(v) { Time.parse(v) }
14
- property 'start_date_local', transform_with: ->(v) { Time.parse(v) }
15
17
  property 'start_index'
16
18
  property 'end_index'
17
19
  property 'average_speed'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Map < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  module Mixins
@@ -21,7 +23,7 @@ module Strava
21
23
  end
22
24
 
23
25
  def distance_in_miles_s
24
- return unless distance && distance.positive?
26
+ return unless distance&.positive?
25
27
 
26
28
  format('%gmi', format('%.2f', distance_in_miles))
27
29
  end
@@ -31,13 +33,13 @@ module Strava
31
33
  end
32
34
 
33
35
  def distance_in_yards_s
34
- return unless distance && distance.positive?
36
+ return unless distance&.positive?
35
37
 
36
38
  format('%gyd', format('%.1f', distance_in_yards))
37
39
  end
38
40
 
39
41
  def distance_in_meters_s
40
- return unless distance && distance.positive?
42
+ return unless distance&.positive?
41
43
 
42
44
  format('%gm', format('%d', distance_in_meters))
43
45
  end
@@ -47,7 +49,7 @@ module Strava
47
49
  end
48
50
 
49
51
  def distance_in_kilometers_s
50
- return unless distance && distance.positive?
52
+ return unless distance&.positive?
51
53
 
52
54
  format('%gkm', format('%.2f', distance_in_kilometers))
53
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  module Mixins
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strava
4
+ module Models
5
+ module Mixins
6
+ module StartDateLocal
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ property 'start_date_local', transform_with: ->(v) { ::Time.parse(v) }
11
+
12
+ def start_date_local
13
+ extracted_datetime = self['start_date_local']
14
+ # some strava object do not contain a timezone property i.e. `Lap`
15
+ timezone_shift = conditional_timezone(extracted_datetime)
16
+ ::Time.new(extracted_datetime.year,
17
+ extracted_datetime.month,
18
+ extracted_datetime.day,
19
+ extracted_datetime.hour,
20
+ extracted_datetime.min,
21
+ extracted_datetime.sec,
22
+ timezone_shift)
23
+ end
24
+
25
+ private
26
+
27
+ def conditional_timezone(extracted_datetime)
28
+ if key?(:timezone)
29
+ if timezone.include?('+')
30
+ timezone_shift_string('+')
31
+ elsif timezone.include?('-')
32
+ timezone_shift_string('-')
33
+ else
34
+ raise ArgumentError 'No operator of timezone correction detectable!'
35
+ end
36
+ else
37
+ calculate_timezone(extracted_datetime)
38
+ end
39
+ end
40
+
41
+ def calculate_timezone(extracted_datetime)
42
+ if start_date == extracted_datetime
43
+ timezone_diff_shift_string(0, '-')
44
+ elsif extracted_datetime < start_date
45
+ timezone_diff_shift_string((extracted_datetime - start_date), '-')
46
+ elsif extracted_datetime > start_date
47
+ timezone_diff_shift_string((extracted_datetime - start_date), '+')
48
+ else
49
+ raise ArgumentError 'No operator of timezone correction detectable!'
50
+ end
51
+ end
52
+
53
+ def timezone_shift_string(operator)
54
+ diff_hours = timezone.split(operator).last.to_i
55
+ "#{operator}#{format_int_leading_zero(diff_hours)}:00"
56
+ end
57
+
58
+ def timezone_diff_shift_string(time_diff, operator)
59
+ diff_hours = (time_diff.abs / 3600).to_i
60
+ "#{operator}#{format_int_leading_zero(diff_hours)}:00"
61
+ end
62
+
63
+ def format_int_leading_zero(int)
64
+ format('%02d', int)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  module Mixins
@@ -28,11 +30,11 @@ module Strava
28
30
  end
29
31
 
30
32
  def pace_per_100_yards_s
31
- convert_meters_per_second_to_pace average_speed, :"100yd"
33
+ convert_meters_per_second_to_pace average_speed, :'100yd'
32
34
  end
33
35
 
34
36
  def pace_per_100_meters_s
35
- convert_meters_per_second_to_pace average_speed, :"100m"
37
+ convert_meters_per_second_to_pace average_speed, :'100m'
36
38
  end
37
39
 
38
40
  def pace_per_kilometer_s
@@ -40,13 +42,13 @@ module Strava
40
42
  end
41
43
 
42
44
  def kilometer_per_hour_s
43
- return unless average_speed && average_speed.positive?
45
+ return unless average_speed&.positive?
44
46
 
45
47
  format('%.1fkm/h', average_speed * 3.6)
46
48
  end
47
49
 
48
50
  def miles_per_hour_s
49
- return unless average_speed && average_speed.positive?
51
+ return unless average_speed&.positive?
50
52
 
51
53
  format('%.1fmph', average_speed * 2.23694)
52
54
  end
@@ -73,13 +75,13 @@ module Strava
73
75
  # Convert speed (m/s) to pace (min/mile or min/km) in the format of 'x:xx'
74
76
  # http://yizeng.me/2017/02/25/convert-speed-to-pace-programmatically-using-ruby
75
77
  def convert_meters_per_second_to_pace(speed, unit = :mi)
76
- return unless speed && speed.positive?
78
+ return unless speed&.positive?
77
79
 
78
80
  total_seconds = case unit
79
81
  when :mi then 1609.344 / speed
80
82
  when :km then 1000 / speed
81
- when :"100yd" then 91.44 / speed
82
- when :"100m" then 100 / speed
83
+ when :'100yd' then 91.44 / speed
84
+ when :'100m' then 100 / speed
83
85
  end
84
86
  minutes, seconds = total_seconds.divmod(60)
85
87
  seconds = seconds.round
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  class Model < Hashie::Trash
3
5
  include Hashie::Extensions::IgnoreUndeclared
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Photo < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Photos < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class PowerZoneRanges < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Route < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class RunningRace < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Segment < Model
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class SegmentEffort < Model
4
6
  include Mixins::Distance
5
7
  include Mixins::Time
8
+ include Mixins::StartDateLocal
6
9
 
7
10
  property 'id'
8
11
  property 'resource_state'
@@ -10,7 +13,6 @@ module Strava
10
13
  property 'activity', transform_with: ->(v) { Strava::Models::Activity.new(v) }
11
14
  property 'athlete', transform_with: ->(v) { Strava::Models::Athlete.new(v) }
12
15
  property 'start_date', transform_with: ->(v) { Time.parse(v) }
13
- property 'start_date_local', transform_with: ->(v) { Time.parse(v) }
14
16
  property 'start_index'
15
17
  property 'end_index'
16
18
  property 'average_heartrate'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class SegmentLeaderboard < Model
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class SegmentLeaderboardEntry < Model
4
6
  include Mixins::Time
7
+ include Mixins::StartDateLocal
5
8
 
6
9
  property 'athlete_name'
7
10
  property 'start_date', transform_with: ->(v) { Time.parse(v) }
8
- property 'start_date_local', transform_with: ->(v) { Time.parse(v) }
9
11
  property 'rank'
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class SegmentStats < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class SimilarActivities < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Split < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Stream < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class StreamSet < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class TimedZoneRange < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Token < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Trend < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Upload < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class ZoneRange < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Models
3
5
  class Zones < Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module OAuth
3
5
  class Client < Strava::Web::Client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module OAuth
3
5
  module Config
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
- VERSION = '0.4.2'.freeze
4
+ VERSION = '0.4.3'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Web
3
5
  class Client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Web
3
5
  module Config
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Web
3
5
  module Connection
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Web
3
5
  module Response
4
6
  class RaiseError < ::Faraday::Response::Middleware
5
- ClientErrorStatuses = (400...600).freeze
7
+ CLIENT_ERROR_STATUSES = (400...600).freeze
6
8
 
7
9
  def on_complete(env)
8
10
  case env[:status]
@@ -11,7 +13,7 @@ module Strava
11
13
  when 407
12
14
  # mimic the behavior that we get with proxy requests with HTTPS
13
15
  raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
14
- when ClientErrorStatuses
16
+ when CLIENT_ERROR_STATUSES
15
17
  raise Strava::Errors::Fault, response_values(env)
16
18
  end
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Web
3
5
  module Request
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Webhooks
3
5
  class Client < Strava::Web::Client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Webhooks
3
5
  module Config
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Webhooks
3
5
  module Models
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Webhooks
3
5
  module Models
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Strava
2
4
  module Webhooks
3
5
  module Models
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
  require 'faraday_middleware'
3
5
  require 'json'
@@ -5,6 +7,7 @@ require 'logger'
5
7
  require 'hashie'
6
8
  require 'time'
7
9
 
10
+ require 'active_support'
8
11
  require 'active_support/core_ext/object/to_query'
9
12
  require 'active_support/core_ext/hash'
10
13
  require 'active_support/concern'
@@ -17,6 +20,7 @@ require_relative 'strava/errors/fault'
17
20
  require_relative 'strava/models/mixins/distance'
18
21
  require_relative 'strava/models/mixins/elevation'
19
22
  require_relative 'strava/models/mixins/time'
23
+ require_relative 'strava/models/mixins/start_date_local'
20
24
 
21
25
  require_relative 'strava/models/model'
22
26
  require_relative 'strava/models/token'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strava-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-03 00:00:00.000000000 Z
11
+ date: 2022-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,6 +116,7 @@ files:
116
116
  - lib/strava/models/map.rb
117
117
  - lib/strava/models/mixins/distance.rb
118
118
  - lib/strava/models/mixins/elevation.rb
119
+ - lib/strava/models/mixins/start_date_local.rb
119
120
  - lib/strava/models/mixins/time.rb
120
121
  - lib/strava/models/model.rb
121
122
  - lib/strava/models/photo.rb
@@ -154,7 +155,8 @@ files:
154
155
  homepage: http://github.com/dblock/strava-ruby-client
155
156
  licenses:
156
157
  - MIT
157
- metadata: {}
158
+ metadata:
159
+ rubygems_mfa_required: 'true'
158
160
  post_install_message:
159
161
  rdoc_options: []
160
162
  require_paths:
@@ -163,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
165
  requirements:
164
166
  - - ">="
165
167
  - !ruby/object:Gem::Version
166
- version: '0'
168
+ version: '2.5'
167
169
  required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  requirements:
169
171
  - - ">="