Class: AdoptAPet::Pet::ResponseHelper
- Inherits:
-
Object
- Object
- AdoptAPet::Pet::ResponseHelper
- Defined in:
- lib/adopt_a_pet/pet.rb
Overview
Class for Adopt-A-Pet Pet API response object helpers
Class Method Summary collapse
-
.extract_photos(object) ⇒ Array<Pet::Photo>
Extracts photos from a hash and pushes them into the Pet’s photos.
-
.get_large_results_photo(object, photos) ⇒ Array<Pet::Photo>
Pull a large results photo, if it exists in the API return object.
-
.get_other_photos(object, photos) ⇒ Array<Pet::Photo>
Pull any additional photos, if they exists in the API return object.
-
.get_results_photo(object, photos) ⇒ Array<Pet::Photo>
Pull a results photo, if it exists in the API return object.
Class Method Details
.extract_photos(object) ⇒ Array<Pet::Photo>
Extracts photos from a hash and pushes them into the Pet’s photos
159 160 161 162 163 164 165 166 |
# File 'lib/adopt_a_pet/pet.rb', line 159 def self.extract_photos(object) photos = [] # Get the various photos that could be returned for a pet photos = get_results_photo(object, photos) photos = get_large_results_photo(object, photos) get_other_photos(object, photos) end |
.get_large_results_photo(object, photos) ⇒ Array<Pet::Photo>
Pull a large results photo, if it exists in the API return object
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/adopt_a_pet/pet.rb', line 196 def self.get_large_results_photo(object, photos) unless object.dig('large_results_photo_url').nil? photos = photos.push( original: Photo.new( object.dig('large_results_photo_height'), object.dig('large_results_photo_width'), object.dig('large_results_photo_url') ) ) end photos end |
.get_other_photos(object, photos) ⇒ Array<Pet::Photo>
Pull any additional photos, if they exists in the API return object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/adopt_a_pet/pet.rb', line 217 def self.get_other_photos(object, photos) if (image_objects = object.dig('images')) image_objects.each do |image| photos = photos.push( original: Photo.new( image.dig('original_height'), image.dig('original_width'), image.dig('original_url') ), thumbnail: Photo.new( image.dig('thumbnail_height'), image.dig('thumbnail_width'), image.dig('thumbnail_url') ) ) end end photos end |
.get_results_photo(object, photos) ⇒ Array<Pet::Photo>
Pull a results photo, if it exists in the API return object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/adopt_a_pet/pet.rb', line 175 def self.get_results_photo(object, photos) unless object.dig('results_photo_url').nil? photos = photos.push( original: Photo.new( object.dig('results_photo_height'), object.dig('results_photo_width'), object.dig('results_photo_url') ) ) end photos end |