From 26e775444ad2c7603e8564d02d370211e83294e8 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Wed, 22 Jun 2011 19:52:19 +0200 Subject: Implement fax API (which I haven't been able to test successfully and which isn't supported) --- smsmatrix.scm | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/smsmatrix.scm b/smsmatrix.scm index 61d6a8a..008184e 100644 --- a/smsmatrix.scm +++ b/smsmatrix.scm @@ -37,7 +37,7 @@ (module smsmatrix (smsmatrix-username smsmatrix-password get-credits get-rate carrier-name message-status call-with-csv-report - send-sms) + send-sms send-fax) (import chicken scheme) @@ -277,4 +277,39 @@ entry)) res)))) +;; The fax API is undocumented except for a Perl example and unsupported +(define (send-fax recipients filename #!key + username password group (error-on-failure #t)) + (let-auth 'send-fax username password + (let* ((recipient-type (if group 'group 'phone)) ;; TODO: test if group works for faxes + (recipients (if (string? recipients) ;; TODO: Check if multi-recipients works + recipients + (string-intersperse recipients ","))) + (res (api-request 'send-fax fax-uri + `((username . ,username) + (password . ,password) + (,recipient-type . ,recipients) + (file file: ,filename filename: ,filename + headers: ((content-type application/pdf)))) + 'pin '(id statuscode statustxt timestamp)))) + (print res) + ;; Check for errors in phone number recipients if it was asked for + (when error-on-failure + (for-each (lambda (entry) + (let ((status (alist-ref 'statuscode entry)) + (status-text (alist-ref 'statustxt entry)) + (pin (alist-ref 'pin entry))) + (error-on-bad-result-code + 'send-fax status status-text pin))) + res)) + (map (lambda (entry) + (map (lambda (key/value) + (let ((key (car key/value)) + (value (cdr key/value))) + (case key + ((statuscode timestamp) (cons key (string->number value))) + (else key/value)))) + entry)) + res)))) + ) \ No newline at end of file -- cgit v1.2.3