Sha256: 2d64f3ccf3885b3b6716b72de4354873ff6b4d90fd37e24835177c1380b6adcc

Contents?: true

Size: 1.28 KB

Versions: 25

Compression:

Stored size: 1.28 KB

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Ipstack < Base

    def address(format = :full)
      s = region_code.empty? ? "" : ", #{region_code}"
      "#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "")
    end

    def state
      @data['region_name']
    end

    def state_code
      @data['region_code']
    end

    def country
      @data['country_name']
    end

    def postal_code
      @data['zip'] || @data['zipcode'] || @data['zip_code']
    end

    def self.response_attributes
      [
        ['ip', ''],
        ['hostname', ''],
        ['continent_code', ''],
        ['continent_name', ''],
        ['country_code', ''],
        ['country_name', ''],
        ['region_code', ''],
        ['region_name', ''],
        ['city', ''],
        ['zip', ''],
        ['latitude', 0],
        ['longitude', 0],
        ['location', {}],
        ['time_zone', {}],
        ['currency', {}],
        ['connection', {}],
        ['security', {}],
      ]
    end

    response_attributes.each do |attr, default|
      define_method attr do
        @data[attr] || default
      end
    end

    def metro_code
      Geocoder.log(:warn, "Ipstack does not implement `metro_code` in api results.  Please discontinue use.")
      0 # no longer implemented by ipstack
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
geocoder-1.8.3 lib/geocoder/results/ipstack.rb
geocoder-1.8.2 lib/geocoder/results/ipstack.rb
geocoder-1.8.1 lib/geocoder/results/ipstack.rb
geocoder-1.8.0 lib/geocoder/results/ipstack.rb
geocoder-1.7.5 lib/geocoder/results/ipstack.rb
geocoder-1.7.4 lib/geocoder/results/ipstack.rb
geocoder-1.7.3 lib/geocoder/results/ipstack.rb
geocoder-1.7.2 lib/geocoder/results/ipstack.rb
geocoder-1.7.1 lib/geocoder/results/ipstack.rb
geocoder-1.7.0 lib/geocoder/results/ipstack.rb
geocoder-1.6.7 lib/geocoder/results/ipstack.rb
geocoder-1.6.6 lib/geocoder/results/ipstack.rb
geocoder-1.6.5 lib/geocoder/results/ipstack.rb
geocoder-1.6.4 lib/geocoder/results/ipstack.rb
geocoder-1.6.3 lib/geocoder/results/ipstack.rb
geocoder-1.6.2 lib/geocoder/results/ipstack.rb
geocoder-1.6.1 lib/geocoder/results/ipstack.rb
geocoder-1.6.0 lib/geocoder/results/ipstack.rb
geocoder-1.5.2 lib/geocoder/results/ipstack.rb
really-broken-geocoder-2.0.0 lib/geocoder/results/ipstack.rb