Class: GitFit::Sync::XingZhe

Inherits:
Base
  • Object
show all
Defined in:
lib/git_fit/sync/xingzhe.rb

Constant Summary collapse

BASE_HOST =
'www.imxingzhe.com'
LOGIN_PATH =
'/api/v1/user/login/'
WORKOUTS_PATH =
'/api/v1/pgworkout/'
STREAM_PATH =
'/api/v1/pgworkout/'
DETAIL_PATH =
'/api/v1/pgworkout/'
RSA_PUBKEY =
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDmuQkBbijudDAJgfffDeeIButqWHZvUwcRuvWdg89393FSdz3IJUHc0rgI/S3WuU8N0VePJLmVAZtCOK4qe4FY/eKmWpJmn7JfXB4HTMWjPVoyRZmSYjW4L8GrWmh51Qj7DwpTADadF3aq04o+s1b8LXJa8r6+TIqqL5WUHtRqmQIDAQAB'
SPORT_MAP =
{
  3 => 'ride', 1 => 'run', 2 => 'hike',
  5 => 'swim', 6 => 'walk', 11 => 'ski', 13 => 'workout'
}.freeze
RAW_EXT =
'json'
SESSION_TTL =
30 * 24 * 60 * 60

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

#initializeXingZhe

Returns a new instance of XingZhe.



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

def initialize(...)
  super
  @email = @config['email']
  @password = @config['password']
  @session_path = @config['session_path'] || GitFit::Auth.file('xingzhe', 'session.json')
end

Instance Method Details

#auth_error?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/git_fit/sync/xingzhe.rb', line 80

def auth_error?
  [302, 401, 403].include?(@last_http_code)
end

#authenticateObject



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

def authenticate
  if load_session && session_valid?
    @auth_method = 'cached'
    return true
  end
  if 
    @auth_method = 'login'
    return true
  end
  false
end

#before_callObject



39
40
41
42
# File 'lib/git_fit/sync/xingzhe.rb', line 39

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

#last_auth_codeObject



84
85
86
# File 'lib/git_fit/sync/xingzhe.rb', line 84

def last_auth_code
  @last_http_code
end

#pending_idsObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/git_fit/sync/xingzhe.rb', line 56

def pending_ids
  existing = existing_run_ids
  ids = []
  offset = 0
  limit = 50
  loop do
    acts = fetch_page(offset, limit)
    break if acts.nil? || acts.empty?
    acts.each do |act|
      aid = act['id'].to_s
      next if existing.include?(aid) && raw_file_exists?(aid)
      type = map_sport(act['sport'])
      next if skip_type?(type)
      ids << { id: aid, type: type, summary: act }
    end
    offset += limit
  end
  ids
end

#process_one(pending) ⇒ Object



76
77
78
# File 'lib/git_fit/sync/xingzhe.rb', line 76

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