| Store | Cart

Re: read_nonblock' : end of file reached (EOFError)

From: Lukas W. <shis...@googlemail.com>
Tue, 31 Jan 2012 13:10:38 +0900
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/.

Recent Messages in this Thread
Lukas W. Jan 31, 2012 02:00 am
Lukas W. Jan 31, 2012 04:10 am
Messages in this thread