Module: DogAPI
- Defined in:
- lib/dogceo.rb
Class Method Summary collapse
-
.breeds_list ⇒ Object
LIST ALL BREEDS.
-
.images_by_breed(breed) ⇒ Object
ALL IMAGES FROM A BREED COLLECTION.
-
.images_by_sub_breed(breed, sub_breed) ⇒ Object
LIST ALL SUB-BREED IMAGES.
-
.multiple_random_images(images_number) ⇒ Object
DISPLAY MULTIPLE RANDOM IMAGES FROM ALL DOGS COLLECTION.
-
.multiple_random_images_by_breed(breed, images_number) ⇒ Object
MULTIPLE IMAGES FROM A BREED COLLECTION.
-
.multiple_random_images_by_sub_breed(breed, sub_breed, images_number) ⇒ Object
MULTIPLE IMAGES FROM A SUB-BREED COLLECTION.
-
.random_image ⇒ Object
DISPLAY SINGLE RANDOM IMAGE FROM ALL DOGS COLLECTION.
-
.random_image_by_breed(breed) ⇒ Object
RANDOM IMAGE FROM A BREED COLLECTION.
-
.random_image_by_sub_breed(breed, sub_breed) ⇒ Object
SINGLE RANDOM IMAGE FROM A SUB BREED COLLECTION.
-
.sub_breeds_list(breed) ⇒ Object
LIST ALL SUB-BREEDS.
Class Method Details
.breeds_list ⇒ Object
LIST ALL BREEDS
Returns hash of all the breeds as keys and sub-breeds as values if it has Raises DogAPIException
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/dogceo.rb', line 184 def breeds_list begin response = get_request('breeds/list/all') json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.images_by_breed(breed) ⇒ Object
ALL IMAGES FROM A BREED COLLECTION
-
`breed` breed name
Returns array of all the images from a breed, e.g. hound Raises DogAPIException
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/dogceo.rb', line 102 def images_by_breed(breed) begin response = get_request("breed/#{breed.strip}/images") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.images_by_sub_breed(breed, sub_breed) ⇒ Object
LIST ALL SUB-BREED IMAGES
-
`breed` breed name
-
`sub_breed` sub_breed name
Returns array of all the images from the sub-breed Raises DogAPIException
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/dogceo.rb', line 166 def images_by_sub_breed(breed, sub_breed) begin response = get_request("breed/#{breed.strip}/#{sub_breed.strip}/images") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.multiple_random_images(images_number) ⇒ Object
DISPLAY MULTIPLE RANDOM IMAGES FROM ALL DOGS COLLECTION
-
`images_number` number of images
NOTE ~ Max number returned is 50
Return multiple random dog image Raises DogAPIException
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dogceo.rb', line 41 def multiple_random_images(images_number) begin response = get_request("breeds/image/random/#{images_number}") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.multiple_random_images_by_breed(breed, images_number) ⇒ Object
MULTIPLE IMAGES FROM A BREED COLLECTION
-
`breed` breed name
-
`images_number` number of images
Return multiple random dog image from a breed, e.g. hound Raises DogAPIException
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/dogceo.rb', line 82 def multiple_random_images_by_breed(breed, images_number) begin response = get_request("breed/#{breed.strip}/images/random/#{images_number}") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.multiple_random_images_by_sub_breed(breed, sub_breed, images_number) ⇒ Object
MULTIPLE IMAGES FROM A SUB-BREED COLLECTION
-
`breed` breed name
-
`sub_breed` sub_breed name
-
`images_number` number of images
Return multiple random dog images from a sub-breed, e.g. Afghan Hound Raises DogAPIException
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/dogceo.rb', line 145 def multiple_random_images_by_sub_breed(breed, sub_breed, images_number) begin response = get_request("breed/#{breed.strip}/#{sub_breed.strip}/images/random/#{images_number}") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.random_image ⇒ Object
DISPLAY SINGLE RANDOM IMAGE FROM ALL DOGS COLLECTION
return a random dog image
Raises DogAPIException
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dogceo.rb', line 19 def random_image begin response = get_request('breeds/image/random') json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.random_image_by_breed(breed) ⇒ Object
RANDOM IMAGE FROM A BREED COLLECTION
-
`breed` breed name
Returns a random dog image from a breed, e.g. hound Raises DogAPIException
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dogceo.rb', line 61 def random_image_by_breed(breed) begin response = get_request("breed/#{breed.strip}/images/random") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.random_image_by_sub_breed(breed, sub_breed) ⇒ Object
SINGLE RANDOM IMAGE FROM A SUB BREED COLLECTION
-
`breed` breed name
-
`sub_breed` sub_breed name
Returns a random dog image from a sub-breed, e.g. Afghan Ho Raises DogAPIException
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/dogceo.rb', line 123 def random_image_by_sub_breed(breed, sub_breed) begin response = get_request("breed/#{breed.strip}/#{sub_breed.strip}/images/random") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |
.sub_breeds_list(breed) ⇒ Object
LIST ALL SUB-BREEDS
-
`breed` breed name
Returns array of all the sub-breeds from a breed if it has sub-breeds Raises DogAPIException
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/dogceo.rb', line 204 def sub_breeds_list(breed) begin response = get_request("breed/#{breed.strip}/list") json = JSON.parse(response) if json['status'] != 'success' raise DogAPIException.new(json['message']) end if json['message'].length == 0 raise DogAPIException.new('the breed does not have sub-breeds') end return json['message'] rescue => ex raise DogAPIException.new(ex.) end end |