hipbot 0.2.1 → 0.3
raw patch · 8 files changed
+23/−9 lines, 8 filesdep +resource-poolPVP ok
version bump matches the API change (PVP)
Dependencies added: resource-pool
API changes (from Hackage documentation)
- HipBot.API: pgAPI :: MonadIO m => Connection -> HipBotAPI m
+ HipBot.API: pgAPI :: MonadIO m => Pool Connection -> HipBotAPI m
Files
- .travis.yml +0/−2
- hipbot.cabal +2/−1
- src/HipBot.hs +1/−0
- src/HipBot/API.hs +15/−6
- src/HipBot/Internal/HipBot.hs +1/−0
- src/HipBot/Internal/OAuth.hs +2/−0
- src/HipBot/Internal/Resources.hs +1/−0
- src/HipBot/Internal/Types.hs +1/−0
.travis.yml view
@@ -11,8 +11,6 @@ matrix: allow_failures:- # wreq fails to build on 7.10.1 https://github.com/bos/wreq/issues/61- - env: CABALVER=1.22 GHCVER=7.10.1 - env: CABALVER=head GHCVER=head # Note: the distinction between `before_install` and `install` is not important.
hipbot.cabal view
@@ -1,5 +1,5 @@ name: hipbot-version: 0.2.1+version: 0.3 license: BSD3 license-file: LICENSE author: Richard Wallace <rwallace@atlassian.com>@@ -54,6 +54,7 @@ , mtl >=2.0.1 && <2.3 , network-uri >=2.4 && <3 , postgresql-simple >=0.4 && <1+ , resource-pool >=0.2 && <1 , safe >=0.2 && <1 , stm >=2.3 && <3 , text >=0.11 && <1.3
src/HipBot.hs view
@@ -34,6 +34,7 @@ import Network.HTTP.Client import Network.HTTP.Types import qualified Network.Wreq as Wreq+import Prelude import Safe import HipBot.API
src/HipBot/API.hs view
@@ -17,10 +17,13 @@ import Control.Monad.IO.Class import qualified Data.ByteString.UTF8 as B import qualified Data.HashMap.Strict as HashMap+import Data.Int import Data.Monoid+import Data.Pool import Database.PostgreSQL.Simple import Database.PostgreSQL.Simple.FromField import Database.PostgreSQL.Simple.FromRow+import Prelude import Safe import HipBot.Internal.Types@@ -60,8 +63,8 @@ oid } -pgAPI :: MonadIO m => Connection -> HipBotAPI m-pgAPI conn = HipBotAPI+pgAPI :: MonadIO m => Pool Connection -> HipBotAPI m+pgAPI pool = HipBotAPI { apiInsertRegistration = \r t -> let stmt = "insert into hipbot (" <> pgFields <> ") values (?, ?, ?, ?, ?, ?, ?)"@@ -75,20 +78,26 @@ , t ^. expires ) in- liftIO . void . execute conn stmt $ row+ liftIO . void . executePool pool stmt $ row , apiDeleteRegistration = let stmt = "delete from hipbot where oauthId = ?"- in liftIO . void . execute conn stmt . Only+ in liftIO . void . executePool pool stmt . Only , apiLookupRegistration = let q = "select " <> pgFields <> " from hipbot where oauthId = ?"- in liftIO . fmap (fmap getRegRow . headMay) . query conn q . Only+ in liftIO . fmap (fmap getRegRow . headMay) . queryPool pool q . Only , apiUpdateAccessToken = \oid t -> let stmt = "update hipbot set accessToken = ?, accessTokenExpires = ? where oauthId = ?" ps = (t ^. accessToken, t ^. expires, oid) in- liftIO . void . execute conn stmt $ ps+ liftIO . void . executePool pool stmt $ ps }++executePool :: ToRow q => Pool Connection -> Query -> q -> IO Int64+executePool pool stmt = withResource pool . (\row conn -> execute conn stmt row)++queryPool :: (ToRow q, FromRow r) => Pool Connection -> Query -> q -> IO [r]+queryPool pool q = withResource pool . (\a conn -> query conn q a) pgFields :: Query pgFields = "oauthId, capabilitiesUrl, roomId, groupId, oauthSecret, accessToken, accessTokenExpires"
src/HipBot/Internal/HipBot.hs view
@@ -10,6 +10,7 @@ import qualified Network.HTTP.Client as HTTP import Network.HTTP.Client.TLS import qualified Network.Wreq as Wreq+import Prelude import HipBot.API import HipBot.Internal.Types
src/HipBot/Internal/OAuth.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -22,6 +23,7 @@ import Network.HTTP.Client (HttpException) import Network.HTTP.Types import qualified Network.Wreq as Wreq+import Prelude import HipBot.API import HipBot.Internal.HipBot
src/HipBot/Internal/Resources.hs view
@@ -19,6 +19,7 @@ import Network.HTTP.Types import Network.Wai (lazyRequestBody) import Network.Wai.Lens+import Prelude import qualified Web.JWT as JWT import Webcrank.Wai
src/HipBot/Internal/Types.hs view
@@ -28,6 +28,7 @@ import Network.HTTP.Types import Network.URI (URI) import qualified Network.URI as URI+import Prelude newtype AbsoluteURI = AbsoluteURI URI deriving (Eq, Typeable)