Module: RongCloud::Request

Includes:
Signature
Included in:
Service
Defined in:
lib/rong_cloud/request.rb

Overview

Handle api request, based on Ruby’s built-in Net::HTTP, support both HTTP and HTTPS

Instance Method Summary collapse

Methods included from Signature

#signature, #signed_headers

Instance Method Details

#request(path, params = nil, content_type = :form_data) ⇒ Hash

Returns the parsed response represented by JSON.

Parameters:

  • path (String)

    The api endpoint

  • params (Hash) (defaults to: nil)

    api params

  • content_type (Symbol) (defaults to: :form_data)

    required formatting for request data, :form_data or :json

Returns:

  • (Hash)

    the parsed response represented by JSON

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rong_cloud/request.rb', line 18

def request(path, params = nil, content_type = :form_data)
  uri = get_uri(path)
  req = initialize_request(uri, params, content_type)

  use_ssl = uri.scheme == 'https'
  timeout = RongCloud::Configuration.timeout
  request_options = { use_ssl: use_ssl, open_timeout: timeout, read_timeout: timeout }

  res = Net::HTTP.start(uri.hostname, uri.port, request_options) do |http|
    inspect_debug_informations(req, uri, request_options)
    http.request(req)
  end

  inspect_debug_informations(res)
  handle_response(res)
end