Sendgrid first api requests.
This commit is contained in:
parent
d1bbfc3b3b
commit
9fb6b33ffc
|
@ -16,6 +16,15 @@
|
|||
(defn build-url [path]
|
||||
(str (:api-host @api-config) version path))
|
||||
|
||||
(defn verify-email [email]
|
||||
(merge default-authed-payload
|
||||
{:uri (build-url "/email-verification/verify")
|
||||
:method :post
|
||||
:format (json-request-format)
|
||||
:response-format (json-response-format {:keywords? true})
|
||||
:keywords? true
|
||||
:params email}))
|
||||
|
||||
(defn send-email [email]
|
||||
(merge default-authed-payload
|
||||
{:uri (build-url "/email")
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
(defn init-config [cfg]
|
||||
(c/init-config cfg))
|
||||
|
||||
(defn verify-email [email]
|
||||
(c/verify-email email))
|
||||
|
||||
(defn send-email [email]
|
||||
(c/send-email email))
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{:paths ["src" "resources"]
|
||||
:deps {}
|
||||
:aliases {:test {:extra-paths ["test"]
|
||||
:extra-deps {}}}}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
(ns org.aplex.rest-sendgrid.oly@fry)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
(ns org.aplex.rest-sendgrid.core
|
||||
(:require
|
||||
[ajax.core :refer [json-request-format json-response-format]]
|
||||
[org.aplex.helpers.interface :as h]))
|
||||
|
||||
(def version "v3")
|
||||
(def api-config (atom {:api-host "https://api.sendgrid.com/"
|
||||
:api-key (h/get-env "SENDGRID_API_KEY" "NO API KEY SUPPLIED")}))
|
||||
|
||||
(def default-authed-payload {:headers {"Authorization" (str "Bearer " (:api-key @api-config))
|
||||
"content-type" "application/json"}})
|
||||
|
||||
(defn init-config [cfg]
|
||||
(reset! api-config (merge @api-config cfg)))
|
||||
|
||||
(defn build-url [path]
|
||||
(str (:api-host @api-config) version path))
|
||||
|
||||
(defn send-email
|
||||
"https://docs.sendgrid.com/api-reference/mail-send/mail-send"
|
||||
[email]
|
||||
(merge default-authed-payload
|
||||
{:uri (build-url "/mail/send")
|
||||
:method :post
|
||||
:format (json-request-format)
|
||||
:response-format (json-response-format {:keywords? true})
|
||||
:keywords? true
|
||||
:params email}))
|
||||
|
||||
(comment (send-email {:to ""}))
|
|
@ -0,0 +1,5 @@
|
|||
(ns org.aplex.rest-sendgrid.interface
|
||||
(:require [org.aplex.rest-sendgrid.core :as c]))
|
||||
|
||||
(defn send-email [email]
|
||||
(c/send-email email))
|
|
@ -0,0 +1,6 @@
|
|||
(ns org.aplex.rest-sendgrid.interface-test
|
||||
(:require [clojure.test :as test :refer :all]
|
||||
[org.aplex.rest-sendgrid.interface :as rest-sendgrid]))
|
||||
|
||||
(deftest dummy-test
|
||||
(is (= 1 1)))
|
1
deps.edn
1
deps.edn
|
@ -1,6 +1,7 @@
|
|||
{:paths ["development/src"
|
||||
"components/helpers/src"
|
||||
"components/rest-stability-ai/src"
|
||||
"components/rest-sendgrid/src"
|
||||
"components/rest-mailersend/src"]
|
||||
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
|
||||
org.clojure/clojurescript {:mvn/version "1.11.60"}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(:require
|
||||
[org.aplex.helpers.interface :as h]
|
||||
[ajax.core
|
||||
:refer [ajax-request GET json-request-format json-response-format POST ]]
|
||||
:refer [ajax-request]]
|
||||
[org.aplex.mailersend.interface :as m]))
|
||||
|
||||
(def response (atom nil))
|
||||
|
@ -21,14 +21,22 @@
|
|||
(m/send-email)
|
||||
(h/attach-handler prn))
|
||||
|
||||
(-> {:to [{:email "olymk2@gmail.com"
|
||||
(-> {:email "olymk2@gmail.com"}
|
||||
(m/verify-email)
|
||||
(h/attach-handler (partial reset! response))
|
||||
(ajax-request)
|
||||
(deref))
|
||||
@response
|
||||
|
||||
|
||||
(-> {:to [{:email #_"test@theplantscape.com" "oly@digitaloctave.com"
|
||||
:name "oly"}]
|
||||
:from {:email "test@theplantscape.com"
|
||||
:from {:email "hello@theplantscape.com"
|
||||
:name "test"}
|
||||
:subject "Test mailersend api"
|
||||
:text "Hi {$name}"
|
||||
:html "Hi {$name}"
|
||||
:variables [{:email "olymk2@gmail.com"
|
||||
#_:variables #_[{:email "olymk2@gmail.com"
|
||||
:substitutions [{:var "name"
|
||||
:value "Test name"}]}]}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
(ns backend.sendgrid
|
||||
(:require
|
||||
[org.aplex.helpers.interface :as h]
|
||||
[ajax.core
|
||||
:refer [ajax-request]]
|
||||
[org.aplex.rest-sendgrid.interface :as m]))
|
||||
|
||||
(def response (atom nil))
|
||||
|
||||
(-> {:personalizations:to [{:email "oly@digitaloctave.com"
|
||||
:name "oly"}]
|
||||
:from {:email "hello@theplantscape.com"
|
||||
:name "test"}
|
||||
:subject "Test sendgrid api"
|
||||
:content [{:type "text/plain" :value "body"}]
|
||||
}
|
||||
|
||||
(m/send-email)
|
||||
(h/attach-handler (partial reset! response))
|
||||
)
|
||||
|
||||
(-> {:personalizations [{:to [{:email "oly@digitaloctave.com"
|
||||
:name "oly"}]}]
|
||||
:from {:email "hello@theplantscape.com"
|
||||
:name "test"}
|
||||
:subject "Test sendgrid api"
|
||||
:content [{:type "text/plain" :value "email body"}
|
||||
{:type "text/html" :value "email body"}]
|
||||
}
|
||||
|
||||
(m/send-email)
|
||||
(h/attach-handler (partial reset! response))
|
||||
(ajax-request)
|
||||
(deref))
|
||||
|
||||
@response
|
||||
|
Loading…
Reference in New Issue