Class: Travis::CLI::ApiCommand

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

Direct Known Subclasses

Console, Endpoint, Login, Raw, RepoCommand, Sync, Token, Whatsup, Whoami

Instance Attribute Summary collapse

Attributes inherited from Command

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

Instance Method Summary collapse

Methods included from Travis::Client::Methods

#access_token, #access_token=, #api_endpoint, #api_endpoint=, #artifact, #build, #explicit_api_endpoint?, #github_auth, #job, #repo, #repos, #restart, #user, #worker, #workers

Methods inherited from Command

abstract, abstract?, command_name, #command_name, #debug, #execute, #help, #parse, #say, skip, #terminal, #usage, #write_to

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

#initializeApiCommand

Returns a new instance of ApiCommand.



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

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



61
62
63
# File 'lib/travis/cli/api_command.rb', line 61

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

#detected_endpoint?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/travis/cli/api_command.rb', line 57

def detected_endpoint?
  api_endpoint == detected_endpoint
end

#endpoint_configObject



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

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

#org?Boolean

Returns:

  • (Boolean)


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

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

#pro?Boolean

Returns:

  • (Boolean)


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

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

#setupObject



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

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

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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/travis/cli/api_command.rb', line 65

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

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

    if count % steps == 0
      steps = count/10 + 1
      output.print dot
    end
  end
end