Class: GitFit::Sync::XOSS
- Inherits:
-
Base
- Object
- Base
- GitFit::Sync::XOSS
show all
- Defined in:
- lib/git_fit/sync/xoss.rb
Constant Summary
collapse
- FIT_FILE_PATH =
"/api/v3/activity/%<id>s/fit_file/"
- BASE_URL =
"https://backend.xoss.co"
- LOGIN_PATH =
"/api/v1/jwt-token/"
- REFRESH_PATH =
"/api/v1/jwt-token/refresh/"
- ACTIVITIES_PATH =
"/api/v3/activity/"
- ACCESS_TOKEN_TTL =
86400
- SPORT_MAP =
{
1 => "run",
2 => "ride",
3 => "other",
4 => "workout",
5 => "swim",
11 => "walk"
}.freeze
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 ⇒ XOSS
Returns a new instance of XOSS.
29
30
31
32
33
34
|
# File 'lib/git_fit/sync/xoss.rb', line 29
def initialize(...)
super
@email = @config["email"]
@password = @config["password"]
@token_path = @config["token_path"] || File.join("data", "cache", "xoss_tokens.json")
end
|
Instance Method Details
#authenticate ⇒ Object
41
42
43
44
45
46
|
# File 'lib/git_fit/sync/xoss.rb', line 41
def authenticate
return true if load_tokens && access_token_valid?
return true if refresh_access_token
return true if login
false
end
|
#before_call ⇒ Object
36
37
38
39
|
# File 'lib/git_fit/sync/xoss.rb', line 36
def before_call
return false if @email.nil? || @password.nil?
super
end
|
#pending_ids ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/git_fit/sync/xoss.rb', line 48
def pending_ids
existing = existing_run_ids
ids = []
offset = 1
limit = 50
loop do
acts = fetch_page(offset, limit)
break if acts.nil? || acts.empty?
acts.each do |act|
act_id = act["id"].to_s
next if existing.include?(act_id) && raw_file_exists?(act_id)
type = map_sport(act["sport"])
next if skip_type?(type)
ids << { id: act_id, type: type, summary: act }
end
offset += limit
end
ids
end
|
#process_one(pending) ⇒ Object
68
69
70
|
# File 'lib/git_fit/sync/xoss.rb', line 68
def process_one(pending)
process_activity(pending[:summary])
end
|