Try this:
def search_google
api_key = 'xxx'
base_url = 'https://www.googleapis.com/customsearch/v1?key='
tail_url = '&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json'
main_url = base_url + api_key + tail_url
url = URI.parse(URI.encode(main_url))
response = Net::HTTP.start(url.host, use_ssl: true, verify_mode:
OpenSSL::SSL::VERIFY_NONE) do |http|
http.get url.request_uri
end
case response
when Net::HTTPRedirection
# repeat the request using response['Location']
when Net::HTTPSuccess
outputData = JSON.parse response.body
else
# response code isn't a 200; raise an exception
pp response.error!
end
return outputData
end
--
Posted via http://www.ruby-forum.com/.