mirror of
https://github.com/correl/elm-paginated.git
synced 2024-11-23 19:19:52 +00:00
Ignore case when getting Link header
This commit is contained in:
parent
e8478da3da
commit
5c4e7802d7
1 changed files with 25 additions and 2 deletions
|
@ -13,6 +13,7 @@ module Paginated
|
||||||
|
|
||||||
{-| A library for Facilitates fetching data from a paginated JSON API.
|
{-| A library for Facilitates fetching data from a paginated JSON API.
|
||||||
|
|
||||||
|
|
||||||
# Requests and Responses
|
# Requests and Responses
|
||||||
|
|
||||||
@docs Request, Response, get, post
|
@docs Request, Response, get, post
|
||||||
|
@ -39,6 +40,7 @@ module Paginated
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
import Char
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
import Http
|
import Http
|
||||||
import Json.Decode exposing (Decoder)
|
import Json.Decode exposing (Decoder)
|
||||||
|
@ -186,12 +188,18 @@ fromResponse options response =
|
||||||
(Json.Decode.list options.decoder)
|
(Json.Decode.list options.decoder)
|
||||||
response.body
|
response.body
|
||||||
|
|
||||||
|
normalize : Dict String String -> Dict String String
|
||||||
|
normalize =
|
||||||
|
Dict.toList
|
||||||
|
>> Dict.fromList
|
||||||
|
|
||||||
|
nextPage : Maybe String
|
||||||
nextPage =
|
nextPage =
|
||||||
Dict.get "Link" response.headers
|
header "Link" response.headers
|
||||||
|> Maybe.map Paginated.Util.links
|
|> Maybe.map Paginated.Util.links
|
||||||
|> Maybe.andThen (Dict.get "next")
|
|> Maybe.andThen (Dict.get "next")
|
||||||
in
|
in
|
||||||
case nextPage of
|
case Debug.log "nextPage" nextPage of
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Result.map Complete items
|
Result.map Complete items
|
||||||
|
|
||||||
|
@ -200,3 +208,18 @@ fromResponse options response =
|
||||||
(Partial (request { options | url = url }))
|
(Partial (request { options | url = url }))
|
||||||
items
|
items
|
||||||
|
|
||||||
|
|
||||||
|
{-| Look up a header (case-insensitive)
|
||||||
|
-}
|
||||||
|
header : String -> Dict String String -> Maybe String
|
||||||
|
header header headers =
|
||||||
|
let
|
||||||
|
normalized =
|
||||||
|
Dict.toList headers
|
||||||
|
|> List.map (\( k, v ) -> ( String.map Char.toLower k, v ))
|
||||||
|
|> Dict.fromList
|
||||||
|
|
||||||
|
key =
|
||||||
|
String.map Char.toLower header
|
||||||
|
in
|
||||||
|
Dict.get key normalized
|
||||||
|
|
Loading…
Reference in a new issue