Class: GoogleImageApi::Client
- Inherits:
-
Object
- Object
- GoogleImageApi::Client
- 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
- #find(query, options = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #request(options) ⇒ Object
- #request_image(query, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Client
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, = {} ) query = Url.new(query).title rescue query Result.new( request_image( query, ) ) end |
#request(options) ⇒ Object
13 14 15 16 |
# File 'lib/google_image_api/client.rb', line 13 def request( ) require 'open-uri' URI.parse( url_for( ) ).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, = {} ) request({:q => query}.merge( ) ) end |