class Fog::Softlayer::Product::Real
Makes real connections to Softlayer.
Attributes
Public Instance Methods
# 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
# 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
# File lib/fog/softlayer/requests/product/get_packages.rb, line 22 def get_packages request(:product_package, :get_all_objects) end
# 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
Sends the real request to the real SoftLayer service.
@param [String] service
...ayer.com/rest/v3/Softlayer_Service_Name...
@param path [String]
...ayer.com/rest/v3/Softlayer_Service_Name/path.json
@param [Hash] options @option options [Array<Hash>] :body
HTTP request body parameters
@option options [String] :softlayer_api_url
Override the default (or configured) API endpoint
@option options [String] :softlayer_username
Email or user identifier for user based authentication
@option options [String] :softlayer_api_key
Password for user based authentication
@return [Excon::Response]
# 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
Private Instance Methods
# File lib/fog/softlayer/product.rb, line 110 def credentialize_url(username, apikey) @request_url = "https://#{username}:#{apikey}@#{@request_url}" end
Try to smallCamelCase the path before appending it to the @request_url
# File lib/fog/softlayer/product.rb, line 129 def set_sl_path(path) path = path.to_s.softlayer_underscore.softlayer_camelize @request_url += "/#{path}.json" end
Prepend “SoftLayer_” to the service name and Snake_Camel_Case the string before appending it to the @request_url.
On DNS we have the service: SoftLayer_Dns_Domain_ResourceRecord As it does NOT follow any pattern, you can specify :dns_domain_resourceRecord So #set_sl_service will NOT change you service name case (just first letters), pay attention
# File lib/fog/softlayer/product.rb, line 121 def set_sl_service(service) service = "SoftLayer_" << service.to_s.gsub(/^softlayer_/i, '').split('_').map{|i| i[0].upcase + i[1..-1]}.join('_') @request_url += "/#{service}" end
# File lib/fog/softlayer/product.rb, line 134 def user_agent_header {"User-Agent" => "Fog SoftLayer Adapter #{Fog::Softlayer::VERSION}"} end