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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
# File 'lib/cat_api/client.rb', line 11

def initialize(defaults={})
  @defaults = defaults
  response = get "#{ BASE_URL }categories/list"
  @categories = CatAPI::Categories.new( Nokogiri::XML(response) ).results
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



7
8
9
# File 'lib/cat_api/client.rb', line 7

def categories
  @categories
end

Instance Method Details

#get_images(options = {}) ⇒ Object



17
18
19
20
21
22
# File 'lib/cat_api/client.rb', line 17

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