Skip to content

Commit

Permalink
ip from request
Browse files Browse the repository at this point in the history
  • Loading branch information
cmthakur committed Dec 16, 2014
1 parent 20923e5 commit f5b23dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class App < Sinatra::Base
set :logging, true
set :raise_errors, true
set :show_exceptions, false
set :port, 3001
set :port, 8080


get '/' do
ip = params['ip']
ip = params['ip'] || request.ip
Tracker.country_codes(ip)
end

get '/details' do
ip = params['ip']
ip = params['ip'] || request.ip
Tracker.get_details(ip).to_json
end

Expand Down
6 changes: 3 additions & 3 deletions lib/tracker.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Tracker

def self.get_details(ip)
geoip.city(ip).to_hash
geoip.city(ip).to_hash rescue {}
end

def self.country_codes(ip)
details = geoip.city(ip)
details[:country_code2] || details[:country_code3]
details = geoip.city(ip) || []
(details[:country_code2] || details[:country_code3]) rescue "N/A"
end


Expand Down

0 comments on commit f5b23dc

Please sign in to comment.