Class: Timezone::NetHTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/timezone/net_http_client.rb

Overview

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 but be aware that the Google timezone API uses https protocol.

Examples:

Timezone::Configure.begin do |c|
  c.http_client = Timezone::NetHTTPClient
end

Instance Method Summary collapse

Constructor Details

#initialize(protocol, host) ⇒ NetHTTPClient

Returns a new instance of NetHTTPClient.



15
16
17
18
19
# File 'lib/timezone/net_http_client.rb', line 15

def initialize(protocol, host)
  uri = URI.parse("#{protocol}://#{host}")
  @http = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = (protocol == 'https')
end

Instance Method Details

#get(url) ⇒ Object



21
22
23
# File 'lib/timezone/net_http_client.rb', line 21

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