Begin working on Http requests.

This commit is contained in:
2018-12-08 13:49:30 -08:00
parent c292a4c29b
commit 3656b0f3f0
7 changed files with 128 additions and 11 deletions

37
src/Scylla/Http.elm Normal file
View File

@@ -0,0 +1,37 @@
module Scylla.Http exposing (..)
import Scylla.Model exposing (..)
import Scylla.Api exposing (..)
import Scylla.Sync exposing (syncResponseDecoder)
import Scylla.Login exposing (loginResponseDecoder, Username, Password)
import Json.Encode exposing (object, string)
import Http exposing (request, jsonBody, expectJson)
-- Http Requests
firstSync : ApiUrl -> ApiToken -> Cmd Msg
firstSync apiUrl token = request
{ method = "GET"
, headers = authenticatedHeaders token
, url = apiUrl ++ "/sync"
, body = jsonBody <| object []
, expect = expectJson ReceiveSyncResponse syncResponseDecoder
, timeout = Nothing
, tracker = Nothing
}
login : ApiUrl -> Username -> Password -> Cmd Msg
login apiUrl username password = request
{ method = "POST"
, headers = basicHeaders
, url = apiUrl ++ "/login"
, body = jsonBody <| object
[ ("type", string "m.login.password")
, ("identifier", object
[ ("type", string "m.id.user")
, ("user", string username)
] )
, ("password", string password)
]
, expect = expectJson ReceiveLoginResponse loginResponseDecoder
, timeout = Nothing
, tracker = Nothing
}