Welcome to the CHICKEN Scheme pasting service

send-grid.scm added by anonymous on Sun Nov 11 21:48:26 2012

(module send-grid
  (;; params
   api-user api-key

   ;; procs
   send-mail)

(import scheme chicken)
(use http-client uri-common intarweb json srfi-1 srfi-18)

(define api-user (make-parameter ""))
(define api-key (make-parameter ""))

(define (rest-action url method parameters)
  (vector->list (with-input-from-request
                 (make-request method: method uri: (uri-reference url)) parameters json-read)))

(define (send-mail #!key (subject #f) (text #f) (html #f) (from #f) (from-name #f) (to #f) (reply-to #f) (api-user (api-user)) (api-key (api-key)))
  (if (and subject (or text html) from from-name to reply-to)
      (rest-action "https://sendgrid.com/api/mail.send.json" 'POST
                   `((api_user . ,api-user)
                     (api_key . ,api-key)
                     (subject . ,subject)
                     (to . ,to)
                     (replyto . ,reply-to)
                     ,(if html `(html . ,html) `(text . ,text))
                     (from . ,from)
                     (fromname . ,from-name)))
      (abort "All parameters are required for successfully sending mail.")))
)

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which egg provides `hash-table-ref'?
Visually impaired? Let me spell it for you (wav file) download WAV