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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a7c9cb4fc57801cd466d836a5941b01cf0f49e9
4
- data.tar.gz: e72912d816c947fc9a851033d53b4651f77aff7a
3
+ metadata.gz: dc00dae7ebf51c9d7599d4b0b0686f1715b4aab9
4
+ data.tar.gz: 8c4aee16fc7b2c0637312d32451fd0ce7576e7e3
5
5
  SHA512:
6
- metadata.gz: 58bea7a08f9a92bcfcbd63e1e4c2cc6cf651fba33d8e860cdae5b83011fa337c671dc9242bf98a2ff7c7def7f3d747d531c4e0d2f60e8f7aa6c88e6a382c0886
7
- data.tar.gz: 808b16ff22cfe47857124c5b18fb40b779d83f8afd1b149968754ae34d56e452791246e55328f7ec839e7d51b794c18b38d95c749686ec48f511b0b86ad40c8f
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
- TODO: build out Breed.search instance methods for specific searches.
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 into your config/application.rb:
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("dog", "33165") # => returns an array of Pets
39
- client.find_pet("38747365") # => returns a single Pet
40
- client.find_shelters("33131") # => returns an array of Shelters
41
- client.get_shelter("FL54") # => returns a single Shelter object
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("38747365")
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
@@ -7,7 +7,7 @@ require_relative 'petfinder/breed'
7
7
  require 'open-uri'
8
8
 
9
9
  module Petfinder
10
- VERSION = "1.0.3.4"
10
+ VERSION = "1.0.3.5"
11
11
 
12
12
  class Error < StandardError; end
13
13
 
@@ -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
@@ -11,15 +11,7 @@ module Petfinder
11
11
  end
12
12
 
13
13
  def get_pets
14
- get_shelter_pets = API_BASE_URI + "shelter.getPets?key=#{Client.new.api_key}&id=#{id}&output=basic&format=json"
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
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.12
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.