Skip to content

Commit f1ffd84

Browse files
authored
chore: update json decode logic to match giphy api (#290)
1 parent 9e35409 commit f1ffd84

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

recipes/CatGifsHalogenHooks/src/Main.purs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ hookComponent = Hooks.component \_ _ -> Hooks.do
5252
httpResult = case errorOrResponse of
5353
Right jsonRec | jsonRec.status == StatusCode 200 ->
5454
case decodeJson jsonRec.body of
55-
Right rec -> RD.Success rec.data.image_url
55+
Right rec -> RD.Success rec.data.images.downsized.url
5656
_ -> RD.Failure "decode error"
5757
_ ->
5858
RD.Failure "http error"
@@ -91,9 +91,13 @@ hookComponent = Hooks.component \_ _ -> Hooks.do
9191
]
9292
]
9393

94-
decodeJson :: Json -> Either JsonDecodeError { data :: { image_url :: String }}
94+
decodeJson :: Json -> Either JsonDecodeError { data :: { images :: { downsized :: { url :: String } } } }
9595
decodeJson = decode $
9696
CA.object "data" $ CAR.record
97-
{ data: CA.object "image_url" $ CAR.record
98-
{ image_url: CA.string }
97+
{ data: CA.object "images" $ CAR.record
98+
{ images: CA.object "downsized" $ CAR.record
99+
{ downsized: CA.object "url" $ CAR.record
100+
{ url: CA.string }
101+
}
102+
}
99103
}

0 commit comments

Comments
 (0)