-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unused Elm package sporto/erl * Update elm version and package dependencies in elm-package.json * Mechanic changes to upgrade to Elm 0.18 - No more primes in variable names - Arguments flipped for `andThen` - Changes in core library functions, modules `Json.Decode` and `Task` - No more Html.App * For Elm 0.18 upgrade: Migrate from evancz/elm-http to elm-lang/http We also now use lukewestby/elm-http-builder to replace our own helper functions here. * Fix type vagueness of function withExpectJsonApi * Adopt new function names of etaque/elm-form * Adopt new function names of debois/elm-mdl v8 See https://github.com/debois/elm-mdl/blob/v8/MIGRATION.md * Type annotations in Config_*.elm * Reimplement routing (Elm 0.18, without sporto/hop) References: https://github.com/evancz/url-parser/blob/2.0.1/examples/Example.elm * Remove config parameter basePath Implementation currently won't support any non-empty basePath. May be added back again later if needed. * Requests need 'Content-Type: application/vnd.api+json' in JSON API The standard functions of elm-lang/http and lukewestby/elm-http-builder to add a JSON body automatically set 'Content-Type: application/json' in the header, which is not conforming to JSON API. http://jsonapi.org/format/#introduction * Show nicer and shorter notices in case of Http errors. The need for this change comes with elm-lang/http, as a naive `toString` approach may result in very long text here. Also don't save the httpError in the model. We don't need it. * Configure Travis CI to use Elm 0.18.0
- Loading branch information
1 parent
30869fb
commit 5d4790e
Showing
8 changed files
with
230 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
module Api.Util exposing (..) | ||
|
||
import Result.Extra | ||
import Task exposing (Task) | ||
import Json.Encode as Encode | ||
import Json.Decode as Decode | ||
import Http | ||
import HttpBuilder | ||
import JsonApi | ||
import JsonApi.Extra | ||
import JsonApi.Decode | ||
|
||
|
||
{-| Infix notation for Result.andThen. Makes andThen-chains look nicer. | ||
-} | ||
infixl 0 :> | ||
(:>) : Result x a -> (a -> Result x b) -> Result x b | ||
(:>) = | ||
Result.andThen | ||
flip Result.andThen | ||
|
||
|
||
{-| Insert accessToken into Http header | ||
{-| Convenience version of `Task.attempt` that performs Tasks that may fail. | ||
That's the same as in `elm-lang/core 4.x` (Elm 0.17) | ||
-} | ||
withAccessToken : String -> Http.Request -> Http.Request | ||
withAccessToken accessToken = | ||
JsonApi.Extra.withHeader "Authorization" ("Bearer " ++ accessToken) | ||
attempt : (e -> msg) -> (a -> msg) -> Task e a -> Cmd msg | ||
attempt errorTagger successTagger task = | ||
Task.attempt (Result.Extra.unpack errorTagger successTagger) task | ||
|
||
|
||
{-| Build a GET request | ||
{-| Insert accessToken into Http header | ||
-} | ||
requestGet : String -> Http.Request | ||
requestGet url = | ||
{ verb = "GET" | ||
, headers = [] | ||
, url = url | ||
, body = Http.empty | ||
} | ||
withAccessToken : String -> HttpBuilder.RequestBuilder a -> HttpBuilder.RequestBuilder a | ||
withAccessToken accessToken = | ||
HttpBuilder.withHeader "Authorization" ("Bearer " ++ accessToken) | ||
|
||
|
||
{-| Build a POST request | ||
{-| Insert a JSON value as the body of a RequestBuilder. | ||
This will set the `Content-Type: application/vnd.api+json` header, | ||
as required by JSON API standard. | ||
-} | ||
requestPost : String -> String -> Http.Request | ||
requestPost url body = | ||
{ verb = "POST" | ||
, headers = [] | ||
, url = url | ||
, body = Http.string body | ||
} | ||
withJsonApiBody : Encode.Value -> HttpBuilder.RequestBuilder a -> HttpBuilder.RequestBuilder a | ||
withJsonApiBody jsonValue = | ||
HttpBuilder.withBody <| | ||
Http.stringBody "application/vnd.api+json" (Encode.encode 0 jsonValue) | ||
|
||
|
||
{-| Send a Http request with default settings | ||
and decode the response from a JSON API document | ||
{-| Expect the response body to be a JsonApi Document. | ||
-} | ||
sendDefJsonApi : | ||
withExpectJsonApi : | ||
(JsonApi.Document -> Result String a) | ||
-> Http.Request | ||
-> Task Http.Error a | ||
sendDefJsonApi assembleResponse request = | ||
JsonApi.Extra.sendJsonApi assembleResponse Http.defaultSettings request | ||
|
||
-> HttpBuilder.RequestBuilder () | ||
-> HttpBuilder.RequestBuilder a | ||
withExpectJsonApi assembleResponse requestBuilder = | ||
requestBuilder | ||
|> HttpBuilder.withHeader "Accept" "application/vnd.api+json" | ||
|> HttpBuilder.withExpect | ||
(Http.expectJson | ||
(JsonApi.Decode.document | ||
|> Decode.andThen | ||
(\document -> | ||
case assembleResponse document of | ||
Ok successValue -> | ||
Decode.succeed successValue | ||
|
||
{-| Send a Http request with default settings | ||
and decode the response from JSON | ||
-} | ||
sendDefJson : | ||
Decode.Decoder a | ||
-> Http.Request | ||
-> Task Http.Error a | ||
sendDefJson decodeResponse request = | ||
request | ||
|> Http.send Http.defaultSettings | ||
|> Http.fromJson decodeResponse | ||
Err errorMessage -> | ||
Decode.fail errorMessage | ||
) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
module Config exposing (..) | ||
|
||
|
||
baseRoot : String | ||
baseRoot = | ||
"https://participateapp.github.io" | ||
|
||
|
||
basePath = | ||
"" | ||
|
||
|
||
facebookRedirectPath : String | ||
facebookRedirectPath = | ||
"facebook_redirect" | ||
|
||
|
||
facebookClientId : String | ||
facebookClientId = | ||
"1583083548592686" | ||
|
||
|
||
apiUrl : String | ||
apiUrl = | ||
"https://participate-api.herokuapp.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
module Config exposing (..) | ||
|
||
|
||
baseRoot : String | ||
baseRoot = | ||
-- "https://oliverbarnes.github.io" | ||
"http://localhost:3000" | ||
|
||
|
||
basePath = | ||
-- "/participate" | ||
"" | ||
|
||
|
||
facebookRedirectPath : String | ||
facebookRedirectPath = | ||
"facebook_redirect" | ||
|
||
|
||
facebookClientId : String | ||
facebookClientId = | ||
"1583083701926004" | ||
|
||
|
||
apiUrl : String | ||
apiUrl = | ||
-- "https://participate-api.herokuapp.com" | ||
"http://localhost:4000" |
Oops, something went wrong.