Class: GitFit::Sync::GarminBaseDI

Inherits:
GarminBase show all
Defined in:
lib/git_fit/sync/garmin_base_di.rb

Direct Known Subclasses

GarminCom

Constant Summary collapse

DI_CLIENT_IDS =
%w[
  GARMIN_CONNECT_MOBILE_ANDROID_DI_2025Q2
  GARMIN_CONNECT_MOBILE_ANDROID_DI_2024Q4
  GARMIN_CONNECT_MOBILE_ANDROID_DI
].freeze

Constants inherited from GarminBase

GitFit::Sync::GarminBase::CLIENT_ID, GitFit::Sync::GarminBase::OAUTH_CONSUMER_URL, GitFit::Sync::GarminBase::SSO_HEADERS

Instance Attribute Summary

Attributes inherited from GarminBase

#generated_secret

Attributes inherited from Base

#auth_method, #progress_reported

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GarminBase

#initialize, #pending_ids, #process_one, #source_prefix

Methods inherited from Base

adapters, #auth_error?, #build_progress_info, #call, camelcase_to_snakecase, config_key, #initialize, #last_auth_code, #pending_ids, #process_one, register_adapter, register_config, register_test_adapter, test_adapters

Constructor Details

This class inherits a constructor from GitFit::Sync::GarminBase

Class Method Details

.source_prefixObject



8
9
10
# File 'lib/git_fit/sync/garmin_base_di.rb', line 8

def self.source_prefix
  'garmin'
end

Instance Method Details

#authenticateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/git_fit/sync/garmin_base_di.rb', line 18

def authenticate
  @oauth_consumer = fetch_oauth_consumer

  if load_tokens
    if access_token_valid?
      @auth_method = 'token'
      return true
    end
    begin
      if refresh_token
        @auth_method = 'refreshed'
        return true
      end
    rescue AuthError
      remove_stale_tokens
    end
  end

  if load_auth_seed
    if access_token_valid?
      @auth_method = 'seed'
      return true
    end
    begin
      if refresh_token
        @auth_method = 'refreshed'
        return true
      end
    rescue AuthError
      @access_token = nil
    end
  end

  puts 'Garmin: no valid DI token found'
  puts '  First time: git fit auth garmin'
  puts '  Refresh:    git fit auth garmin --sync'
  false
end

#before_callObject



57
58
59
60
61
62
63
64
65
# File 'lib/git_fit/sync/garmin_base_di.rb', line 57

def before_call
  if @config['auth_seed'].to_s.empty? && !File.exist?(token_path)
    puts 'Garmin: auth_seed not configured and no cached token'
    puts '  Run: git fit auth garmin'
    return false
  end
  @start_time = Time.now
  true
end

#reauth_hintObject



67
68
69
# File 'lib/git_fit/sync/garmin_base_di.rb', line 67

def reauth_hint
  'Re-auth: git fit auth garmin --sync'
end