Top Level Namespace

Constant Summary collapse

API_ENDPOINT =

BASE API URI

'https://dog.ceo/api'

Instance Method Summary collapse

Instance Method Details

#all_breed_images(breed) ⇒ Object

Returns an array of all available images of the given breed.



23
24
25
26
27
# File 'lib/dog-api-bindings.rb', line 23

def all_breed_images(breed)
  response = HTTP.get("#{API_ENDPOINT}/breed/#{breed}/images")
  hashed_response = response.parse['message'] if response.code == 200
  hashed_response || "Could not connect to the API, Status Code: #{response.code}"
end

#all_sub_breed_images(breed, sub_breed) ⇒ Object

Returns an array of all available images of the given breed and sub-breed.



30
31
32
33
34
# File 'lib/dog-api-bindings.rb', line 30

def all_sub_breed_images(breed, sub_breed)
  response = HTTP.get("#{API_ENDPOINT}/breed/#{breed}/#{sub_breed}/images")
  hashed_response = response.parse['message'] if response.code == 200
  hashed_response || "Could not connect to the API, Status Code: #{response.code} Perhaps this breed does not have any sub-breeds?"
end

#breeds_listObject

Returns a hash of all available breeds.



9
10
11
12
13
# File 'lib/dog-api-bindings.rb', line 9

def breeds_list
  response = HTTP.get("#{API_ENDPOINT}/breeds/list/all")
  hashed_response = response.parse['message'] if response.code == 200
  hashed_response or "Could not connect to the API, Status Code: #{response.code}"
end

#random_breed_images(breed, amount) ⇒ Object

Returns an array of breed images equivalent to the passed amount.

Due to API limitations, it can only return an amount between 1 and 50.



52
53
54
55
56
57
58
59
60
# File 'lib/dog-api-bindings.rb', line 52

def random_breed_images(breed, amount)
  if amount >= 1 && amount <= 50
    response = HTTP.get("#{API_ENDPOINT}/breed/#{breed}/images/random/#{amount}")
    hashed_response = response.parse['message'] if response.code == 200
    hashed_response || "Could not connect to the API, Status Code: #{response.code}"
  else
    'Can only return between 1 and 50 images.'
  end
end

#random_images(amount) ⇒ Object

Returns an array of random breed images equivalent to the passed amount.

Due to API limitations, it can only return an amount between 1 and 50.



39
40
41
42
43
44
45
46
47
# File 'lib/dog-api-bindings.rb', line 39

def random_images(amount)
  if amount >= 1 && amount <= 50
    response = HTTP.get("#{API_ENDPOINT}/breeds/image/random/#{amount}")
    hashed_response = response.parse['message'] if response.code == 200
    hashed_response || "Could not connect to the API, Status Code: #{response.code}"
  else
    'Can only return between 1 and 50 images.'
  end
end

#random_sub_breed_images(breed, sub_breed, amount) ⇒ Object

Returns an array of sub-breed images equivalent to the passed amount.

Due to API limitations, it can only return an amount between 1 and 50.



65
66
67
68
69
70
71
72
73
# File 'lib/dog-api-bindings.rb', line 65

def random_sub_breed_images(breed, sub_breed, amount)
  if amount >= 1 && amount <= 50
    response = HTTP.get("#{API_ENDPOINT}/breed/#{breed}/#{sub_breed}/images/random/#{amount}")
    hashed_response = response.parse['message'] if response.code == 200
    hashed_response || "Could not connect to the API, Status Code: #{response.code} Perhaps this breed does not have any sub-breeds?"
  else
    'Can only return between 1 and 50 images.'
  end
end

#sub_breeds_list(breed) ⇒ Object

Returns a hash of all available sub-breeds of the given breed.



16
17
18
19
20
# File 'lib/dog-api-bindings.rb', line 16

def sub_breeds_list(breed)
  response = HTTP.get("#{API_ENDPOINT}/breed/#{breed}/list")
  hashed_response = response.parse['message'] if response.code == 200
  hashed_response || "Could not connect to the API, Status Code: #{response.code}. Perhaps this breed does not have any sub-breeds?"
end