-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathupload.rb
47 lines (38 loc) · 996 Bytes
/
upload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
module Strava
module Models
class Upload < Strava::Models::Response
property 'id'
property 'external_id'
property 'error'
property 'status'
property 'activity_id'
def processing?
validate!
activity_id.nil?
end
def processed?
!processing?
end
private
def validate!
raise_when_background_job_failed!
end
def raise_when_background_job_failed!
response = http_response.response
return unless response_contains_error_message?(response)
raise Strava::Errors::UploadError, response_values(response)
end
def response_contains_error_message?(response)
response.status == 200 && response.body['error'].present?
end
def response_values(response)
{
status: response.status,
headers: response.headers,
body: response.body
}
end
end
end
end