Generalize fetch function by using a type var (#12)

I will need it to fetch an user account so it has to able to decode
something else than a `List Status`.
Using a type variable allows the calling function to provide the
decoder, and thus we can reuse `fetch` for something else.
This commit is contained in:
Vincent Jousse 2017-04-20 21:33:17 +02:00 committed by Nicolas Perriault
parent 347806877b
commit 8627bffbe0

View File

@ -374,11 +374,11 @@ toResponse result =
Result.mapError extractError result Result.mapError extractError result
fetchStatusList : Client -> String -> HttpBuilder.RequestBuilder (List Status) fetch : Client -> String -> Decode.Decoder a -> HttpBuilder.RequestBuilder a
fetchStatusList client endpoint = fetch client endpoint decoder =
HttpBuilder.get (client.server ++ endpoint) HttpBuilder.get (client.server ++ endpoint)
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token) |> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|> HttpBuilder.withExpect (Http.expectJson (Decode.list statusDecoder)) |> HttpBuilder.withExpect (Http.expectJson decoder)
@ -436,17 +436,17 @@ send tagger builder =
fetchUserTimeline : Client -> HttpBuilder.RequestBuilder (List Status) fetchUserTimeline : Client -> HttpBuilder.RequestBuilder (List Status)
fetchUserTimeline client = fetchUserTimeline client =
fetchStatusList client "/api/v1/timelines/home" fetch client "/api/v1/timelines/home" (Decode.list statusDecoder)
fetchLocalTimeline : Client -> HttpBuilder.RequestBuilder (List Status) fetchLocalTimeline : Client -> HttpBuilder.RequestBuilder (List Status)
fetchLocalTimeline client = fetchLocalTimeline client =
fetchStatusList client "/api/v1/timelines/public?local=true" fetch client "/api/v1/timelines/public?local=true" (Decode.list statusDecoder)
fetchPublicTimeline : Client -> HttpBuilder.RequestBuilder (List Status) fetchPublicTimeline : Client -> HttpBuilder.RequestBuilder (List Status)
fetchPublicTimeline client = fetchPublicTimeline client =
fetchStatusList client "/api/v1/timelines/public" fetch client "/api/v1/timelines/public" (Decode.list statusDecoder)
postStatus : Client -> StatusRequestBody -> HttpBuilder.RequestBuilder Status postStatus : Client -> StatusRequestBody -> HttpBuilder.RequestBuilder Status