oauth2: move set-query-params to urls.

char-rename
John Benediktsson 2017-01-22 14:44:33 -08:00
parent d1242003ba
commit 33f2fbd099
2 changed files with 7 additions and 10 deletions

View File

@ -13,12 +13,15 @@ TUPLE: url protocol username password host port path query anchor ;
: query-param ( url key -- value )
swap query>> at ;
: set-or-delete ( val key query -- )
: set-or-delete ( value key query -- )
pick [ set-at ] [ delete-at drop ] if ;
: set-query-param ( url value key -- url )
pick query>> [ <linked-hash> ] unless* [ set-or-delete ] keep >>query ;
: set-query-params ( url params -- url )
[ swap set-query-param ] assoc-each ;
ERROR: malformed-port ;
: parse-host ( string -- host/f port/f )

View File

@ -1,16 +1,10 @@
! Copyright (C) 2016 Björn Lindqvist.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs calendar combinators http.client io
json.reader kernel make math.order sequences unicode urls webbrowser ;
json.reader kernel make math.order sequences unicode urls
webbrowser ;
IN: oauth2
! Random utility
: set-query-params ( url params -- url )
[ first2 swap set-query-param ] each ;
: string+params>url ( string params -- url )
[ >url ] dip set-query-params ;
: console-prompt ( query -- str/f )
write flush readln [ blank? ] trim
dup "" = [ drop f ] [ ] if ;
@ -78,7 +72,7 @@ TUPLE: oauth2
] { } make ;
: oauth2>auth-uri ( oauth2 -- uri )
[ auth-uri>> ] [ auth-params ] bi string+params>url ;
[ auth-uri>> >url ] [ auth-params ] bi set-query-params ;
! Other flows can be useful to support too.
: console-flow ( oauth2 -- tokens/f )