Class: RestCore::QueryResponse

Inherits:
Object
  • Object
show all
Includes:
Middleware
Defined in:
lib/rest-core/middleware/query_response.rb

Constant Summary collapse

QUERY_RESPONSE_HEADER =
{'Accept' => 'application/x-www-form-urlencoded'}.freeze

Constants included from Middleware

Middleware::METHODS_WITH_PAYLOAD, Middleware::UNRESERVED

Constants included from RestCore

ASYNC, CLIENT, DRY, FAIL, HIJACK, LOG, PROMISE, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, REQUEST_URI, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_KEY, RESPONSE_SOCKET, RESPONSE_STATUS, Simple, TIMER, Universal, VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Middleware

#contain_binary?, contain_binary?, #error_callback, #escape, escape, #fail, #give_promise, #has_payload?, has_payload?, #id, included, #log, #merge_hash, merge_hash, percent_encode, #percent_encode, #request_uri, request_uri, #run, string_keys, #string_keys

Methods included from RestCore

eagerload, id

Class Method Details

.membersObject



6
# File 'lib/rest-core/middleware/query_response.rb', line 6

def self.members; [:query_response]; end

Instance Method Details

#call(env, &k) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/rest-core/middleware/query_response.rb', line 12

def call env, &k
  return app.call(env, &k) if env[DRY]
  return app.call(env, &k) unless query_response(env)

  headers = QUERY_RESPONSE_HEADER.merge(env[REQUEST_HEADERS]||{})
  app.call(env.merge(REQUEST_HEADERS => headers)) do |response|
    body = ParseQuery.parse_query(response[RESPONSE_BODY])
    yield(response.merge(RESPONSE_BODY => body))
  end
end