petfinder 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -8
- data/.rspec +1 -0
- data/.travis.yml +4 -3
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -12
- data/Gemfile.lock +39 -36
- data/LICENSE.txt +1 -1
- data/README.md +67 -44
- data/Rakefile +0 -8
- data/bin/bundle +114 -0
- data/bin/console +14 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/rackup +29 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/safe_yaml +29 -0
- data/bin/setup +8 -0
- data/lib/petfinder.rb +13 -11
- data/lib/petfinder/api.rb +44 -0
- data/lib/petfinder/client.rb +16 -75
- data/lib/petfinder/mash.rb +5 -0
- data/lib/petfinder/version.rb +1 -1
- data/petfinder.gemspec +16 -11
- metadata +31 -57
- data/lib/petfinder/auth.rb +0 -12
- data/lib/petfinder/breeds.rb +0 -13
- data/lib/petfinder/pet.rb +0 -80
- data/lib/petfinder/shelter.rb +0 -23
- data/lib/petfinder/xml_mapper.rb +0 -21
- data/spec/client_spec.rb +0 -62
- data/spec/fixtures/auth.xml +0 -17
- data/spec/fixtures/breed_list.xml +0 -40
- data/spec/fixtures/pet.xml +0 -47
- data/spec/fixtures/pet_list.xml +0 -966
- data/spec/fixtures/shelter.xml +0 -26
- data/spec/fixtures/shelter_list.xml +0 -189
- data/spec/pet_spec.rb +0 -41
- data/spec/shelter_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4a9842b812f2dfe0d78832d1911c77bbb96a13575c2a539ac71f9bddab55a0f
|
4
|
+
data.tar.gz: f3fa81db5471239ec8b2256f9aee94e054bfadfbe2297acc40e848f27f498f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 614b1d2afb98c21d3e7917abafeb944e336b13a0c1187d08f33ca539f15dfb74a769947844939f6867eb1bd5ab879ddec37c8a7c6e469f6c2b7ddf02f33af304
|
7
|
+
data.tar.gz: 940f4c7da2924f0e39a41ce8c5c573c2a80fa6073bb4e15782b0b890814632c11d35dcbca7ce4c95e3dce51b742a0f1da58303eee443d8e3757da8af4dca864e
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,59 +1,62 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
petfinder (
|
5
|
-
|
6
|
-
|
4
|
+
petfinder (2.0.0)
|
5
|
+
hashie
|
6
|
+
oauth2
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
12
|
-
public_suffix (>= 2.0.2, <
|
13
|
-
coderay (1.1.2)
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
14
13
|
crack (0.4.3)
|
15
14
|
safe_yaml (~> 1.0.0)
|
16
15
|
diff-lcs (1.3)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
rspec
|
16
|
+
faraday (1.0.0)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
hashdiff (1.0.0)
|
19
|
+
hashie (4.0.0)
|
20
|
+
jwt (2.2.1)
|
21
|
+
multi_json (1.14.1)
|
22
|
+
multi_xml (0.6.0)
|
23
|
+
multipart-post (2.1.1)
|
24
|
+
oauth2 (1.4.2)
|
25
|
+
faraday (>= 0.8, < 2.0)
|
26
|
+
jwt (>= 1.0, < 3.0)
|
27
|
+
multi_json (~> 1.3)
|
28
|
+
multi_xml (~> 0.5)
|
29
|
+
rack (>= 1.2, < 3)
|
30
|
+
public_suffix (4.0.2)
|
31
|
+
rack (2.0.8)
|
32
|
+
rake (12.3.3)
|
33
|
+
rspec (3.9.0)
|
34
|
+
rspec-core (~> 3.9.0)
|
35
|
+
rspec-expectations (~> 3.9.0)
|
36
|
+
rspec-mocks (~> 3.9.0)
|
37
|
+
rspec-core (3.9.1)
|
38
|
+
rspec-support (~> 3.9.1)
|
39
|
+
rspec-expectations (3.9.0)
|
35
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-mocks (3.
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-mocks (3.9.1)
|
38
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-support (3.
|
41
|
-
safe_yaml (1.0.
|
42
|
-
webmock (3.
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-support (3.9.2)
|
46
|
+
safe_yaml (1.0.5)
|
47
|
+
webmock (3.7.6)
|
43
48
|
addressable (>= 2.3.6)
|
44
49
|
crack (>= 0.3.2)
|
45
|
-
hashdiff
|
50
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
46
51
|
|
47
52
|
PLATFORMS
|
48
53
|
ruby
|
49
54
|
|
50
55
|
DEPENDENCIES
|
51
|
-
bundler (~> 1.3)
|
52
56
|
petfinder!
|
53
|
-
|
54
|
-
|
55
|
-
rspec (>= 2.14)
|
57
|
+
rake (~> 12.0)
|
58
|
+
rspec (~> 3.0)
|
56
59
|
webmock
|
57
60
|
|
58
61
|
BUNDLED WITH
|
59
|
-
1.
|
62
|
+
2.1.2
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,10 @@
|
|
7
7
|
[gem]: https://rubygems.org/gems/petfinder
|
8
8
|
[travis]: http://travis-ci.org/ehutzelman/petfinder
|
9
9
|
|
10
|
-
Ruby gem wrapper for the [Petfinder API](
|
10
|
+
Ruby gem wrapper for the [Petfinder API v2.0](https://www.petfinder.com/developers/v2/docs).
|
11
|
+
|
12
|
+
**NOTE**: The gem to support v1.0 of the API can be found on the [v1 branch](https://github.com/ehutzelman/petfinder/tree/v1), but be warned that
|
13
|
+
Petfinder will be deprecating this v1 API in early 2020.
|
11
14
|
|
12
15
|
## Installation
|
13
16
|
|
@@ -25,7 +28,7 @@ Or install it yourself as:
|
|
25
28
|
|
26
29
|
## Get your API key
|
27
30
|
|
28
|
-
Get your Petfinder API key at:
|
31
|
+
Get your Petfinder API key at: https://www.petfinder.com/developers
|
29
32
|
|
30
33
|
## Usage
|
31
34
|
|
@@ -45,70 +48,90 @@ petfinder = Petfinder::Client.new
|
|
45
48
|
|
46
49
|
## Examples
|
47
50
|
|
48
|
-
#### Return a list of dogs in the "90210" zip code
|
51
|
+
#### Return a list of dogs in the "90210" zip code (with pagination)
|
52
|
+
A hash of parameters can be passed to this method, but none are required. You can find the full set of allowable parameters here:
|
53
|
+
[Petfinder animals endpoint documentation](https://www.petfinder.com/developers/v2/docs/#get-animals).
|
49
54
|
|
50
55
|
```ruby
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# => "
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
animals, pagination = petfinder.animals(type: 'dog', location: '90210', page: 1)
|
57
|
+
|
58
|
+
animals.first.name
|
59
|
+
# => "Tyra"
|
60
|
+
animals.first.photos.first.full
|
61
|
+
# => "https://dl5zpyw5k3jeb.cloudfront.net/photos/pets/47027518/2/?bust=1578168103"
|
62
|
+
animals.first.organization_id
|
63
|
+
# => "CA2350"
|
64
|
+
|
65
|
+
animals.pagination.count_per_page
|
66
|
+
# => "20"
|
67
|
+
animals.pagination.total_pages
|
68
|
+
# => "8853"
|
60
69
|
```
|
61
70
|
|
62
|
-
####
|
71
|
+
#### Return a list of organizations (with pagination)
|
72
|
+
A hash of parameters can be passed to this method, but none are required. You can find the full set of allowable parameters here:
|
73
|
+
[Petfinder organizations endpoint documentation](https://www.petfinder.com/developers/v2/docs/#get-organizations).
|
63
74
|
|
64
75
|
```ruby
|
65
|
-
petfinder.
|
66
|
-
|
67
|
-
# page 2
|
68
|
-
petfinder.find_pets('dog', 77057, count: 25, offset: 25)
|
76
|
+
organizations, pagination = petfinder.organizations({ location: '90210', limit: 5 })
|
69
77
|
|
70
|
-
|
71
|
-
|
78
|
+
organizations.first.name
|
79
|
+
# => "STAR Eco Station"
|
72
80
|
|
73
|
-
|
74
|
-
|
81
|
+
organizations.pagination.count_per_page
|
82
|
+
# => "5"
|
83
|
+
organizations.pagination.total_count
|
84
|
+
# => "265"
|
85
|
+
organizations.pagination.total_pages
|
86
|
+
# => "53"
|
75
87
|
```
|
76
88
|
|
77
|
-
#### Return information about the shelter with id "
|
89
|
+
#### Return information about the organization (shelter) with id "CA2350"
|
78
90
|
|
79
91
|
```ruby
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
92
|
+
organization = petfinder.organization('CA2350')
|
93
|
+
|
94
|
+
organization.name
|
95
|
+
# => "Promise 4 Paws"
|
84
96
|
|
85
|
-
|
97
|
+
organization.address.city
|
98
|
+
# => "San Juan Capistrano"
|
99
|
+
```
|
86
100
|
|
101
|
+
#### Return a list of animal types
|
87
102
|
```ruby
|
88
|
-
|
89
|
-
breeds = petfinder.breeds(animal_type)
|
103
|
+
types = petfinder.types
|
90
104
|
|
91
|
-
|
92
|
-
|
93
|
-
pet = petfinder.pet(id)
|
105
|
+
types.first.name
|
106
|
+
# => "Dog"
|
94
107
|
|
95
|
-
|
96
|
-
|
108
|
+
types.first.colors
|
109
|
+
# => ["Brown", "Black", "Yellow"]
|
110
|
+
```
|
97
111
|
|
98
|
-
|
99
|
-
|
112
|
+
#### Return a list of breeds for a given animal type
|
113
|
+
```ruby
|
114
|
+
breeds = petfinder.breeds('dog')
|
100
115
|
|
101
|
-
|
102
|
-
|
103
|
-
shelters = petfinder.find_shelters_by_breed(animal_type, breed)
|
116
|
+
breeds.length
|
117
|
+
# => 275
|
104
118
|
|
105
|
-
|
119
|
+
breeds.first.name
|
120
|
+
# => "Affenpinscher"
|
106
121
|
```
|
107
122
|
|
108
|
-
##
|
123
|
+
## Handling errors
|
124
|
+
A Petfinder::Error exception will be raised if the response fails with a bad response. This exception contains a hash of error information returned by Petfinder.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
animals, pagination = petfinder.animals(type: 'invalid_type')
|
128
|
+
# => Petfinder::Error (Invalid Request: The request contains invalid parameters.)
|
129
|
+
|
130
|
+
rescue Petfinder::Error => exception
|
109
131
|
|
110
|
-
|
111
|
-
|
132
|
+
exception.data
|
133
|
+
# => {"type"=>"https://www.petfinder.com/developers/v2/docs/errors/ERR-00002/", "status"=>400, "title"=>"Invalid Request", "detail"=>"The request contains invalid parameters.", "invalid-params"=>[{"in"=>"query", "path"=>"type", "message"=>"invalid_type is not a valid animal type."}]}
|
134
|
+
```
|
112
135
|
|
113
136
|
## Contributing
|
114
137
|
|
@@ -120,7 +143,7 @@ shelter = petfinder.shelter(shelter_id)
|
|
120
143
|
|
121
144
|
## Copyright
|
122
145
|
|
123
|
-
Copyright (c) 2010-
|
146
|
+
Copyright (c) 2010-2020 Eric Hutzelman.
|
124
147
|
See [LICENSE][] for details.
|
125
148
|
|
126
149
|
[license]: LICENSE.txt
|
data/Rakefile
CHANGED
data/bin/bundle
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||=
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def bundler_requirement
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
71
|
+
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
73
|
+
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
75
|
+
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
77
|
+
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
79
|
+
|
80
|
+
requirement
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_bundler!
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
85
|
+
|
86
|
+
activate_bundler
|
87
|
+
end
|
88
|
+
|
89
|
+
def activate_bundler
|
90
|
+
gem_error = activation_error_handling do
|
91
|
+
gem "bundler", bundler_requirement
|
92
|
+
end
|
93
|
+
return if gem_error.nil?
|
94
|
+
require_error = activation_error_handling do
|
95
|
+
require "bundler/version"
|
96
|
+
end
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
99
|
+
exit 42
|
100
|
+
end
|
101
|
+
|
102
|
+
def activation_error_handling
|
103
|
+
yield
|
104
|
+
nil
|
105
|
+
rescue StandardError, LoadError => e
|
106
|
+
e
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
m.load_bundler!
|
111
|
+
|
112
|
+
if m.invoked_as_script?
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
114
|
+
end
|