Module: GeoipRails
- Defined in:
- lib/geoip_rails.rb,
lib/geoip_rails/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Class Method Summary collapse
- .area_code(ip) ⇒ Object
- .city(ip) ⇒ Object
-
.country(ip) ⇒ Object
def geolocation ip = request.remote_ip HTTParty.get(“freegeoip.net/json/#ip”) end.
- .country_code(ip) ⇒ Object
- .find_by_ip(ip) ⇒ Object
- .find_by_ip_and_format(ip, format) ⇒ Object
-
.geolocate(*args) ⇒ Object
def print ip, format puts find_by_ip_and_format ip, format end.
- .latitude(ip) ⇒ Object
- .longitude(ip) ⇒ Object
- .metro_code(ip) ⇒ Object
- .region_code(ip) ⇒ Object
- .region_name(ip) ⇒ Object
- .zipcode(ip) ⇒ Object
Class Method Details
.area_code(ip) ⇒ Object
77 78 79 |
# File 'lib/geoip_rails.rb', line 77 def area_code ip find_by_ip(ip)["area_code"] end |
.city(ip) ⇒ Object
49 50 51 |
# File 'lib/geoip_rails.rb', line 49 def city ip find_by_ip(ip)["city"] end |
.country(ip) ⇒ Object
def geolocation ip = request.remote_ip HTTParty.get(“freegeoip.net/json/#ip”) end
41 42 43 |
# File 'lib/geoip_rails.rb', line 41 def country ip find_by_ip(ip)["country_name"] end |
.country_code(ip) ⇒ Object
45 46 47 |
# File 'lib/geoip_rails.rb', line 45 def country_code ip find_by_ip(ip)["country_code"] end |
.find_by_ip(ip) ⇒ Object
7 8 9 |
# File 'lib/geoip_rails.rb', line 7 def find_by_ip ip HTTParty.get("http://freegeoip.net/json/#{ip}") end |
.find_by_ip_and_format(ip, format) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/geoip_rails.rb', line 11 def find_by_ip_and_format ip, format ip = ip.downcase format = format.downcase `wget "http://freegeoip.net/#{format}/#{ip}"` response = "" File.open("#{ip}").each { |line| response += line}#.gsub("\n", " ") `rm -rf #{ip}` return response end |
.geolocate(*args) ⇒ Object
def print ip, format
puts find_by_ip_and_format ip, format
end
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/geoip_rails.rb', line 25 def geolocate(*args) supported_formats = ["json", "xml", "csv"] if args.length == 1 find_by_ip(args[0]) else format = args[1].strip.downcase format = "json" if !supported_formats.include?(format) find_by_ip_and_format(args[0], format) end end |
.latitude(ip) ⇒ Object
65 66 67 |
# File 'lib/geoip_rails.rb', line 65 def latitude ip find_by_ip(ip)["latitude"] end |
.longitude(ip) ⇒ Object
69 70 71 |
# File 'lib/geoip_rails.rb', line 69 def longitude ip find_by_ip(ip)["longitude"] end |
.metro_code(ip) ⇒ Object
73 74 75 |
# File 'lib/geoip_rails.rb', line 73 def metro_code ip find_by_ip(ip)["metro_code"] end |
.region_code(ip) ⇒ Object
53 54 55 |
# File 'lib/geoip_rails.rb', line 53 def region_code ip find_by_ip(ip)["region_code"] end |
.region_name(ip) ⇒ Object
57 58 59 |
# File 'lib/geoip_rails.rb', line 57 def region_name ip find_by_ip(ip)["region_name"] end |
.zipcode(ip) ⇒ Object
61 62 63 |
# File 'lib/geoip_rails.rb', line 61 def zipcode ip find_by_ip(ip)["zipcode"] end |