Class: Travis::CLI::ApiCommand

Inherits:
Command
  • Object
show all
Includes:
Travis::Client::Methods
Defined in:
lib/travis/cli/api_command.rb

Constant Summary

Constants inherited from Command

Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK

Constants included from Tools::Assets

Tools::Assets::BASE

Instance Attribute Summary collapse

Attributes inherited from Command

#arguments, #config, #debug, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods included from Travis::Client::Methods

#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #hooks, #job, #lint, #logout, #regenerate_token, #remove_token, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, #command_name, command_name, #debug?, description, #error, #execute, #help, #info, #last_check, #on_signal, #parse, #say, skip, subcommands, #terminal, #time, #usage, #usage_for, #warn, #write_to

Methods included from Tools::Assets

asset, asset_path

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

#initializeApiCommand

Returns a new instance of ApiCommand.



49
50
51
52
# File 'lib/travis/cli/api_command.rb', line 49

def initialize(*)
  @session = Travis::Client.new(agent_info: "command #{command_name}")
  super
end

Instance Attribute Details

#enterprise_nameObject

Returns the value of attribute enterprise_name.



10
11
12
# File 'lib/travis/cli/api_command.rb', line 10

def enterprise_name
  @enterprise_name
end

#sessionObject (readonly)

Returns the value of attribute session.



11
12
13
# File 'lib/travis/cli/api_command.rb', line 11

def session
  @session
end

Instance Method Details

#authenticateObject



86
87
88
# File 'lib/travis/cli/api_command.rb', line 86

def authenticate
  error "not logged in, please run #{command("login#{endpoint_option}")}" if access_token.nil?
end

#detected_endpoint?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/travis/cli/api_command.rb', line 82

def detected_endpoint?
  api_endpoint == detected_endpoint
end

#endpoint_configObject



54
55
56
57
# File 'lib/travis/cli/api_command.rb', line 54

def endpoint_config
  config['endpoints'] ||= {}
  config['endpoints'][api_endpoint] ||= {}
end

#enterprise?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/travis/cli/api_command.rb', line 70

def enterprise?
  !!endpoint_config['enterprise']
end

#org?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/travis/cli/api_command.rb', line 78

def org?
  api_endpoint == Travis::Client::ORG_URI
end

#pro?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/travis/cli/api_command.rb', line 74

def pro?
  api_endpoint == Travis::Client::COM_URI
end

#setupObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/travis/cli/api_command.rb', line 59

def setup
  setup_enterprise
  self.api_endpoint = default_endpoint if default_endpoint and not explicit_api_endpoint?
  self.access_token               ||= fetch_token
  endpoint_config['access_token'] ||= access_token
  endpoint_config['insecure']       = insecure unless insecure.nil?
  self.insecure                     = endpoint_config['insecure']
  session.ssl                       = { verify: false } if insecure?
  authenticate if pro? || enterprise?
end

#sync(block = true, dot = '.') ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/travis/cli/api_command.rb', line 90

def sync(block = true, dot = '.')
  user.sync

  steps = count = 1
  while block && user.reload.syncing?
    count += 1
    sleep(1)

    if (count % steps).zero?
      steps = count / 10 + 1
      output.print dot
    end
  end
end