Class: Ipbase::Endpoints
- Inherits:
-
Object
- Object
- Ipbase::Endpoints
- Defined in:
- lib/ipbase/endpoints.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
writeonly
Sets the attribute apikey.
Instance Method Summary collapse
- #call_api(route) ⇒ Object
- #info(ip, language = '') ⇒ Object
-
#initialize(options = {}) ⇒ Endpoints
constructor
A new instance of Endpoints.
- #status ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Endpoints
Returns a new instance of Endpoints.
6 7 8 |
# File 'lib/ipbase/endpoints.rb', line 6 def initialize( = {}) @apikey = [:apikey] || Ipbase.configuration.apikey end |
Instance Attribute Details
#apikey=(value) ⇒ Object (writeonly)
Sets the attribute apikey
4 5 6 |
# File 'lib/ipbase/endpoints.rb', line 4 def apikey=(value) @apikey = value end |
Instance Method Details
#call_api(route) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ipbase/endpoints.rb', line 18 def call_api(route) begin @response = RestClient.get "#{Ipbase::BASE_URL}#{route}&apikey=#{@apikey}", { 'Accept' => 'application/json' } rescue RestClient::ExceptionWithResponse => e @data = e.response end end |
#info(ip, language = '') ⇒ Object
14 15 16 |
# File 'lib/ipbase/endpoints.rb', line 14 def info(ip, language = '') @result = call_api(sprintf('info?ip=%s&language=%s', ip, language)) end |
#status ⇒ Object
10 11 12 |
# File 'lib/ipbase/endpoints.rb', line 10 def status() @result = call_api('status?type=quota') end |