Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates Dog API endpoint with v2 #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions keywords/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@ def self.picture
end

module Dog
# Get a random fact about dogs thanks to https://kinduff.github.io/dog-api/.
# Get a random fact about dogs thanks to https://dogapi.dog.
#
# API URL: "http://dog-api.kinduff.com/api/facts"
# API URL: "https://dogapi.dog/api/v2/facts"
# Example API response:
# {
# "facts":
# [
# "Dogs have three eyelids. The third lid, called a nictitating membrane or \"haw,\" keeps the eye lubricated and protected."
# ],
# "success":true
# "data": [
# {
# "id": "05e0601b-c669-44d6-8308-ea9f7ce48dd6",
# "type": "fact",
# "attributes": {
# "body": "The average city dog lives 3 years longer than a country dog."
# }
# }
# ]
# }
def self.fact
response = HTTP.get("https://dog-api.kinduff.com/api/facts")
JSON.parse(response.to_s)["facts"].first
response = HTTP.get("https://dogapi.dog/api/v2/facts")
JSON.parse(response.to_s)["data"].first["attributes"]["body"]
end

# Get a random picture of a dog thanks to https://dog.ceo/.
Expand Down