Module: SoraGeocoding

Defined in:
lib/sora_geocoding.rb,
lib/sora_geocoding/url.rb,
lib/sora_geocoding/base.rb,
lib/sora_geocoding/query.rb,
lib/sora_geocoding/logger.rb,
lib/sora_geocoding/geohash.rb,
lib/sora_geocoding/request.rb,
lib/sora_geocoding/version.rb,
lib/sora_geocoding/exceptions.rb,
lib/sora_geocoding/results/base.rb,
lib/sora_geocoding/configuration.rb,
lib/sora_geocoding/results/geocoding.rb,
lib/sora_geocoding/results/yahoo_geocoder.rb

Overview

This library takes into account the number of API calls and address lookup to get the latitude and longitude. The API uses the Geocoding API and the Yahoo! Geocoder API.

Defined Under Namespace

Modules: Results Classes: Base, Configuration, ConfigurationError, ConfigurationHash, ForbiddenError, Geohash, InvalidRequest, Logger, NetworkError, NotFoundError, OverQueryLimitError, PaymentRequiredError, ProxyAuthenticationRequiredError, Query, Request, RequestDenied, ResponseParseError, ServiceUnavailable, Timeout, Url

Constant Summary collapse

VERSION =
'0.2.2'.freeze

Class Method Summary collapse

Class Method Details

.config ⇒ Object

Read-only access to the singleton's config data.



33
34
35
# File 'lib/sora_geocoding/configuration.rb', line 33

def self.config
  Configuration.instance.data
end

.config_for_lookup(lookup_name) ⇒ Object

Read-only access to specific config data.



40
41
42
43
44
45
# File 'lib/sora_geocoding/configuration.rb', line 40

def self.config_for_lookup(lookup_name)
  data = config.clone
  data.select! { |key, _value| Configuration::OPTIONS.include?(key) }
  data.merge!(config[lookup_name]) if config.key?(lookup_name)
  data
end

.configure(options = nil) ⇒ Object

Configuration options should be set by passing a hash:

SoraGeocoding.configure(
:timeout     => 5,
:site        => 'yahoo',
:yahoo_appid => '2a9fsa983jaslfj982fjasd'
)


26
27
28
# File 'lib/sora_geocoding/configuration.rb', line 26

def self.configure(options = nil)
  options ? Configuration.instance.configure(options) : config
end

.coordinates(address, options = {}) ⇒ Object

Look up the coordinates of the given street or IP address.



29
30
31
32
33
34
# File 'lib/sora_geocoding.rb', line 29

def self.coordinates(address, options = {})
  results = search(address, options)
  return if results.nil?

  { site: results[:site], coordinates: site_specific_coordinates(results[:site], results[:data]) }
end

.geohash(latitude, longitude) ⇒ Object

Generate a Geohash from latitude and longitude.



39
40
41
42
# File 'lib/sora_geocoding.rb', line 39

def self.geohash(latitude, longitude)
  geohash = Geohash.new(latitude, longitude)
  geohash.encode
end

.log(level, message) ⇒ Object



5
6
7
# File 'lib/sora_geocoding/logger.rb', line 5

def self.log(level, message)
  Logger.instance.log(level, message)
end

.search(query, options = {}) ⇒ Object

Search for information about an address or a set of coordinates.



21
22
23
24
# File 'lib/sora_geocoding.rb', line 21

def self.search(query, options = {})
  query = SoraGeocoding::Query.new(query, options) unless query.is_a?(SoraGeocoding::Query)
  query.nil? ? nil : query.execute
end