Class: IpInfo::API
- Inherits:
-
Object
- Object
- IpInfo::API
- 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
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#initialize ⇒ API
constructor
Using for adding adding api_key for requests API_KEY you can get from: ipinfodb.com/account.php.
-
#lookup(ip, options = {}) ⇒ Object
Retreive the remote location of a given ip address.
Methods included from Parser
Methods included from Request
Constructor Details
#initialize ⇒ API
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()
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_key ⇒ Object
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 befalse(default) ortrue
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, = {}) query(ip, ) end |