Class: Freegeoip::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/freegeoip/request.rb

Constant Summary collapse

ENDPOINT =
"http://freegeoip.net/"
FORMAT =
'json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote) ⇒ Request

Returns a new instance of Request.



12
13
14
# File 'lib/freegeoip/request.rb', line 12

def initialize(remote)
  @remote = remote
end

Instance Attribute Details

#remoteObject (readonly)

Returns the value of attribute remote.



10
11
12
# File 'lib/freegeoip/request.rb', line 10

def remote
  @remote
end

Instance Method Details

#getObject



16
17
18
19
20
21
# File 'lib/freegeoip/request.rb', line 16

def get
  uri = URI(ENDPOINT + FORMAT + "/" + remote)
  res = Net::HTTP.get(uri)

  JSON.parse(res)
end