Class: BatchApi::InternalMiddleware::DecodeJsonBody

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_api/internal_middleware/decode_json_body.rb

Overview

Public: a middleware that decodes the body of any individual batch operation if the it’s JSON.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DecodeJsonBody

Public: initialize the middleware.



7
8
9
# File 'lib/batch_api/internal_middleware/decode_json_body.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
# File 'lib/batch_api/internal_middleware/decode_json_body.rb', line 11

def call(env)
  @app.call(env).tap do |result|
    result.body = MultiJson.load(result.body) if should_decode?(result)
  end
end