Class: FaradayMiddleware::YoutubeAuthHeader
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::YoutubeAuthHeader
- Defined in:
- lib/tubeclip/middleware/faraday_authheader.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, headers) ⇒ YoutubeAuthHeader
constructor
A new instance of YoutubeAuthHeader.
Constructor Details
#initialize(app, headers) ⇒ YoutubeAuthHeader
Returns a new instance of YoutubeAuthHeader.
20 21 22 |
# File 'lib/tubeclip/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/tubeclip/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" => "3.0") 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 |