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, config_key, register_adapter, register_config, register_test_adapter, test_adapters

Constructor Details

#initializeXingZhe

Returns a new instance of XingZhe.



26
27
28
29
30
# File 'lib/git_fit/sync/xingzhe.rb', line 26

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

Instance Method Details

#authenticateObject



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

def authenticate
  
end

#before_callObject



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

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

#pending_idsObject



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

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



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

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