Class: Petfinder::Client
- Inherits:
-
Object
- Object
- Petfinder::Client
- Defined in:
- lib/petfinder/client.rb
Instance Method Summary collapse
-
#breeds(animal_type) ⇒ Object
Valid animal types: barnyard, bird, cat, dog, horse, pig, reptile, smallfurry.
-
#find_pets(animal_type, location, options = {}) ⇒ Object
Options available: breed, size, sex, age, offset, count.
-
#find_shelters(location, options = {}) ⇒ Object
Options available: name, offset, count.
-
#find_shelters_by_breed(animal_type, breed, options = {}) ⇒ Object
Options available: offset, count.
-
#initialize(api_key = Petfinder.api_key, api_secret = Petfinder.api_secret) ⇒ Client
constructor
A new instance of Client.
- #pet(id) ⇒ Object
-
#random_pet(options = {}) ⇒ Object
Options available: animal, breed, size, sex, location, shelterid.
- #shelter(id) ⇒ Object
-
#shelter_pets(id, options = {}) ⇒ Object
Options available: status, offset, count.
- #token ⇒ Object
Constructor Details
#initialize(api_key = Petfinder.api_key, api_secret = Petfinder.api_secret) ⇒ Client
Returns a new instance of Client.
4 5 6 7 |
# File 'lib/petfinder/client.rb', line 4 def initialize(api_key = Petfinder.api_key, api_secret = Petfinder.api_secret) @api_key, @api_secret = api_key, api_secret raise Petfinder::Error.new("API key is required") unless @api_key end |
Instance Method Details
#breeds(animal_type) ⇒ Object
Valid animal types: barnyard, bird, cat, dog, horse, pig, reptile, smallfurry
10 11 12 13 |
# File 'lib/petfinder/client.rb', line 10 def breeds(animal_type) response = perform_get("/breed.list", { :animal => animal_type }) Breeds.new(response).breeds end |
#find_pets(animal_type, location, options = {}) ⇒ Object
Options available: breed, size, sex, age, offset, count
28 29 30 31 32 |
# File 'lib/petfinder/client.rb', line 28 def find_pets(animal_type, location, = {}) query = .merge(:animal => animal_type, :location => location) response = perform_get("/pet.find", query) Pet.multiple(response) end |
#find_shelters(location, options = {}) ⇒ Object
Options available: name, offset, count
40 41 42 43 44 |
# File 'lib/petfinder/client.rb', line 40 def find_shelters(location, = {}) query = .merge(:location => location) response = perform_get("/shelter.find", query) Shelter.multiple(response) end |
#find_shelters_by_breed(animal_type, breed, options = {}) ⇒ Object
Options available: offset, count
47 48 49 50 51 |
# File 'lib/petfinder/client.rb', line 47 def find_shelters_by_breed(animal_type, breed, = {}) query = .merge(:animal => animal_type, :breed => breed) response = perform_get("/shelter.listByBreed", query) Shelter.multiple(response) end |
#pet(id) ⇒ Object
15 16 17 18 |
# File 'lib/petfinder/client.rb', line 15 def pet(id) response = perform_get("/pet.get", { :id => id }) Pet.new(response) end |
#random_pet(options = {}) ⇒ Object
Options available: animal, breed, size, sex, location, shelterid
21 22 23 24 25 |
# File 'lib/petfinder/client.rb', line 21 def random_pet( = {}) query = .merge(:output => 'full') response = perform_get("/pet.getRandom", query) Pet.new(response) end |
#shelter(id) ⇒ Object
34 35 36 37 |
# File 'lib/petfinder/client.rb', line 34 def shelter(id) response = perform_get("/shelter.get", { :id => id }) Shelter.new(response) end |
#shelter_pets(id, options = {}) ⇒ Object
Options available: status, offset, count
54 55 56 57 58 |
# File 'lib/petfinder/client.rb', line 54 def shelter_pets(id, = {}) query = .merge(:id => id) response = perform_get("/shelter.getPets", query) Pet.multiple(response) end |
#token ⇒ Object
60 61 62 63 |
# File 'lib/petfinder/client.rb', line 60 def token response = perform_get("/auth.getToken", { :sig => digest_key_and_secret }) Auth.new(response).token end |