petfinder-wrap 1.0.3.4 → 1.0.3.5
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.
- checksums.yaml +4 -4
- data/README.md +32 -8
- data/lib/petfinder-wrap.rb +1 -1
- data/lib/petfinder/client.rb +17 -0
- data/lib/petfinder/shelter.rb +1 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc00dae7ebf51c9d7599d4b0b0686f1715b4aab9
|
4
|
+
data.tar.gz: 8c4aee16fc7b2c0637312d32451fd0ce7576e7e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ca4a8657817948e9eaad99022115de9cf2581f263120476b2ad296e9752cd27310257d0fd116f6d8ed584e27fd2e4a745262097753c0cfd38b3fd55aaeb7372
|
7
|
+
data.tar.gz: 616219478f3ebe3791e836fb5ee7739621540c3893e1396b2b282a8f19b8901e6acb8b87fd2cfa0c27828e5e2edb02d59170a2b6c57ecb0335108d11644a7315
|
data/README.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
A simple gem for the Petfinder API using JSON responses and a traversal method.
|
4
4
|
|
5
|
-
|
5
|
+
Coming in the next release:
|
6
|
+
|
7
|
+
* Options hashes (you rubes love options hashes)
|
8
|
+
* <#Breed>.search_by instance method
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -16,34 +19,55 @@ And then execute:
|
|
16
19
|
|
17
20
|
$ bundle
|
18
21
|
|
22
|
+
OR:
|
23
|
+
```
|
24
|
+
$ bundle add petfinder-wrap
|
25
|
+
$ bundle install
|
26
|
+
```
|
27
|
+
to automatically add it to your Gemfile and install it.
|
28
|
+
|
19
29
|
Or install it yourself as:
|
20
30
|
|
21
31
|
$ gem install petfinder-wrap
|
22
32
|
|
23
33
|
## Usage
|
24
34
|
|
25
|
-
If you are using in a rails app, place the following
|
35
|
+
If you are using in a rails app, place the following
|
36
|
+
into config/initializers/petfinder.rb:
|
26
37
|
|
27
38
|
```ruby
|
28
39
|
Petfinder.configure do |config|
|
29
40
|
config.api_key = "YOUR API KEY HERE"
|
30
|
-
config.api_secret = "YOUR API SECRET HERE"
|
41
|
+
config.api_secret = "YOUR API SECRET HERE" # not needed yet, do not use
|
31
42
|
end
|
32
43
|
```
|
44
|
+
|
33
45
|
note: Currently, the API does not utilize a client secret for any requests. You are probably better off not setting this value in your code. In the future if they add PUT, POST, DELETE endpoints that require auth, the above config will work, if someone wants to build out those methods.
|
34
46
|
|
47
|
+
For non-rails applications, add the gem to your Gemfile (see above) then:
|
48
|
+
`your_app.rb:`
|
49
|
+
```ruby
|
50
|
+
require 'petfinder-wrap'
|
51
|
+
|
52
|
+
Petfinder.configure do |config|
|
53
|
+
config.api_key = "YOUR API KEY HERE"
|
54
|
+
config.api_secret = "YOUR API SECRET HERE" # not needed yet, do not use
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
35
58
|
Afterward, you should be able to use
|
36
59
|
```ruby
|
37
60
|
client = Petfinder::Client.new
|
38
|
-
client.find_pets
|
39
|
-
client.find_pet
|
40
|
-
client.find_shelters
|
41
|
-
client.get_shelter
|
61
|
+
client.find_pets "dog", "33165" # => returns an array of Pets
|
62
|
+
client.find_pet "38747365" # => returns a single Pet
|
63
|
+
client.find_shelters "33131" # => returns an array of Shelters
|
64
|
+
client.get_shelter "FL54" # => returns a single Shelter object
|
42
65
|
```
|
43
66
|
|
67
|
+
|
44
68
|
Additionally, try methods like
|
45
69
|
```ruby
|
46
|
-
pet = client.find_pet
|
70
|
+
pet = client.find_pet "38747365"
|
47
71
|
pet.name # => returns the pet's name
|
48
72
|
pet.photos # => returns an array of Photo objects, with multiple size urls accessible by .small, .medium, .large, .thumbnail, .tiny
|
49
73
|
pet.contact_info # => returns a hash of callable method names for contact info
|
data/lib/petfinder-wrap.rb
CHANGED
data/lib/petfinder/client.rb
CHANGED
@@ -69,6 +69,23 @@ module Petfinder
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
def get_shelter_pets shelter
|
73
|
+
get_shelter_pets = API_BASE_URI + "shelter.getPets?key=#{@api_key}&id=#{shelter.id}&output=basic&format=json"
|
74
|
+
response = open(get_shelter_pets).read
|
75
|
+
res = []
|
76
|
+
if resp = JSON.parse(response)
|
77
|
+
begin
|
78
|
+
resp["petfinder"]["pets"]["pet"].each do |pet|
|
79
|
+
res << Pet.new(pet)
|
80
|
+
end
|
81
|
+
rescue NoMethodError => e
|
82
|
+
puts e.message
|
83
|
+
puts "Invalid response received from API. Check your query"
|
84
|
+
end
|
85
|
+
res
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
72
89
|
def find_shelters location
|
73
90
|
find_shelters_request = API_BASE_URI + "shelter.find?key=#{@api_key}&location=#{location}&format=json"
|
74
91
|
response = open(find_shelters_request).read
|
data/lib/petfinder/shelter.rb
CHANGED
@@ -11,15 +11,7 @@ module Petfinder
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_pets
|
14
|
-
|
15
|
-
response = open(get_shelter_pets).read
|
16
|
-
res = []
|
17
|
-
if resp = JSON.parse(response)
|
18
|
-
resp["petfinder"]["pets"]["pet"].each do |pet|
|
19
|
-
# res << Petfinder::Pet.new(pet[1][0])
|
20
|
-
res << Pet.new(pet)
|
21
|
-
end
|
22
|
-
end
|
14
|
+
res = Client.new.get_shelter_pets self
|
23
15
|
res
|
24
16
|
end
|
25
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petfinder-wrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.3.
|
4
|
+
version: 1.0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro De Ona
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.6.
|
138
|
+
rubygems_version: 2.6.11
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: A Ruby wrapper for the Petfinder RESTful API.
|