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
Constant Summary
Constants included from Request
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#initialize(options = {}) {|_self| ... } ⇒ 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(options = {}) {|_self| ... } ⇒ API
Using for adding adding api_key for requests API_KEY you can get from: ipinfodb.com/account.php
Constructor yields a block to allow more complicated object configuration.
It takes options with single optional key:
-
api_key
: string of api_key
Example:
ip_info = IpInfo::API.new()
26 27 28 29 30 |
# File 'lib/ip_info/api.rb', line 26 def initialize( = {}) yield self if block_given? self.api_key ||= .fetch(:api_key) { fail ApiKeyError.new("API key is missing.") } 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)
40 41 42 |
# File 'lib/ip_info/api.rb', line 40 def lookup(ip, = {}) query(ip, ) end |