Skip to content

Instantly share code, notes, and snippets.

@papoanaya
Created November 9, 2012 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papoanaya/4042979 to your computer and use it in GitHub Desktop.
Save papoanaya/4042979 to your computer and use it in GitHub Desktop.
Web Sequence Diagram from newLisp
;;
;; Web Sequence Diagram Interface - newLisp
;;
(define (url-encode str)
(replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0))
(define (url-decode str)
(replace "+" str " ") ; optional
(replace "%([0-9A-F][0-9A-F])" str (format "%c" (int (append "0x" $1))) 1))
(define (getSequenceDiagram text outputfile (style "default"))
(set 'request (list (eval 'text) (eval 'style)))
(set 'urladdress "http://www.websequencediagrams.com/index.php")
(set 'urldata (join (list "message=" text "&style=" (url-encode style))))
(set 'result (post-url urladdress urldata ))
(set 'expr (regex "(\\?img=[a-zA-Z0-9]+)" result))
(if (nil? expr)
(write-line "Something went wrong")
(begin
(set 'image (get-url (join (list "http://www.websequencediagrams.com/" (first expr) ) )) )
(write-file outputfile image))))
(getSequenceDiagram "alice->bob: authentication request \n bob-->alice: response" "c:\\out.png" "qsd")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment