Class: Travis::CLI::ApiCommand

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

Direct Known Subclasses

Endpoint, Login, Raw, RepoCommand, Whoami

Instance Attribute Summary collapse

Attributes inherited from Command

#arguments, #config, #force_interactive, #terminal

Instance Method Summary collapse

Methods included from Travis::Client::Methods

#access_token, #access_token=, #api_endpoint, #api_endpoint=, #explicit_api_endpoint?, #github_auth, #repo, #repos, #user

Methods inherited from Command

abstract, abstract?, command_name, #command_name, #execute, #help, #input, #input=, #output, #output=, #parse, #say, skip, #usage, #write_to

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

#initializeApiCommand

Returns a new instance of ApiCommand.



15
16
17
18
# File 'lib/travis/cli/api_command.rb', line 15

def initialize(*)
  @session = Travis::Client.new
  super
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/travis/cli/api_command.rb', line 7

def session
  @session
end

Instance Method Details

#authenticateObject



43
44
45
# File 'lib/travis/cli/api_command.rb', line 43

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

#detected_endpoint?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/travis/cli/api_command.rb', line 39

def detected_endpoint?
  api_endpoint == detected_endpoint
end

#endpoint_configObject



20
21
22
23
# File 'lib/travis/cli/api_command.rb', line 20

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

#org?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/travis/cli/api_command.rb', line 35

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

#pro?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/travis/cli/api_command.rb', line 31

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

#setupObject



25
26
27
28
29
# File 'lib/travis/cli/api_command.rb', line 25

def setup
  self.access_token               ||= fetch_token
  endpoint_config['access_token'] ||= access_token
  authenticate if pro?
end