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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b28e75a76d5020eee7da565a46a5fed8474fa20e143264d0052dc53964556cd5
4
- data.tar.gz: 49cf181c6c288f43fca0fcff463ced1f28e3a830d0b56957fd8a994669df693b
3
+ metadata.gz: a4a9842b812f2dfe0d78832d1911c77bbb96a13575c2a539ac71f9bddab55a0f
4
+ data.tar.gz: f3fa81db5471239ec8b2256f9aee94e054bfadfbe2297acc40e848f27f498f19
5
5
  SHA512:
6
- metadata.gz: 0eef74086d9f3ab7e342be2736d08c62559745b465efc01972165036f8fa34f0a8bfddf2ac24dbfae6353361689a07da6e9923a1b9705aab64d5c5793369ce16
7
- data.tar.gz: 7b1de5fd3613965e76e3676ca4f013faa3cec4068adf2488ad8aaae8e7a77f21b3b32348f238b8c3666b694c188682ecba611b10414d4978e72248a7667667ea
6
+ metadata.gz: 614b1d2afb98c21d3e7917abafeb944e336b13a0c1187d08f33ca539f15dfb74a769947844939f6867eb1bd5ab879ddec37c8a7c6e469f6c2b7ddf02f33af304
7
+ data.tar.gz: 940f4c7da2924f0e39a41ce8c5c573c2a80fa6073bb4e15782b0b890814632c11d35dcbca7ce4c95e3dce51b742a0f1da58303eee443d8e3757da8af4dca864e
data/.gitignore CHANGED
@@ -1,9 +1,13 @@
1
1
  .DS_STORE
2
- coverage/*
3
- pkg/*
4
- tmp/*
5
- *.gem
6
- .bundle
7
- .rvmrc
8
- rdoc/*
9
- bin
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
+ ---
1
2
  language: ruby
3
+ cache: bundler
2
4
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0.0
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 2.0.0
2
+ -----
3
+ * Rewrite for new petfinder API v2.0 which uses JSON and oauth2
4
+
1
5
  1.0.4
2
6
  -----
3
7
  * Update gem dependencies to latest versions
data/Gemfile CHANGED
@@ -1,14 +1,6 @@
1
1
  source 'https://rubygems.org'
2
-
3
- gem 'rake'
4
-
5
- group :development do
6
- gem 'pry'
7
- end
8
-
9
- group :test do
10
- gem 'rspec', '>= 2.14'
11
- gem 'webmock'
12
- end
13
-
14
2
  gemspec
3
+
4
+ gem "rake", "~> 12.0"
5
+ gem "rspec", "~> 3.0"
6
+ gem "webmock"
data/Gemfile.lock CHANGED
@@ -1,59 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- petfinder (1.0.4)
5
- excon (~> 0.26)
6
- nokogiri (~> 1.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.5.2)
12
- public_suffix (>= 2.0.2, < 4.0)
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
- excon (0.59.0)
18
- hashdiff (0.3.7)
19
- method_source (0.9.0)
20
- mini_portile2 (2.3.0)
21
- nokogiri (1.8.1)
22
- mini_portile2 (~> 2.3.0)
23
- pry (0.11.2)
24
- coderay (~> 1.1.0)
25
- method_source (~> 0.9.0)
26
- public_suffix (3.0.1)
27
- rake (12.2.1)
28
- rspec (3.7.0)
29
- rspec-core (~> 3.7.0)
30
- rspec-expectations (~> 3.7.0)
31
- rspec-mocks (~> 3.7.0)
32
- rspec-core (3.7.0)
33
- rspec-support (~> 3.7.0)
34
- rspec-expectations (3.7.0)
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.7.0)
37
- rspec-mocks (3.7.0)
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.7.0)
40
- rspec-support (3.7.0)
41
- safe_yaml (1.0.4)
42
- webmock (3.1.0)
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
- pry
54
- rake
55
- rspec (>= 2.14)
57
+ rake (~> 12.0)
58
+ rspec (~> 3.0)
56
59
  webmock
57
60
 
58
61
  BUNDLED WITH
59
- 1.16.0
62
+ 2.1.2
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Eric Hutzelman
1
+ Copyright (c) 2020 Eric Hutzelman
2
2
 
3
3
  MIT License
4
4
 
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](http://www.petfinder.com/developers/api-docs).
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: http://www.petfinder.com/developers/api-key
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
- pets = petfinder.find_pets('dog', '90210')
52
- pets.count
53
- # => "25"
54
-
55
- pets.first.name
56
- # => "Petey"
57
-
58
- pets.first.shelterid
59
- # => "CA123"
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
- #### Returning paged results
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.find_pets('dog', 77057, count: 25)
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
- # page 3
71
- petfinder.find_pets('dog', 77057, count: 25, offset: 50)
78
+ organizations.first.name
79
+ # => "STAR Eco Station"
72
80
 
73
- # page 4
74
- petfinder.find_pets('dog', 77057, count: 25, offset: 75)
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 "CA123"
89
+ #### Return information about the organization (shelter) with id "CA2350"
78
90
 
79
91
  ```ruby
80
- shelter = petfinder.shelter('CA123')
81
- shelter.name
82
- # => "Melrose Place SPCA"
83
- ```
92
+ organization = petfinder.organization('CA2350')
93
+
94
+ organization.name
95
+ # => "Promise 4 Paws"
84
96
 
85
- #### Other available methods
97
+ organization.address.city
98
+ # => "San Juan Capistrano"
99
+ ```
86
100
 
101
+ #### Return a list of animal types
87
102
  ```ruby
88
- # Valid animal types: barnyard, bird, cat, dog, horse, pig, reptile, smallfurry
89
- breeds = petfinder.breeds(animal_type)
103
+ types = petfinder.types
90
104
 
91
- # Options available: animal, breed, size, sex, location, shelterid
92
- pet = petfinder.random_pet(options)
93
- pet = petfinder.pet(id)
105
+ types.first.name
106
+ # => "Dog"
94
107
 
95
- # Options available: breed, size, sex, age, offset, count
96
- pets = petfinder.find_pets(animal_type, location, options)
108
+ types.first.colors
109
+ # => ["Brown", "Black", "Yellow"]
110
+ ```
97
111
 
98
- # Options available: status, offset, count
99
- pets = shelter_pets(shelter_id, options)
112
+ #### Return a list of breeds for a given animal type
113
+ ```ruby
114
+ breeds = petfinder.breeds('dog')
100
115
 
101
- # Options available: name, offset, count
102
- shelters = petfinder.find_shelters(location, options)
103
- shelters = petfinder.find_shelters_by_breed(animal_type, breed)
116
+ breeds.length
117
+ # => 275
104
118
 
105
- shelter = petfinder.shelter(shelter_id)
119
+ breeds.first.name
120
+ # => "Affenpinscher"
106
121
  ```
107
122
 
108
- ## TODO
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
- * Implement use of security token when Petfinder requires it
111
- * Support paging for results
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-2013 Eric Hutzelman.
146
+ Copyright (c) 2010-2020 Eric Hutzelman.
124
147
  See [LICENSE][] for details.
125
148
 
126
149
  [license]: LICENSE.txt
data/Rakefile CHANGED
@@ -4,11 +4,3 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
-
8
- task :console do
9
- require "irb"
10
- require "irb/completion"
11
- require "petfinder"
12
- ARGV.clear
13
- IRB.start
14
- end
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