Sha256: f89ee25625ea4b9ad18ccb09674f4a61176e28b0669b44d6d906bd5b5205d4a5

Contents?: true

Size: 800 Bytes

Versions: 4

Compression:

Stored size: 800 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)
      @http = Net::HTTP.new(config.uri.host, config.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

4 entries across 4 versions & 1 rubygems

Version Path
timezone-1.2.8 lib/timezone/net_http_client.rb
timezone-1.2.7 lib/timezone/net_http_client.rb
timezone-1.2.6 lib/timezone/net_http_client.rb
timezone-1.2.5 lib/timezone/net_http_client.rb