Class: GitFit::Sync::XOSS

Inherits:
Base
  • Object
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

#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

#initializeXOSS

Returns a new instance of XOSS.



31
32
33
34
35
36
# File 'lib/git_fit/sync/xoss.rb', line 31

def initialize(...)
  super
  @email = @config['email']
  @password = @config['password']
  @token_path = @config['token_path'] || File.join('data', 'auth', 'xoss_tokens.json')
end

Instance Method Details

#authenticateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/git_fit/sync/xoss.rb', line 43

def authenticate
  if load_tokens && access_token_valid?
    @auth_method = 'cached'
    return true
  end
  if refresh_access_token
    @auth_method = 'refreshed'
    return true
  end
  if 
    @auth_method = 'login'
    return true
  end
  false
end

#before_callObject



38
39
40
41
# File 'lib/git_fit/sync/xoss.rb', line 38

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

#pending_idsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/git_fit/sync/xoss.rb', line 59

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



79
80
81
# File 'lib/git_fit/sync/xoss.rb', line 79

def process_one(pending)
  process_activity(pending[:summary])
end