Class: Fog::Softlayer::Product::Real

Inherits:
Object
  • Object
show all
Includes:
Compute::Shared, Slapi
Defined in:
lib/fog/softlayer/product.rb,
lib/fog/softlayer/requests/product/place_order.rb,
lib/fog/softlayer/requests/product/get_packages.rb,
lib/fog/softlayer/requests/product/get_package_item.rb,
lib/fog/softlayer/requests/product/get_package_items.rb

Overview

Makes real connections to Softlayer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Compute::Shared

#initialize, valid_request?

Methods included from Slapi

slapi_request

Instance Attribute Details

#default_domainObject

Returns the value of attribute default_domain.



55
56
57
# File 'lib/fog/softlayer/product.rb', line 55

def default_domain
  @default_domain
end

Instance Method Details

#get_package_item(package_id, id) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/fog/softlayer/requests/product/get_package_item.rb', line 28

def get_package_item(package_id, id)
  request(
    :product_package,
    package_id.to_s + '/getItems',
    query: 'queryEngineVersion=2&objectFilter={"items":{"id":{"operation":'+id.to_s+'}}}'
  )
end

#get_package_items(package_id) ⇒ Object



22
23
24
# File 'lib/fog/softlayer/requests/product/get_package_items.rb', line 22

def get_package_items(package_id)
  request(:product_package, package_id.to_s + '/getItems', query: 'queryEngineVersion=2&objectMask=id;capacity;description;itemTaxCategoryId;keyName;softwareDescriptionId;units;upgradeItemId')
end

#get_packagesObject



22
23
24
# File 'lib/fog/softlayer/requests/product/get_packages.rb', line 22

def get_packages
  request(:product_package, :get_all_objects)
end

#place_order(order_template) ⇒ Object



242
243
244
# File 'lib/fog/softlayer/requests/product/place_order.rb', line 242

def place_order(order_template)
  request(:product_order, :place_order, :body => order_template, :http_method => :POST)
end

#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) (defaults to: {})

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)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fog/softlayer/product.rb', line 75

def 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(@credentials[:username], @credentials[: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[:body] = Fog::JSON.encode({:parameters => [ options[:body] ]}) unless options[:body].nil?
  params[:query] = options[:query] unless options[:query].nil?

  # 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