Sha256: 56aa19eac8eb74c3ba6a9d90e1e2684555559ad9018a84f2fe2d2cc985cfcede

Contents?: true

Size: 708 Bytes

Versions: 1

Compression:

Stored size: 708 Bytes

Contents

module Where
  class IpAddress < Where::Base
    GEOPLUGIN_URL = 'http://www.geoplugin.net/json.gp?ip='
    FREEGEOIP_URL = 'http://freegeoip.net/json/'

    def self.geocode(address, opts={})
      api_url = opts[:geocoder] == 'geoplugin' ? GEOPLUGIN_URL : FREEGEOIP_URL
      super(address, api_url)
    end

    def initialize(data='')
      super(data.to_s.gsub('geoplugin_', ''))
    end

    def latitude=(val)
      @lat = val
    end

    def longitude=(val)
      @lng = val
    end

    def accuracy
      if street
        'street_address'
      elsif city
        'city'
      elsif region
        'region'
      elsif country
        'country'
      else
        ''
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
where-0.0.2 lib/where/ip_address.rb