Top Level Namespace

Constant Summary collapse

API_ENDPOINT =
'https://dog.ceo/api'

Instance Method Summary collapse

Instance Method Details

#return_breed_images(breed) ⇒ Object



19
20
21
22
23
# File 'lib/dog-api.rb', line 19

def return_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

#return_breeds_listObject



7
8
9
10
11
# File 'lib/dog-api.rb', line 7

def return_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

#return_random_breed_images(breed, amount) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/dog-api.rb', line 41

def return_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

#return_random_images(amount) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/dog-api.rb', line 31

def return_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

#return_random_sub_breed_images(breed, sub_breed, amount) ⇒ Object



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

def return_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

#return_sub_breed_images(breed, sub_breed) ⇒ Object



25
26
27
28
29
# File 'lib/dog-api.rb', line 25

def return_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

#return_sub_breeds_list(breed) ⇒ Object



13
14
15
16
17
# File 'lib/dog-api.rb', line 13

def return_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