diff --git a/components/rest-mailersend/src/org/aplex/mailersend/core.cljc b/components/rest-mailersend/src/org/aplex/mailersend/core.cljc index c288df1..cd04a15 100644 --- a/components/rest-mailersend/src/org/aplex/mailersend/core.cljc +++ b/components/rest-mailersend/src/org/aplex/mailersend/core.cljc @@ -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") diff --git a/components/rest-mailersend/src/org/aplex/mailersend/interface.cljc b/components/rest-mailersend/src/org/aplex/mailersend/interface.cljc index f94bfe0..62119c5 100644 --- a/components/rest-mailersend/src/org/aplex/mailersend/interface.cljc +++ b/components/rest-mailersend/src/org/aplex/mailersend/interface.cljc @@ -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)) diff --git a/components/rest-sendgrid/deps.edn b/components/rest-sendgrid/deps.edn new file mode 100644 index 0000000..28d4733 --- /dev/null +++ b/components/rest-sendgrid/deps.edn @@ -0,0 +1,4 @@ +{:paths ["src" "resources"] + :deps {} + :aliases {:test {:extra-paths ["test"] + :extra-deps {}}}} diff --git a/components/rest-sendgrid/resources/rest-sendgrid/.keep b/components/rest-sendgrid/resources/rest-sendgrid/.keep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/components/rest-sendgrid/resources/rest-sendgrid/.keep @@ -0,0 +1 @@ + diff --git a/components/rest-sendgrid/src/org/aplex/rest_sendgrid/.#interface.cljc b/components/rest-sendgrid/src/org/aplex/rest_sendgrid/.#interface.cljc new file mode 100644 index 0000000..422cb57 --- /dev/null +++ b/components/rest-sendgrid/src/org/aplex/rest_sendgrid/.#interface.cljc @@ -0,0 +1,2 @@ +(ns org.aplex.rest-sendgrid.oly@fry) + diff --git a/components/rest-sendgrid/src/org/aplex/rest_sendgrid/core.cljc b/components/rest-sendgrid/src/org/aplex/rest_sendgrid/core.cljc new file mode 100644 index 0000000..9b1e46f --- /dev/null +++ b/components/rest-sendgrid/src/org/aplex/rest_sendgrid/core.cljc @@ -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 ""})) diff --git a/components/rest-sendgrid/src/org/aplex/rest_sendgrid/interface.cljc b/components/rest-sendgrid/src/org/aplex/rest_sendgrid/interface.cljc new file mode 100644 index 0000000..6b407ea --- /dev/null +++ b/components/rest-sendgrid/src/org/aplex/rest_sendgrid/interface.cljc @@ -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)) diff --git a/components/rest-sendgrid/test/org/aplex/rest_sendgrid/interface_test.clj b/components/rest-sendgrid/test/org/aplex/rest_sendgrid/interface_test.clj new file mode 100644 index 0000000..c408162 --- /dev/null +++ b/components/rest-sendgrid/test/org/aplex/rest_sendgrid/interface_test.clj @@ -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))) diff --git a/deps.edn b/deps.edn index 9a646d1..651477c 100644 --- a/deps.edn +++ b/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"} diff --git a/development/src/backend/mailersend.clj b/development/src/backend/mailersend.clj index 62be892..22c1238 100644 --- a/development/src/backend/mailersend.clj +++ b/development/src/backend/mailersend.clj @@ -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"}]}]} diff --git a/development/src/backend/sendgrid.clj b/development/src/backend/sendgrid.clj new file mode 100644 index 0000000..7b2561a --- /dev/null +++ b/development/src/backend/sendgrid.clj @@ -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 +