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'

Instance Attribute Summary

Attributes inherited from Base

#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.



29
30
31
32
33
# File 'lib/git_fit/sync/xingzhe.rb', line 29

def initialize(...)
  super
  @email = @config['email']
  @password = @config['password']
end

Instance Method Details

#authenticateObject



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

def authenticate
  
end

#before_callObject



35
36
37
38
# File 'lib/git_fit/sync/xingzhe.rb', line 35

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

#pending_idsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/git_fit/sync/xingzhe.rb', line 44

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



64
65
66
# File 'lib/git_fit/sync/xingzhe.rb', line 64

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