Class: Kscript::KkIpLookupUtils
- Inherits:
-
Base
- Object
- Base
- Kscript::KkIpLookupUtils
show all
- Defined in:
- lib/kscript/plugins/kk_ip_lookup_utils.rb
Constant Summary
collapse
- IP_API_BASE_URL =
'http://ip-api.com/json'
- IP_CHECK_URL =
'https://api.ipify.org?format=json'
Instance Attribute Summary collapse
Attributes inherited from Base
#logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#human_output?, inherited, #with_error_handling
Constructor Details
Returns a new instance of KkIpLookupUtils.
17
18
19
20
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 17
def initialize(*args, **opts)
super
@ip_address = args.first || fetch_public_ip
end
|
Instance Attribute Details
#ip_address ⇒ Object
Returns the value of attribute ip_address.
15
16
17
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 15
def ip_address
@ip_address
end
|
Class Method Details
.arguments ⇒ Object
37
38
39
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 37
def self.arguments
'<ip_address>'
end
|
.author ⇒ Object
49
50
51
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 49
def self.author
'kk'
end
|
.description ⇒ Object
53
54
55
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 53
def self.description
'Query IP geolocation and ISP info.'
end
|
.group ⇒ Object
45
46
47
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 45
def self.group
'network'
end
|
.usage ⇒ Object
41
42
43
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 41
def self.usage
"kscript ip_lookup <ip_address>\nkscript ip_lookup 8.8.8.8"
end
|
Instance Method Details
#fetch_location ⇒ Object
31
32
33
34
35
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 31
def fetch_location
validate_ip_address!
response = make_api_request
handle_response(response)
end
|
#run(*args, **_opts) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/kscript/plugins/kk_ip_lookup_utils.rb', line 22
def run(*args, **_opts)
with_error_handling do
ip = args.first || @ip_address
validate_ip_address!(ip)
response = make_api_request(ip)
handle_response(response)
end
end
|