petfinder 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ Ruby gem wrapper for the {Petfinder API}[http://www.petfinder.com/developers/api
4
4
 
5
5
  == Installation
6
6
 
7
- sudo gem install petfinder
7
+ sudo gem install petfinder
8
8
 
9
9
  == Get your API key
10
10
 
@@ -12,6 +12,38 @@ Get your Petfinder API key at: http://www.petfinder.com/developers/api-key
12
12
 
13
13
  == Usage
14
14
 
15
+ === Instantiate a client
16
+
17
+ petfinder = Petfinder::Client.new('your_api_key', 'your_api_secret')
18
+
19
+ === or configure once
20
+
21
+ Petfinder.configure do |config|
22
+ config.api_key = 'your_api_key'
23
+ config.api_secret = 'your_api_secret'
24
+ end
25
+ petfinder = Petfinder::Client.new
26
+
27
+ == Examples
28
+
29
+ ==== Return a list of dogs in the "90210" zip code
30
+
31
+ pets = petfinder.find_pets('dog', '90210')
32
+ pets.count
33
+ # => "25"
34
+
35
+ pets.first.name
36
+ # => "Petey"
37
+
38
+ pets.first.shelterid
39
+ # => "CA123"
40
+
41
+ ==== Return information about the shelter with id "CA123"
42
+
43
+ shelter = petfinder.shelter('CA123')
44
+ shelter.name
45
+ # => "Melrose Place SPCA"
46
+
15
47
  == TODO
16
48
 
17
49
  * Implement use of security token when Petfinder requires it
data/Rakefile CHANGED
@@ -11,10 +11,10 @@ begin
11
11
  gem.homepage = "http://github.com/ehutzelman/petfinder"
12
12
  gem.authors = ["Eric Hutzelman"]
13
13
 
14
- gem.add_dependency('hashie', '>= 0.1.3')
14
+ gem.add_dependency('happymapper', '>= 0.3.2')
15
15
  gem.add_dependency('httparty', '>= 0.5.0')
16
16
 
17
- gem.add_development_dependency "shoulda", ">= 2.10.1"
17
+ gem.add_development_dependency "rspec", ">= 1.3.0"
18
18
  gem.add_development_dependency 'fakeweb', '>= 1.2.5'
19
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
20
  end
@@ -23,29 +23,21 @@ rescue LoadError
23
23
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
24
  end
25
25
 
26
- require 'rake/testtask'
27
- Rake::TestTask.new(:test) do |test|
28
- test.libs << 'lib' << 'test'
29
- test.pattern = 'test/**/test_*.rb'
30
- test.verbose = true
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
31
30
  end
32
31
 
33
- begin
34
- require 'rcov/rcovtask'
35
- Rcov::RcovTask.new do |test|
36
- test.libs << 'test'
37
- test.pattern = 'test/**/test_*.rb'
38
- test.verbose = true
39
- end
40
- rescue LoadError
41
- task :rcov do
42
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
- end
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
44
36
  end
45
37
 
46
- task :test => :check_dependencies
38
+ task :spec => :check_dependencies
47
39
 
48
- task :default => :test
40
+ task :default => :spec
49
41
 
50
42
  require 'rake/rdoctask'
51
43
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/lib/petfinder.rb CHANGED
@@ -1,6 +1,5 @@
1
- require 'rubygems'
2
1
  require 'httparty'
3
- require 'hashie'
2
+ require 'happymapper'
4
3
  require 'digest/md5'
5
4
 
6
5
  module Petfinder
@@ -19,4 +18,9 @@ module Petfinder
19
18
  end
20
19
 
21
20
  directory = File.expand_path(File.dirname(__FILE__))
22
- require File.join(directory, 'petfinder', 'client')
21
+
22
+ require File.join(directory, 'petfinder', 'client')
23
+ require File.join(directory, 'petfinder', 'pet')
24
+ require File.join(directory, 'petfinder', 'breeds')
25
+ require File.join(directory, 'petfinder', 'shelter')
26
+ require File.join(directory, 'petfinder', 'auth')
@@ -0,0 +1,13 @@
1
+ module Petfinder
2
+
3
+ class Auth
4
+ include HappyMapper
5
+
6
+ tag 'auth'
7
+ element :key, String
8
+ element :token, String
9
+ element :expires, String
10
+ element :expiresString, String
11
+ end
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ module Petfinder
2
+
3
+ class Breeds
4
+ include HappyMapper
5
+ tag 'breeds'
6
+
7
+ has_many :breeds, String, :tag => 'breed'
8
+ end
9
+
10
+ end
@@ -15,64 +15,60 @@ module Petfinder
15
15
  # Valid animal types: barnyard, bird, cat, dog, horse, pig, reptile, smallfurry
16
16
  def breeds(animal_type)
17
17
  response = perform_get("/breed.list", :query => {:animal => animal_type})
18
- return_as_array(response.breeds.breed)
18
+ Breeds.parse(response, :single => true).breeds
19
19
  end
20
20
 
21
21
  def pet(id)
22
22
  response = perform_get("/pet.get", :query => {:id => id})
23
- response.pet
23
+ Pet.parse(response, :single => true)
24
24
  end
25
25
 
26
26
  # Options available: animal, breed, size, sex, location, shelterid
27
27
  def random_pet(options = {})
28
28
  response = perform_get("/pet.getRandom", :query => {:output => 'full'})
29
- response.pet
29
+ Pet.parse(response, :single => true)
30
30
  end
31
31
 
32
32
  # Options available: breed, size, sex, age, offset, count
33
33
  def find_pets(animal_type, location, options = {})
34
34
  query = options.merge(:animal => animal_type, :location => location)
35
35
  response = perform_get("/pet.find", :query => query)
36
- return_as_array(response.pets.pet)
36
+ Pet.parse(response)
37
37
  end
38
38
 
39
39
  def shelter(id)
40
40
  response = perform_get("/shelter.get", :query => {:id => id})
41
- response.shelter
41
+ Shelter.parse(response, :single => true)
42
42
  end
43
43
 
44
44
  # Options available: name, offset, count
45
45
  def find_shelters(location, options = {})
46
46
  query = options.merge(:location => location)
47
47
  response = perform_get("/shelter.find", :query => query)
48
- return_as_array(response.shelters.shelter)
48
+ Shelter.parse(response)
49
49
  end
50
50
 
51
51
  # Options available: offset, count
52
52
  def find_shelters_by_breed(animal_type, breed, options = {})
53
53
  query = options.merge(:animal => animal_type, :breed => breed)
54
54
  response = perform_get("/shelter.listByBreed", :query => query)
55
- return_as_array(response.shelters.shelter)
55
+ Shelter.parse(response)
56
56
  end
57
57
 
58
58
  # Options available: status, offset, count
59
59
  def shelter_pets(id, options = {})
60
60
  query = options.merge(:id => id)
61
61
  response = perform_get("/shelter.getPets", :query => query)
62
- return_as_array(response.pets.pet)
62
+ Pet.parse(response)
63
63
  end
64
64
 
65
65
  def token
66
66
  response = perform_get("/auth.getToken", :query => {:sig => digest_key_and_secret})
67
- response.auth.token
67
+ Auth.parse(response, :single => true).token
68
68
  end
69
69
 
70
70
  private
71
71
 
72
- def return_as_array(object)
73
- object.class == Array ? object : [object]
74
- end
75
-
76
72
  def digest_key_and_secret
77
73
  raise "API secret is required" if @api_secret.blank?
78
74
  Digest::MD5.hexdigest(@api_secret + "key=#{@api_key}")
@@ -81,7 +77,7 @@ module Petfinder
81
77
  def perform_get(uri, options = {})
82
78
  response = self.class.get(uri, options)
83
79
  raise_errors(response)
84
- mash = Hashie::Mash.new(response['petfinder'])
80
+ response.body
85
81
  end
86
82
 
87
83
  def raise_errors(response)
@@ -0,0 +1,77 @@
1
+ module Petfinder
2
+
3
+ class Photo
4
+ include HappyMapper
5
+
6
+ tag 'photo'
7
+ attribute :id, String
8
+ attribute :size, String
9
+ element :url, String, :tag => '.'
10
+ end
11
+
12
+ class Pet
13
+ include HappyMapper
14
+ attr_accessor :pictures
15
+
16
+ tag 'pet'
17
+ element :id, Integer
18
+ element :shelter_id, String, :tag => 'shelterId'
19
+ element :shelter_pet_id, String, :tag => 'shelterPetId'
20
+ element :name, String
21
+ element :animal, String
22
+ has_many :breeds, String, :tag => 'breed', :deep => true
23
+ element :mix, String
24
+ element :age, String
25
+ element :sex, String
26
+ element :size, String
27
+ has_many :options, String, :tag => 'option', :deep => true
28
+ element :description, String
29
+ element :last_update, DateTime, :tag => 'lastUpdate'
30
+ element :status, String
31
+ has_many :photos, Photo, :tag => 'photo', :deep => true
32
+
33
+ private :photos
34
+
35
+ after_parse do |pet|
36
+ pet.remove_link_from_description
37
+ pet.consolidate_photos
38
+ end
39
+
40
+ def remove_link_from_description
41
+ self.description = description[0..description.index("\n") - 1] if description.index("\n")
42
+ end
43
+
44
+ def consolidate_photos
45
+ @pictures = []
46
+ photos.map {|photo| photo.id}.uniq.each do |id|
47
+ @pictures << Picture.new(photos.select {|photo| photo.id == id})
48
+ end
49
+ end
50
+ end
51
+
52
+ class Picture
53
+ attr_reader :large, :medium, :small, :thumbnail, :tiny
54
+
55
+ def initialize(photos)
56
+ photos.each do |photo|
57
+ case photo.size
58
+ when "x"
59
+ @large = photo.url
60
+ when "pn"
61
+ @medium = photo.url
62
+ when "fpm"
63
+ @small = photo.url
64
+ when "pnt"
65
+ @thumbnail = photo.url
66
+ when "t"
67
+ @tiny = photo.url
68
+ end
69
+ end
70
+ end
71
+
72
+ def to_s
73
+ large
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,22 @@
1
+ module Petfinder
2
+
3
+ class Shelter
4
+ include HappyMapper
5
+
6
+ tag 'shelter'
7
+ element :id, String
8
+ element :name, String
9
+ element :address1, String
10
+ element :address2, String
11
+ element :city, String
12
+ element :state, String
13
+ element :zip, String
14
+ element :country, String
15
+ element :latitude, String
16
+ element :longitude, String
17
+ element :phone, String
18
+ element :fax, String
19
+ element :email, String
20
+ end
21
+
22
+ end
data/petfinder.gemspec ADDED
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{petfinder}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Hutzelman"]
12
+ s.date = %q{2010-07-09}
13
+ s.description = %q{Ruby gem wrapper for the Petfinder API}
14
+ s.email = %q{ehutzelman@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/petfinder.rb",
27
+ "lib/petfinder/auth.rb",
28
+ "lib/petfinder/breeds.rb",
29
+ "lib/petfinder/client.rb",
30
+ "lib/petfinder/pet.rb",
31
+ "lib/petfinder/shelter.rb",
32
+ "petfinder.gemspec",
33
+ "spec/fixtures/auth.xml",
34
+ "spec/fixtures/breed_list.xml",
35
+ "spec/fixtures/pet.xml",
36
+ "spec/fixtures/pet_list.xml",
37
+ "spec/fixtures/shelter.xml",
38
+ "spec/fixtures/shelter_list.xml",
39
+ "spec/petfinder_spec.rb",
40
+ "spec/spec.opts",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/ehutzelman/petfinder}
44
+ s.rdoc_options = ["--charset=UTF-8"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = %q{1.3.7}
47
+ s.summary = %q{Ruby gem wrapper for the Petfinder API}
48
+ s.test_files = [
49
+ "spec/petfinder_spec.rb",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<happymapper>, [">= 0.3.2"])
59
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.0"])
60
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
61
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.5"])
62
+ else
63
+ s.add_dependency(%q<happymapper>, [">= 0.3.2"])
64
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
65
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
66
+ s.add_dependency(%q<fakeweb>, [">= 1.2.5"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<happymapper>, [">= 0.3.2"])
70
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
71
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
72
+ s.add_dependency(%q<fakeweb>, [">= 1.2.5"])
73
+ end
74
+ end
75
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Petfinder::Client do
4
+ before do
5
+ @client = Petfinder::Client.new('1234567', 'mysekrit')
6
+ end
7
+
8
+ it "should get a random pet" do
9
+ stub_get("http://api.petfinder.com/pet.getRandom?key=1234567&output=full", "pet.xml")
10
+ pet = @client.random_pet
11
+ pet.name.should == 'Charlie'
12
+ end
13
+
14
+ it "should get a specific pet by id" do
15
+ stub_get("http://api.petfinder.com/pet.get?key=1234567&id=123", "pet.xml")
16
+ pet = @client.pet(123)
17
+ pet.name.should == 'Charlie'
18
+ end
19
+
20
+ it "should find pets matching a query" do
21
+ stub_get("http://api.petfinder.com/pet.find?key=1234567&animal=dog&location=77007", "pet_list.xml")
22
+ pets = @client.find_pets('dog', '77007')
23
+ pets.first.name.should == 'Petey'
24
+ end
25
+
26
+ describe "retrieving a pet" do
27
+ before do
28
+ stub_get("http://api.petfinder.com/pet.getRandom?key=1234567&output=full", "pet.xml")
29
+ @pet = @client.random_pet
30
+ end
31
+
32
+ it "should hide photos collection" do
33
+ @pet.should_not respond_to(:photos)
34
+ end
35
+
36
+ it "should reorganize photos for pet as pictures" do
37
+ @pet.pictures[0].thumbnail.should == 'http://photocache.petfinder.com/fotos/IL173/IL173.10141994-1-pnt.jpg'
38
+ @pet.pictures[1].large.should == 'http://photocache.petfinder.com/fotos/IL173/IL173.10141994-2-x.jpg'
39
+ end
40
+ end
41
+
42
+ it "should get the list of breeds for the given animal type" do
43
+ stub_get("http://api.petfinder.com/breed.list?key=1234567&animal=horse", "breed_list.xml")
44
+ breeds = @client.breeds('horse')
45
+ breeds.first.should == "Appaloosa"
46
+ end
47
+
48
+ it "should get a specific shelter by id" do
49
+ stub_get("http://api.petfinder.com/shelter.get?key=1234567&id=123", "shelter.xml")
50
+ shelter = @client.shelter(123)
51
+ shelter.name.should == 'Lucky Dog Rescue'
52
+ end
53
+
54
+ it "should find shelters matching a query" do
55
+ stub_get("http://api.petfinder.com/shelter.find?key=1234567&location=77007", "shelter_list.xml")
56
+ shelters = @client.find_shelters('77007')
57
+ shelters.first.name.should == 'Pup Squad Animal Rescue'
58
+ end
59
+
60
+ it "should find shelters matching a breed" do
61
+ stub_get("http://api.petfinder.com/shelter.listByBreed?key=1234567&animal=horse&breed=arabian", "shelter_list.xml")
62
+ shelters = @client.find_shelters_by_breed('horse', 'arabian')
63
+ shelters.first.name.should == 'Pup Squad Animal Rescue'
64
+ end
65
+
66
+ it "should get the list of pets available for the given shelter" do
67
+ stub_get("http://api.petfinder.com/shelter.getPets?key=1234567&id=123", "pet_list.xml")
68
+ pets = @client.shelter_pets(123)
69
+ pets.first.name.should == 'Petey'
70
+ end
71
+
72
+ it "should get an authorization token" do
73
+ digest = @client.send(:digest_key_and_secret)
74
+ stub_get("http://api.petfinder.com/auth.getToken?key=1234567&sig=#{digest}", "auth.xml")
75
+ @client.token.should == '39038a000f404335d90bab019c0c7e2d'
76
+ end
77
+
78
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,21 +1,16 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'fakeweb'
5
-
6
- begin require 'redgreen'; rescue LoadError; end
7
-
8
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
10
4
  require 'petfinder'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'fakeweb'
11
8
 
12
- class Test::Unit::TestCase
9
+ Spec::Runner.configure do |config|
13
10
  end
14
11
 
15
12
  def fixture_file(filename)
16
- return '' if filename == ''
17
- file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
18
- File.read(file_path)
13
+ File.read(File.dirname(__FILE__) + "/fixtures/#{filename}")
19
14
  end
20
15
 
21
16
  def stub_get(url, filename, options={})
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petfinder
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 0
8
8
  - 1
9
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Eric Hutzelman
@@ -14,30 +15,34 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-12 00:00:00 -05:00
18
+ date: 2010-07-09 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: hashie
22
+ name: happymapper
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 23
27
30
  segments:
28
31
  - 0
29
- - 1
30
32
  - 3
31
- version: 0.1.3
33
+ - 2
34
+ version: 0.3.2
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: httparty
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 11
41
46
  segments:
42
47
  - 0
43
48
  - 5
@@ -46,26 +51,30 @@ dependencies:
46
51
  type: :runtime
47
52
  version_requirements: *id002
48
53
  - !ruby/object:Gem::Dependency
49
- name: shoulda
54
+ name: rspec
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 27
55
62
  segments:
56
- - 2
57
- - 10
58
63
  - 1
59
- version: 2.10.1
64
+ - 3
65
+ - 0
66
+ version: 1.3.0
60
67
  type: :development
61
68
  version_requirements: *id003
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: fakeweb
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ">="
68
76
  - !ruby/object:Gem::Version
77
+ hash: 21
69
78
  segments:
70
79
  - 1
71
80
  - 2
@@ -90,15 +99,21 @@ files:
90
99
  - Rakefile
91
100
  - VERSION
92
101
  - lib/petfinder.rb
102
+ - lib/petfinder/auth.rb
103
+ - lib/petfinder/breeds.rb
93
104
  - lib/petfinder/client.rb
94
- - test/fixtures/auth.xml
95
- - test/fixtures/breed_list.xml
96
- - test/fixtures/pet.xml
97
- - test/fixtures/pet_list.xml
98
- - test/fixtures/shelter.xml
99
- - test/fixtures/shelter_list.xml
100
- - test/helper.rb
101
- - test/test_petfinder.rb
105
+ - lib/petfinder/pet.rb
106
+ - lib/petfinder/shelter.rb
107
+ - petfinder.gemspec
108
+ - spec/fixtures/auth.xml
109
+ - spec/fixtures/breed_list.xml
110
+ - spec/fixtures/pet.xml
111
+ - spec/fixtures/pet_list.xml
112
+ - spec/fixtures/shelter.xml
113
+ - spec/fixtures/shelter_list.xml
114
+ - spec/petfinder_spec.rb
115
+ - spec/spec.opts
116
+ - spec/spec_helper.rb
102
117
  has_rdoc: true
103
118
  homepage: http://github.com/ehutzelman/petfinder
104
119
  licenses: []
@@ -109,26 +124,30 @@ rdoc_options:
109
124
  require_paths:
110
125
  - lib
111
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
112
128
  requirements:
113
129
  - - ">="
114
130
  - !ruby/object:Gem::Version
131
+ hash: 3
115
132
  segments:
116
133
  - 0
117
134
  version: "0"
118
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
119
137
  requirements:
120
138
  - - ">="
121
139
  - !ruby/object:Gem::Version
140
+ hash: 3
122
141
  segments:
123
142
  - 0
124
143
  version: "0"
125
144
  requirements: []
126
145
 
127
146
  rubyforge_project:
128
- rubygems_version: 1.3.6
147
+ rubygems_version: 1.3.7
129
148
  signing_key:
130
149
  specification_version: 3
131
150
  summary: Ruby gem wrapper for the Petfinder API
132
151
  test_files:
133
- - test/helper.rb
134
- - test/test_petfinder.rb
152
+ - spec/petfinder_spec.rb
153
+ - spec/spec_helper.rb
@@ -1,67 +0,0 @@
1
- require 'helper'
2
-
3
- class TestPetfinder < Test::Unit::TestCase
4
-
5
- context "When working with the Petfinder API" do
6
- setup do
7
- @client = Petfinder::Client.new('1234567', 'mysekrit')
8
- end
9
-
10
- should "get a random pet" do
11
- stub_get("http://api.petfinder.com/pet.getRandom?key=1234567&output=full", "pet.xml")
12
- pet = @client.random_pet
13
- assert_equal 'Charlie', pet.name
14
- end
15
-
16
- should "get a specific pet by id" do
17
- stub_get("http://api.petfinder.com/pet.get?key=1234567&id=123", "pet.xml")
18
- pet = @client.pet(123)
19
- assert_equal 'Charlie', pet.name
20
- end
21
-
22
- should "find pets matching a query" do
23
- stub_get("http://api.petfinder.com/pet.find?key=1234567&animal=dog&location=77007", "pet_list.xml")
24
- pets = @client.find_pets('dog', '77007')
25
- assert_equal 'Petey', pets.first.name
26
- end
27
-
28
- should "get the list of breeds for the given animal type" do
29
- stub_get("http://api.petfinder.com/breed.list?key=1234567&animal=horse", "breed_list.xml")
30
- breeds = @client.breeds('horse')
31
- assert_equal 'Appaloosa', breeds.first
32
- end
33
-
34
- should "get a specific shelter by id" do
35
- stub_get("http://api.petfinder.com/shelter.get?key=1234567&id=123", "shelter.xml")
36
- shelter = @client.shelter(123)
37
- assert_equal 'Lucky Dog Rescue', shelter.name
38
- end
39
-
40
- should "find shelters matching a query" do
41
- stub_get("http://api.petfinder.com/shelter.find?key=1234567&location=77007", "shelter_list.xml")
42
- shelters = @client.find_shelters('77007')
43
- assert_equal 'Pup Squad Animal Rescue', shelters.first.name
44
- end
45
-
46
- should "find shelters matching a breed" do
47
- stub_get("http://api.petfinder.com/shelter.listByBreed?key=1234567&animal=horse&breed=arabian", "shelter_list.xml")
48
- shelters = @client.find_shelters_by_breed('horse', 'arabian')
49
- assert_equal 'Pup Squad Animal Rescue', shelters.first.name
50
- end
51
-
52
- should "get the list of pets available for the given shelter" do
53
- stub_get("http://api.petfinder.com/shelter.getPets?key=1234567&id=123", "pet_list.xml")
54
- pets = @client.shelter_pets(123)
55
- assert_equal 'Petey', pets.first.name
56
- end
57
-
58
- should "get an authorization token" do
59
- digest = @client.send(:digest_key_and_secret)
60
- stub_get("http://api.petfinder.com/auth.getToken?key=1234567&sig=#{digest}", "auth.xml")
61
- assert_equal '39038a000f404335d90bab019c0c7e2d', @client.token
62
- end
63
-
64
- end
65
-
66
-
67
- end