Class: GoogleImageApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_image_api/client.rb

Constant Summary collapse

BASE_URL =
"https://ajax.googleapis.com/ajax/services/search/images?v=1.0"

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



5
6
# File 'lib/google_image_api/client.rb', line 5

def initialize
end

Instance Method Details

#find(query, options = {}) ⇒ Object



8
9
10
11
# File 'lib/google_image_api/client.rb', line 8

def find( query, options = {} )
  query = Url.new(query).title rescue query
  Result.new( request_image( query, options ) )
end

#request(options) ⇒ Object



13
14
15
16
# File 'lib/google_image_api/client.rb', line 13

def request( options )
  require 'open-uri'
  URI.parse( url_for( options ) ).read( "User-Agent" => "Ruby/#{RUBY_VERSION}" )
end

#request_image(query, options = {}) ⇒ Object



18
19
20
# File 'lib/google_image_api/client.rb', line 18

def request_image( query, options = {} )
  request({:q => query}.merge( options ) )
end