class Geoplugin::Locate
Attributes
areacode[R]
city[R]
continentcode[R]
countrycode[R]
countryname[R]
currencycode[R]
currencyconverter[R]
currencysymbol[R]
currencysymbol_utf[R]
dmacode[R]
latitude[R]
longitude[R]
region[R]
regioncode[R]
regionname[R]
request[R]
status[R]
Public Class Methods
locate(ip = nil, options)
click to toggle source
locate
# File lib/geoplugin/locate.rb, line 50 def self.locate(ip = nil, options) response = apiresponse(ip, options) new(response) unless response.empty? end
new(attributes)
click to toggle source
# File lib/geoplugin/locate.rb, line 29 def initialize(attributes) @request = attributes['geoplugin_request'] @status = attributes['geoplugin_status'] @city = attributes['geoplugin_city'] @region = attributes['geoplugin_region'] @areacode = attributes['geoplugin_areaCode'] @dmacode = attributes['geoplugin_dmaCode'] @countrycode = attributes['geoplugin_countryCode'] @countryname = attributes['geoplugin_countryName'] @continentcode = attributes['geoplugin_continentCode'] @latitude = attributes['geoplugin_latitude'] @longitude = attributes['geoplugin_longitude'] @regioncode = attributes['geoplugin_regionCode'] @regionname = attributes['geoplugin_regionName'] @currencycode = attributes['geoplugin_currencyCode'] @currencysymbol = attributes['geoplugin_currencySymbol'] @currencysymbol_utf = attributes['geoplugin_currencySymbol_UTF8'] @currencyconverter = attributes['geoplugin_currencyConverter'] end
Private Class Methods
apiresponse(ip = nil, options = {})
click to toggle source
# File lib/geoplugin/locate.rb, line 58 def self.apiresponse(ip = nil, options = {}) return [] unless (not ip or IPAddress.valid? ip) url = "#{options[:ssl] ? API_SSL_URL : API_URL}?#{ip ? 'ip=' + ip : '?jsoncallback=?'}#{options[:key] ? '&k=' + options[:key] : ''}#{options[:base_currency] ? '&base_currency=' + options[:base_currency] : ''}" response = Faraday.get(URI.parse(URI.encode(url))) response.success? ? JSON.parse(response.body) : [] end