Class: Freegeoip::Request
- Inherits:
-
Object
- Object
- Freegeoip::Request
- 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
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(remote, api_key) ⇒ Request
constructor
A new instance of Request.
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
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
12 13 14 |
# File 'lib/freegeoip/request.rb', line 12 def remote @remote end |
Instance Method Details
#get ⇒ Object
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 |