Skip to content

Commit eb5f889

Browse files
committed
move to util
1 parent ccd2405 commit eb5f889

File tree

6 files changed

+117
-7
lines changed

6 files changed

+117
-7
lines changed

example_test.clj

-1
This file was deleted.

src/gfycat_api/core.clj

+2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
(keyword (clojure.string/replace key #"_" "-")))
99
(def client-info (json/read-str (slurp ".client_info.json")
1010
:key-fn clojure-stylify))
11+
1112
(defn- gfycat-request [path query-params]
1213
(-> (client/get (str "https://api.gfycat.com/v1/" path)
1314
{:content-type :json
1415
:accept "text/html"
1516
:query-params query-params})
1617
:body
1718
(json/read-str :key-fn clojure-stylify)))
19+
1820
(defn get-token []
1921
(let [token-chan (chan)]
2022
(go

src/gfycat_api/util.clj

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns gfycat-api.util)
2+
3+
(defn get-gfycats-with [keys search-result]
4+
"returns list of gfycats with selected parameters,
5+
removes all other parameters"
6+
(map #(select-keys % keys) (:gfycats search-result)))

test/gfycat_api/core_test.clj

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns gfycat-api.core-test
22
(:require [clojure.test :refer [deftest is testing]]
33
[gfycat-api.core :as core]
4-
[clojure.core.async :refer [go <! <!! >! >!! alt! alt!! chan]]))
4+
))
55

66
#_(deftest get-token-test
77
(let [token (<!! (core/get-token))]
88
(is (not (nil? token)))
99
(is (= (:expires-in token) 3600))))
1010
(def token (:access-token (<!! (core/get-token))))
11-
(deftest search-test
12-
(testing "should return one gfycat search result"
13-
(let [search-result (core/search token "thanos power up" 1)]
14-
(is (= search-result {}))))
15-
(testing "searchnig with cursor"))
11+
#_(deftest search-test
12+
(testing "should return one gfycat search result"
13+
(let [search-result (core/search token "wow" 1)]
14+
(is (= search-result {}))))
15+
(testing "searchnig with cursor"))

test/gfycat_api/fixtures.clj

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
(ns gfycat-api.fixtures)
2+
(def single-gfycat-search-result
3+
{:cursor ""
4+
:gfycats
5+
[{:description "Illustrator, Instagram, Facebook, graphics, Snapchat, free, Adobe Creative Cloud, visual effects, ambient effects, free footage, After effects, compositing, Photoshop, GIF, motion, after effects"
6+
:tags ["compositing" "facebook" "free" "gif" "graphics" "illustrator" "instagram" "motion" "photoshop" "snapchat"]
7+
:max2mbGif "https://thumbs.gfycat.com/FondFocusedClownanemonefish-small.gif"
8+
:webmSize 657581
9+
:gfySlug "compositing-illustrator-photoshop"
10+
:miniUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.mp4"
11+
:numFrames 250
12+
:dislikes 0
13+
:avgColor "#C9C7C6"
14+
:mp4Url "https://giant.gfycat.com/FondFocusedClownanemonefish.mp4"
15+
:miniPosterUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.jpg"
16+
:gifUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-size_restricted.gif"
17+
:thumb100PosterUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.jpg"
18+
:domainWhitelist []
19+
20+
:content-urls {:max2mbGif {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-small.gif"
21+
:size 1681055
22+
:height 158
23+
:width 280}
24+
:webm {:url "https://giant.gfycat.com/FondFocusedClownanemonefish.webm"
25+
:size 657581
26+
:height 720
27+
:width 1280}
28+
:mp4 {:url "https://giant.gfycat.com/FondFocusedClownanemonefish.mp4"
29+
:size 1777677
30+
:height 720
31+
:width 1280}
32+
:max1mbGif {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-max-1mb.gif"
33+
:size 816111
34+
:height 158
35+
:width 280}
36+
:webp {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish.webp"
37+
:size 504468
38+
:height 0
39+
:width 0}
40+
:largeGif {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-size_restricted.gif"
41+
:size 4762903
42+
:height 250
43+
:width 444}
44+
:max5mbGif {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-size_restricted.gif"
45+
:size 4762903
46+
:height 250
47+
:width 444}
48+
:mobilePoster {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.jpg"
49+
:size 11867
50+
:height 360
51+
:width 640}
52+
:mobile {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.mp4"
53+
:size 532078
54+
:height 360
55+
:width 640}
56+
:100pxGif {:url "https://thumbs.gfycat.com/FondFocusedClownanemonefish-max-1mb.gif"
57+
:size 816111
58+
:height 158
59+
:width 280}}
60+
:gif100px "https://thumbs.gfycat.com/FondFocusedClownanemonefish-max-1mb.gif"
61+
:frameRate 25
62+
:max1mbGif "https://thumbs.gfycat.com/FondFocusedClownanemonefish-max-1mb.gif"
63+
:gfyNumber "742741416"
64+
:width 1280
65+
:gatekeeper 0
66+
:mobilePosterUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.jpg"
67+
:source 1
68+
:likes 0
69+
:curated 0
70+
:createDate 1553634301
71+
:title "Canadian Flag waving animated using MIR plug in after effects - free motion graphics"
72+
:languageText2 ""
73+
:nsfw "0"
74+
:extraLemmas ""
75+
:hasAudio true
76+
:max5mbGif "https://thumbs.gfycat.com/FondFocusedClownanemonefish-size_restricted.gif"
77+
:languageCategories nil
78+
:mp4Size 1777677
79+
:url "https://youtu.be/uGZpBKLQdSg"
80+
:mobileUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-mobile.mp4"
81+
:gfyId "fondfocusedclownanemonefish"
82+
:gfyName "FondFocusedClownanemonefish"
83+
:posterUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish-poster.jpg"
84+
:hasTransparency false
85+
:webpUrl "https://thumbs.gfycat.com/FondFocusedClownanemonefish.webp"
86+
:webmUrl "https://giant.gfycat.com/FondFocusedClownanemonefish.webm"
87+
:userName "anonymous"
88+
:published 1
89+
:rating "PG"
90+
:height 720
91+
:views 27828}]
92+
:related ["compositing" "facebook" "free" "gif" "graphics" "illustrator" "instagram" "motion" "photoshop" "snapchat" "illustrator" " instagram" " facebook" " graphics" " snapchat" " free" " adobe creative cloud" " visual effects" " ambient effects" " free footage" " after effects" " compositing" " photoshop" " gif" " motion"]
93+
:found 2})

test/gfycat_api/util_test.clj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(ns gfycat-api.core-test
2+
(:require
3+
[clojure.test :refer [deftest is testing]]
4+
[gfycat-api.fixtures :as fixtures]
5+
[gfycat-api.util :as util]))
6+
7+
(deftest search-result-filtering
8+
(is (= (util/get-gfycats-with [:title] fixtures/single-gfycat-search-result)
9+
'({:title
10+
"Canadian Flag waving animated using MIR plug in after effects - free motion graphics"}))))

0 commit comments

Comments
 (0)