huginn_strava_agent 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2806334223a93f535eec627c84537b3d30affacf91ade6df381380d3c33eda2
4
- data.tar.gz: 55cb8e7042f5661eaf3b5f98b4f4f69e2a757973f12c031a608abb4e21c4042b
3
+ metadata.gz: cc6684033edfcf1fa8b4b600fc5eac5d6f217bccb063c45972a5d4295d6d23d1
4
+ data.tar.gz: f9549083e22ad194108b71a30eb99f261807cbb60a4fa0c4d90302bc91f0b902
5
5
  SHA512:
6
- metadata.gz: 6fb6f5d192013b1e4732c1ac02ed0a210cf727c4d60dd283ab9abbf25d546135fa75629fb142aad6dc78e4386ba07c36883a10d8aef81ac06204c51f7e7d02a8
7
- data.tar.gz: feb7d03492de0d0be57a8ab675b302b6ea70088e5861b9ee847b05614666191bc4bad8fe6ca7ef6f7fa4b4cb9c0ff0187490d1ae158eb807e2ddfe7570828eb6
6
+ metadata.gz: f4d13b291a2220746b6c6a9244502301806ded70cafcaa5e4c9d686b18da69de85b4e13ccb7d1b06f2409ce961ac6edf03103ffc42295e03e9e0b988412b546e
7
+ data.tar.gz: 49901394e2ed814d70742704ca17986de380123a70c68545a3679d337c744027293df23e2c0a71ce332c2e95860d8da93120b503619c107001321291d0f91406
@@ -17,6 +17,8 @@ module Agents
17
17
 
18
18
  `refresh_token` is needed to refresh your token.
19
19
 
20
+ `per_page` is the number of result per page when possible.
21
+
20
22
  `client_id` is mandatory for authentication.
21
23
 
22
24
  `client_secret` is mandatory for authentication.
@@ -101,6 +103,7 @@ module Agents
101
103
  'client_secret' => '',
102
104
  'refresh_token' => '',
103
105
  'bearer_token' => '',
106
+ 'per_page' => '5',
104
107
  'debug' => 'false',
105
108
  'expected_receive_period_in_days' => '2',
106
109
  }
@@ -111,11 +114,16 @@ module Agents
111
114
  form_configurable :client_secret, type: :string
112
115
  form_configurable :refresh_token, type: :string
113
116
  form_configurable :bearer_token, type: :string
117
+ form_configurable :per_page, type: :string
114
118
  form_configurable :debug, type: :boolean
115
119
  form_configurable :expected_receive_period_in_days, type: :string
116
120
  def validate_options
117
121
  errors.add(:base, "type has invalid value: should be 'token_refresh' 'get_activities'") if interpolated['type'].present? && !%w(token_refresh get_activities).include?(interpolated['type'])
118
122
 
123
+ unless options['per_page'].present? || !['get_activities'].include?(options['type'])
124
+ errors.add(:base, "per_page is a required field")
125
+ end
126
+
119
127
  unless options['client_id'].present?
120
128
  errors.add(:base, "client_id is a required field")
121
129
  end
@@ -194,16 +202,16 @@ module Agents
194
202
  log_curl_output(response.code,response.body)
195
203
 
196
204
  payload = JSON.parse(response.body)
197
- memory['expires_at'] = payload['expires_at']
205
+ memory['credentials'] = payload
198
206
 
199
207
  end
200
208
 
201
209
  def check_token_validity()
202
210
 
203
- if memory['expires_at'].nil?
211
+ if memory['credentials'].nil?
204
212
  token_refresh()
205
213
  else
206
- timestamp_to_compare = memory['expires_at']
214
+ timestamp_to_compare = memory['credentials']['expires_at']
207
215
  current_timestamp = Time.now.to_i
208
216
  difference_in_hours = (timestamp_to_compare - current_timestamp) / 3600.0
209
217
  if difference_in_hours < 2
@@ -218,7 +226,7 @@ module Agents
218
226
  def get_activities()
219
227
 
220
228
  check_token_validity()
221
- uri = URI.parse("https://www.strava.com/api/v3/athlete/activities")
229
+ uri = URI.parse("https://www.strava.com/api/v3/athlete/activities?per_page=#{interpolated['per_page']}")
222
230
  request = Net::HTTP::Get.new(uri)
223
231
  request["Authorization"] = "Bearer #{interpolated['bearer_token']}"
224
232
 
@@ -237,7 +245,7 @@ module Agents
237
245
  if payload != memory['last_status']
238
246
  payload.each do |activity|
239
247
  found = false
240
- if !memory['last_status'].nil? and memory['last_status']['activity'].present?
248
+ if !memory['last_status'].nil? and memory['last_status'].present?
241
249
  last_status = memory['last_status']
242
250
  if interpolated['debug'] == 'true'
243
251
  log "last_status"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huginn_strava_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Germain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-25 00:00:00.000000000 Z
11
+ date: 2023-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler