1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00
rest-client--rest-client/lib/restclient/platform.rb
Andy Brody d554909ef9 Add a more descriptive rest-client user agent.
Identify ourselves as rest-client and also include system architecture
and ruby / ruby engine version information.

For example:

    User-Agent: rest-client/1.7.2 (linux-gnu x86_64) ruby/1.9.3p550

    User-Agent: rest-client/1.7.2 (linux x86_64) jruby/1.7.9 (1.9.3p392)
2014-11-02 18:24:09 -08:00

49 lines
1.2 KiB
Ruby

require 'rbconfig'
module RestClient
module Platform
# Return true if we are running on a darwin-based Ruby platform. This will
# be false for jruby even on OS X.
#
# @return [Boolean]
def self.mac_mri?
RUBY_PLATFORM.include?('darwin')
end
# Return true if we are running on Windows.
#
# @return [Boolean]
#
def self.windows?
# Ruby only sets File::ALT_SEPARATOR on Windows, and the Ruby standard
# library uses that to test what platform it's on.
!!File::ALT_SEPARATOR
end
# Return true if we are running on jruby.
#
# @return [Boolean]
#
def self.jruby?
# defined on mri >= 1.9
RUBY_ENGINE == 'jruby'
end
def self.architecture
"#{RbConfig::CONFIG['host_os']} #{RbConfig::CONFIG['host_cpu']}"
end
def self.ruby_agent_version
case RUBY_ENGINE
when 'jruby'
"jruby/#{JRUBY_VERSION} (#{RUBY_VERSION}p#{RUBY_PATCHLEVEL})"
else
"#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
end
end
def self.default_user_agent
"rest-client/#{VERSION} (#{architecture}) #{ruby_agent_version}"
end
end
end