-
Notifications
You must be signed in to change notification settings - Fork 65
/
giphy.clj
32 lines (23 loc) 路 955 Bytes
/
giphy.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns yetibot.api.giphy
(:require
[taoensso.timbre :refer [info warn error]]
[clojure.string :as s]
[clj-http.client :as client]
[clojure.core.memoize :as memo]
[schema.core :as sch]
[yetibot.core.config :refer [get-config]]
[yetibot.core.util.http :refer [get-json encode]]))
(def base-url "http://api.giphy.com/v1")
(defn config [] (get-config {:key String} [:giphy]))
(defn configured? [] (nil? (:error (config))))
(defn api-key [] (:key (:value (config))))
(defn endpoint [path] (str base-url path))
(defn translate-endpoint [query]
(endpoint (str "/gifs/translate?s=" (encode query) "&rating=pg-13&api_key=" (api-key))))
(defn translate [term]
(info (translate-endpoint term))
(get-json (translate-endpoint term)))
(defn random []
(get-json (endpoint (str "/gifs/random?rating=pg-13&api_key=" (api-key)))))
(defn trending []
(get-json (endpoint (str "/gifs/trending?rating=pg-13&api_key=" (api-key)))))