Method: VagrantCloud::Client#initialize

Defined in:
lib/vagrant_cloud/client.rb

#initialize(access_token: nil, url_base: nil, retry_count: nil, retry_interval: nil, instrumentor: nil) ⇒ Client

Create a new Client instance

Parameters:

  • access_token (String) (defaults to: nil)

    Authentication token for API requests

  • url_base (String) (defaults to: nil)

    URL used to make API requests

  • retry_count (Integer) (defaults to: nil)

    Number of retries on idempotent requests

  • retry_interval (Integer) (defaults to: nil)

    Number of seconds to wait between requests

  • instrumentor (Instrumentor::Core) (defaults to: nil)

    Instrumentor to use



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vagrant_cloud/client.rb', line 45

def initialize(access_token: nil, url_base: nil, retry_count: nil, retry_interval: nil, instrumentor: nil)
  url_base = API_DEFAULT_URL if url_base.nil?
  remote_url = URI.parse(url_base)
  @url_base = "#{remote_url.scheme}://#{remote_url.host}"
  @path_base = remote_url.path
  if @path_base.empty? || @path_base == API_V1_PATH || @path_base == API_V2_PATH
    @path_base = nil
  end
  @auth = Auth.new(access_token: access_token)
  @retry_count = retry_count.nil? ? IDEMPOTENT_RETRIES : retry_count.to_i
  @retry_interval = retry_interval.nil? ? IDEMPOTENT_RETRY_INTERVAL : retry_interval.to_i
  @instrumentor = instrumentor.nil? ? Instrumentor::Collection.new : instrumentor
  headers = {}.tap do |h|
    h["Accept"] = "application/json"
    h["Content-Type"] = "application/json"
  end
  @connection_lock = Mutex.new
  @connection = Excon.new(url_base,
    headers: headers,
    instrumentor: @instrumentor
  )
end