-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pamplemousse
committed
Nov 25, 2024
1 parent
c4cbd2f
commit c31db48
Showing
8 changed files
with
60 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
module CatGifs.Commands exposing (..) | ||
|
||
import CatGifs.Models exposing (CatGif, CatGifsUrl) | ||
import CatGifs.Models exposing (CatGif, cat500) | ||
import Decoders exposing (decodeUrl) | ||
import Http exposing (expectJson) | ||
import Json.Decode as Decode | ||
import Json.Decode.Pipeline exposing (requiredAt) | ||
import Messages exposing (Msg) | ||
import RemoteData | ||
import Url exposing (Protocol(..), Url) | ||
|
||
|
||
fetchCatGif : CatGifsUrl -> Cmd Msg | ||
fetchCatGif : Url -> Cmd Msg | ||
fetchCatGif url = | ||
Http.get | ||
{ url = url | ||
, expect = expectJson (RemoteData.fromResult >> Messages.OnFetchCatGif) decodeCatGifUrl | ||
{ url = url |> Url.toString | ||
, expect = expectJson (RemoteData.fromResult >> Messages.OnFetchCatGif) decodeCatGif | ||
} | ||
|
||
|
||
decodeCatGifUrl : Decode.Decoder CatGif | ||
decodeCatGifUrl = | ||
decodeCatGif : Decode.Decoder CatGif | ||
decodeCatGif = | ||
Decode.succeed CatGif | ||
|> requiredAt [ "data", "images", "original", "url" ] Decode.string | ||
|> requiredAt [ "data", "images", "original", "url" ] (Decode.map (Maybe.withDefault cat500) decodeUrl) |
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,12 +1,18 @@ | ||
module CatGifs.Models exposing (..) | ||
module CatGifs.Models exposing (CatGif, cat500, catGifDefaultUrl) | ||
|
||
-- URL of the source providing GIF URLs. | ||
import Url exposing (Protocol(..), Url) | ||
|
||
|
||
type alias CatGifsUrl = | ||
String | ||
cat500 : Url | ||
cat500 = | ||
Url Https "http.cat" Nothing "images/500.jpg" Nothing Nothing | ||
|
||
|
||
catGifDefaultUrl : Url | ||
catGifDefaultUrl = | ||
Url Https "api.giphy.com" Nothing "v1/gifs/random" (Just "tag=cat") Nothing | ||
|
||
|
||
type alias CatGif = | ||
{ gifUrl : String -- URL of the GIF resource on the internet. | ||
{ gifUrl : Url -- URL of the GIF resource on the internet. | ||
} |
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
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