Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#encode(data) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/geoip_server.rb', line 55

def encode data
  {
    # The host or IP address string as requested
    :ip => data.request,
    # The IP address string after looking up the host
    :ip_lookup => data.ip,
    # The ISO3166-1 two-character country code
    :country_code => data.country_code2,
    # The ISO3166-2 three-character country code
    :country_code_long => data.country_code3,
    # The ISO3166 English-language name of the country
    :country => data.country_name,
    # The two-character continent code
    :continent => data.continent_code,
    # The region name
    :region => data.region_name,
    # The city name
    :city => data.city_name,
    # The postal code
    :postal_code => data.postal_code,
    # The latitude
    :lat => data.latitude,
    # The longitude
    :lng => data.longitude,
    # The USA DMA code, if available
    :dma_code => data.dma_code,
    # The area code, if available
    :area_code => data.area_code,
    # Timezone, if available
    :timezone => data.timezone,
  }
end

#respond_with(json) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/geoip_server.rb', line 41

def respond_with json
  # jsonp support
  callback, variable = params[:callback], params[:variable]
  if callback && variable
    "var #{variable} = #{json};\n#{callback}(#{variable});"
  elsif variable
    "var #{variable} = #{json};"
  elsif callback
    "#{callback}(#{json});"
  else
    json
  end
end