Class: PetFinder::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pet_finder/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Client

TODO: make this a singleton class



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

def initialize(key)
  Client.default_params({:key => key})
end

Instance Method Details

#find_pets(location, opts = {}) ⇒ Object

ARGUMENTS: location string required the ZIP/postal code or city and state where the search should begin OPTIONS: animal string optional type of animal (barnyard, bird, cat, dog, horse, pig, reptile, smallfurry) breed string optional breed of animal (use pet.listBreeds for a list of valid breeds) size string optional size of animal (S=small, M=medium, L=large, XL=extra-large) sex character optional M=male, F=female age string optional age of the animal (Baby, Young, Adult, Senior) offset string optional set this to the value of lastOffset returned by a previous call to pet.find, and it will retrieve the next result set count integer optional how many records to return for this particular API call (default is 25) output string optional (default=basic) How much of each record to return: basic (no description) or full (includes description)



61
62
63
64
65
66
67
68
# File 'lib/pet_finder/client.rb', line 61

def find_pets(location, opts={})
  query = {
    :location => location
  }.merge(opts)
  res = Client.get('/pet.find', :query => query).parsed_response['petfinder']['pets']['pet']
  res = [res] unless res.is_a?(Array)
  res.map{|p| Pet.new(p)} unless res.nil? || res.empty?
end

#find_shelters(location, opts = {}) ⇒ Object

ARGUMENTS:

location string  required  the ZIP/postal code or city and state where the search should begin

OPTIONS:

name string  optional if location is specified full or partial shelter name
offset integer optional  offset into the result set (default is 0)
count  integer optional  how many records to return for this particular API call (default is 25)


23
24
25
26
27
28
29
30
# File 'lib/pet_finder/client.rb', line 23

def find_shelters(location, opts={})
  query = {
    :location => location
  }.merge(opts)
  res = Client.get('/shelter.find', :query => query).parsed_response['petfinder']['shelters']['shelter']
  res = [res] unless res.is_a?(Array)
  res.map{|atts| Shelter.new(atts)} unless res.nil? || res.empty?
end

#get_pet(pet_id, opts = {}) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/pet_finder/client.rb', line 87

def get_pet(pet_id, opts={})
  query = {
    :id => pet_id
  }.merge(opts)
  res = Client.get('/pet.get', :query => query).parsed_response['petfinder']['pet']
  Pet.new(res) unless res.nil?
end

#get_shelter(shelter_id, opts = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pet_finder/client.rb', line 33

def get_shelter(shelter_id, opts={})
  query = {
    :id => shelter_id
  }.merge(opts)
  res = Client.get('/shelter.get', :query => query).parsed_response['petfinder']['shelter']
  Shelter.new(res) unless res.nil?
end

#list_breeds(animal) ⇒ Object

breed.list ARGUMENTS: animal string required type of animal (barnyard, bird, cat, dog, horse, pig, reptile, smallfurry)



44
45
46
47
# File 'lib/pet_finder/client.rb', line 44

def list_breeds(animal)
  query = {:animal => animal}
  res = Client.get('/breed.list', :query => query).parsed_response['petfinder']['breeds']['breed']
end