Class: GoogleWebTranslate::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/google_web_translate/http_client.rb

Overview

HTTP client functionality

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTTPClient

Returns a new instance of HTTPClient.



12
13
14
# File 'lib/google_web_translate/http_client.rb', line 12

def initialize(options = {})
  @user_agent = options[:user_agent] || self.class.user_agent
end

Class Method Details

.user_agentObject



6
7
8
9
10
# File 'lib/google_web_translate/http_client.rb', line 6

def self.user_agent
  gem_version = "GoogleWebTranslate/#{VERSION}"
  platform_version = "(#{RUBY_PLATFORM}) #{RUBY_ENGINE}/#{RUBY_VERSION}"
  gem_version + ' ' + platform_version
end

Instance Method Details

#get(url) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/google_web_translate/http_client.rb', line 16

def get(url)
  uri = URI.parse(url)
  request = Net::HTTP::Get.new(uri)
  request['User-Agent'] = @user_agent
  options = { use_ssl: uri.scheme == 'https' }
  Net::HTTP.start(uri.host, uri.port, options) do |http|
    http.request(request)
  end
end