! Copyright (C) 2020 John Benediktsson
-! See http://factorcode.org/license.txt for BSD license
+! See https://factorcode.org/license.txt for BSD license
USING: accessors assocs base64 calendar calendar.format
-checksums.hmac checksums.sha combinators combinators.smart
-formatting fry http http.client json.reader json.writer kernel
-locals make math.parser namespaces random sequences ;
+checksums.hmac checksums.sha combinators.smart formatting
+hex-strings http http.client json kernel make namespaces random
+sequences splitting ;
IN: visionect
SYMBOL: visionect-base-url
-visionect-base-url [ "http://localhost:8081" ] initialize
+visionect-base-url [ "https://localhost:8081" ] initialize
SYMBOL: visionect-api-key
[ "content-type" header ]
[ "date" header ]
[ url>> path>> ]
- } cleave>array "\n" join
+ } cleave>array join-lines
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 ;
+ now timestamp>http-string "Date" set-header
+ dup visionect-authorization "Authorization" set-header ;
: visionect-request ( request -- data )
set-visionect-headers http-request nip ;
: visionect-post ( post-data path -- data )
visionect-url <post-request>
- dup post-data>> content-type>> "content-type" set-header
+ dup post-data>> dup post-data?
+ [ content-type>> "Content-Type" set-header ] [ drop ] if
visionect-request ;
PRIVATE>
"multipart/form-data; boundary=\"" boundary "\"" 3append :> content-type
content-type <post-data>
[
- "--" % boundary % "\n" %
- "Content-Disposition: form-data; name=\"image\"; filename=\"image.png\"\n" %
- "Content-Type: image/png\n" %
- "\n" %
- png-data % "\n" %
- "--" % boundary % "--\n" %
+ "--" % boundary % "\r\n" %
+ "Content-Disposition: form-data; name=\"image\"; filename=\"image.png\"\r\n" %
+ "Content-Type: image/png\r\n" %
+ "\r\n" %
+ png-data % "\r\n" %
+ "--" % boundary % "--\r\n" %
] B{ } make >>data
"/backend/" uuid append visionect-post drop ;