Method: SoftLayer::Client#initialize

Defined in:
lib/softlayer/Client.rb

#initialize(options = {}) ⇒ Client

Clients are built with a number of settings:

  • :username - The username of the account you wish to access through the API

  • :api_key - The API key used to authenticate the user with the API

  • :endpoint_url - The API endpoint the client should connect to. This defaults to API_PUBLIC_ENDPOINT

  • :user_agent - A string that is passed along as the user agent when the client sends requests to the server

  • :timeout - An integer number of seconds to wait until network requests time out. Corresponds to the network_timeout property of the client

If these arguments are not provided then the client will try to locate them using other sources including global variables, and the SoftLayer config file (if one exists)



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/softlayer/Client.rb', line 99

def initialize(options = {})
  @services = { }

  settings = Config.client_settings(options)

  # pick up the username from the options, the global, or assume no username
  @username = settings[:username]

  # do a similar thing for the api key
  @api_key = settings[:api_key]

  # grab token pair
  @userId = settings[:userId]
  @authToken = settings[:authToken]

  # and the endpoint url
  @endpoint_url = settings[:endpoint_url] || API_PUBLIC_ENDPOINT

  # set the user agent to the one provided, or set it to a default one
  @user_agent = settings[:user_agent] || "softlayer_api gem/#{SoftLayer::VERSION} (Ruby #{RUBY_PLATFORM}/#{RUBY_VERSION})"

  # and assign a time out if the settings offer one
  @network_timeout = settings[:timeout] if settings.has_key?(:timeout)

  raise "A SoftLayer Client requires an endpoint URL" if !@endpoint_url || @endpoint_url.empty?
end