Class: Timezone::Configure
- Inherits:
-
Object
- Object
- Timezone::Configure
- 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.
Class Method Summary collapse
- .begin {|_self| ... } ⇒ Object
- .default_for_list ⇒ Object
- .default_for_list=(*list) ⇒ Object
- .geonames_lookup ⇒ Object
-
.geonames_protocol ⇒ String
The Geonames API HTTP protocol.
-
.geonames_protocol=(protocol) ⇒ Object
The Geonames API HTTP protocol.
-
.geonames_url ⇒ String
The Geonames API URL.
-
.geonames_url=(url) ⇒ Object
(also: url=)
The Geonames API URL.
-
.google_api_key ⇒ String
The Google API key.
-
.google_api_key=(api_key) ⇒ Object
Google API key.
-
.google_client_id ⇒ String
The Google Client ID (for enterprise).
-
.google_client_id=(client) ⇒ Object
Google Client ID (for enterprise).
- .google_lookup ⇒ Object
-
.google_protocol ⇒ String
The Google API HTTP protocol.
-
.google_protocol=(protocol) ⇒ Object
The Google API HTTP protocol.
-
.google_url ⇒ String
The Google API URL.
-
.google_url=(url) ⇒ Object
The Google API URL.
-
.http_client ⇒ Object
The HTTP client that handles requests to Geonames and Google.
-
.http_client=(client) ⇒ Object
The HTTP client that handles requests to Geonames and Google.
- .lookup ⇒ Object
- .lookup=(lookup) ⇒ Object
- .order_list_by ⇒ Object
- .order_list_by=(order) ⇒ Object
-
.protocol ⇒ String
Use Google protocol if key has been set else use Geonames protocol.
- .replace(what, with = Hash.new) ⇒ Object
- .replacements ⇒ Object
-
.url ⇒ String
Use Google URL if key has been set else use Geonames URL.
-
.use_google? ⇒ Boolean
Use Google API if key has been set.
-
.use_google_enterprise? ⇒ Boolean
Sign Google API request if client given (for enterprise).
-
.username ⇒ String
The Geonames API username.
-
.username=(username) ⇒ Object
The Geonames API username.
Class Method Details
.begin {|_self| ... } ⇒ Object
208 209 210 |
# File 'lib/timezone/configure.rb', line 208 def self.begin yield self end |
.default_for_list ⇒ Object
221 222 223 |
# File 'lib/timezone/configure.rb', line 221 def self.default_for_list @@default_list ||= nil end |
.default_for_list=(*list) ⇒ Object
225 226 227 |
# File 'lib/timezone/configure.rb', line 225 def self.default_for_list=(*list) @@default_list = list.flatten! end |
.geonames_lookup ⇒ Object
87 88 89 |
# File 'lib/timezone/configure.rb', line 87 def self.geonames_lookup @geonames_lookup ||= Timezone::Lookup::Geonames.new(self) end |
.geonames_protocol ⇒ String
The Geonames API HTTP protocol
147 148 149 |
# File 'lib/timezone/configure.rb', line 147 def self.geonames_protocol @@geonames_protocol ||= 'http' end |
.geonames_protocol=(protocol) ⇒ Object
The Geonames API HTTP protocol
139 140 141 |
# File 'lib/timezone/configure.rb', line 139 def self.geonames_protocol=(protocol) @@geonames_protocol = protocol end |
.geonames_url ⇒ String
The Geonames API URL
95 96 97 |
# File 'lib/timezone/configure.rb', line 95 def self.geonames_url @@geonames_url ||= 'api.geonames.org' end |
.geonames_url=(url) ⇒ Object Also known as: url=
The Geonames API URL
103 104 105 |
# File 'lib/timezone/configure.rb', line 103 def self.geonames_url=(url) @@geonames_url = url end |
.google_api_key ⇒ String
The Google API key
31 32 33 |
# File 'lib/timezone/configure.rb', line 31 def self.google_api_key @google_api_key ||= nil end |
.google_api_key=(api_key) ⇒ Object
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_client_id ⇒ String
The Google Client ID (for enterprise)
47 48 49 |
# File 'lib/timezone/configure.rb', line 47 def self.google_client_id @google_client_id ||= nil end |
.google_client_id=(client) ⇒ Object
Google Client ID (for enterprise)
55 56 57 |
# File 'lib/timezone/configure.rb', line 55 def self.google_client_id=(client) @google_client_id = client end |
.google_lookup ⇒ Object
83 84 85 |
# File 'lib/timezone/configure.rb', line 83 def self.google_lookup @google_lookup ||= Timezone::Lookup::Google.new(self) end |
.google_protocol ⇒ String
The Google API HTTP protocol
163 164 165 |
# File 'lib/timezone/configure.rb', line 163 def self.google_protocol @@google_protocol ||= 'https' end |
.google_protocol=(protocol) ⇒ Object
The Google API HTTP protocol
155 156 157 |
# File 'lib/timezone/configure.rb', line 155 def self.google_protocol=(protocol) @@google_protocol = protocol end |
.google_url ⇒ String
The Google API URL
115 116 117 |
# File 'lib/timezone/configure.rb', line 115 def self.google_url @@google_url ||= 'maps.googleapis.com' end |
.google_url=(url) ⇒ Object
The Google API URL
123 124 125 |
# File 'lib/timezone/configure.rb', line 123 def self.google_url=(url) @@google_url = url end |
.http_client ⇒ Object
The HTTP client that handles requests to Geonames and Google
179 180 181 |
# File 'lib/timezone/configure.rb', line 179 def self.http_client @@http_client ||= Timezone::NetHTTPClient end |
.http_client=(client) ⇒ Object
The HTTP client that handles requests to Geonames and Google
188 189 190 |
# File 'lib/timezone/configure.rb', line 188 def self.http_client=(client) @@http_client = client end |
.lookup ⇒ Object
77 78 79 80 81 |
# File 'lib/timezone/configure.rb', line 77 def self.lookup return @lookup if @lookup use_google? ? google_lookup : geonames_lookup end |
.lookup=(lookup) ⇒ Object
73 74 75 |
# File 'lib/timezone/configure.rb', line 73 def self.lookup=(lookup) @lookup = lookup && lookup.new(self) end |
.order_list_by ⇒ Object
229 230 231 |
# File 'lib/timezone/configure.rb', line 229 def self.order_list_by @@order_by ||= :utc_offset end |
.order_list_by=(order) ⇒ Object
233 234 235 |
# File 'lib/timezone/configure.rb', line 233 def self.order_list_by=(order) @@order_by = order end |
.protocol ⇒ String
Use Google protocol if key has been set else use Geonames protocol
171 172 173 |
# File 'lib/timezone/configure.rb', line 171 def self.protocol use_google? ? google_protocol : geonames_protocol end |
.replace(what, with = Hash.new) ⇒ Object
212 213 214 215 |
# File 'lib/timezone/configure.rb', line 212 def self.replace(what, with = Hash.new) replacements # instantiate @@replacements @@replacements[what] = with[:with] end |
.replacements ⇒ Object
217 218 219 |
# File 'lib/timezone/configure.rb', line 217 def self.replacements @@replacements ||= {} end |
.url ⇒ String
Use Google URL if key has been set else use Geonames URL
131 132 133 |
# File 'lib/timezone/configure.rb', line 131 def self.url use_google? ? google_url : geonames_url end |
.use_google? ⇒ Boolean
Use Google API if key has been set
62 63 64 |
# File 'lib/timezone/configure.rb', line 62 def self.use_google? !!google_api_key end |
.use_google_enterprise? ⇒ Boolean
Sign Google API request if client given (for enterprise)
69 70 71 |
# File 'lib/timezone/configure.rb', line 69 def self.use_google_enterprise? use_google? && !!google_client_id end |
.username ⇒ String
The Geonames API username
196 197 198 |
# File 'lib/timezone/configure.rb', line 196 def self.username @@username ||= nil end |
.username=(username) ⇒ Object
The Geonames API username
204 205 206 |
# File 'lib/timezone/configure.rb', line 204 def self.username=(username) @@username = username end |