Class: Pilot::Manager

Inherits:
Object
  • Object
show all
Defined in:
pilot/lib/pilot/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Access the current configuration



50
51
52
# File 'pilot/lib/pilot/manager.rb', line 50

def config
  @config
end

Instance Method Details

#api_tokenObject



32
33
34
35
36
# File 'pilot/lib/pilot/manager.rb', line 32

def api_token
  @api_token ||= Spaceship::ConnectAPI::Token.create(config[:api_key]) if config[:api_key]
  @api_token ||= Spaceship::ConnectAPI::Token.from_json_file(config[:api_key_path]) if config[:api_key_path]
  return @api_token
end

#appObject

The app object we’re currently using



39
40
41
42
43
44
45
46
47
# File 'pilot/lib/pilot/manager.rb', line 39

def app
  @app_id ||= fetch_app_id

  @app ||= Spaceship::ConnectAPI::App.get(app_id: @app_id)
  unless @app
    UI.user_error!("Could not find app with #{(config[:apple_id] || config[:app_identifier])}")
  end
  return @app
end

#fetch_app_idObject

Config Related



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'pilot/lib/pilot/manager.rb', line 55

def fetch_app_id
  @app_id ||= config[:apple_id]
  return @app_id if @app_id
  config[:app_identifier] = fetch_app_identifier

  if config[:app_identifier]
    @app ||= Spaceship::ConnectAPI::App.find(config[:app_identifier])
    UI.user_error!("Couldn't find app '#{config[:app_identifier]}' on the account of '#{config[:username]}' on App Store Connect") unless @app
    @app_id ||= @app.id
  end

  @app_id ||= UI.input("Could not automatically find the app ID, please enter it here (e.g. 956814360): ")

  return @app_id
end

#fetch_app_identifierObject



71
72
73
74
75
76
77
# File 'pilot/lib/pilot/manager.rb', line 71

def fetch_app_identifier
  result = config[:app_identifier]
  result ||= FastlaneCore::IpaFileAnalyser.fetch_app_identifier(config[:ipa])
  result ||= UI.input("Please enter the app's bundle identifier: ")
  UI.verbose("App identifier (#{result})")
  return result
end

#fetch_app_platform(required: true) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'pilot/lib/pilot/manager.rb', line 79

def fetch_app_platform(required: true)
  result = config[:app_platform]
  result ||= FastlaneCore::IpaFileAnalyser.fetch_app_platform(config[:ipa]) if config[:ipa]
  if required
    result ||= UI.input("Please enter the app's platform (appletvos, ios, osx): ")
    UI.user_error!("App Platform must be ios, appletvos, or osx") unless ['ios', 'appletvos', 'osx'].include?(result)
    UI.verbose("App Platform (#{result})")
  end
  return result
end

#loginObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'pilot/lib/pilot/manager.rb', line 19

def 
  if api_token
    UI.message("Creating authorization token for App Store Connect API")
    Spaceship::ConnectAPI.token = api_token
  else
    config[:username] ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

    UI.message("Login to App Store Connect (#{config[:username]})")
    Spaceship::ConnectAPI.(config[:username], use_portal: false, use_tunes: true, tunes_team_id: config[:team_id], team_name: config[:team_name])
    UI.message("Login successful")
  end
end

#start(options, should_login: true) ⇒ Object



13
14
15
16
17
# File 'pilot/lib/pilot/manager.rb', line 13

def start(options, should_login: true)
  return if @config # to not login multiple times
  @config = options
   if 
end