Class: GitFit::Sync::Keep
- Inherits:
-
Base
- Object
- Base
- GitFit::Sync::Keep
show all
- Defined in:
- lib/git_fit/sync/keep.rb
Constant Summary
collapse
- LOGIN_URL =
'https://api.gotokeep.com/v1.1/users/login'
- STATS_URL =
'https://api.gotokeep.com/pd/v3/stats/detail?dateUnit=all&type=%{sport}&lastDate=%{last_date}'
- LOG_URL =
'https://api.gotokeep.com/pd/v3/%{sport}log/%{run_id}'
- AES_KEY =
Base64.decode64('NTZmZTU5OzgyZzpkODczYw==')
- AES_IV =
Base64.decode64('MjM0Njg5MjQzMjkyMDMwMA==')
- PLACEHOLDER_POLYLINE =
'gqqrFurkeU??'
- KEEP_TYPES =
%w[running hiking cycling].freeze
- KEEP_RAW_EXT =
'json'
- TYPE_MAP =
{
'outdoorWalking' => 'walk',
'outdoorRunning' => 'run',
'outdoorCycling' => 'ride',
'indoorRunning' => 'run',
'mountaineering' => 'hike',
}.freeze
- STRAVA_TYPE_MAP =
{
'outdoorWalking' => 'Walk',
'outdoorRunning' => 'Run',
'outdoorCycling' => 'Ride',
'indoorRunning' => 'VirtualRun',
'mountaineering' => 'Hiking',
}.freeze
- TIMESTAMP_THRESHOLD =
3_600_000
- HR_THRESHOLD =
100
Instance Attribute Summary
Attributes inherited from Base
#auth_method, #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
#initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil) ⇒ Keep
Returns a new instance of Keep.
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/git_fit/sync/keep.rb', line 47
def initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil)
super
@phone = @config['phone'] || @config['mobile']
@password = @config['password']
@headers = {
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8',
}
@session = nil
end
|
Instance Method Details
#authenticate ⇒ Object
63
64
65
66
67
|
# File 'lib/git_fit/sync/keep.rb', line 63
def authenticate
@session = login
@auth_method = 'login' if @session
@session ? true : false
end
|
#before_call ⇒ Object
58
59
60
61
|
# File 'lib/git_fit/sync/keep.rb', line 58
def before_call
return false if @phone.nil? || @password.nil?
super
end
|
#pending_ids ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/git_fit/sync/keep.rb', line 69
def pending_ids
existing = existing_run_ids
ids = []
KEEP_TYPES.each do |sport|
compound_ids = fetch_run_ids(sport)
compound_ids.each do |cid|
keep_id = (cid) || cid
run_id = "keep_#{keep_id}"
has_existing = existing.include?(run_id)
has_raw = raw_file_exists?(keep_id)
next if has_existing && has_raw
ids << { id: cid, keep_id: keep_id, sport: sport, has_raw: has_raw }
end
end
ids
end
|
#process_one(pending) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/git_fit/sync/keep.rb', line 86
def process_one(pending)
if pending[:has_raw]
upsert_from_raw(pending[:id])
else
sync_single_run_with_raw(pending[:id], pending[:sport])
end
end
|