(.using [library [lux (.full) [abstract [monad (.only do)]] [control ["[0]" io (.only IO)] ["[0]" try (.only Try)] ["[0]" exception (.only exception:)]] [data ["[0]" product] [text ["%" format (.only format)]]] ["[0]" meta "_" ["[1]/[0]" version]] [tool [compiler ["[0]" version]]] [world [net (.only URL) [uri (.only URI)] ["[0]" http "_" ["[1]" client] ["[1]/[0]" status] ["@[1]" /]]]]]] ["[0]" // ["[1][0]" identity (.only Identity)] ["/[1]" // "_" ["[1][0]" artifact (.only Version Artifact) [extension (.only Extension)]]]]) (type: .public Address URL) (template [] [(exception: .public ( [url URL status Nat]) (exception.report "URL" (%.text url) "Status Code" (%.nat status)))] [download_failure] [upload_failure] ) (def: .public (uri version_template artifact extension) (-> Version Artifact Extension URI) (format (///artifact.uri version_template artifact) extension)) (def: .public user_agent (format "LuxAedifex/" (version.format meta/version.latest))) (def: base_headers (List [Text Text]) (list ["User-Agent" ..user_agent])) (implementation: .public (repository http identity address) (All (_ s) (-> (http.Client IO) (Maybe Identity) Address (//.Repository IO))) (def: description address) (def: (download uri) (do [! (try.with io.monad)] [[status message] (is (IO (Try (@http.Response IO))) (http.get (format address uri) (http.headers ..base_headers) {.#None} http))] (case status (pattern (static http/status.ok)) (# ! each product.right ((the @http.#body message) {.#None})) _ (do ! [_ ((the @http.#body message) {.#Some 0})] (# io.monad in (exception.except ..download_failure [(format address uri) status])))))) (def: (upload uri content) (do (try.with io.monad) [[status message] (is (IO (Try (@http.Response IO))) (http.put (format address uri) (http.headers (case identity {.#None} ..base_headers {.#Some [user password]} (partial_list ["Authorization" (//identity.basic_auth user password)] ..base_headers))) {.#Some content} http)) _ ((the @http.#body message) {.#Some 0})] (case status (pattern (static http/status.created)) (in []) _ (# io.monad in (exception.except ..upload_failure [(format address uri) status]))))) )