Class: ShipStation::Middleware::JSONRequest

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/ship_station/middleware.rb

Overview

This middleware adds a “Content-Type: application/json” HTTP header

Instance Method Summary collapse

Instance Method Details

#add_header(headers) ⇒ Object



32
33
34
# File 'lib/ship_station/middleware.rb', line 32

def add_header(headers)
  headers.merge! "Content-Type" => "application/json"
end

#call(env) ⇒ Object



37
38
39
40
41
42
# File 'lib/ship_station/middleware.rb', line 37

def call(env)
  unless env.method == :get
    env[:body] = encode env[:body] unless env[:body].respond_to?(:to_s)
  end
  @app.call(env)
end