http-api-data 0.4.2 → 0.4.3
raw patch · 5 files changed
+100/−12 lines, 5 filesdep ~attoparsecdep ~attoparsec-iso8601dep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: attoparsec, attoparsec-iso8601, base, base-compat, bytestring, hashable, hspec, quickcheck-instances, semigroups, text, text-show, time-compat, transformers
API changes (from Hackage documentation)
- Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.FromHttpApiData Data.Time.Calendar.Compat.DayOfWeek
- Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.ToHttpApiData Data.Time.Calendar.Compat.DayOfWeek
+ Web.Internal.FormUrlEncoded: instance Web.Internal.FormUrlEncoded.FromFormKey Data.Time.Calendar.Month.Compat.Month
+ Web.Internal.FormUrlEncoded: instance Web.Internal.FormUrlEncoded.FromFormKey Data.Time.Calendar.Quarter.Compat.Quarter
+ Web.Internal.FormUrlEncoded: instance Web.Internal.FormUrlEncoded.FromFormKey Data.Time.Calendar.Quarter.Compat.QuarterOfYear
+ Web.Internal.FormUrlEncoded: instance Web.Internal.FormUrlEncoded.ToFormKey Data.Time.Calendar.Month.Compat.Month
+ Web.Internal.FormUrlEncoded: instance Web.Internal.FormUrlEncoded.ToFormKey Data.Time.Calendar.Quarter.Compat.Quarter
+ Web.Internal.FormUrlEncoded: instance Web.Internal.FormUrlEncoded.ToFormKey Data.Time.Calendar.Quarter.Compat.QuarterOfYear
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.FromHttpApiData Data.Time.Calendar.Month.Compat.Month
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.FromHttpApiData Data.Time.Calendar.Quarter.Compat.Quarter
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.FromHttpApiData Data.Time.Calendar.Quarter.Compat.QuarterOfYear
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.FromHttpApiData Data.Time.Calendar.Week.DayOfWeek
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.ToHttpApiData Data.Time.Calendar.Month.Compat.Month
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.ToHttpApiData Data.Time.Calendar.Quarter.Compat.Quarter
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.ToHttpApiData Data.Time.Calendar.Quarter.Compat.QuarterOfYear
+ Web.Internal.HttpApiData: instance Web.Internal.HttpApiData.ToHttpApiData Data.Time.Calendar.Week.DayOfWeek
Files
- CHANGELOG.md +6/−0
- http-api-data.cabal +14/−12
- src/Web/Internal/FormUrlEncoded.hs +8/−0
- src/Web/Internal/HttpApiData.hs +66/−0
- test/Web/Internal/HttpApiDataSpec.hs +6/−0
CHANGELOG.md view
@@ -1,3 +1,9 @@+0.4.3+-----++* Add `Quarter`, `QuarterOfYear` and `Month` instances+* Support `bytestring-0.11`+ 0.4.2 -----
http-api-data.cabal view
@@ -1,6 +1,6 @@ cabal-version: >= 1.10 name: http-api-data-version: 0.4.2+version: 0.4.3 synopsis: Converting to/from HTTP API data like URL pieces, headers and query parameters. category: Web@@ -31,7 +31,7 @@ GHC==8.4.4, GHC==8.6.5, GHC==8.8.4,- GHC==8.10.2+ GHC==8.10.3 flag use-text-show description: Use text-show library for efficient ToHttpApiData implementations.@@ -44,7 +44,7 @@ -- GHC bundled build-depends: base >= 4.7 && < 4.15- , bytestring >= 0.10.4.0 && < 0.11+ , bytestring >= 0.10.4.0 && < 0.12 , containers >= 0.5.5.1 && < 0.7 , text >= 1.2.3.0 && < 1.3 , transformers >= 0.3 && < 0.6@@ -56,15 +56,15 @@ -- other-dependencies build-depends: attoparsec >= 0.13.2.2 && < 0.14- , attoparsec-iso8601 >= 1.0.1.0 && < 1.1+ , attoparsec-iso8601 >= 1.0.2.0 && < 1.1 , base-compat >= 0.10.5 && < 0.12 , cookie >= 0.4.3 && < 0.5 , hashable >= 1.2.7.0 && < 1.4 , http-types >= 0.12.3 && < 0.13 , tagged >= 0.8.5 && < 0.9- , time-compat >= 1.9.2 && < 1.10- , unordered-containers >= 0.2.10.0 && < 0.3- , uuid-types >= 1.0.3 && <1.1+ , time-compat >= 1.9.5 && < 1.10+ , unordered-containers >= 0.2.10.0 && < 0.3+ , uuid-types >= 1.0.3 && < 1.1 if !impl(ghc >= 7.10) build-depends:@@ -104,16 +104,18 @@ , bytestring , cookie , http-api-data- , nats , text , time-compat , unordered-containers , uuid-types - build-depends: HUnit >= 1.6.0.0 && <1.7- , hspec >= 2.7.1 && <2.8- , QuickCheck >= 2.13.1 && <2.15- , quickcheck-instances >= 0.3.21 && <0.4+ if !impl(ghc >= 7.10)+ build-depends: nats++ build-depends: HUnit >= 1.6.0.0 && <1.7+ , hspec >= 2.7.1 && <2.8+ , QuickCheck >= 2.13.1 && <2.15+ , quickcheck-instances >= 0.3.25.2 && <0.4 source-repository head type: git
src/Web/Internal/FormUrlEncoded.hs view
@@ -52,6 +52,8 @@ import qualified Data.Text.Lazy as Lazy import Data.Time.Compat (Day, LocalTime, NominalDiffTime, UTCTime, ZonedTime)+import Data.Time.Calendar.Month.Compat (Month)+import Data.Time.Calendar.Quarter.Compat (Quarter, QuarterOfYear (..)) import Data.Void (Void) import Data.Word (Word16, Word32, Word64, Word8) import GHC.Exts (Constraint, IsList (..))@@ -113,6 +115,9 @@ instance ToFormKey ZonedTime where toFormKey = toQueryParam instance ToFormKey UTCTime where toFormKey = toQueryParam instance ToFormKey NominalDiffTime where toFormKey = toQueryParam+instance ToFormKey Quarter where toFormKey = toQueryParam+instance ToFormKey QuarterOfYear where toFormKey = toQueryParam+instance ToFormKey Month where toFormKey = toQueryParam instance ToFormKey String where toFormKey = toQueryParam instance ToFormKey Text where toFormKey = toQueryParam@@ -172,6 +177,9 @@ instance FromFormKey ZonedTime where parseFormKey = parseQueryParam instance FromFormKey UTCTime where parseFormKey = parseQueryParam instance FromFormKey NominalDiffTime where parseFormKey = parseQueryParam+instance FromFormKey Quarter where parseFormKey = parseQueryParam+instance FromFormKey QuarterOfYear where parseFormKey = parseQueryParam+instance FromFormKey Month where parseFormKey = parseQueryParam instance FromFormKey String where parseFormKey = parseQueryParam instance FromFormKey Text where parseFormKey = parseQueryParam
src/Web/Internal/HttpApiData.hs view
@@ -55,6 +55,9 @@ secondsToNominalDiffTime) import Data.Time.Format.Compat (defaultTimeLocale, iso8601DateFormat)+import Data.Time.Calendar.Month.Compat (Month)+import Data.Time.Calendar.Quarter.Compat (Quarter, QuarterOfYear (..),+ toYearQuarter) import Data.Typeable (Typeable) import qualified Data.UUID.Types as UUID import Data.Version (Version, parseVersion,@@ -516,7 +519,43 @@ toEncodedUrlPiece = unsafeToEncodedUrlPiece +-- | +-- >>> toUrlPiece Q4+-- "q4"+instance ToHttpApiData QuarterOfYear where+ toUrlPiece Q1 = "q1"+ toUrlPiece Q2 = "q2"+ toUrlPiece Q3 = "q3"+ toUrlPiece Q4 = "q4" +-- |+-- >>> import Data.Time.Calendar.Quarter.Compat (Quarter (..))+-- >>> MkQuarter 8040+-- 2010-Q1+--+-- >>> toUrlPiece $ MkQuarter 8040+-- "2010-q1"+--+instance ToHttpApiData Quarter where+ toUrlPiece q = case toYearQuarter q of+ (y, qoy) -> T.pack (show y ++ "-" ++ f qoy)+ where+ f Q1 = "q1"+ f Q2 = "q2"+ f Q3 = "q3"+ f Q4 = "q4"++-- |+-- >>> import Data.Time.Calendar.Month.Compat (Month (..))+-- >>> MkMonth 24482+-- 2040-03+--+-- >>> toUrlPiece $ MkMonth 24482+-- "2040-03"+--+instance ToHttpApiData Month where+ toUrlPiece = T.pack . formatTime defaultTimeLocale "%Y-%m"+ instance ToHttpApiData NominalDiffTime where toUrlPiece = toUrlPiece . nominalDiffTimeToSeconds toEncodedUrlPiece = unsafeToEncodedUrlPiece@@ -704,6 +743,9 @@ -- Right 2015-10-03 00:14:24 UTC instance FromHttpApiData UTCTime where parseUrlPiece = runAtto Atto.utcTime +-- |+-- >>> parseUrlPiece "Monday" :: Either Text DayOfWeek+-- Right Monday instance FromHttpApiData DayOfWeek where parseUrlPiece t = case Map.lookup (T.toLower t) m of Just dow -> Right dow@@ -714,6 +756,30 @@ instance FromHttpApiData NominalDiffTime where parseUrlPiece = fmap secondsToNominalDiffTime . parseUrlPiece++-- |+-- >>> parseUrlPiece "2021-01" :: Either Text Month+-- Right 2021-01+instance FromHttpApiData Month where parseUrlPiece = runAtto Atto.month++-- |+-- >>> parseUrlPiece "2021-q1" :: Either Text Quarter+-- Right 2021-Q1+instance FromHttpApiData Quarter where parseUrlPiece = runAtto Atto.quarter++-- |+-- >>> parseUrlPiece "q2" :: Either Text QuarterOfYear+-- Right Q2+--+-- >>> parseUrlPiece "Q3" :: Either Text QuarterOfYear+-- Right Q3+instance FromHttpApiData QuarterOfYear where+ parseUrlPiece t = case T.toLower t of+ "q1" -> return Q1+ "q2" -> return Q2+ "q3" -> return Q3+ "q4" -> return Q4+ _ -> Left "Invalid quarter of year" instance FromHttpApiData All where parseUrlPiece = coerce (parseUrlPiece :: Text -> Either Text Bool) instance FromHttpApiData Any where parseUrlPiece = coerce (parseUrlPiece :: Text -> Either Text Bool)
test/Web/Internal/HttpApiDataSpec.hs view
@@ -14,6 +14,8 @@ import qualified Data.Text.Encoding as TE import qualified Data.Text.Lazy as L import Data.Time.Compat+import Data.Time.Calendar.Month.Compat (Month)+import Data.Time.Calendar.Quarter.Compat (Quarter, QuarterOfYear (..)) import qualified Data.UUID.Types as UUID import Data.Version import Data.Word@@ -86,6 +88,10 @@ checkUrlPiece (Proxy :: Proxy ZonedTime) "ZonedTime" checkUrlPiece (Proxy :: Proxy UTCTime) "UTCTime" checkUrlPiece (Proxy :: Proxy NominalDiffTime) "NominalDiffTime"+ checkUrlPiece (Proxy :: Proxy DayOfWeek) "DayOfWeek"+ checkUrlPiece (Proxy :: Proxy Quarter) "Quarter"+ checkUrlPiece (Proxy :: Proxy QuarterOfYear) "QuarterOfYear"+ checkUrlPiece (Proxy :: Proxy Month) "Month" checkUrlPiece (Proxy :: Proxy DayOfWeek) "DayOfWeek" checkUrlPiece (Proxy :: Proxy Version) "Version" checkUrlPiece (Proxy :: Proxy UUID.UUID) "UUID"