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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 47a41c15628e5a05277200f92fe73134cbb5abd9
4
- data.tar.gz: e9a0e41e252308424899152388c13a792026a251
2
+ SHA256:
3
+ metadata.gz: 194b9424594d700859ccb94d133b7a594be01dba5b6aa07649b92c909a0b81a7
4
+ data.tar.gz: 2d0afad0a028a584d09c25ff5ef3707e9f4f02333507330eba9db0d4e99ec1c1
5
5
  SHA512:
6
- metadata.gz: 42f1ddc329ac0aba83f4fb1e85b41344a4b9f26d299ba3f5309906c785bd68f2652128b05c0efbc48db9f7c7474e88959b19f11873a81e1d69c4037f0264d105
7
- data.tar.gz: 6e7f47c52417058239fb457a55304e895911db0516e717e3fbf74140bc3756fafc890ad513d504bc84fecdaa125eb591f0d3e2b651f19773a14e2d13516b8543
6
+ metadata.gz: 96cea717773b8116e6d2b76aa35ef97ad8c3fb3231ceaf4ee0ccc997492bba357a71a08a8d0cd108331f937cd9e83647532f48ba51595303e734627f78be4488
7
+ data.tar.gz: 3be76b22eac55fb37c536eaf8a720d0d4c77c3be947272ed9386127c36e7dc234488f747a0d818667f3e96accdfa21837c257fc4020df17f6cd12c7938d0134a
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
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -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
@@ -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"
@@ -1,49 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- petfinder (1.0.1)
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.3.5)
12
- coderay (1.0.9)
13
- crack (0.4.1)
14
- safe_yaml (~> 0.9.0)
15
- diff-lcs (1.2.4)
16
- excon (0.26.0)
17
- method_source (0.8.2)
18
- mini_portile (0.5.1)
19
- nokogiri (1.6.0)
20
- mini_portile (~> 0.5.0)
21
- pry (0.9.12.2)
22
- coderay (~> 1.0.5)
23
- method_source (~> 0.8)
24
- slop (~> 3.4)
25
- rake (10.1.0)
26
- rspec (2.14.1)
27
- rspec-core (~> 2.14.0)
28
- rspec-expectations (~> 2.14.0)
29
- rspec-mocks (~> 2.14.0)
30
- rspec-core (2.14.5)
31
- rspec-expectations (2.14.2)
32
- diff-lcs (>= 1.1.3, < 2.0)
33
- rspec-mocks (2.14.3)
34
- safe_yaml (0.9.7)
35
- slop (3.4.6)
36
- webmock (1.13.0)
37
- addressable (>= 2.2.7)
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
- pry
47
- rake
48
- rspec (>= 2.14)
57
+ rake (~> 12.0)
58
+ rspec (~> 3.0)
49
59
  webmock
60
+
61
+ BUNDLED WITH
62
+ 2.1.4
@@ -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
@@ -1,6 +1,16 @@
1
1
  # Petfinder
2
2
 
3
- Ruby gem wrapper for the [Petfinder API](http://www.petfinder.com/developers/api-docs).
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: http://www.petfinder.com/developers/api-key
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
- Petfinder.configure do |config|
32
- config.api_key = 'your_api_key'
33
- config.api_secret = 'your_api_secret'
34
- end
35
- petfinder = Petfinder::Client.new
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
- pets = petfinder.find_pets('dog', '90210')
42
- pets.count
43
- # => "25"
89
+ #### Return information about the organization (shelter) with id "CA2350"
44
90
 
45
- pets.first.name
46
- # => "Petey"
91
+ ```ruby
92
+ organization = petfinder.organization('CA2350')
47
93
 
48
- pets.first.shelterid
49
- # => "CA123"
94
+ organization.name
95
+ # => "Promise 4 Paws"
50
96
 
51
- #### Return information about the shelter with id "CA123"
97
+ organization.address.city
98
+ # => "San Juan Capistrano"
99
+ ```
52
100
 
53
- shelter = petfinder.shelter('CA123')
54
- shelter.name
55
- # => "Melrose Place SPCA"
101
+ #### Return a list of animal types
102
+ ```ruby
103
+ types = petfinder.types
56
104
 
57
- ## TODO
105
+ types.first.name
106
+ # => "Dog"
58
107
 
59
- * Implement use of security token when Petfinder requires it
60
- * Support paging for results
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
@@ -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