Class: GeocoderSimplified::GeocoderApi
- Inherits:
-
Object
- Object
- GeocoderSimplified::GeocoderApi
- Defined in:
- lib/geocoder-simplified/base.rb
Overview
< RedisTable
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#max_calls_per_day ⇒ Object
readonly
Returns the value of attribute max_calls_per_day.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #count ⇒ Object
- #dump ⇒ Object
-
#initialize(name, key, max_calls_per_day) ⇒ GeocoderApi
constructor
A new instance of GeocoderApi.
- #locate(place_name) ⇒ Object
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
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
24 25 26 |
# File 'lib/geocoder-simplified/base.rb', line 24 def counter @counter end |
#key ⇒ Object (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_day ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/geocoder-simplified/base.rb', line 24 def name @name end |
#symbol ⇒ Object (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
#count ⇒ Object
32 33 34 |
# File 'lib/geocoder-simplified/base.rb', line 32 def count @counter.count end |
#dump ⇒ Object
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 |