module BatchRequestApi::BatchSequential

Public Instance Methods

batch_sequential(env) click to toggle source
# File lib/batch_request_api/batch_sequential.rb, line 7
def batch_sequential(env)
  requests = get_payload(env)
  responses = requests.map do |item|
    process_request(env.deep_dup, item)
  end
  build_response(response_hash(responses))
end

Private Instance Methods

handoff_to_rails(env) click to toggle source
# File lib/batch_request_api/batch_sequential.rb, line 23
def handoff_to_rails(env)
  status, headers, body = @app.call(env)
  body.close if body.respond_to? :close
  { status: status, headers: headers, response: JSON.parse(body.body) }
end
process_request(env, item) click to toggle source
# File lib/batch_request_api/batch_sequential.rb, line 17
def process_request(env, item)
  json_body = item['body'].to_json
  setup_env(env, item, json_body)
  handoff_to_rails(env)
end
response_hash(responses) click to toggle source
# File lib/batch_request_api/batch_sequential.rb, line 29
def response_hash(responses)
  { status: 200, headers: { 'Content-Type' => 'application/json' }, response: responses }
end