ruby `rescue in block in connect': Failed to open TCP connection to api

Multi tool use
ruby `rescue in block in connect': Failed to open TCP connection to api
I am fairly new to ruby and I am having issues using code that I found on this
github. It is meant to use the Whitepages API to use their service and I am using it to do a reverse phone lookup. Here is my whitepages.rb file:
require 'json'
require 'net/https'
require 'uri'
class Whitepages
#Initialize the Whitepages class
# * api_key - The API key obtained from the Whitpages Developer website
def initialize(api_key)
api_version = "1.0"
@api_key = api_key
@base_uri = "http://api.whitepages.com/"
@find_person_uri = @base_uri + "find_person/" + api_version + "/?"
@reverse_phone_uri = @base_uri + "reverse_phone/" + api_version + "/?"
@reverse_address_uri = @base_uri + "reverse_address/" + api_version + "/?"
@uri = URI.parse(@base_uri)
@http = Net::HTTP.new(@uri.host, @uri.port)
end
#Retrieves contact information about a telephone number
#Accepts a hash:
# * phone - May be 7 digits if state provided otherwise 10 (*REQUIRED*)
# * state - Two digit code for the state
#More details may be found here: http://developer.whitepages.com/docs/Methods/reverse_phone
def reverse_phone(options)
resp, data = @http.get(build_uri(options, "reverse_phone"))
if resp.code== 200
return JSON.parse(data)
else
raise Exception,"code",resp.code
end
end
#Build the appropriate URL
def build_uri(options, type)
case type
when "reverse_phone"
built_uri = @reverse_phone_uri
when "reverse_address"
built_uri = @reverse_address_uri
when "find_person"
built_uri = @find_person_uri
end
options.each do |key,value|
if value != nil
built_uri = built_uri + key + "=" + value.gsub(' ', '%20') + ";"
end
end
built_uri = built_uri + "api_key=" + @api_key + ";outputtype=JSON"
return built_uri
end
end
And here is the class I use to test the code:
require 'rubygems'
require './whitepages'
API_KEY = MY ACTUAL API KEY AS A STRING
wp = Whitepages.new(API_KEY)
data = wp.reverse_phone({ "phone" => "4155551212",
"state" => "CA" })
When I run this file, I get the error: rescue in block in connect': Failed to open TCP connection to api.whitepages.com:80 (getaddrinfo: Name or service not known) (SocketError)
rescue in block in connect': Failed to open TCP connection to api.whitepages.com:80 (getaddrinfo: Name or service not known) (SocketError)
I can't find anything online specifically about connecting to APIs that would help me. Please, any help is greatly appreciated. PS: If you need to test the code, it does not take long at all to get a free API key from whitepages.com
proapi.whitepages.com:80
using
proagpi.whitepages.com
in the browser seems to show that it is no longer accessible..any help on how i can get this to work would be great– tee
Jul 1 at 13:02
proagpi.whitepages.com
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Most recent commit on that repo was four years ago, and a cursory Google search yields this information, which would seem to indicate that your target URL should be
proapi.whitepages.com:80
. It's possible that github repo is outdated.– Silvio Mayolo
Jul 1 at 3:58