Class: CircleCi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/circleci/config.rb

Overview

Config class used internally. Configure API calls using CircleCi.configure

Constant Summary collapse

DEFAULT_VERSION =
'v1.1'.freeze
DEFAULT_HOST =
'https://circleci.com'.freeze
DEFAULT_URI =
"#{DEFAULT_HOST}/api/#{DEFAULT_VERSION}".freeze
DEFAULT_PORT =
443

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, proxy: nil, version: DEFAULT_VERSION, token: nil, request_overrides: {}, logger: nil) ⇒ Config

rubocop:disable Metrics/ParameterLists



21
22
23
24
25
26
27
28
29
# File 'lib/circleci/config.rb', line 21

def initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, proxy: nil, version: DEFAULT_VERSION, token: nil, request_overrides: {}, logger: nil)
  @host = host
  @port = port
  @proxy = proxy.nil? ? false : proxy
  @version = version
  @token = token
  @request_overrides = request_overrides
  @logger = logger || Logger.new(STDOUT)
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



14
15
16
# File 'lib/circleci/config.rb', line 14

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/circleci/config.rb', line 14

def logger
  @logger
end

#portObject

Returns the value of attribute port.



14
15
16
# File 'lib/circleci/config.rb', line 14

def port
  @port
end

#proxyObject

Returns the value of attribute proxy.



14
15
16
# File 'lib/circleci/config.rb', line 14

def proxy
  @proxy
end

#proxy_hostObject

Returns the value of attribute proxy_host.



14
15
16
# File 'lib/circleci/config.rb', line 14

def proxy_host
  @proxy_host
end

#proxy_passObject

Returns the value of attribute proxy_pass.



14
15
16
# File 'lib/circleci/config.rb', line 14

def proxy_pass
  @proxy_pass
end

#proxy_portObject

Returns the value of attribute proxy_port.



14
15
16
# File 'lib/circleci/config.rb', line 14

def proxy_port
  @proxy_port
end

#proxy_userObject

Returns the value of attribute proxy_user.



14
15
16
# File 'lib/circleci/config.rb', line 14

def proxy_user
  @proxy_user
end

#request_overridesObject

Returns the value of attribute request_overrides.



14
15
16
# File 'lib/circleci/config.rb', line 14

def request_overrides
  @request_overrides
end

#tokenObject

Returns the value of attribute token.



14
15
16
# File 'lib/circleci/config.rb', line 14

def token
  @token
end

#versionObject

Returns the value of attribute version.



14
15
16
# File 'lib/circleci/config.rb', line 14

def version
  @version
end

Instance Method Details

#proxy_to_portObject



40
41
42
# File 'lib/circleci/config.rb', line 40

def proxy_to_port
  proxy_port || 80
end

#proxy_uriObject



44
45
46
47
48
49
50
# File 'lib/circleci/config.rb', line 44

def proxy_uri
  return unless @proxy && proxy_host

  host_uri = URI.parse(proxy_host)
  userinfo = proxy_userinfo? ? "#{proxy_user}:#{proxy_pass}@" : ''
  URI.parse("#{host_uri.scheme}://#{userinfo}#{host_uri.host}:#{proxy_to_port}#{host_uri.path}")
end

#proxy_userinfo?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/circleci/config.rb', line 36

def proxy_userinfo?
  proxy_user && proxy_pass
end

#uriObject

rubocop:enable Metrics/ParameterLists



32
33
34
# File 'lib/circleci/config.rb', line 32

def uri
  URI.parse("#{@host || DEFAULT_HOST}:#{@port || DEFAULT_PORT}/api/#{@version || DEFAULT_VERSION}")
end