Class: DeskApi::Request::EncodeJson

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/desk_api/request/encode_json.rb

Overview

EncodeJson is the Faraday middleware that dumps a json string from whatever is specified in the request body. It also sets the “Content-Type” header.

Author:

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

Changes the request before it gets sent

Parameters:

  • env (Hash)

    the request hash



44
45
46
47
48
49
50
# File 'lib/desk_api/request/encode_json.rb', line 44

def call(env)
  env[:request_headers]['Content-Type'] = 'application/json'
  if env[:body] && !env[:body].to_s.empty?
    env[:body] = ::JSON.dump(env[:body])
  end
  @app.call env
end