Class: Ipbase::Endpoints

Inherits:
Object
  • Object
show all
Defined in:
lib/ipbase/endpoints.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Endpoints

Returns a new instance of Endpoints.



6
7
8
# File 'lib/ipbase/endpoints.rb', line 6

def initialize(options = {})
  @apikey = options[:apikey] || Ipbase.configuration.apikey
end

Instance Attribute Details

#apikey=(value) ⇒ Object (writeonly)

Sets the attribute apikey

Parameters:

  • value

    the value to set the attribute apikey to.



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

#statusObject



10
11
12
# File 'lib/ipbase/endpoints.rb', line 10

def status()
  @result = call_api('status?type=quota')
end