Created
March 1, 2012 00:28
-
-
Save samth/1946155 to your computer and use it in GitHub Desktop.
rudimentary github wrangling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [samth@loki:~ plt] curl -u 'samth:PASSWORD' --data '{"title":"the title"}' https://api.github.com/repos/samth/test-bugs/issues |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang at-exp racket | |
| (require net/url net/base64 net/uri-codec (planet dherman/json)) | |
| ;; http-authorization-header : string string -> string | |
| (define (http-authorization-header username password) | |
| (let ([username-bytes (string->bytes/utf-8 username)] | |
| [password-bytes (string->bytes/utf-8 password)]) | |
| (string-append | |
| "Authorization: Basic " | |
| (bytes->string/utf-8 | |
| (base64-encode | |
| (bytes-append username-bytes #":" password-bytes) #""))))) | |
| (define data ;; works | |
| (string->bytes/utf-8 (jsexpr->json (hash 'title "found a bug")))) | |
| (define data1 ;; works | |
| @(compose string->bytes/utf-8 string-append){{"title":"found a bug","body":"you cannot be serious" }}) | |
| (define data2 ;; works | |
| @(compose string->bytes/utf-8 string-append){{"title":"found a bug","body":"you cannot be serious"}}) | |
| (define (go d) | |
| (port->string | |
| (post-pure-port | |
| (string->url "https://api.github.com/repos/samth/test-bugs/issues") | |
| d | |
| (list (http-authorization-header "samth" "PASSWD"))))) |
Author
Can you fork this gist with a version that works? And why does the base64 string affect the later newline?
Author
Note for the future: current gist works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nc -l 9898).regexp-replaced it away and both versions work.base64-encodefor the line separator.