Class: GeocoderSimplified::GeocoderApi

Inherits:
Object
  • Object
show all
Defined in:
lib/geocoder-simplified/base.rb

Overview

< RedisTable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, key, max_calls_per_day) ⇒ GeocoderApi

Returns a new instance of GeocoderApi.



25
26
27
28
29
30
31
# File 'lib/geocoder-simplified/base.rb', line 25

def initialize(name, key, max_calls_per_day)
  @name = name + POSTFIX
  @key = key
  @max_calls_per_day = max_calls_per_day
  @symbol = name.underscore.to_sym
  @counter = RedisExpiringCounter.new(@name, Util::SECONDS_PER_DAY, @max_calls_per_day)
end

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



24
25
26
# File 'lib/geocoder-simplified/base.rb', line 24

def counter
  @counter
end

#keyObject (readonly)

Returns the value of attribute key.



24
25
26
# File 'lib/geocoder-simplified/base.rb', line 24

def key
  @key
end

#max_calls_per_dayObject (readonly)

Returns the value of attribute max_calls_per_day.



24
25
26
# File 'lib/geocoder-simplified/base.rb', line 24

def max_calls_per_day
  @max_calls_per_day
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/geocoder-simplified/base.rb', line 24

def name
  @name
end

#symbolObject (readonly)

Returns the value of attribute symbol.



24
25
26
# File 'lib/geocoder-simplified/base.rb', line 24

def symbol
  @symbol
end

Instance Method Details

#countObject



32
33
34
# File 'lib/geocoder-simplified/base.rb', line 32

def count
  @counter.count
end

#dumpObject



35
36
37
# File 'lib/geocoder-simplified/base.rb', line 35

def dump
  @counter.dump
end

#locate(place_name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/geocoder-simplified/base.rb', line 38

def locate(place_name)
  location = []
  latitude = 0.0
  longitude = 0.0

  Geocoder::Configuration.lookup = @symbol # set the geocoder to use this api

  begin
    warning_text = Util.capture_stderr do
      location = Geocoder.search(place_name)
      increment_count
    end
    # Write sucess to log here
    #Rails.logger.warn "Geocoder: " + warning_text if warning_text != ""
  rescue StandardError => e
    # Write fail to log here
    #Rails.logger.error "Geocoder: " + @name + ": "+ e.to_s
  end

  if not (location.nil? or location.count == 0)
    latitude = location.first.latitude
    longitude = location.first.longitude
  end

  return latitude, longitude
end