File: ipapi_com.rb

package info (click to toggle)
ruby-geocoder 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 732 kB
  • sloc: ruby: 6,173; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 739 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'geocoder/results/base'

module Geocoder::Result
  class IpapiCom < Base

    def coordinates
      [lat, lon]
    end

    def address
      "#{city}, #{state_code} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
    end

    def state
      region_name
    end

    def state_code
      region
    end

    def postal_code
      zip
    end

    def country_code
      @data['countryCode']
    end

    def region_name
      @data['regionName']
    end

    def self.response_attributes
      %w[country region city zip timezone isp org as reverse query status message mobile proxy lat lon]
    end

    response_attributes.each do |attribute|
      define_method attribute do
        @data[attribute]
      end
    end

  end
end