 ! Copyright (C) 2020 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
+
 USING: accessors assocs base64 calendar calendar.format
-checksums.hmac checksums.sha combinators formatting http
-http.client json.reader json.writer kernel math.parser
-namespaces sequences ;
+checksums.hmac checksums.sha combinators combinators.smart
+formatting fry http http.client json.reader json.writer kernel
+locals make math.parser namespaces random sequences ;
+
 IN: visionect
 
 SYMBOL: visionect-base-url


! ## BACKENDS

: http-backend ( png uuid -- )
    "/backend/" prepend visionect-put drop ;


<PRIVATE

: visionect-authorization ( request -- auth )
    {
        [ method>> ]
        [ "content-sha256" header ]
        [ "content-type" header ]
        [ "date" header ]
        [ url>> path>> ]
    } cleave>array "\n" join
    visionect-api-secret get sha-256 hmac-bytes >base64
    visionect-api-key get ":" rot 3append ;

: set-visionect-headers ( request -- request )
    now timestamp>http-string "date" set-header
    dup visionect-authorization "authorization" set-header ;

: visionect-request ( request -- data )
    set-visionect-headers http-request nip ;
