Upgrade library to Elm 0.19

This commit is contained in:
Correl Roush 2018-09-21 15:00:48 -04:00
parent 4a8cc6266b
commit 6ac7101d96
4 changed files with 52 additions and 53 deletions

View file

@ -1,18 +0,0 @@
{
"version": "3.0.1",
"summary": "A library for fetching data from paginated JSON REST APIs.",
"repository": "https://github.com/correl/elm-paginated.git",
"license": "MIT",
"source-directories": [
"src"
],
"exposed-modules": [
"Paginated"
],
"dependencies": {
"elm-community/maybe-extra": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}

20
elm.json Normal file
View file

@ -0,0 +1,20 @@
{
"type": "package",
"name": "correl/elm-paginated",
"summary": "A library for fetching data from paginated JSON REST APIs.",
"license": "MIT",
"version": "3.0.1",
"exposed-modules": [
"Paginated"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0",
"elm/http": "1.0.0 <= v < 2.0.0",
"elm/json": "1.0.0 <= v < 2.0.0",
"elm/regex": "1.0.0 <= v < 2.0.0",
"elm/time": "1.0.0 <= v < 2.0.0",
"elm-community/maybe-extra": "5.0.0 <= v < 6.0.0"
},
"test-dependencies": {}
}

View file

@ -1,13 +1,9 @@
module Paginated module Paginated exposing
exposing ( Request, get, post
( Request , RequestOptions, request
, RequestOptions , send
, request , toTask
, get )
, post
, send
, toTask
)
{-| A library for Facilitates fetching data from a paginated JSON API. {-| A library for Facilitates fetching data from a paginated JSON API.
@ -39,7 +35,6 @@ import Http
import Json.Decode exposing (Decoder) import Json.Decode exposing (Decoder)
import Paginated.Util import Paginated.Util
import Task exposing (Task) import Task exposing (Task)
import Time
{-| Describes an API request. {-| Describes an API request.
@ -50,7 +45,7 @@ type alias RequestOptions a =
, url : String , url : String
, body : Http.Body , body : Http.Body
, decoder : Decoder a , decoder : Decoder a
, timeout : Maybe Time.Time , timeout : Maybe Float
, withCredentials : Bool , withCredentials : Bool
} }
@ -78,7 +73,7 @@ headers and other options. For example:
Paginated.request Paginated.request
{ method = "GET" { method = "GET"
, headers = [Http.header "Private-Token" "XXXXXXXXXXXXXXXX"] , headers = [ Http.header "Private-Token" "XXXXXXXXXXXXXXXX" ]
, url = url , url = url
, body = Http.emptyBody , body = Http.emptyBody
, decoder = decoder , decoder = decoder
@ -128,8 +123,8 @@ send :
(Result Http.Error (List a) -> msg) (Result Http.Error (List a) -> msg)
-> Request a -> Request a
-> Cmd msg -> Cmd msg
send resultToMessage request = send resultToMessage request_ =
toTask request toTask request_
|> Task.attempt resultToMessage |> Task.attempt resultToMessage
@ -154,8 +149,8 @@ recurse =
Task.andThen Task.andThen
(\response -> (\response ->
case response of case response of
Partial request _ -> Partial request_ _ ->
httpRequest request httpRequest request_
|> Http.toTask |> Http.toTask
|> Task.map (update response) |> Task.map (update response)
|> recurse |> recurse
@ -176,8 +171,8 @@ update old new =
( Partial _ oldItems, Complete newItems ) -> ( Partial _ oldItems, Complete newItems ) ->
Complete (oldItems ++ newItems) Complete (oldItems ++ newItems)
( Partial _ oldItems, Partial request newItems ) -> ( Partial _ oldItems, Partial request_ newItems ) ->
Partial request (oldItems ++ newItems) Partial request_ (oldItems ++ newItems)
{-| Convert a `Request` to a `Http.Request` that can then be sent via {-| Convert a `Request` to a `Http.Request` that can then be sent via
@ -212,6 +207,7 @@ fromResponse options response =
Json.Decode.decodeString Json.Decode.decodeString
(Json.Decode.list options.decoder) (Json.Decode.list options.decoder)
response.body response.body
|> Result.mapError Json.Decode.errorToString
nextPage : Maybe String nextPage : Maybe String
nextPage = nextPage =
@ -219,20 +215,20 @@ fromResponse options response =
|> 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 nextPage of
Nothing -> Nothing ->
Result.map Complete items Result.map Complete items
Just url -> Just url ->
Result.map Result.map
(Partial (request { options | url = url })) (Partial (request { options | url = url }))
items items
{-| Look up a header (case-insensitive) {-| Look up a header (case-insensitive)
-} -}
header : String -> Dict String String -> Maybe String header : String -> Dict String String -> Maybe String
header header headers = header name headers =
let let
normalized = normalized =
Dict.toList headers Dict.toList headers
@ -240,6 +236,6 @@ header header headers =
|> Dict.fromList |> Dict.fromList
key = key =
String.map Char.toLower header String.map Char.toLower name
in in
Dict.get key normalized Dict.get key normalized

View file

@ -25,13 +25,14 @@ links s =
_ -> _ ->
Nothing Nothing
in in
Regex.find Regex.All linkPattern s Regex.find linkPattern s
|> List.map .submatches |> List.map .submatches
|> List.map toTuples |> List.map toTuples
|> Maybe.Extra.values |> Maybe.Extra.values
|> Dict.fromList |> Dict.fromList
linkPattern : Regex.Regex linkPattern : Regex.Regex
linkPattern = linkPattern =
Regex.regex "<(.*?)>; rel=\"(.*?)\"" Regex.fromString "<(.*?)>; rel=\"(.*?)\""
|> Maybe.withDefault Regex.never