mirror of
https://github.com/correl/elm-paginated.git
synced 2024-11-23 11:09:51 +00:00
Upgrade library to Elm 0.19
This commit is contained in:
parent
4a8cc6266b
commit
6ac7101d96
4 changed files with 52 additions and 53 deletions
|
@ -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
20
elm.json
Normal 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": {}
|
||||||
|
}
|
|
@ -1,10 +1,6 @@
|
||||||
module Paginated
|
module Paginated exposing
|
||||||
exposing
|
( Request, get, post
|
||||||
( Request
|
, RequestOptions, request
|
||||||
, RequestOptions
|
|
||||||
, request
|
|
||||||
, get
|
|
||||||
, post
|
|
||||||
, send
|
, send
|
||||||
, toTask
|
, toTask
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 =
|
||||||
|
@ -232,7 +228,7 @@ fromResponse options response =
|
||||||
{-| 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
|
||||||
|
|
|
@ -25,7 +25,7 @@ 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
|
||||||
|
@ -34,4 +34,5 @@ links s =
|
||||||
|
|
||||||
linkPattern : Regex.Regex
|
linkPattern : Regex.Regex
|
||||||
linkPattern =
|
linkPattern =
|
||||||
Regex.regex "<(.*?)>; rel=\"(.*?)\""
|
Regex.fromString "<(.*?)>; rel=\"(.*?)\""
|
||||||
|
|> Maybe.withDefault Regex.never
|
||||||
|
|
Loading…
Reference in a new issue