Getting Google Image search to work within Rails

Hi,
I’m getting this strange behavior when I try to run search for
images using Google Images API. I suspect it’s because of my code and
not the API itself, here’s what I wrote:

uri = URI.parse("https://ajax.googleapis.com/")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
path = "ajax/services/search/images?v=1.0&q=gatsby&key=<key>"
path = URI.escape(path)
response = http.get(path, {"HTTP_REFERER" => "<my website>", 'User-

Agent’ => ‘mozilla’})
data = response.body
result = JSON.parse(data)

I’m creating the HTTP object this way(with just the server, then
calling the GET on the path) because I wanted to set the use_ssl flag
explicitly.

The response I get is:

302 Moved

302 Moved

The document has moved here.

When I try to access the same URL using curl, it works perfectly and
returns a JSON object, so I know the data is not wrong. Any ideas?

Older discussions related to the Image search said that the URL was a
plain HTTP url, it seems to have been changed to use HTTPS recently.

Thanks in advance !

Sudarshan