Class: Twofishes::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twofishes/client.rb

Class Method Summary collapse

Class Method Details

.geocode(location, options = {}) ⇒ Twofishes::Result

Geocodes a given string.

Examples:

Twofishes::Client.geocode('Zurich, Switzerland')

Parameters:

  • location (String)
  • list (Array)

    of additional ResponseIncludes constants

Returns:



15
16
17
18
19
20
21
# File 'lib/twofishes/client.rb', line 15

def self.geocode(location, options = {})
  handle_response do
    options[:query] = location
    request = Twofishes::GeocodeRequest.new(options)
    thrift_client.geocode(request)
  end
end

.handle_responseObject



48
49
50
51
52
# File 'lib/twofishes/client.rb', line 48

def self.handle_response
  Result.from_response(yield)
rescue => e
  raise Twofishes::InvalidResponseError, e.message
end

.reverse_geocode(coordinates, options = {}) ⇒ Twofishes::Result

Reverse geocodes lat/lng.

Examples:

Twofishes::Client.reverse_geocode([47.3787733, 8.5273363])

Parameters:

  • latitude, (Array)

    longitude pair

Returns:



30
31
32
33
34
35
36
# File 'lib/twofishes/client.rb', line 30

def self.reverse_geocode(coordinates, options = {})
  handle_response do
    options[:ll] = coordinates
    request = Twofishes::GeocodeRequest.new(options)
    thrift_client.reverseGeocode(request)
  end
end

.thrift_clientObject



38
39
40
41
42
43
44
45
46
# File 'lib/twofishes/client.rb', line 38

def self.thrift_client
  ThriftClient.new(
    Geocoder::Client,
    Twofishes.configuration.address,
    retries: Twofishes.configuration.retries,
    timeout: Twofishes.configuration.timeout,
    connect_timeout: Twofishes.configuration.connect_timeout
  )
end