Class: Timezone::NetHTTPClient
- Inherits:
-
Object
- Object
- Timezone::NetHTTPClient
- 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.
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(protocol, host) ⇒ NetHTTPClient
constructor
A new instance of NetHTTPClient.
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 |