huginn_strava_agent 0.1.10 → 0.1.12
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 +4 -4
- data/lib/huginn_strava_agent/strava_agent.rb +32 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e58dd075a0272e7e2db4245f15f604b13d300362d2b639a07de53406c9e6bc6d
|
4
|
+
data.tar.gz: 838eaaf3790536a3af4961f47622bfa4676d75cd06e5cdf120ceef6812b481d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4cb08fe89928ab9dba767ac2508c410d1f106f0cbba4b7d12b865697f76441fe003b977cd00cdeac8043870a10686e4b7ede302b5b3d2a7a802fd4402e6cd7
|
7
|
+
data.tar.gz: ff1508ad1a3ed12c1c8710ae738b591641d7f8eddd56ad76f14f818471893f7be30843df3bb205181fba3a281e612b1ef95f01f8f4ae135a4330921254555a23
|
@@ -13,9 +13,11 @@ module Agents
|
|
13
13
|
|
14
14
|
`debug` is used for verbose mode.
|
15
15
|
|
16
|
-
`bearer_token` is mandatory for authentication.
|
16
|
+
`bearer_token` is mandatory for authentication (to avoid issue when refresh is needed, continue to use the default value for this field).
|
17
17
|
|
18
|
-
`refresh_token` is needed to refresh your token.
|
18
|
+
`refresh_token` is needed to refresh your token (to avoid issue when refresh is needed, continue to use the default value for this field).
|
19
|
+
|
20
|
+
`per_page` is the number of result per page when possible.
|
19
21
|
|
20
22
|
`client_id` is mandatory for authentication.
|
21
23
|
|
@@ -99,8 +101,9 @@ module Agents
|
|
99
101
|
'type' => 'get_activities',
|
100
102
|
'client_id' => '',
|
101
103
|
'client_secret' => '',
|
102
|
-
'refresh_token' => '',
|
103
|
-
'bearer_token' => '',
|
104
|
+
'refresh_token' => '{% credential strava_refresh_token %}',
|
105
|
+
'bearer_token' => '{% credential strava_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
|
@@ -160,6 +168,12 @@ module Agents
|
|
160
168
|
|
161
169
|
private
|
162
170
|
|
171
|
+
def set_credential(name, value)
|
172
|
+
c = user.user_credentials.find_or_initialize_by(credential_name: name)
|
173
|
+
c.credential_value = value
|
174
|
+
c.save!
|
175
|
+
end
|
176
|
+
|
163
177
|
def log_curl_output(code,body)
|
164
178
|
|
165
179
|
log "request status : #{code}"
|
@@ -194,6 +208,18 @@ module Agents
|
|
194
208
|
log_curl_output(response.code,response.body)
|
195
209
|
|
196
210
|
payload = JSON.parse(response.body)
|
211
|
+
if interpolated['refresh_token'] != payload['refresh_token']
|
212
|
+
set_credential("strava_refresh_token", payload['refresh_token'])
|
213
|
+
if interpolated['debug'] == 'true'
|
214
|
+
log "strava_refresh_token credential updated"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
if interpolated['bearer_token'] != payload['access_token']
|
218
|
+
set_credential("strava_bearer_token", payload['access_token'])
|
219
|
+
if interpolated['debug'] == 'true'
|
220
|
+
log "strava_bearer_token credential updated"
|
221
|
+
end
|
222
|
+
end
|
197
223
|
memory['expires_at'] = payload['expires_at']
|
198
224
|
|
199
225
|
end
|
@@ -212,13 +238,12 @@ module Agents
|
|
212
238
|
log "refresh not needed"
|
213
239
|
end
|
214
240
|
end
|
215
|
-
|
216
241
|
end
|
217
242
|
|
218
243
|
def get_activities()
|
219
244
|
|
220
245
|
check_token_validity()
|
221
|
-
uri = URI.parse("https://www.strava.com/api/v3/athlete/activities")
|
246
|
+
uri = URI.parse("https://www.strava.com/api/v3/athlete/activities?per_page=#{interpolated['per_page']}")
|
222
247
|
request = Net::HTTP::Get.new(uri)
|
223
248
|
request["Authorization"] = "Bearer #{interpolated['bearer_token']}"
|
224
249
|
|
@@ -237,7 +262,7 @@ module Agents
|
|
237
262
|
if payload != memory['last_status']
|
238
263
|
payload.each do |activity|
|
239
264
|
found = false
|
240
|
-
if !memory['last_status'].nil? and memory['last_status']
|
265
|
+
if !memory['last_status'].nil? and memory['last_status'].present?
|
241
266
|
last_status = memory['last_status']
|
242
267
|
if interpolated['debug'] == 'true'
|
243
268
|
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.
|
4
|
+
version: 0.1.12
|
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-
|
11
|
+
date: 2023-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|