Sha256: 8516e986ecfe027b21d126bd75e79d20f3c7663fabf45730543e79a3a0f4378b

Contents?: true

Size: 730 Bytes

Versions: 1

Compression:

Stored size: 730 Bytes

Contents

require 'net/http'

module GoogleWebTranslate
  # HTTP client functionality
  class HTTPClient
    def self.user_agent
      gem_version = "GoogleWebTranslate/#{VERSION}"
      platform_version = "(#{RUBY_PLATFORM}) #{RUBY_ENGINE}/#{RUBY_VERSION}"
      gem_version + ' ' + platform_version
    end

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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
google_web_translate-0.2.2 lib/google_web_translate/http_client.rb