petfinder-wrap 1.0.1.1 → 1.0.2

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: 77edfce7c300f6582f65205f797109729bba997a
4
- data.tar.gz: 8f6fa5d47055eea64e31b7636ab59a6260a42c95
3
+ metadata.gz: 3ab6b7c94720a53888477c2c8519fbc46e8bc7cf
4
+ data.tar.gz: e5f5748b5e3be165aae7869decedcbe88470c2e5
5
5
  SHA512:
6
- metadata.gz: 1852593cefe69a224708b4ff78279fd121e20a35ae4a752bbfd90111d8e93bb40e29c3d558ba2b3cc137f9da90acc8909eeb79ee0c2881b25045b8f40ccf8ce2
7
- data.tar.gz: 6fdbacb05cd5113d4955d05ecc3ae713769cc768cc5a4e41cb5449195999bfbf59a90704972d0872ebb3f2f24a347701226c45ac011cf85b728569f3351689b3
6
+ metadata.gz: 803522b07aca748be568a07c66a204658418541e4c401cd51b51f5cfb7d7aeff208fa0d57c714ea1fa6b8eb3cfaafac79f3268bab2e821e803b1af5f0d11e6ef
7
+ data.tar.gz: c86cb53eadd15c028316dcf31e56cc7fa6284df39b766917ed5770446ac183e307a404fe47499f20e8aa8efed5fcb0134a28de5da64bb341d269957d6565e4ba
data/README.md CHANGED
@@ -46,6 +46,7 @@ Additionally, try methods like
46
46
  pet = client.find_pet("38747365")
47
47
  pet.name # => returns the pet's name
48
48
  pet.contact # => returns a hash of contact info
49
+ pet.photos # => returns an array of Photo objects, with multiple size urls accessible by .small, .medium, .large, .thumbnail, .tiny
49
50
  ```
50
51
  the same should function for shelters.
51
52
 
@@ -6,7 +6,7 @@ require_relative 'petfinder/client'
6
6
  require 'open-uri'
7
7
 
8
8
  module Petfinder
9
- VERSION = "1.0.1.1"
9
+ VERSION = "1.0.2"
10
10
 
11
11
  class Error < StandardError; end
12
12
 
@@ -6,12 +6,69 @@ module Petfinder
6
6
  json_attributes "name", "breed", "age", "size", "id", "shelter_id",
7
7
  "description", "shelter_id"
8
8
 
9
- attr_reader :media, :contact
9
+ attr_reader :attributes, :contact_info
10
10
  def initialize pet_hash
11
11
  @attributes = pet_hash
12
+ @contact_info = contact
12
13
  end
13
14
 
15
+ def photos
16
+ parse_photos if @photos.nil?
17
+ @photos
18
+ end
19
+
20
+ private
21
+
14
22
  def contact
23
+ class << self
24
+ json_attributes "phone", "state", "email", "city",
25
+ "zip", "fax", "address1"
26
+ end
27
+ end
28
+
29
+ def parse_photos
30
+ @photos = []
31
+ @attributes["media"]["photos"]["photo"].each do |photo|
32
+ add_photo photo, photo["$t"]
33
+ end
34
+ end
35
+
36
+ def add_photo photo, url
37
+ size = photo["@size"]
38
+ photo = set_photo photo
39
+ case size
40
+ when "x"
41
+ photo.large = url
42
+ when "pn"
43
+ photo.medium = url
44
+ when "fpm"
45
+ photo.small = url
46
+ when "pnt"
47
+ photo.tiny = url
48
+ end
49
+ @photos << photo unless @photos.find_index photo
15
50
  end
51
+
52
+ def set_photo photo
53
+ @photos.each do |existing_photo|
54
+ if photo["@id"] == existing_photo.id
55
+ return existing_photo
56
+ end
57
+ end
58
+ Photo.new photo
59
+ end
60
+
61
+ class Photo
62
+
63
+ attr_accessor :large, :medium, :small, :thumbnail, :tiny
64
+ attr_reader :id, :attributes
65
+
66
+ def initialize attributes
67
+ @attributes = attributes
68
+ @id = attributes["@id"]
69
+ end
70
+
71
+ end
72
+
16
73
  end
17
74
  end
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.1.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro De Ona