packages feed

leanpub-wreq 1.1 → 1.1.0.1

raw patch · 3 files changed

+48/−16 lines, 3 filesdep +mwc-randomdep −lensdep −randodep ~aesondep ~bytestringdep ~textPVP ok

version bump matches the API change (PVP)

Dependencies added: mwc-random

Dependencies removed: lens, rando

Dependency ranges changed: aeson, bytestring, text, time

API changes (from Hackage documentation)

Files

changelog.md view
@@ -7,3 +7,13 @@   * Drop support for GHC 8.6   * Add support for GHC 8.8 and 8.10   * Tighten dependency bounds++1.1.0.1 - 2021 Mar 9++  * Change dependency from `rando` to `mwc-random`+    for generating random coupon codes++  * Relax dependency bounds++  * Remove `lens` dependency (although `wreq`+    incurs it transitively anyway)
leanpub-wreq.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.0  name: leanpub-wreq-version: 1.1+version: 1.1.0.1  synopsis: Use the Leanpub API via Wreq category: Web@@ -35,15 +35,14 @@         Leanpub.Wreq      build-depends:-        aeson ^>=1.5+        aeson ^>= 1.4 || ^>=1.5       , base ^>= 4.13 || ^>= 4.14-      , bytestring ^>= 0.11+      , bytestring ^>= 0.10 || ^>= 0.11       , exceptions ^>= 0.10-      , lens ^>= 5.0       , leanpub-concepts ^>= 1.0 || ^>= 1.1-      , rando ^>= 0.0-      , text ^>= 1.2.3-      , time ^>= 1.11+      , mwc-random ^>= 0.15+      , text ^>= 1.2.4+      , time ^>= 1.9 || ^>= 1.11       , transformers ^>=0.5       , unordered-containers ^>= 0.2.13       , wreq ^>= 0.5.3
library/Leanpub/Wreq.hs view
@@ -30,6 +30,9 @@ import Control.Monad hiding (fail, foldM) import Control.Monad.IO.Class import Control.Monad.Fail+import Data.Function ((&))+import Data.Functor.Const+import Data.Functor.Identity import qualified Data.List import Data.Maybe import Data.Monoid@@ -44,11 +47,8 @@ -- leanpub-concepts import Leanpub.Concepts --- lens-import Control.Lens ((&), (.~), (^.))---- rando-import System.Random.Pick (pickOne)+-- mwc-random+import System.Random.MWC (GenIO, createSystemRandom, uniformRM)  -- text import           Data.Text (Text)@@ -68,6 +68,22 @@ import           Network.Wreq.Session (Session, newAPISession) import qualified Network.Wreq.Session +------------------------------------------------------------++-- from the 'lens' library++type Getting r s a = (a -> Const r a) -> s -> Const r s++(^.) :: s -> Getting a s a -> a+s ^. l = getConst (l Const s)++type ASetter s t a b = (a -> Identity b) -> s -> Identity t++(.~) :: ASetter s t a b -> b -> s -> t+l .~ b = fmap runIdentity $ l (\_ -> Identity b)++------------------------------------------------------------+ text :: String -> Text text = Data.Text.pack @@ -290,10 +306,11 @@   do     requireKey     start <- liftIO getToday+    g <- liftIO createSystemRandom      (sequence_ . replicate (fromIntegral n))       do-        code <- liftIO randomCouponCode+        code <- liftIO (randomCouponCode g)         wreqPostAeson_             [slug, text "coupons"]             (freeBookParams start code uses noteMaybe)@@ -327,11 +344,17 @@ formatDay :: Day -> String formatDay = Data.Time.formatTime Data.Time.defaultTimeLocale "%Y-%m-%d" -randomCouponCode :: IO CouponCode-randomCouponCode =+randomCouponCode :: GenIO -> IO CouponCode+randomCouponCode g =   do     s <- sequence (Data.List.replicate 20 randomChar)     return (CouponCode (text s))   where-    randomChar = pickOne charset+    randomChar = pickOne g charset     charset = ['a'..'z'] ++ ['0'..'9']++pickOne :: GenIO -> [a] -> IO a+pickOne g xs =+  do+    i <- uniformRM (0, length xs - 1) g+    return (xs !! i)