packages feed

leanpub-wreq 1.1.0.1 → 1.1.0.2

raw patch · 3 files changed

+25/−17 lines, 3 filesdep ~mwc-randomdep ~unordered-containersPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: mwc-random, unordered-containers

API changes (from Hackage documentation)

+ Leanpub.Wreq: [contextRandom] :: Context -> GenIO
- Leanpub.Wreq: Context :: Session -> Maybe ApiSecretKey -> Context
+ Leanpub.Wreq: Context :: Session -> Maybe ApiSecretKey -> GenIO -> Context

Files

changelog.md view
@@ -17,3 +17,7 @@    * Remove `lens` dependency (although `wreq`     incurs it transitively anyway)++1.1.0.2 - 2021 Mar 10++  * Relax mwc-random lower bound to allow 0.14
leanpub-wreq.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.0  name: leanpub-wreq-version: 1.1.0.1+version: 1.1.0.2  synopsis: Use the Leanpub API via Wreq category: Web@@ -40,9 +40,9 @@       , bytestring ^>= 0.10 || ^>= 0.11       , exceptions ^>= 0.10       , leanpub-concepts ^>= 1.0 || ^>= 1.1-      , mwc-random ^>= 0.15+      , mwc-random ^>= 0.14 || ^>= 0.15       , text ^>= 1.2.4-      , time ^>= 1.9 || ^>= 1.11+      , time ^>= 1.9 || ^>= 1.10 || ^>= 1.11       , transformers ^>=0.5       , unordered-containers ^>= 0.2.13       , wreq ^>= 0.5.3
library/Leanpub/Wreq.hs view
@@ -1,6 +1,6 @@ {-# OPTIONS_GHC -Wall -fdefer-typed-holes #-} -{-# LANGUAGE BlockArguments, DerivingVia, LambdaCase, RecordWildCards #-}+{-# LANGUAGE BlockArguments, DerivingVia, LambdaCase, NamedFieldPuns #-}  module Leanpub.Wreq   (@@ -48,7 +48,7 @@ import Leanpub.Concepts  -- mwc-random-import System.Random.MWC (GenIO, createSystemRandom, uniformRM)+import System.Random.MWC (GenIO, createSystemRandom, uniformR)  -- text import           Data.Text (Text)@@ -96,6 +96,7 @@   Context     { contextSession :: Session     , contextKeyMaybe :: Maybe ApiSecretKey+    , contextRandom :: GenIO     }  {- | There are two ways to run a 'Leanpub' action:@@ -114,7 +115,7 @@  requireKey :: Leanpub () requireKey =-    Leanpub \Context{..} ->+    Leanpub \Context{ contextKeyMaybe } ->         when (isNothing contextKeyMaybe) (fail "API key is required.")  ------------------------------------------------------------@@ -124,7 +125,7 @@     createContext (config baseConfigData) >>= action  createContext :: ConfigData -> IO Context-createContext ConfigData{..} =+createContext ConfigData{ configData_session, configData_key } =   do     contextSession <-         case configData_session of@@ -137,8 +138,10 @@             KeyConfig_File x  -> fmap Just (readKeyFile x)             KeyConfig_Nothing -> return Nothing -    return Context{..}+    contextRandom <- createSystemRandom +    return Context{ contextSession, contextKeyMaybe, contextRandom }+ {- | Construct a 'Config' by using '<>' to combine any of the following:  * Either 'configKey' or 'configKeyFile' (not both)@@ -213,7 +216,7 @@  wreqGet :: Path -> Extension -> [QueryParam] -> Leanpub WreqResponse wreqGet path extension params =-    Leanpub \Context{..} ->+    Leanpub \Context{ contextKeyMaybe, contextSession } ->       let           url = makeUrl path extension @@ -229,7 +232,7 @@  wreqPost :: Path -> Extension -> [FormParam] -> Leanpub WreqResponse wreqPost path extension params =-    Leanpub \Context{..} ->+    Leanpub \Context{ contextKeyMaybe, contextSession } ->         let             url = makeUrl path extension @@ -306,11 +309,9 @@   do     requireKey     start <- liftIO getToday-    g <- liftIO createSystemRandom-     (sequence_ . replicate (fromIntegral n))       do-        code <- liftIO (randomCouponCode g)+        code <- randomCouponCode         wreqPostAeson_             [slug, text "coupons"]             (freeBookParams start code uses noteMaybe)@@ -344,17 +345,20 @@ formatDay :: Day -> String formatDay = Data.Time.formatTime Data.Time.defaultTimeLocale "%Y-%m-%d" -randomCouponCode :: GenIO -> IO CouponCode-randomCouponCode g =+randomCouponCode :: Leanpub CouponCode+randomCouponCode =   do     s <- sequence (Data.List.replicate 20 randomChar)     return (CouponCode (text s))++randomChar :: Leanpub Char+randomChar = Leanpub \Context{ contextRandom } ->+    pickOne contextRandom charset   where-    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+    i <- uniformR (0, length xs - 1) g     return (xs !! i)