Class: Timezone::Configure

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

Overview

Configuration class for the Timezone gem.

You’ll want to sign up for a geonames username at Geonames. Use the username to configure your application for latitude and longitude based timezone searches. Alternatively, you’ll want to sign up for a Google api key at / Google. Use the api key to configure your application for latitude and longitude based timezone searches.

If you aren’t going to initialize timezone objects based on lat,lng then this configuration is not necessary.

Examples:

Timezone::Configure.begin do |c|
  c.geonames_url = 'api.geonames.org'
  c.username = 'foo-bar'
  c.google_api_key = 'abc123'
end

Class Method Summary collapse

Class Method Details

.begin {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



179
180
181
# File 'lib/timezone/configure.rb', line 179

def self.begin
  yield self
end

.default_for_listObject



192
193
194
# File 'lib/timezone/configure.rb', line 192

def self.default_for_list
  @@default_list ||= nil
end

.default_for_list=(*list) ⇒ Object



196
197
198
# File 'lib/timezone/configure.rb', line 196

def self.default_for_list=(*list)
  @@default_list = list.flatten!
end

.geonames_lookupObject



58
59
60
# File 'lib/timezone/configure.rb', line 58

def self.geonames_lookup
  @geonames_lookup ||= Timezone::Lookup::Geonames.new(self)
end

.geonames_protocolString

The Geonames API HTTP protocol

Returns:

  • (String)

    the Geonames API HTTP protocol (‘http’)



118
119
120
# File 'lib/timezone/configure.rb', line 118

def self.geonames_protocol
  @@geonames_protocol ||= 'http'
end

.geonames_protocol=(protocol) ⇒ Object

The Geonames API HTTP protocol

Parameters:

  • protocol (String)

    the Geonames API HTTP procotol



110
111
112
# File 'lib/timezone/configure.rb', line 110

def self.geonames_protocol=(protocol)
  @@geonames_protocol = protocol
end

.geonames_urlString

The Geonames API URL

Returns:

  • (String)

    the Geonames API URL (‘api.geonames.org’)



66
67
68
# File 'lib/timezone/configure.rb', line 66

def self.geonames_url
  @@geonames_url ||= 'api.geonames.org'
end

.geonames_url=(url) ⇒ Object Also known as: url=

The Geonames API URL

Parameters:

  • url (String)

    the Geonames API URL



74
75
76
# File 'lib/timezone/configure.rb', line 74

def self.geonames_url=(url)
  @@geonames_url = url
end

.google_api_keyString

The Google API key

Returns:

  • (String)

    the Google API key (‘abc123’)



31
32
33
# File 'lib/timezone/configure.rb', line 31

def self.google_api_key
  @google_api_key
end

.google_api_key=(api_key) ⇒ Object

Google API key

Parameters:

  • api_key (String)

    the Google API key



39
40
41
# File 'lib/timezone/configure.rb', line 39

def self.google_api_key=(api_key)
  @google_api_key = api_key
end

.google_lookupObject



54
55
56
# File 'lib/timezone/configure.rb', line 54

def self.google_lookup
  @google_lookup ||= Timezone::Lookup::Google.new(self)
end

.google_protocolString

The Google API HTTP protocol

Returns:

  • (String)

    the Google API HTTP protocol (‘https’)



134
135
136
# File 'lib/timezone/configure.rb', line 134

def self.google_protocol
  @@google_protocol ||= 'https'
end

.google_protocol=(protocol) ⇒ Object

The Google API HTTP protocol

Parameters:

  • protocol (String)

    the Google API HTTP procotol



126
127
128
# File 'lib/timezone/configure.rb', line 126

def self.google_protocol=(protocol)
  @@google_protocol = protocol
end

.google_urlString

The Google API URL

Returns:

  • (String)

    the Google API URL (‘maps.googleapis.com’)



86
87
88
# File 'lib/timezone/configure.rb', line 86

def self.google_url
  @@google_url ||= 'maps.googleapis.com'
end

.google_url=(url) ⇒ Object

The Google API URL

Parameters:

  • url (String)

    the Google API URL



94
95
96
# File 'lib/timezone/configure.rb', line 94

def self.google_url=(url)
  @@google_url = url
end

.http_clientObject

The HTTP client that handles requests to Geonames and Google

Returns:



150
151
152
# File 'lib/timezone/configure.rb', line 150

def self.http_client
  @@http_client ||= Timezone::NetHTTPClient
end

.http_client=(client) ⇒ Object

The HTTP client that handles requests to Geonames and Google

Parameters:

  • client (Object)

    the HTTP client that handles requests to Geonames and Google



159
160
161
# File 'lib/timezone/configure.rb', line 159

def self.http_client=(client)
  @@http_client = client
end

.lookupObject



50
51
52
# File 'lib/timezone/configure.rb', line 50

def self.lookup
  use_google? ? google_lookup : geonames_lookup
end

.order_list_byObject



200
201
202
# File 'lib/timezone/configure.rb', line 200

def self.order_list_by
  @@order_by ||= :utc_offset
end

.order_list_by=(order) ⇒ Object



204
205
206
# File 'lib/timezone/configure.rb', line 204

def self.order_list_by=(order)
  @@order_by = order
end

.protocolString

Use Google protocol if key has been set else use Geonames protocol

Returns:

  • (String)

    the Google or Geonames API protocol



142
143
144
# File 'lib/timezone/configure.rb', line 142

def self.protocol
  use_google? ? google_protocol : geonames_protocol
end

.replace(what, with = Hash.new) ⇒ Object



183
184
185
186
# File 'lib/timezone/configure.rb', line 183

def self.replace(what, with = Hash.new)
  replacements # instantiate @@replacements
  @@replacements[what] = with[:with]
end

.replacementsObject



188
189
190
# File 'lib/timezone/configure.rb', line 188

def self.replacements
  @@replacements ||= {}
end

.urlString

Use Google URL if key has been set else use Geonames URL

Returns:

  • (String)

    the Google or Geonames API URL



102
103
104
# File 'lib/timezone/configure.rb', line 102

def self.url
  use_google? ? google_url : geonames_url
end

.use_google?Boolean

Use Google API if key has been set

Returns:

  • (Boolean)


46
47
48
# File 'lib/timezone/configure.rb', line 46

def self.use_google?
  !!google_api_key
end

.usernameString

The Geonames API username

Returns:

  • (String)

    the Geonames API username (‘foo-bar’)



167
168
169
# File 'lib/timezone/configure.rb', line 167

def self.username
  @@username
end

.username=(username) ⇒ Object

The Geonames API username

Parameters:

  • username (String)

    the Geonames API username



175
176
177
# File 'lib/timezone/configure.rb', line 175

def self.username=(username)
  @@username = username
end