Class: GitFit::Sync::GarminBase
- Inherits:
-
Base
- Object
- Base
- GitFit::Sync::GarminBase
show all
- Defined in:
- lib/git_fit/sync/garmin_base.rb
Constant Summary
collapse
- CLIENT_ID =
'GCM_ANDROID_DARK'
- OAUTH_CONSUMER_URL =
'https://thegarth.s3.amazonaws.com/oauth_consumer.json'
{
'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'en-US,en;q=0.9',
}.freeze
Instance Attribute Summary collapse
Attributes inherited from Base
#progress_reported
Instance Method Summary
collapse
Methods inherited from Base
adapters, #build_progress_info, #call, camelcase_to_snakecase, config_key, register_adapter, register_config, register_test_adapter, test_adapters
Constructor Details
Returns a new instance of GarminBase.
34
35
36
37
38
39
40
41
|
# File 'lib/git_fit/sync/garmin_base.rb', line 34
def initialize(...)
super
@domain = 'garmin.com'
@email = @config['email']
@password = @config['password']
@secret = @config['secret']
@ssl_verify = @config.key?('ssl_verify') ? @config['ssl_verify'] : true
end
|
Instance Attribute Details
#generated_secret ⇒ Object
Returns the value of attribute generated_secret.
43
44
45
|
# File 'lib/git_fit/sync/garmin_base.rb', line 43
def generated_secret
@generated_secret
end
|
Instance Method Details
#authenticate ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/git_fit/sync/garmin_base.rb', line 50
def authenticate
@oauth_consumer = fetch_oauth_consumer
if @secret
if parse_secret_string(@secret)
return true if access_token_valid?
begin
return true if refresh_oauth2_via_oauth1
rescue AuthError
end
end
end
begin
return true if load_tokens && access_token_valid?
return true if load_tokens && refresh_oauth2_via_oauth1
rescue AuthError
remove_stale_tokens
end
return false if @email.to_s.empty? || @password.to_s.empty?
ticket = sso_login
@oauth1_token = fetch_oauth1_token(ticket)
@access_token = exchange_oauth2
@generated_secret = dump_secret
unless verify_access_token
@generated_secret = nil
raise AuthError, 'New tokens failed API verify — SSO result invalid'
end
save_secret_to_config
save_tokens
true
end
|
#before_call ⇒ Object
45
46
47
48
|
# File 'lib/git_fit/sync/garmin_base.rb', line 45
def before_call
return false if @email.to_s.empty? && @secret.to_s.empty?
super
end
|
#pending_ids ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/git_fit/sync/garmin_base.rb', line 85
def pending_ids
existing = existing_run_ids
ids = []
start = 0
limit = 100
loop do
activities = fetch_activity_list(start, limit)
break if activities.nil? || activities.empty?
activities.each do |act|
act_id = act['activityId'].to_s
type = map_type(act['activityType'])
next if skip_type?(type)
next if existing.include?(act_id) && raw_file_exists?(act_id)
ids << { id: act_id, type: type }
end
start += limit
end
ids
end
|
#process_one(pending) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/git_fit/sync/garmin_base.rb', line 105
def process_one(pending)
act_id = pending[:id]
type = pending[:type]
details = fetch_activity_detail(act_id)
return nil unless details
polyline = fetch_summary_polyline(act_id)
unless raw_file_exists?(act_id)
download_fit_raw(act_id)
l2 = fit_to_l2(act_id)
write_standardized_json(l2, act_id) if l2
end
attrs = build_attrs(details, act_id, type, polyline)
if (start_t = parse_garmin_time(details.dig('summaryDTO', 'startTimeGMT')))
local_t = resolve_local_time(start_t, act_id, polyline)
attrs[:start_date_local] = local_t.iso8601 if local_t
end
upsert_activity(attrs)
attrs
end
|