Class: AddressGeocoder::Requester Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/address_geocoder/requester.rb

Overview

This class is abstract.

Abstract base class for making requests to maps APIs

Since:

  • 0.0.1

Direct Known Subclasses

MapsApi::Google::Requester

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Requester

Returns a new instance of Requester.

Since:

  • 0.0.1



23
24
25
# File 'lib/address_geocoder/requester.rb', line 23

def initialize(args = {})
  @parser = args[:parser]
end

Instance Attribute Details

#address=(value) ⇒ Hash (writeonly)

Returns the address to use in the request.

Returns:

  • (Hash)

    the address to use in the request

Since:

  • 0.0.1



12
13
14
# File 'lib/address_geocoder/requester.rb', line 12

def address=(value)
  @address = value
end

#api_key=(value) ⇒ Hash (writeonly)

Returns the api_key to use in the request.

Returns:

  • (Hash)

    the api_key to use in the request

Since:

  • 0.0.1



18
19
20
# File 'lib/address_geocoder/requester.rb', line 18

def api_key=(value)
  @api_key = value
end

#language=(value) ⇒ Hash (writeonly)

Returns the language to return the request in.

Returns:

  • (Hash)

    the language to return the request in

Since:

  • 0.0.1



15
16
17
# File 'lib/address_geocoder/requester.rb', line 15

def language=(value)
  @language = value
end

#parser=(value) ⇒ Parser (writeonly)

Returns a class instance.

Returns:

  • (Parser)

    a class instance

Since:

  • 0.0.1



9
10
11
# File 'lib/address_geocoder/requester.rb', line 9

def parser=(value)
  @parser = value
end

#resultHash (readonly)

Returns the result of a request to a maps API.

Returns:

  • (Hash)

    the result of a request to a maps API

Since:

  • 0.0.1



21
22
23
# File 'lib/address_geocoder/requester.rb', line 21

def result
  @result
end

Instance Method Details

#array_resultArray<Hash>

This method is abstract.

Abstract base method for returning a compacted, flattened array of different address responses.

Returns a collection of possible addresses.

Returns:

  • (Array<Hash>)

    a collection of possible addresses

Since:

  • 0.0.1



43
44
45
# File 'lib/address_geocoder/requester.rb', line 43

def array_result
  [@result['results']].flatten
end

#connection_error(msg) ⇒ Object

Raise a connection error

Raises:

Since:

  • 0.0.1



48
49
50
# File 'lib/address_geocoder/requester.rb', line 48

def connection_error(msg)
  raise ConnectionError, msg
end

#make_callvoid

This method is abstract.

Abstract base method for initiating a call to a maps API

This method returns an undefined value.

Raises:

Since:

  • 0.0.1



29
30
31
# File 'lib/address_geocoder/requester.rb', line 29

def make_call
  raise NeedToOveride, 'make_call'
end

#success?Boolean

This method is abstract.

Abstract base method for checking if a call to a maps API suceeded

Returns true, or false if the request failed.

Returns:

  • (Boolean)

    true, or false if the request failed.

Raises:

Since:

  • 0.0.1



36
37
38
# File 'lib/address_geocoder/requester.rb', line 36

def success?
  raise NeedToOveride, 'success?'
end