123456789_123456789_123456789_123456789_123456789_

Class: Timezone::NetHTTPClient

Relationships & Source Files
Inherits: Object
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.

Examples:

Timezone::Lookup.config(:google) do |c|
  c.api_key = 'foo'
  c.request_handler = Timezone::NetHTTPClient
end

Class Method Summary

Instance Method Summary

Constructor Details

.new(config) ⇒ NetHTTPClient

[ GitHub ]

  
# File 'lib/timezone/net_http_client.rb', line 20

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

Instance Method Details

#get(url)

[ GitHub ]

  
# File 'lib/timezone/net_http_client.rb', line 27

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