Class: GitFit::Sync::Keep

Inherits:
Base
  • Object
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??".freeze
KEEP_TYPES =
%w[running hiking cycling].freeze
KEEP_RAW_EXT =
"json".freeze
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

#progress_reported

Instance Method Summary collapse

Methods inherited from Base

adapters, #build_progress_info, #call, 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.



45
46
47
48
49
50
51
52
53
54
# File 'lib/git_fit/sync/keep.rb', line 45

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

#authenticateObject



61
62
63
64
# File 'lib/git_fit/sync/keep.rb', line 61

def authenticate
  @session = 
  @session ? true : false
end

#before_callObject



56
57
58
59
# File 'lib/git_fit/sync/keep.rb', line 56

def before_call
  return false if @phone.nil? || @password.nil?
  super
end

#pending_idsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/git_fit/sync/keep.rb', line 66

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 = extract_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



83
84
85
86
87
88
89
# File 'lib/git_fit/sync/keep.rb', line 83

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