class Travis::CLI::ApiCommand
def authenticate
def authenticate error "not logged in, please run #{command("login#{endpoint_option}")}" if access_token.nil? end
def default_endpoint
def default_endpoint ENV['TRAVIS_ENDPOINT'] || config['default_endpoint'] end
def detected_endpoint
def detected_endpoint default_endpoint || Travis::Client::ORG_URI end
def detected_endpoint?
def detected_endpoint? api_endpoint == detected_endpoint end
def endpoint_config
def endpoint_config config['endpoints'] ||= {} config['endpoints'][api_endpoint] ||= {} end
def endpoint_option
def endpoint_option return "" if org? and detected_endpoint? return " --org" if org? return " --pro" if pro? " -e %p" % api_endpoint end
def fetch_token
def fetch_token ENV['TRAVIS_TOKEN'] || endpoint_config['access_token'] end
def github_endpoint
def github_endpoint load_gh GH.with({}).api_host end
def initialize(*)
def initialize(*) @session = Travis::Client.new(:agent_info => "command #{command_name}") super end
def listen(*args)
def listen(*args) super(*args) do |listener| on_signal { listener.disconnect } yield listener end end
def load_gh
def load_gh return if defined? GH require 'gh' gh_config = session.config['github'] gh_config &&= gh_config.inject({}) { |h,(k,v)| h.update(k.to_sym => v) } gh_config ||= {} gh_config[:ssl] = Travis::Client::Session::SSL_OPTIONS gh_config[:ssl] = { :verify => false } if gh_config[:api_url] and gh_config[:api_url] != "https://api.github.com" GH.set(gh_config) end
def org?
def org? api_endpoint == Travis::Client::ORG_URI end
def pro?
def pro? api_endpoint == Travis::Client::PRO_URI end
def setup
def setup self.api_endpoint = default_endpoint if default_endpoint and not explicit_api_endpoint? self.access_token ||= fetch_token endpoint_config['access_token'] ||= access_token authenticate if pro? end
def sync(block = true, dot = '.')
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