Class: Travis::CLI::ApiCommand
- Includes:
- Travis::Client::Methods
- Defined in:
- lib/travis/cli/api_command.rb
Direct Known Subclasses
Accounts, Console, Endpoint, Lint, Login, Logout, Monitor, Raw, RepoCommand, Report, Repos, Sync, Token, Whatsup, Whoami
Constant Summary
Constants inherited from Command
Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK
Constants included from Tools::Assets
Instance Attribute Summary collapse
-
#enterprise_name ⇒ Object
Returns the value of attribute enterprise_name.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Attributes inherited from Command
#arguments, #config, #debug, #force_interactive, #formatter, #input, #output
Instance Method Summary collapse
- #authenticate ⇒ Object
- #detected_endpoint? ⇒ Boolean
- #endpoint_config ⇒ Object
- #enterprise? ⇒ Boolean
-
#initialize ⇒ ApiCommand
constructor
A new instance of ApiCommand.
- #org? ⇒ Boolean
- #pro? ⇒ Boolean
- #setup ⇒ Object
- #sync(block = true, dot = '.') ⇒ Object
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, #repo, #repos, #restart, #user
Methods inherited from Command
abstract, abstract?, #check_completion, #check_ruby, #check_version, #command_name, command_name, #debug?, description, #execute, #help, #info, #last_check, #on_signal, #parse, #say, skip, subcommands, #terminal, #time, #usage, #usage_for, #write_to
Methods included from Tools::Assets
Methods included from Parser
Constructor Details
#initialize ⇒ ApiCommand
Returns a new instance of ApiCommand.
40 41 42 43 |
# File 'lib/travis/cli/api_command.rb', line 40 def initialize(*) @session = Travis::Client.new(:agent_info => "command #{command_name}") super end |
Instance Attribute Details
#enterprise_name ⇒ Object
Returns the value of attribute enterprise_name.
7 8 9 |
# File 'lib/travis/cli/api_command.rb', line 7 def enterprise_name @enterprise_name end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
8 9 10 |
# File 'lib/travis/cli/api_command.rb', line 8 def session @session end |
Instance Method Details
#authenticate ⇒ Object
77 78 79 |
# File 'lib/travis/cli/api_command.rb', line 77 def authenticate error "not logged in, please run #{command("login#{endpoint_option}")}" if access_token.nil? end |
#detected_endpoint? ⇒ Boolean
73 74 75 |
# File 'lib/travis/cli/api_command.rb', line 73 def detected_endpoint? api_endpoint == detected_endpoint end |
#endpoint_config ⇒ Object
45 46 47 48 |
# File 'lib/travis/cli/api_command.rb', line 45 def endpoint_config config['endpoints'] ||= {} config['endpoints'][api_endpoint] ||= {} end |
#enterprise? ⇒ Boolean
61 62 63 |
# File 'lib/travis/cli/api_command.rb', line 61 def enterprise? !!endpoint_config['enterprise'] end |
#org? ⇒ Boolean
69 70 71 |
# File 'lib/travis/cli/api_command.rb', line 69 def org? api_endpoint == Travis::Client::ORG_URI end |
#pro? ⇒ Boolean
65 66 67 |
# File 'lib/travis/cli/api_command.rb', line 65 def pro? api_endpoint == Travis::Client::PRO_URI end |
#setup ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/travis/cli/api_command.rb', line 50 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? or enterprise? end |
#sync(block = true, dot = '.') ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/travis/cli/api_command.rb', line 81 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 |