From 6a7a5a1c9591c34b8c6696412543217a5469fb6e Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Mon, 10 Sep 2018 00:46:52 -0400 Subject: [PATCH] add contract for identity type - fix typo in docs: `personal-access-token` is not a valid identity type - add a contract for identity types - use the contract for some util functions --- scribblings/github-api.scrbl | 6 +++--- utils.rkt | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scribblings/github-api.scrbl b/scribblings/github-api.scrbl index 8099e18..68588f4 100644 --- a/scribblings/github-api.scrbl +++ b/scribblings/github-api.scrbl @@ -18,12 +18,12 @@ Before you begin making requests to the GitHub api, you must create an identity. @defstruct[github-identity ([type symbol?] [data list?])]{ This struct holds your GitHub identity. - @racket[type] must be one of the following symbols: @racket['password 'personal-access-token 'oauth] + @racket[type] must be one of the following symbols: @racket['password 'personal-token 'oauth] @racket['password] authentication simply uses your GitHub username and password. - @racket['personal-access-token] authentication allows you + @racket['personal-token] authentication allows you to send your GitHub username and a personal access token (created on your GitHub settings page.) @racket['oauth] uses an OAuth token for authorization. @@ -580,4 +580,4 @@ name of the webhook. (define delete-response (del-hook)) (if (= 204 (github-response-code delete-response)) (displayln "successfully removed webhook") - (displayln "trouble removing webhook"))] \ No newline at end of file + (displayln "trouble removing webhook"))] diff --git a/utils.rkt b/utils.rkt index de0d261..401b438 100644 --- a/utils.rkt +++ b/utils.rkt @@ -4,10 +4,10 @@ github-api-req/c github-api-resp/c (contract-out - [struct github-identity ([type symbol?] [data (listof string?)])] + [struct github-identity ([type github-identity-type/c] [data (listof string?)])] [struct github-response ([code number?] [data jsexpr?])] [get-status-code (-> string? number?)] - [make-auth-header (-> symbol? (listof string?) string?)] + [make-auth-header (-> github-identity-type/c (listof string?) string?)] [port->jsexpr (-> input-port? jsexpr?)] [->string (-> any/c string?)])) @@ -18,6 +18,9 @@ (define github-api-resp/c github-response?) (define github-api-req/c (->* (string?) [#:method string? #:data string? #:media-type string?] github-api-resp/c)) +(define github-identity-type/c + (or/c 'password 'personal-token 'oauth2)) + (module+ test (require rackunit)) (define (base64-encode-string s) @@ -100,4 +103,4 @@ (module+ test (check-true (jsexpr? (port->jsexpr (open-input-string "")))) (check-true (jsexpr? (port->jsexpr - (open-input-string "{\"test\": 3}"))))) \ No newline at end of file + (open-input-string "{\"test\": 3}")))))