From 4051efaf481afb1606c0e833f3c6eae0f075ed3f Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Mon, 20 Jun 2011 23:52:07 +0200 Subject: Always use https when a username/password is required and use the slightly shorter POST syntax in trunk http-client --- smsmatrix.scm | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/smsmatrix.scm b/smsmatrix.scm index 7c1531a..61d6a8a 100644 --- a/smsmatrix.scm +++ b/smsmatrix.scm @@ -51,22 +51,23 @@ ;; (if the URIs change the API probably changes too), but still... ;; Informational -(define balance-uri "http://www.smsmatrix.com/balance") (define carrier-uri "http://www.smsmatrix.com/carrier") -(define csv-report-uri "http://www.smsmatrix.com/csv_report") -(define status-uri "http://www.smsmatrix.com/matrix_status") (define rate-uris - '((sms . "https://www.smsmatrix.com/sms_rate") - (voice . "https://www.smsmatrix.com/voice_rate") - (tts . "https://www.smsmatrix.com/tts_rate"))) + '((sms . "http://www.smsmatrix.com/sms_rate") + (voice . "http://www.smsmatrix.com/voice_rate") + (tts . "http://www.smsmatrix.com/tts_rate"))) +;; These require login, so use https +(define balance-uri "https://www.smsmatrix.com/balance") +(define status-uri "https://www.smsmatrix.com/matrix_status") +(define csv-report-uri "https://www.smsmatrix.com/csv_report") ;; Sending messages (define sms-uri "https://www.smsmatrix.com/matrix") (define fax-uri "https://www.smsmatrix.com/matrix_fax") -(define tts-uri "http://www.smsmatrix.com/matrix_tts") -(define voice-upload-uri "http://www.smsmatrix.com/matrix_voice") -(define voice-link-uri "http://www.smsmatrix.com/matrix_voicew") -(define voice-tts-uri "http://www.smsmatrix.com/matrix_vtts") +(define tts-uri "https://www.smsmatrix.com/matrix_tts") +(define voice-upload-uri "https://www.smsmatrix.com/matrix_voice") +(define voice-link-uri "https://www.smsmatrix.com/matrix_voicew") +(define voice-tts-uri "https://www.smsmatrix.com/matrix_vtts") ;; All values from 0 - 399 (inclusive) mean success, other values mean failure. ;; Yes, this means this list is incomplete. Let's just hope they're not going @@ -139,14 +140,16 @@ alist (next-line))))))))))) (define (api-request loc uri params split-at required-result-values) - (let* ((request (make-request method: 'POST uri: (uri-reference uri))) - (res (call-with-input-request - request params (lambda (port) - (read-fields-as-alist port split-at))))) + (let ((res (call-with-input-request uri params + (lambda (port) + (read-fields-as-alist port split-at))))) (for-each (lambda (element) - (unless (alist-ref element res) - (error loc (conc "Did not return a value for \"" element "\"!")))) + (for-each + (lambda (entry) + (unless (alist-ref element entry) + (error loc (conc "Did not return a value for \"" element "\"!")))) + (if split-at res (list res)))) required-result-values) res)) @@ -235,13 +238,12 @@ ;; different than =-separated lists of key/value pairs and "email" vs "username" (define (call-with-csv-report proc #!key username password limit incoming-only) (let-auth 'csv-report username password - (let* ((request (make-request method: 'POST - uri: (uri-reference csv-report-uri))) - (params `((email . ,username) - (password . ,password) - (limit . ,limit) - (in . ,(if incoming-only 1 0))))) - (call-with-input-request request params proc)))) + (call-with-input-request csv-report-uri + `((email . ,username) + (password . ,password) + (limit . ,limit) + (in . ,(if incoming-only 1 0))) + proc))) (define (send-sms recipients message #!key username password group tts-fallback (error-on-failure #t)) @@ -255,7 +257,7 @@ (,recipient-type . ,recipients) (txt . ,message) (tts . ,(if tts-fallback 1 0))) - 'pin '()))) + 'pin '(id statuscode statustxt timestamp)))) ;; Check for errors in phone number recipients if it was asked for (when error-on-failure (for-each (lambda (entry) -- cgit v1.2.3