huginn_strava_agent 0.1.0 → 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 +4 -4
- data/lib/huginn_strava_agent/strava_agent.rb +20 -11
- 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: cc6684033edfcf1fa8b4b600fc5eac5d6f217bccb063c45972a5d4295d6d23d1
|
4
|
+
data.tar.gz: f9549083e22ad194108b71a30eb99f261807cbb60a4fa0c4d90302bc91f0b902
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,22 +202,23 @@ module Agents
|
|
194
202
|
log_curl_output(response.code,response.body)
|
195
203
|
|
196
204
|
payload = JSON.parse(response.body)
|
197
|
-
memory['
|
205
|
+
memory['credentials'] = payload
|
198
206
|
|
199
207
|
end
|
200
208
|
|
201
209
|
def check_token_validity()
|
202
210
|
|
203
|
-
|
204
|
-
|
205
|
-
current_timestamp = Time.now.to_i
|
206
|
-
|
207
|
-
difference_in_hours = (timestamp_to_compare - current_timestamp) / 3600.0
|
208
|
-
|
209
|
-
if difference_in_hours < 2
|
211
|
+
if memory['credentials'].nil?
|
210
212
|
token_refresh()
|
211
213
|
else
|
212
|
-
|
214
|
+
timestamp_to_compare = memory['credentials']['expires_at']
|
215
|
+
current_timestamp = Time.now.to_i
|
216
|
+
difference_in_hours = (timestamp_to_compare - current_timestamp) / 3600.0
|
217
|
+
if difference_in_hours < 2
|
218
|
+
token_refresh()
|
219
|
+
else
|
220
|
+
log "refresh not needed"
|
221
|
+
end
|
213
222
|
end
|
214
223
|
|
215
224
|
end
|
@@ -217,7 +226,7 @@ module Agents
|
|
217
226
|
def get_activities()
|
218
227
|
|
219
228
|
check_token_validity()
|
220
|
-
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']}")
|
221
230
|
request = Net::HTTP::Get.new(uri)
|
222
231
|
request["Authorization"] = "Bearer #{interpolated['bearer_token']}"
|
223
232
|
|
@@ -236,7 +245,7 @@ module Agents
|
|
236
245
|
if payload != memory['last_status']
|
237
246
|
payload.each do |activity|
|
238
247
|
found = false
|
239
|
-
if !memory['last_status'].nil? and memory['last_status']
|
248
|
+
if !memory['last_status'].nil? and memory['last_status'].present?
|
240
249
|
last_status = memory['last_status']
|
241
250
|
if interpolated['debug'] == 'true'
|
242
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.
|
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-
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|