Class: Freegeoip::Request

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

Overview

Class to contain main request making logic to api.freegeoip.app

Constant Summary collapse

ENDPOINT =
'https://api.freegeoip.app/json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote, api_key) ⇒ Request

Returns a new instance of Request.



14
15
16
17
# File 'lib/freegeoip/request.rb', line 14

def initialize(remote, api_key)
  @remote = remote
  @api_key = api_key
end

Instance Attribute Details

#remoteObject (readonly)

Returns the value of attribute remote.



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

def remote
  @remote
end

Instance Method Details

#getObject



19
20
21
22
23
24
# File 'lib/freegeoip/request.rb', line 19

def get
  uri = URI("#{ENDPOINT}/#{remote}?apikey=#{@api_key}")
  res = Net::HTTP.get(uri)

  JSON.parse(res)
end