Class: Faraday::Request::YAML

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/request/yaml.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ YAML

Returns a new instance of YAML.



7
8
9
# File 'lib/faraday/request/yaml.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/faraday/request/yaml.rb', line 11

def call(env)
  # Only set the request's Content-Type when actually needed. (Some APIs
  # break when you send a Content-Type header and an empty body on GET 
  # requests.)
  if [:put, :post].include?(env[:method])
    env[:request_headers]['Content-Type'] = 'application/x-yaml'
  end

  if env[:body] && !env[:body].respond_to?(:to_str)
    env[:body] = env[:body].to_yaml
  end
  @app.call env
end