bit.ly: some old-school newfx
parent
4f16212840
commit
3e6c16ce36
|
@ -7,6 +7,8 @@ SYMBOLS: login api-key ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
: of ( assoc key -- value ) swap at ;
|
||||||
|
|
||||||
: make-request ( long-url -- request )
|
: make-request ( long-url -- request )
|
||||||
"http://api.bit.ly/v3/shorten" >url
|
"http://api.bit.ly/v3/shorten" >url
|
||||||
login get "login" set-query-param
|
login get "login" set-query-param
|
||||||
|
@ -17,13 +19,13 @@ SYMBOLS: login api-key ;
|
||||||
ERROR: bad-response json status ;
|
ERROR: bad-response json status ;
|
||||||
|
|
||||||
: check-response ( json -- json )
|
: check-response ( json -- json )
|
||||||
dup "status_code" swap at 200 = [
|
dup "status_code" of 200 = [
|
||||||
dup "status_txt" swap at
|
dup "status_txt" of
|
||||||
bad-response
|
bad-response
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
: parse-response ( response data -- short-url )
|
: parse-response ( response data -- short-url )
|
||||||
nip json> check-response "data" swap at "url" swap at ;
|
nip json> check-response "data" of "url" of ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue