Sha256: e3acb246cfc26f2a529e4081b51ce7998a9fc110313f8bcc256b2f4670c92364

Contents?: true

Size: 846 Bytes

Versions: 8

Compression:

Stored size: 846 Bytes

Contents

require 'uri'
require 'net/http'

module Timezone
  # @!visibility private
  # A basic HTTP Client that handles requests to Geonames and Google.
  #
  # You can create your own version of this class if you want to use
  # a proxy or a different http library such as faraday.
  #
  # @example
  #     Timezone::Lookup.config(:google) do |c|
  #       c.api_key = 'foo'
  #       c.request_handler = Timezone::NetHTTPClient
  #     end
  #
  class NetHTTPClient
    def initialize(config)
      uri = URI.parse("#{config.protocol}://#{config.url}")
      @http = Net::HTTP.new(uri.host, uri.port)
      @http.open_timeout = config.open_timeout || 5
      @http.read_timeout = config.read_timeout || 5
      @http.use_ssl = (config.protocol == 'https'.freeze)
    end

    def get(url)
      @http.request(Net::HTTP::Get.new(url))
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
timezone-1.2.4 lib/timezone/net_http_client.rb
timezone-1.2.3 lib/timezone/net_http_client.rb
timezone-1.2.2 lib/timezone/net_http_client.rb
timezone-1.2.1 lib/timezone/net_http_client.rb
timezone-1.2.0 lib/timezone/net_http_client.rb
timezone-1.1.1 lib/timezone/net_http_client.rb
timezone-1.1.0 lib/timezone/net_http_client.rb
timezone-1.0.0 lib/timezone/net_http_client.rb