Reputation: 1336
I am trying to get information off an IP Address in ruby. The two main types of information I want is the Country it is associated with and if it is malicious or not. The only website I found that can do this is: https://ipdata.co/docs.html which provides ruby code for doing it however as a newbie to ruby, I don't quite understand it. If I paste the ruby code into my file and run it, I get the error:
`require': cannot load such file -- rest_client (LoadError)
I don't know where to get this rest_client file if it exists and I've tried looking everywhere for solutions...Maybe all I need to do is install some sort of gem?? I also got an API key from their site, but I don't see where to apply it. I tried reaching out to the people from ipdata but the only thing the guy told me was that he didn't know ruby that well and couldn't help.
Any help is greatly appreciated.
Upvotes: 0
Views: 221
Reputation: 11102
Usually when you see require
in a Ruby script it is referring to a gem. However there is a mistake in their example: it should be rest-client
not rest_client
.
In this case, you can install the necessary rest-client
gem by running this command in your shell:
gem install rest-client
Regarding the API key, looking at the ipdata python implementation I see that the API key is passed as another HTTP header. So to modify their Ruby example:
require 'rubygems' if RUBY_VERSION < '1.9'
require 'rest-client'
headers = {
:accept => 'application/json',
:api_key => 'YOUR API KEY FROM IPDATA GOES HERE'
}
response = RestClient.get('https://api.ipdata.co/8.8.8.8/', headers)
puts response
Upvotes: 2