Class: Saddle::Middleware::Request::UserAgent
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Saddle::Middleware::Request::UserAgent
- Defined in:
- lib/saddle/middleware/request/user_agent.rb
Overview
Public: Adds a user-agent to the request
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/saddle/middleware/request/user_agent.rb', line 12 def call(env) user_agent = nil # Build a user agent that looks like 'SaddleExample 0.0.1' begin user_agent = client_name = env[:saddle][:client].name parent_module = client_name.split('::')[0..-2].join('::').constantize if parent_module if defined?(parent_module::VERSION) user_agent += " #{parent_module::VERSION}" end end rescue StandardError end env[:request_headers]['User-Agent'] = user_agent if user_agent @app.call env end |