Class: Qravan::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/qravan/query.rb

Overview

Sources for data extractions class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cargo) ⇒ Query

Returns a new instance of Query.



14
15
16
# File 'lib/qravan/query.rb', line 14

def initialize(cargo)
  @cargo ||= cargo
end

Instance Attribute Details

#cargoObject

Returns the value of attribute cargo.



12
13
14
# File 'lib/qravan/query.rb', line 12

def cargo
  @cargo
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/qravan/query.rb', line 18

def call(env)
  query = Rack::Request.new(env)
  request = Qravan::Request.new(JSON.parse(query.body.read), cargo)
  response = Qravan::Response.new(request)

  body = [response.answer]
  status  = 200
  headers = { "content-type" => "application/json" }

  [status, headers, body]
end