-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
27 lines (24 loc) · 991 Bytes
/
core.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
(ns jotun.core
(:require [clj-http.client :as http]
[config.core :refer [env]]))
(defrecord JotunResult
[result error? error])
(defn jotun-post
"Boilerplate for post methods. Return body or error."
[url body]
(let [resp (:body (http/post url
{:form-params body
:content-type :json
:as :json}))
error (:errorId resp)]
(if (or (= error 0) (nil? error))
(JotunResult. resp false "")
(JotunResult. false true (:errorDescription resp)))))
(defn send-captcha
"Function to send a captcha to Anti-captcha."
[task & {:keys [callback-url language-pool soft-id]}]
(let [task-url (str (:anti-captcha-url env) "createTask")
prep-body {:clientKey (:api-key env) :task task}
body (assoc prep-body :callbackUrl callback-url :languagePool language-pool)
pos-body (into {} (filter second body))]
(jotun-post task-url pos-body)))