class Alexandria::WWWAgent

Public Class Methods

new() click to toggle source
# File lib/alexandria/net.rb, line 25
def initialize
  user_agent = "Ruby #{RUBY_VERSION} #{Alexandria::TITLE}/#{Alexandria::VERSION}"
  @extra_request_headers = { "User-Agent" => user_agent }
end
transport() click to toggle source
# File lib/alexandria/net.rb, line 30
def self.transport
  config = Alexandria::Preferences.instance.http_proxy_config
  config ? Net::HTTP.Proxy(*config) : Net::HTTP
end

Public Instance Methods

get(url) click to toggle source
# File lib/alexandria/net.rb, line 35
def get(url)
  uri = URI.parse(url)
  req = Net::HTTP::Get.new(uri.request_uri)
  @extra_request_headers.each_pair do |header_name, value|
    req.add_field(header_name, value)
  end
  WWWAgent.transport.start(uri.host, uri.port) do |http|
    http.request(req)
  end
end
language=(lang) click to toggle source
# File lib/alexandria/net.rb, line 46
def language=(lang)
  @extra_request_headers["Accept-Language"] = lang.to_s
end
user_agent=(agent_string) click to toggle source
# File lib/alexandria/net.rb, line 50
def user_agent=(agent_string)
  @extra_request_headers["User-Agent"] = agent_string
end