Class: GoogleWebTranslate::HTTPClient
- Inherits:
-
Object
- Object
- GoogleWebTranslate::HTTPClient
- Defined in:
- lib/google_web_translate/http_client.rb
Overview
HTTP client functionality
Class Method Summary collapse
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(options = {}) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
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( = {}) @user_agent = [:user_agent] || self.class.user_agent end |
Class Method Details
.user_agent ⇒ Object
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 = { use_ssl: uri.scheme == 'https' } Net::HTTP.start(uri.host, uri.port, ) do |http| http.request(request) end end |