aboutsummaryrefslogtreecommitdiff
path: root/src/client/ServerCommunication.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-07-19 00:45:42 +0200
committerJoris Guyonvarch2015-07-19 00:45:42 +0200
commita6727f104f808e533052f2bd83bc89cd6bfa0522 (patch)
tree2c7b8b16d377c04e9e9a32b74102666f6dae16cf /src/client/ServerCommunication.elm
parent3486644b442a0800f645ec9ae7f3ce8fe2b3c9cd (diff)
downloadbudget-a6727f104f808e533052f2bd83bc89cd6bfa0522.tar.gz
budget-a6727f104f808e533052f2bd83bc89cd6bfa0522.tar.bz2
budget-a6727f104f808e533052f2bd83bc89cd6bfa0522.zip
Adding UI to sign in and sign out
Diffstat (limited to 'src/client/ServerCommunication.elm')
-rw-r--r--src/client/ServerCommunication.elm63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm
new file mode 100644
index 0000000..e29b084
--- /dev/null
+++ b/src/client/ServerCommunication.elm
@@ -0,0 +1,63 @@
+module ServerCommunication
+ ( Communication(..)
+ , sendRequest
+ , serverCommunications
+ ) where
+
+import Signal
+import Task
+import Task exposing (Task)
+import Http
+
+import Update as U
+
+type Communication =
+ NoCommunication
+ | SignIn String
+ | SignOut
+
+serverCommunications : Signal.Mailbox Communication
+serverCommunications = Signal.mailbox NoCommunication
+
+sendRequest : Communication -> Task Http.RawError U.Action
+sendRequest communication =
+ case getRequest communication of
+ Nothing ->
+ Task.succeed U.NoOp
+ Just request ->
+ Http.send Http.defaultSettings request
+ |> Task.map (communicationToAction communication)
+
+getRequest : Communication -> Maybe Http.Request
+getRequest communication =
+ case communication of
+ NoCommunication ->
+ Nothing
+ SignIn login ->
+ Just
+ { verb = "post"
+ , headers = []
+ , url = "/signIn?login=" ++ login
+ , body = Http.empty
+ }
+ SignOut ->
+ Just
+ { verb = "post"
+ , headers = []
+ , url = "/signOut"
+ , body = Http.empty
+ }
+
+communicationToAction : Communication -> Http.Response -> U.Action
+communicationToAction communication response =
+ if response.status == 200
+ then
+ case communication of
+ NoCommunication ->
+ U.NoOp
+ SignIn _ ->
+ U.NoOp
+ SignOut ->
+ U.SignIn
+ else
+ U.NoOp