Class: CatAPI::Client

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

Constant Summary collapse

BASE_URL =
'http://thecatapi.com/api/'

Instance Method Summary collapse

Constructor Details

#initialize(defaults = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(defaults={})
  @defaults = defaults
end

Instance Method Details

#get_images(options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/cat_api/client.rb', line 13

def get_images(options={})
  options = @defaults.merge(options)
  options.delete_if {|k,v| v.nil? || ( v.kind_of?(Array) && v.empty? ) }
  response = get "#{ BASE_URL }images/get?format=xml&#{ URI.encode_www_form options }"
  CatAPI::ImageSearch.new( Nokogiri::XML(response) ).results
end