Library Apps.StorageClient
Require Import FunctionApp List String System.
Import ListNotations.
Open Scope string_scope.
Definition storageURI := "https://andersk.scripts.mit.edu/pwmgr/storage".
Section StorageClient.
Context {world0 world : Type}.
Context {input : Type}.
Context (httpPOST : string → list (string × string) → (abortable world0 httpResponse → input) → action world).
Context (storageId : string).
Definition storageGet id cb :=
httpPOST
(storageURI ++ "/get") [("id", id)]
(fun ra ⇒
match ra with
| started abort ⇒ cb (started abort)
| done r ⇒
match httpResponseStatus r with
| httpOk ⇒ cb (done (inl (httpResponseBody r)))
| _ ⇒ cb (done (inr r))
end
end).
Definition storageSet id old new cb :=
httpPOST
(storageURI ++ "/set") [("id", id); ("old", old); ("new", new)]
(fun ra ⇒
match ra with
| started abort ⇒ cb (started abort)
| done r ⇒
match httpResponseStatus r with
| httpOk ⇒ cb (done (inl None))
| httpPreconditionFailed ⇒ cb (done (inl (Some (httpResponseBody r))))
| _ ⇒ cb (done (inr r))
end
end).
Definition storagePoll id old cb :=
httpPOST
(storageURI ++ "/poll") [("id", id); ("old", old)]
(fun ra ⇒
match ra with
| started abort ⇒ cb (started abort)
| done r ⇒
match httpResponseStatus r with
| httpOk ⇒ cb (done (inl (httpResponseBody r)))
| _ ⇒ cb (done (inr r))
end
end).
End StorageClient.
Import ListNotations.
Open Scope string_scope.
Definition storageURI := "https://andersk.scripts.mit.edu/pwmgr/storage".
Section StorageClient.
Context {world0 world : Type}.
Context {input : Type}.
Context (httpPOST : string → list (string × string) → (abortable world0 httpResponse → input) → action world).
Context (storageId : string).
Definition storageGet id cb :=
httpPOST
(storageURI ++ "/get") [("id", id)]
(fun ra ⇒
match ra with
| started abort ⇒ cb (started abort)
| done r ⇒
match httpResponseStatus r with
| httpOk ⇒ cb (done (inl (httpResponseBody r)))
| _ ⇒ cb (done (inr r))
end
end).
Definition storageSet id old new cb :=
httpPOST
(storageURI ++ "/set") [("id", id); ("old", old); ("new", new)]
(fun ra ⇒
match ra with
| started abort ⇒ cb (started abort)
| done r ⇒
match httpResponseStatus r with
| httpOk ⇒ cb (done (inl None))
| httpPreconditionFailed ⇒ cb (done (inl (Some (httpResponseBody r))))
| _ ⇒ cb (done (inr r))
end
end).
Definition storagePoll id old cb :=
httpPOST
(storageURI ++ "/poll") [("id", id); ("old", old)]
(fun ra ⇒
match ra with
| started abort ⇒ cb (started abort)
| done r ⇒
match httpResponseStatus r with
| httpOk ⇒ cb (done (inl (httpResponseBody r)))
| _ ⇒ cb (done (inr r))
end
end).
End StorageClient.