petfinder_client 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ ## NOTE: use this as an "integration" test between our different objects
4
+
5
+ describe "PetFinder::Client" do
6
+
7
+ before(:each) do
8
+ @client = PetFinder::Client.new('fake')
9
+ end
10
+
11
+ context "finding list of shelters" do
12
+ use_vcr_cassette
13
+ it "should return a list of shelters given a zipcode or city and state" do
14
+ shelters = @client.find_shelters('92102', {:limit => 2})
15
+ shelters.map{|s| s.id}.should == two_shelters.map{|s| s.id}
16
+ end
17
+ end
18
+
19
+ context "get single shelter with id" do
20
+ use_vcr_cassette
21
+ it "should find a single shelter given a shelter id" do
22
+ shelter = @client.get_shelter('fake')
23
+ shelter.id.should == one_shelter.id
24
+ end
25
+ end
26
+
27
+ context "list breeds" do
28
+ use_vcr_cassette
29
+ it "should list breeds given an animal type" do
30
+ breeds = @client.list_breeds('dog').should == dog_breeds_list
31
+ end
32
+ end
33
+
34
+ context "finding list of pets" do
35
+ use_vcr_cassette
36
+ it "should return a list of pets given a zipcode or city and state" do
37
+ pets = @client.find_pets('San Diego, CA', {:count => 2, :animal => 'dog'})
38
+ pets.map{|p| p.id}.should == two_pets.map{|p| p.id}
39
+ end
40
+ end
41
+
42
+ # context "find shelters with breed" do
43
+ # use_vcr_cassette
44
+ # it "should return a list of shelters with a given animal and breed" do
45
+ # client = PetFinder::Client.new('afb752054145806e86da4d38721f2bb6')
46
+ # shelters = client.list_shelters_with_breed('dog', 'collie', {:count => 2})
47
+ # end
48
+ # end
49
+
50
+ context "get single pet with id" do
51
+ use_vcr_cassette
52
+ it "should return a single pet with a given id" do
53
+ pet = @client.get_pet('fake')
54
+ pet.id.should == one_pet.id
55
+ end
56
+ end
57
+
58
+
59
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ # NOTE: you need a valid Pet Finder API Key. Use the PF_API_KEY environment variable.
4
+ # Example: LIVE_PF_API=acbd1234 rspec live_pf_api_spec.rb
5
+
6
+
7
+ # TODO: This spec will test the live API - just in case PetFinder changes it's API format. It should not be run as a normal part of the test suite.
8
+ if ENV['LIVE_PF_API']
9
+
10
+ describe "Live testing of the Pet Finder API" do
11
+
12
+ it "should return a valid client with a valid key" do
13
+ pending "should we test the client upon initialization for a valid API key ?"
14
+ end
15
+
16
+ end
17
+
18
+ end
data/spec/pet_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PetFinder::Pet" do
4
+
5
+ it "should be able to extract a hash of photo urls from it's data" do
6
+ pet = full_pet_objs[0]
7
+ pet.get_photos.should == pet_photos_hash
8
+ end
9
+
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "PetFinder::Shelter" do
5
+
6
+ context "shelter pets" do
7
+ use_vcr_cassette
8
+ it "should return a list of pets that belong to a given shelter" do
9
+ shelter = one_shelter
10
+ # note: we need to instansiate the client here to make this unit test pass - yucky. cost of having the
11
+ # shelter classes dependent on the client class. maybe this method should be moved to the the client class ?
12
+ client = PetFinder::Client.new('fake')
13
+ pets = shelter.get_pets({:count => 2})
14
+ pets.map{|p| p.id}.should == two_shelter_pets.map{|p| p.id}
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,118 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__)))
2
+ $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
3
+ require 'rubygems'
4
+ require 'rspec'
5
+ require 'vcr'
6
+ require 'active_support/core_ext'
7
+
8
+ require 'pet_finder'
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'spec/cassettes'
12
+ c.stub_with :webmock
13
+ end
14
+
15
+ RSpec.configure do |c|
16
+ c.extend VCR::RSpec::Macros
17
+ end
18
+
19
+ CASSETTE_BASE_PATH = 'spec/cassettes/PetFinder_Client/'
20
+
21
+ def two_shelters
22
+ res = []
23
+ # note: this is really just testing HTTParty...
24
+ # yaml = YAML.load(File.open(CASSETTE_BASE_PATH + 'finding_list_of_shelters.yml'))
25
+ # xml = get_cassette_xml(yaml)
26
+ # doc = Nokogiri(xml)
27
+ # doc.xpath('//shelters/shelter').each do |node|
28
+ # res << PetFinder::Shelter.new(Hash.from_xml(node.to_s)['shelter'])
29
+ # end
30
+ shelter_ids = ['CA1080','CA1482']
31
+ shelter_ids.each{|id| res << PetFinder::Shelter.new({:id => id})}
32
+ res
33
+ end
34
+
35
+ def one_shelter
36
+ two_shelters[0]
37
+ end
38
+
39
+ def dog_breeds_list
40
+ # yaml = YAML.load(File.open(CASSETTE_BASE_PATH + 'list_breeds.yml'))
41
+ # xml = get_cassette_xml(yaml)
42
+ # doc = Nokogiri(xml)
43
+ # Hash.from_xml(doc.xpath('//breeds').to_s)['breeds']['breed']
44
+ ["Affenpinscher", "Afghan Hound", "Airedale Terrier", "Akbash", "Akita", "Alaskan Malamute", "American Bulldog", "American Eskimo Dog", "American Hairless Terrier", "American Staffordshire Terrier", "American Water Spaniel", "Anatolian Shepherd", "Appenzell Mountain Dog", "Australian Cattle Dog (Blue Heeler)", "Australian Kelpie", "Australian Shepherd", "Australian Terrier", "Basenji", "Basset Hound", "Beagle", "Bearded Collie", "Beauceron", "Bedlington Terrier", "Belgian Shepherd Dog Sheepdog", "Belgian Shepherd Laekenois", "Belgian Shepherd Malinois", "Belgian Shepherd Tervuren", "Bernese Mountain Dog", "Bichon Frise", "Black and Tan Coonhound", "Black Labrador Retriever", "Black Mouth Cur", "Black Russian Terrier", "Bloodhound", "Blue Lacy", "Bluetick Coonhound", "Boerboel", "Bolognese", "Border Collie", "Border Terrier", "Borzoi", "Boston Terrier", "Bouvier des Flanders", "Boxer", "Boykin Spaniel", "Briard", "Brittany Spaniel", "Brussels Griffon", "Bull Terrier", "Bullmastiff", "Cairn Terrier", "Canaan Dog", "Cane Corso Mastiff", "Carolina Dog", "Catahoula Leopard Dog", "Cattle Dog", "Caucasian Sheepdog (Caucasian Ovtcharka)", "Cavalier King Charles Spaniel", "Chesapeake Bay Retriever", "Chihuahua", "Chinese Crested Dog", "Chinese Foo Dog", "Chinook", "Chocolate Labrador Retriever", "Chow Chow", "Cirneco dell'Etna", "Clumber Spaniel", "Cockapoo", "Cocker Spaniel", "Collie", "Coonhound", "Corgi", "Coton de Tulear", "Curly-Coated Retriever", "Dachshund", "Dalmatian", "Dandi Dinmont Terrier", "Doberman Pinscher", "Dogo Argentino", "Dogue de Bordeaux", "Dutch Shepherd", "English Bulldog", "English Cocker Spaniel", "English Coonhound", "English Pointer", "English Setter", "English Shepherd", "English Springer Spaniel", "English Toy Spaniel", "Entlebucher", "Eskimo Dog", "Feist", "Field Spaniel", "Fila Brasileiro", "Finnish Lapphund", "Finnish Spitz", "Flat-coated Retriever", "Fox Terrier", "Foxhound", "French Bulldog", "Galgo Spanish Greyhound", "German Pinscher", "German Shepherd Dog", "German Shorthaired Pointer", "German Spitz", "German Wirehaired Pointer", "Giant Schnauzer", "Glen of Imaal Terrier", "Golden Retriever", "Gordon Setter", "Great Dane", "Great Pyrenees", "Greater Swiss Mountain Dog", "Greyhound", "Harrier", "Havanese", "Hound", "Hovawart", "Husky", "Ibizan Hound", "Illyrian Sheepdog", "Irish Setter", "Irish Terrier", "Irish Water Spaniel", "Irish Wolfhound", "Italian Greyhound", "Italian Spinone", "Jack Russell Terrier", "Jack Russell Terrier (Parson Russell Terrier)", "Japanese Chin", "Jindo", "Kai Dog", "Karelian Bear Dog", "Keeshond", "Kerry Blue Terrier", "Kishu", "Klee Kai", "Komondor", "Kuvasz", "Kyi Leo", "Labrador Retriever", "Lakeland Terrier", "Lancashire Heeler", "Leonberger", "Lhasa Apso", "Lowchen", "Maltese", "Manchester Terrier", "Maremma Sheepdog", "Mastiff", "McNab", "Miniature Pinscher", "Mountain Cur", "Mountain Dog", "Munsterlander", "Neapolitan Mastiff", "New Guinea Singing Dog", "Newfoundland Dog", "Norfolk Terrier", "Norwegian Buhund", "Norwegian Elkhound", "Norwegian Lundehund", "Norwich Terrier", "Nova Scotia Duck-Tolling Retriever", "Old English Sheepdog", "Otterhound", "Papillon", "Patterdale Terrier (Fell Terrier)", "Pekingese", "Peruvian Inca Orchid", "Petit Basset Griffon Vendeen", "Pharaoh Hound", "Pit Bull Terrier", "Plott Hound", "Podengo Portugueso", "Pointer", "Polish Lowland Sheepdog", "Pomeranian", "Poodle", "Portuguese Water Dog", "Presa Canario", "Pug", "Puli", "Pumi", "Rat Terrier", "Redbone Coonhound", "Retriever", "Rhodesian Ridgeback", "Rottweiler", "Saint Bernard St. Bernard", "Saluki", "Samoyed", "Sarplaninac", "Schipperke", "Schnauzer", "Scottish Deerhound", "Scottish Terrier Scottie", "Sealyham Terrier", "Setter", "Shar Pei", "Sheep Dog", "Shepherd", "Shetland Sheepdog Sheltie", "Shiba Inu", "Shih Tzu", "Siberian Husky", "Silky Terrier", "Skye Terrier", "Sloughi", "Smooth Fox Terrier", "South Russian Ovtcharka", "Spaniel", "Spitz", "Staffordshire Bull Terrier", "Standard Poodle", "Sussex Spaniel", "Swedish Vallhund", "Terrier", "Thai Ridgeback", "Tibetan Mastiff", "Tibetan Spaniel", "Tibetan Terrier", "Tosa Inu", "Toy Fox Terrier", "Treeing Walker Coonhound", "Vizsla", "Weimaraner", "Welsh Corgi", "Welsh Springer Spaniel", "Welsh Terrier", "West Highland White Terrier Westie", "Wheaten Terrier", "Whippet", "White German Shepherd", "Wire Fox Terrier", "Wire-haired Pointing Griffon", "Wirehaired Terrier", "Xoloitzcuintle (Mexican Hairless)", "Yellow Labrador Retriever", "Yorkshire Terrier Yorkie"]
45
+ end
46
+
47
+ def two_pets
48
+ res = []
49
+ # yaml = YAML.load(File.open(CASSETTE_BASE_PATH + 'finding_list_of_pets.yml'))
50
+ # xml = get_cassette_xml(yaml)
51
+ # doc = Nokogiri(xml)
52
+ # doc.xpath('//pets/pet').each{|node| res << PetFinder::Pet.new(Hash.from_xml(node.to_s)['pet'])}
53
+ pet_ids = ['19901761','20775306']
54
+ pet_ids.each{|id| res << PetFinder::Pet.new({:id => id})}
55
+ res
56
+ end
57
+
58
+ def one_pet
59
+ two_pets[0]
60
+ end
61
+
62
+ def full_pet_objs
63
+ res = []
64
+ yaml = YAML.load(File.open(CASSETTE_BASE_PATH + 'finding_list_of_pets.yml'))
65
+ xml = get_cassette_xml(yaml)
66
+ doc = Nokogiri(xml)
67
+ doc.xpath('//pets/pet').each{|node| res << PetFinder::Pet.new(Hash.from_xml(node.to_s)['pet'])}
68
+ res
69
+ end
70
+
71
+ def pet_photos_hash
72
+ my_pet_photos = {}
73
+ yaml = YAML.load(File.open(CASSETTE_BASE_PATH + 'finding_list_of_pets.yml'))
74
+ xml = get_cassette_xml(yaml)
75
+ doc = Nokogiri(xml)
76
+ first_pet_photos_node = doc.xpath('//pets/pet/media/photos')[0]
77
+ all_photos = []
78
+ 0..5.times do |x|
79
+ all_photos << first_pet_photos_node.children.select{|node| node['id'] == x.to_s}
80
+ end
81
+ all_photos.each_with_index do |photo_array, idx|
82
+ res_hash = {
83
+ '500x500' => nil,
84
+ 'max50_height' => nil,
85
+ '300x250' => nil,
86
+ 'max60_wide' => nil,
87
+ 'max95_wide' => nil
88
+ }
89
+ photo_array.each do |photo_node|
90
+ res_hash['500x500'] = photo_node.text if photo_node.text.match(/x\.jpg$/)
91
+ res_hash['max50_height'] = photo_node.text if photo_node.text.match(/t\.jpg$/)
92
+ res_hash['300x250'] = photo_node.text if photo_node.text.match(/pn\.jpg$/)
93
+ res_hash['max60_wide'] = photo_node.text if photo_node.text.match(/pnt\.jpg$/)
94
+ res_hash['max95_wide'] = photo_node.text if photo_node.text.match(/fpm\.jpg$/)
95
+ end
96
+ my_pet_photos["photo_#{idx.to_s}"] = res_hash unless res_hash.values.compact.empty?
97
+ end
98
+ my_pet_photos
99
+ end
100
+
101
+ def two_shelter_pets
102
+ res = []
103
+ # yaml = YAML.load(File.open('spec/cassettes/PetFinder_Shelter/shelter_pets.yml'))
104
+ # xml = get_cassette_xml(yaml)
105
+ # doc = Nokogiri(xml)
106
+ # doc.xpath('//pets/pet').each{|node| res << PetFinder::Pet.new(Hash.from_xml(node.to_s)['pet'])}
107
+ pet_ids = ['10937712','11482281']
108
+ pet_ids.each{|id| res << PetFinder::Pet.new({:id => id})}
109
+ res
110
+ end
111
+
112
+ def get_cassette_xml(yaml)
113
+ yaml['http_interactions'][0]['response']['body']['string']
114
+ end
115
+
116
+
117
+
118
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: petfinder_client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Ben Wanicur
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-05-08 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.1
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: vcr
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.1
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "3.2"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description: Wrapper for Petfinder API
49
+ email: bwanicur@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - lib/pet_finder/client.rb
58
+ - lib/pet_finder/pet.rb
59
+ - lib/pet_finder/shelter.rb
60
+ - lib/pet_finder.rb
61
+ - spec/cassettes/PetFinder_Client/finding_list_of_pets.yml
62
+ - spec/cassettes/PetFinder_Client/finding_list_of_shelters.yml
63
+ - spec/cassettes/PetFinder_Client/get_single_pet_with_id.yml
64
+ - spec/cassettes/PetFinder_Client/get_single_shelter_with_id.yml
65
+ - spec/cassettes/PetFinder_Client/list_breeds.yml
66
+ - spec/cassettes/PetFinder_Shelter/shelter_pets.yml
67
+ - spec/client_spec.rb
68
+ - spec/live_pf_api_spec.rb
69
+ - spec/pet_spec.rb
70
+ - spec/shelter_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: http://github.com/bwanicur/petfinder_client
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.4
92
+ requirements: []
93
+
94
+ rubyforge_project: petfinder_client
95
+ rubygems_version: 1.8.16
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Wrapper for Petfinder API
99
+ test_files: []
100
+