petfinder 1.0.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +12 -8
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +4 -12
- data/Gemfile.lock +47 -34
- data/LICENSE.txt +1 -1
- data/README.md +103 -22
- 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 +43 -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 +36 -61
- data/lib/petfinder/auth.rb +0 -12
- data/lib/petfinder/breeds.rb +0 -13
- data/lib/petfinder/pet.rb +0 -72
- data/lib/petfinder/shelter.rb +0 -19
- 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 -38
- data/spec/shelter_spec.rb +0 -20
- data/spec/spec_helper.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 194b9424594d700859ccb94d133b7a594be01dba5b6aa07649b92c909a0b81a7
|
4
|
+
data.tar.gz: 2d0afad0a028a584d09c25ff5ef3707e9f4f02333507330eba9db0d4e99ec1c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96cea717773b8116e6d2b76aa35ef97ad8c3fb3231ceaf4ee0ccc997492bba357a71a08a8d0cd108331f937cd9e83647532f48ba51595303e734627f78be4488
|
7
|
+
data.tar.gz: 3be76b22eac55fb37c536eaf8a720d0d4c77c3be947272ed9386127c36e7dc234488f747a0d818667f3e96accdfa21837c257fc4020df17f6cd12c7938d0134a
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
2.0.1
|
2
|
+
-----
|
3
|
+
* Update gem dependencies to latest versions
|
4
|
+
|
5
|
+
2.0.0
|
6
|
+
-----
|
7
|
+
* Rewrite for new petfinder API v2.0 which uses JSON and oauth2
|
8
|
+
|
9
|
+
1.0.4
|
10
|
+
-----
|
11
|
+
|
12
|
+
|
13
|
+
1.0.3
|
14
|
+
-----
|
15
|
+
* Adding inspect methods and rake console tasks (JessSumner)
|
16
|
+
|
17
|
+
1.0.2
|
18
|
+
-----
|
19
|
+
* Add contact object to pet (lynnaloo)
|
20
|
+
|
1
21
|
1.0.1
|
2
22
|
-----
|
3
23
|
* Update gem dependencies and versions
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,49 +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
|
-
|
13
|
-
crack (0.4.
|
14
|
-
safe_yaml (~> 0.
|
15
|
-
diff-lcs (1.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
rspec
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
faraday (1.0.1)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
hashdiff (1.0.1)
|
19
|
+
hashie (4.1.0)
|
20
|
+
jwt (2.2.1)
|
21
|
+
multi_json (1.15.0)
|
22
|
+
multi_xml (0.6.0)
|
23
|
+
multipart-post (2.1.1)
|
24
|
+
oauth2 (1.4.4)
|
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.5)
|
31
|
+
rack (2.2.3)
|
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.2)
|
38
|
+
rspec-support (~> 3.9.3)
|
39
|
+
rspec-expectations (3.9.2)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-mocks (3.9.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-support (3.9.3)
|
46
|
+
safe_yaml (1.0.5)
|
47
|
+
webmock (3.8.3)
|
48
|
+
addressable (>= 2.3.6)
|
38
49
|
crack (>= 0.3.2)
|
50
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
39
51
|
|
40
52
|
PLATFORMS
|
41
53
|
ruby
|
42
54
|
|
43
55
|
DEPENDENCIES
|
44
|
-
bundler (~> 1.3)
|
45
56
|
petfinder!
|
46
|
-
|
47
|
-
|
48
|
-
rspec (>= 2.14)
|
57
|
+
rake (~> 12.0)
|
58
|
+
rspec (~> 3.0)
|
49
59
|
webmock
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Petfinder
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/petfinder.png)][gem]
|
4
|
+
[![Build Status](https://secure.travis-ci.org/ehutzelman/petfinder.png?branch=master)][travis]
|
5
|
+
[![Code Climate](https://codeclimate.com/github/ehutzelman/petfinder.png)](https://codeclimate.com/github/ehutzelman/petfinder)
|
6
|
+
|
7
|
+
[gem]: https://rubygems.org/gems/petfinder
|
8
|
+
[travis]: http://travis-ci.org/ehutzelman/petfinder
|
9
|
+
|
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.
|
4
14
|
|
5
15
|
## Installation
|
6
16
|
|
@@ -18,7 +28,7 @@ Or install it yourself as:
|
|
18
28
|
|
19
29
|
## Get your API key
|
20
30
|
|
21
|
-
Get your Petfinder API key at:
|
31
|
+
Get your Petfinder API key at: https://www.petfinder.com/developers
|
22
32
|
|
23
33
|
## Usage
|
24
34
|
|
@@ -28,36 +38,100 @@ Get your Petfinder API key at: http://www.petfinder.com/developers/api-key
|
|
28
38
|
|
29
39
|
### or configure once
|
30
40
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
```ruby
|
42
|
+
Petfinder.configure do |config|
|
43
|
+
config.api_key = 'your_api_key'
|
44
|
+
config.api_secret = 'your_api_secret'
|
45
|
+
end
|
46
|
+
petfinder = Petfinder::Client.new
|
47
|
+
```
|
36
48
|
|
37
49
|
## Examples
|
38
50
|
|
39
|
-
#### 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).
|
54
|
+
|
55
|
+
```ruby
|
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
|
+
pagination.count_per_page
|
66
|
+
# => "20"
|
67
|
+
pagination.total_pages
|
68
|
+
# => "8853"
|
69
|
+
```
|
70
|
+
|
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).
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
organizations, pagination = petfinder.organizations({ location: '90210', limit: 5 })
|
77
|
+
|
78
|
+
organizations.first.name
|
79
|
+
# => "STAR Eco Station"
|
80
|
+
|
81
|
+
pagination.count_per_page
|
82
|
+
# => "5"
|
83
|
+
pagination.total_count
|
84
|
+
# => "265"
|
85
|
+
pagination.total_pages
|
86
|
+
# => "53"
|
87
|
+
```
|
40
88
|
|
41
|
-
|
42
|
-
pets.count
|
43
|
-
# => "25"
|
89
|
+
#### Return information about the organization (shelter) with id "CA2350"
|
44
90
|
|
45
|
-
|
46
|
-
|
91
|
+
```ruby
|
92
|
+
organization = petfinder.organization('CA2350')
|
47
93
|
|
48
|
-
|
49
|
-
|
94
|
+
organization.name
|
95
|
+
# => "Promise 4 Paws"
|
50
96
|
|
51
|
-
|
97
|
+
organization.address.city
|
98
|
+
# => "San Juan Capistrano"
|
99
|
+
```
|
52
100
|
|
53
|
-
|
54
|
-
|
55
|
-
|
101
|
+
#### Return a list of animal types
|
102
|
+
```ruby
|
103
|
+
types = petfinder.types
|
56
104
|
|
57
|
-
|
105
|
+
types.first.name
|
106
|
+
# => "Dog"
|
58
107
|
|
59
|
-
|
60
|
-
|
108
|
+
types.first.colors
|
109
|
+
# => ["Brown", "Black", "Yellow"]
|
110
|
+
```
|
111
|
+
|
112
|
+
#### Return a list of breeds for a given animal type
|
113
|
+
```ruby
|
114
|
+
breeds = petfinder.breeds('dog')
|
115
|
+
|
116
|
+
breeds.length
|
117
|
+
# => 275
|
118
|
+
|
119
|
+
breeds.first.name
|
120
|
+
# => "Affenpinscher"
|
121
|
+
```
|
122
|
+
|
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
|
131
|
+
|
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
|
+
```
|
61
135
|
|
62
136
|
## Contributing
|
63
137
|
|
@@ -66,3 +140,10 @@ Get your Petfinder API key at: http://www.petfinder.com/developers/api-key
|
|
66
140
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
141
|
4. Push to the branch (`git push origin my-new-feature`)
|
68
142
|
5. Create new Pull Request
|
143
|
+
|
144
|
+
## Copyright
|
145
|
+
|
146
|
+
Copyright (c) 2010-2020 Eric Hutzelman.
|
147
|
+
See [LICENSE][] for details.
|
148
|
+
|
149
|
+
[license]: LICENSE.txt
|
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
|