Class: ROM::HTTP::Handlers::JSONRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/http/handlers/json.rb

Overview

Default handler for JSON requests

Class Method Summary collapse

Class Method Details

.call(dataset) ⇒ Array<Hash>

Handle JSON request for the provided dataset

Parameters:

Returns:

  • (Array<Hash>)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rom/http/handlers/json.rb', line 26

def self.call(dataset)
  uri = URI(dataset.uri)

  uri.path = dataset.absolute_path
  uri.query = URI.encode_www_form(dataset.params)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true if uri.scheme.eql?('https')

  request_class = Net::HTTP.const_get(ROM::Inflector.classify(dataset.request_method))

  request = request_class.new(uri.request_uri)

  dataset.headers.each_with_object(request) do |(header, value), request|
    request[header.to_s] = value
  end

  http.request(request)
end