Commit cf27cc77 authored by Stefan Siegl's avatar Stefan Siegl

add timestamp to request url

parent f1c70faa
......@@ -4,6 +4,7 @@ import Html exposing (..)
import Http
import Json.Decode as Decode
import Task
import Time
main : Program Never Model Msg
......@@ -30,19 +31,33 @@ init =
( Model Nothing, doRequest )
-- REQUESTS
doRequest : Cmd Msg
doRequest =
Task.map2 buildTheUrl fetchToken Time.now
|> Task.andThen secondRequest
|> Task.attempt HandleResult
fetchToken : Task.Task Http.Error String
fetchToken =
Decode.field "token" Decode.string
|> Http.get "first.json"
|> Http.toTask
|> Task.andThen secondRequest
|> Task.attempt HandleResult
buildTheUrl : String -> Time.Time -> String
buildTheUrl token time =
token ++ ".json?timestamp=" ++ (toString time)
secondRequest : String -> Task.Task Http.Error String
secondRequest token =
secondRequest url =
Decode.field "message" Decode.string
|> Http.get (token ++ ".json")
|> Http.get url
|> Http.toTask
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment