summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjle <>2019-11-24 05:46:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-11-24 05:46:00 (GMT)
commita86749bc557153bc5601cc6d2a45b5cfe7fd96c2 (patch)
treea89f13aceded46c9100cd06a90442bfca85d3be0
parenta096e2d70b92cf2a2a555b1ff439e24b41272a86 (diff)
version 0.2.4.20.2.4.2
-rw-r--r--CHANGELOG.md10
-rw-r--r--advent-of-code-api.cabal4
-rw-r--r--src/Advent/Types.hs15
3 files changed, 27 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5b07a24..b5a2523 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,16 @@
Changelog
=========
+Version 0.2.4.2
+---------------
+
+*November 23, 2019*
+
+<https://github.com/mstksg/advent-of-code-api/releases/tag/v0.2.4.2>
+
+* Added instances of `ToJSONKey Day`, `ToJSON Day`, `ToJSONKey Part`, `ToJSON
+ Part`.
+
Version 0.2.4.1
---------------
diff --git a/advent-of-code-api.cabal b/advent-of-code-api.cabal
index 3936bf5..eb89ba1 100644
--- a/advent-of-code-api.cabal
+++ b/advent-of-code-api.cabal
@@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
--- hash: 538919b3907c1f6fb7ea04cba6bb88a2137e0861598c39f023ab26534ae8d54f
+-- hash: 00822f3b5bf4103c7c82e15d4dcec35343d1e6a293478fcfdb339c4a7c2ffba1
name: advent-of-code-api
-version: 0.2.4.1
+version: 0.2.4.2
synopsis: Advent of Code REST API bindings and servant API
description: Haskell bindings for Advent of Code REST API and a servant API. Please use
responsibly! See README.md or "Advent" module for an introduction and
diff --git a/src/Advent/Types.hs b/src/Advent/Types.hs
index b6ec06b..4df22f7 100644
--- a/src/Advent/Types.hs
+++ b/src/Advent/Types.hs
@@ -259,16 +259,31 @@ instance FromJSON LeaderboardMember where
Nothing -> fail "bad stamp"
Just i -> pure . posixSecondsToUTCTime $ fromInteger i
+-- | @since 0.2.4.2
+instance ToJSONKey Day where
+ toJSONKey = toJSONKeyText $ T.pack . show . dayInt
instance FromJSONKey Day where
fromJSONKey = FromJSONKeyTextParser (parseJSON . String)
+-- | @since 0.2.4.2
+instance ToJSONKey Part where
+ toJSONKey = toJSONKeyText $ \case
+ Part1 -> "1"
+ Part2 -> "2"
instance FromJSONKey Part where
fromJSONKey = FromJSONKeyTextParser (parseJSON . String)
+-- | @since 0.2.4.2
+instance ToJSON Part where
+ toJSON = String . (\case Part1 -> "1"; Part2 -> "2")
instance FromJSON Part where
parseJSON = withText "Part" $ \case
"1" -> pure Part1
"2" -> pure Part2
_ -> fail "Bad part"
+
+-- | @since 0.2.4.2
+instance ToJSON Day where
+ toJSON = String . T.pack . show . dayInt
instance FromJSON Day where
parseJSON = withText "Day" $ \t ->
case readMaybe (T.unpack t) of