oauth2: move set-query-params to urls.
parent
d1242003ba
commit
33f2fbd099
|
@ -13,12 +13,15 @@ TUPLE: url protocol username password host port path query anchor ;
|
||||||
: query-param ( url key -- value )
|
: query-param ( url key -- value )
|
||||||
swap query>> at ;
|
swap query>> at ;
|
||||||
|
|
||||||
: set-or-delete ( val key query -- )
|
: set-or-delete ( value key query -- )
|
||||||
pick [ set-at ] [ delete-at drop ] if ;
|
pick [ set-at ] [ delete-at drop ] if ;
|
||||||
|
|
||||||
: set-query-param ( url value key -- url )
|
: set-query-param ( url value key -- url )
|
||||||
pick query>> [ <linked-hash> ] unless* [ set-or-delete ] keep >>query ;
|
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 ;
|
ERROR: malformed-port ;
|
||||||
|
|
||||||
: parse-host ( string -- host/f port/f )
|
: parse-host ( string -- host/f port/f )
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
! Copyright (C) 2016 Björn Lindqvist.
|
! Copyright (C) 2016 Björn Lindqvist.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs calendar combinators http.client io
|
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
|
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 )
|
: console-prompt ( query -- str/f )
|
||||||
write flush readln [ blank? ] trim
|
write flush readln [ blank? ] trim
|
||||||
dup "" = [ drop f ] [ ] if ;
|
dup "" = [ drop f ] [ ] if ;
|
||||||
|
@ -78,7 +72,7 @@ TUPLE: oauth2
|
||||||
] { } make ;
|
] { } make ;
|
||||||
|
|
||||||
: oauth2>auth-uri ( oauth2 -- uri )
|
: 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.
|
! Other flows can be useful to support too.
|
||||||
: console-flow ( oauth2 -- tokens/f )
|
: console-flow ( oauth2 -- tokens/f )
|
||||||
|
|
Loading…
Reference in New Issue