Class: Sfctl::Commands::Time::Connections::Add

Inherits:
Sfctl::Command show all
Defined in:
lib/sfctl/commands/time/connections/add.rb

Constant Summary

Constants inherited from Sfctl::Command

Sfctl::Command::CONFIG_FILENAME, Sfctl::Command::CONFIG_PATH, Sfctl::Command::HARVEST_PROVIDER, Sfctl::Command::LINK_CONFIG_FILENAME, Sfctl::Command::LINK_CONFIG_PATH, Sfctl::Command::PROVIDERS_LIST, Sfctl::Command::TOGGL_PROVIDER

Instance Method Summary collapse

Methods inherited from Sfctl::Command

#access_token, #command, #config, #config_present?, #link_config_present?, #read_config, #read_link_config, #save_config!, #save_link_config!

Constructor Details

#initialize(options) ⇒ Add

Returns a new instance of Add.



15
16
17
18
19
# File 'lib/sfctl/commands/time/connections/add.rb', line 15

def initialize(options)
  @options = options
  @pastel = Pastel.new(enabled: !@options['no-color'])
  @prompt = ::TTY::Prompt.new(help_color: :cyan)
end

Instance Method Details

#execute(output: $stdout) ⇒ Object

rubocop:disable Metrics/AbcSize



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sfctl/commands/time/connections/add.rb', line 21

def execute(output: $stdout) # rubocop:disable Metrics/AbcSize
  return if !config_present?(output) || !link_config_present?(output)

  ltoken = access_token
  config.delete(:access_token)
  success, data = Starfish::Client.(@options['starfish-host'], @options['all'], ltoken)
  unless success
    output.puts @pastel.red('Something went wrong. Unable to fetch assignments')
    return
  end

  assignments = filter_assignments(data['assignments'])
  if assignments.length.zero?
    output.puts @pastel.yellow('All assignments already added.')
    return
  end

  provider = @prompt.select('Select provider:', PROVIDERS_LIST)

  assignment_obj = select_assignment(assignments)

  setup_connection!(provider, output, assignment_obj)
end