Class: Request::AuthHeader

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

Instance Method Summary collapse

Constructor Details

#initialize(app, headers) ⇒ AuthHeader

Returns a new instance of AuthHeader.



20
21
22
# File 'lib/youtube_it/middleware/faraday_authheader.rb', line 20

def initialize(app, headers)
  @app, @headers = app, headers
end

Instance Method Details

#call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/youtube_it/middleware/faraday_authheader.rb', line 4

def call(env)
  req_headers = env[:request_headers]
  req_headers.merge!(@headers)
  unless req_headers.include?("GData-Version")
    req_headers.merge!("GData-Version" => "2")
  end
  unless req_headers.include?("Content-Type")
    req_headers.merge!("Content-Type"  => "application/atom+xml; charset=UTF-8")
  end
  unless req_headers.include?("Content-Length")
    req_headers.merge!("Content-Length"  => env[:body] ? "#{env[:body].length}" : "0")
  end

  @app.call(env)
end