Module: Fog::Softlayer::Slapi
- Included in:
- Compute::Softlayer::Mock, Compute::Softlayer::Real, Network::Softlayer::Real, Product::Mock, Product::Real
- Defined in:
- lib/fog/softlayer/core.rb
Class Method Summary collapse
-
.slapi_request(service, path, options) ⇒ Excon::Response
Sends the real request to the real SoftLayer service.
Class Method Details
.slapi_request(service, path, options) ⇒ Excon::Response
Sends the real request to the real SoftLayer service.
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, ) # default HTTP method to get if not passed http_method = [:http_method] || :get # set the target base url @request_url = [:softlayer_api_url] || Fog::Softlayer::SL_API_URL # tack on the username and password credentialize_url([:username], [: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] = [:expected] || [200,201] params[:query] = [:query] unless [:query].nil? unless [:body].nil? [:body] = [[:body]] unless [:body].kind_of?(Array) params[:body] = Fog::JSON.encode({:parameters => [: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 |