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.


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

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


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

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

#detected_endpoint?Boolean

Returns:

  • (Boolean)

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

def detected_endpoint?
  api_endpoint == detected_endpoint
end

#endpoint_configObject


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

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

#org?Boolean

Returns:

  • (Boolean)

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

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

#pro?Boolean

Returns:

  • (Boolean)

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

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

#setupObject


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

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

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


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

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