sendwithus-clj: Clojure SDK for the sendwithus API
This library provides a easy to use interface for integrating the sendwithus for sending and managing all aspects of email transactions.
The sendwithus-clj library can be installed as a dependency from Clojars
[sendwithus-clj "1.0.2"]
Or gradle
compile "sendwithus-clj:sendwithus-clj:1.0.2"
Or maven
<dependency>
<groupId>sendwithus-clj</groupId>
<artifactId>sendwithus-clj</artifactId>
<version>1.0.2</version>
</dependency
(use 'sendwithus-clj.core)
The library provide a simple macro (with-send-with-us [api-key]) that uses your sendwithus api key to wrap all request to the api.
Example:
; gets all drip campaigns
(with-send-with-us "api-key-here"
(get-drip-campaigns))
;=> [{:enabled false, :id dc_HNiKwoKo44UnVnhf9iBmHX, :name My Campaign, :trigger_email_id nil, :drip_steps [{:delay_seconds 604800, :id dcs_TXb27jmMpSv9V3497iHdaL, :email_id tem_B76FSNaAtKYYeqnALoBYVh, :object drip_step}], :object drip_campaign}]
The library also exposes record constructs that make more rich payloads easy:
(defrecord Template [id locale version name subject html text])
(defrecord Recipient [address name])
(defrecord Sender [address reply_to name])
(defrecord Email [email_id recipient cc bcc sender email_data tags headers inline files esp_account locale version_name])
(defrecord RenderRequest [template_id template_data version_id version_name locale strict])
(defrecord DripCampaign [drip_campaign_id recipient cc bcc sender email_data tags esp_account locale])
These can be used directly with the library:
; Sending an email
(with-send-with-us "api-key-here"
(send-email (Email.
"tem_B76FSNaAtKYYeqnALoBYVh"
(Recipient. "[email protected]" "recipient test")
[(Recipient. "[email protected]" "cc test")]
[(Recipient. "[email protected]" "bcc test")]
(Sender. "[email protected]" "[email protected]" "SWU clj")
{:amount "$12.99"}
["tag1" "tag2"]
{:X-HEADER-ONE "custom header"}
{:id "inline-message" :data "SGkgdGhpcyBpcyBhIG1lc3NhZ2U="}
[{:id "doc.txt" :data "SGVsbG8sIHRoaXMgaXMgYSB0ZXh0IGZpbGUuCg=="}]
"esp_1a2b3c4d5e"
"en-US"
"Version")))
;=> {:success true, :status OK, :receipt_id log_37f0270870c138f526cace50b7615f6c, :email {:locale en-US, :version_name Version, :name My Template}}
- (send-email [email]) note: uses the Email. record
- (resend-email [log-id])
- (batch-send [emails]) note: uses a vector of Email. records
- (get-templates [])
- (get-templates [template-id])
- (get-templates [template-id locale])
- (get-templates [template-id locale version])
- (update-template [template]) note: uses the Template. record
- (create-template [template]) note: uses the Template. record
- (add-locale [template]) note: uses the Template. record
- (add-version [template]) note: uses the Template. record with optional locale
- (get-logs [])
- (get-logs [log-id events?])
- (get-snippets [])
- (get-snippets [snippet-id])
- (create-snippet [name body])
- (update-snippet [snippet-id name body])
- (delete-snippet [snippet-id])
- (get-providers [])
- (set-default-provider [provider-id])
- (get-customers [email])
- (get-customer-logs [email])
- (upsert-customer [email])
- (upsert-customer [email email-data])
- (upsert-customer [email email-data locale])
- (delete-customer [email])
- (add-customer-to-group [email group-id])
- (remove-customer-from-group [email group-id])
- (remove-customer-from-campaigns [email])
- (remove-customer-from-campaigns [email campaign-id])
- (add-customer-to-campaign [drip-campaign]) note: this uses the DripCampaign. record
- (get-drip-campaigns [])
- (get-drip-campaigns [drip-campaign-id])
- (get-segments [])
- (send-to-segment [segment-id template-id email-data])
- (get-groups [])
- (create-group [name description])
- (update-group [group-id name description])
- (delete-group [group-id])
All api examples can be found in the sendwithus-clj.examples namespace
- email: [email protected]
If you come across any issues, please file them on the Github project issue tracker.
Check out sendwithus-clj docs
or
Check out the full SendWithUs API Documentation.
Copyright © 2015 Tyler Hoersch
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.