Module: Fog::Softlayer::Slapi

Class Method Summary collapse

Class Method Details

.slapi_request(service, path, options) ⇒ Excon::Response

Sends the real request to the real SoftLayer service.

Parameters:

  • service (String)

    …ayer.com/rest/v3/Softlayer_Service_Name…

  • path (String)

    …ayer.com/rest/v3/Softlayer_Service_Name/path.json

  • options (Hash)

Options Hash (options):

  • :body (Array<Hash>)

    HTTP request body parameters

  • :softlayer_api_url (String)

    Override the default (or configured) API endpoint

  • :softlayer_username (String)

    Email or user identifier for user based authentication

  • :softlayer_api_key (String)

    Password for user based authentication

Returns:

  • (Excon::Response)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/softlayer/core.rb', line 34

def self.slapi_request(service, path, options)
    # default HTTP method to get if not passed
    http_method = options[:http_method] || :get
    # set the target base url
    @request_url = options[:softlayer_api_url] || Fog::Softlayer::SL_API_URL
    # tack on the username and password
    credentialize_url(options[:username], options[:api_key])
    # set the SoftLayer Service name
    set_sl_service(service)
    # set the request path (known as the "method" in SL docs)
    set_sl_path(path)
    # set the query params if any


    # build request params
    params = { :headers => user_agent_header }
    params[:headers]['Content-Type'] = 'application/json'
    params[:expects] = options[:expected] || [200,201]
    params[:query] = options[:query] unless options[:query].nil?
    unless options[:body].nil?
      options[:body] = [options[:body]] unless options[:body].kind_of?(Array)
      params[:body] = Fog::JSON.encode({:parameters => options[:body]})
    end

    # initialize connection object
    @connection = Fog::Core::Connection.new(@request_url, false, params)

    # send it
    response = @connection.request(:method => http_method)

    # decode it
    response.body = Fog::JSON.decode(response.body)
    response
end