Sha256: 03627a50d7d9a4186e5f6f36caec0fb448fd66c86c1fc941d14bd0bc84529015
Contents?: true
Size: 964 Bytes
Versions: 10
Compression:
Stored size: 964 Bytes
Contents
require "etc" require "socket" module Faraday module Conductivity class UserAgent < Faraday::Middleware def initialize(app, options = {}) super(app) @name = options.fetch(:app) { "Faraday" } @version = options.fetch(:version) { "0.0" } @environment = options.fetch(:environment) { Environment.new } end def call(env) env[:request_headers]['User-Agent'] = user_agent @app.call(env) end def user_agent [ app, ruby ].join(' ') end def app "#{@name}/#{@version} (#{@environment.hostname}; #{@environment.login}; #{@environment.pid})" end def ruby "#{RUBY_ENGINE}/#{RUBY_VERSION} (#{RUBY_PATCHLEVEL}; #{RUBY_PLATFORM})" end end class Environment def login Etc.getlogin end def hostname Socket.gethostname end def pid Process.pid end end end end
Version data entries
10 entries across 10 versions & 1 rubygems