Class: IpInfo::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Parser, Request
Defined in:
lib/ip_info/api.rb,
lib/ip_info/parser.rb,
lib/ip_info/request.rb

Defined Under Namespace

Modules: Parser, Request Classes: ApiKeyError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#parse_response

Methods included from Request

#query

Constructor Details

#initializeAPI

Using for adding adding api_key for requests API_KEY you can get from: ipinfodb.com/account.php

Api key also can be stored in environment variable ENV.

It takes one arguments:

  • api_key: string of api_key

Example:

ip_info = IpInfo::API.new()

Raises:



26
27
28
29
# File 'lib/ip_info/api.rb', line 26

def initialize()
  self.api_key ||= ENV['IP_INFO_KEY']
  raise ApiKeyError.new("Error! Add your API key") if api_key.nil?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



14
15
16
# File 'lib/ip_info/api.rb', line 14

def api_key
  @api_key
end

Instance Method Details

#lookup(ip, options = {}) ⇒ Object

Retreive the remote location of a given ip address.

It takes two optional arguments:

  • type: can either be :country (default) or :city

  • time_zone: can either be false (default) or true

Example:

ip_info.lookup('209.85.227.104', type: 'city', time_zone: true)


39
40
41
# File 'lib/ip_info/api.rb', line 39

def lookup(ip, options = {})
  query(ip, options)
end