Class: Faraday::Conductivity::UserAgent

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/conductivity/user_agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ UserAgent

Returns a new instance of UserAgent.



8
9
10
11
12
13
# File 'lib/faraday/conductivity/user_agent.rb', line 8

def initialize(app, options = {})
  super(app)
  @name = options.fetch(:app) { "Faraday" }
  @version = options.fetch(:version) { "0.0" }
  @environment = options.fetch(:environment) { Environment.new }
end

Instance Method Details

#appObject



24
25
26
# File 'lib/faraday/conductivity/user_agent.rb', line 24

def app
  "#{@name}/#{@version} (#{@environment.hostname}; #{@environment.}; #{@environment.pid})"
end

#call(env) ⇒ Object



15
16
17
18
# File 'lib/faraday/conductivity/user_agent.rb', line 15

def call(env)
  env[:request_headers]['User-Agent'] = user_agent
  @app.call(env)
end

#rubyObject



28
29
30
# File 'lib/faraday/conductivity/user_agent.rb', line 28

def ruby
  "#{RUBY_ENGINE}/#{RUBY_VERSION} (#{RUBY_PATCHLEVEL}; #{RUBY_PLATFORM})"
end

#user_agentObject



20
21
22
# File 'lib/faraday/conductivity/user_agent.rb', line 20

def user_agent
  [ app, ruby ].join(' ')
end