git.iko.soy/typeable/pagerduty
on develop help sign in
Re-exporting needed types and constructors via a shallow module
commit68fe229038409c73d7b48f0c2c491b131b593ef0 authorBrendan Hay <brendan.g.hay@gmail.com> dateWed 28 Jan 2015, 10:30 (12 years ago) parent57fb16c
4 files changed+126−25
src/Network/PagerDuty/Integration.hs+4 src/Network/PagerDuty/Internal/Types.hs+19−9 src/Network/PagerDuty/REST.hs+10−16 src/Network/PagerDuty/Types.hs+93
src/Network/PagerDuty/Integration.hs+4
@@ -72,6 +72,9 @@ module Network.PagerDuty.Integration
7272 , rsStatus
7373 , rsMessage
7474 , rsIncidentKey
75+
76+ -- * Re-exported types
77+ , module Network.PagerDuty.Types
7578 ) where
7679
7780import Control.Lens
@@ -85,6 +88,7 @@ import qualified Network.HTTP.Client as Client
8588import Network.PagerDuty.Internal.IO
8689import Network.PagerDuty.Internal.TH
8790import Network.PagerDuty.Internal.Types
91+import Network.PagerDuty.Types hiding (description, message)
8892
8993data Response = Response
9094 { _rsStatus :: Text
src/Network/PagerDuty/Internal/Types.hs+19−9
@@ -52,8 +52,6 @@ import Network.PagerDuty.Internal.Query
5252import Network.PagerDuty.Internal.TH
5353import System.Locale
5454
55−-- FIXME: Verify IncidentId/IncidentKey .. *Id/*Key are actually different or needed
56−
5755newtype CSV a = CSV [a]
5856 deriving (Eq, Show, Monoid)
5957
@@ -142,7 +140,10 @@ deriving instance Eq (Auth a)
142140deriving instance Show (Auth a)
143141
144142newtype SubDomain = SubDomain { subDomain :: ByteString }
145− deriving (Eq, Show, IsString)
143+ deriving (Eq, Show, IsString, ToByteString)
144+
145+mkSubDomain :: ByteString -> SubDomain
146+mkSubDomain = SubDomain
146147
147148domain :: SubDomain -> ByteString
148149domain (SubDomain s)
@@ -179,7 +180,7 @@ prod :: SubDomain -> Auth s -> Manager -> Env s
179180prod d a m = Env d a m None
180181
181182newtype Code = Code Integer
182− deriving (Eq, Show)
183+ deriving (Eq, Show, Num)
183184
184185deriveJSON ''Code
185186
@@ -385,13 +386,13 @@ class Paginate a where
385386 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
386387 next rq = maybe Nothing go
387388 where
388− go x | x^.pgTotal == 0 = Nothing
389− | otherwise = Just $
390− rq & pager ?~ (x & pgOffset +~ x^.pgTotal)
389+ go x | x ^. pgTotal == 0 = Nothing
390+ | otherwise = Just $
391+ rq & pager ?~ (x & pgOffset +~ x ^. pgTotal)
391392 & query %~ (add . clear)
392393 where
393394 add :: Query -> Query
394− add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x^.pgQuery)
395+ add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x ^. pgQuery)
395396
396397 clear :: Query -> Query
397398 clear = deleteBy ((==) `on` fst) (k, Nothing)
@@ -402,6 +403,9 @@ class Paginate a where
402403newtype Key (a :: Symbol) = Key Text
403404 deriving (Eq, Show, IsString)
404405
406+mkKey :: Text -> Key a
407+mkKey = Key
408+
405409instance FromJSON (Key a) where
406410 parseJSON = withText "key" (return . Key)
407411
@@ -422,6 +426,9 @@ type IncidentKey = Key "incident"
422426newtype Id (a :: Symbol) = Id Text
423427 deriving (Eq, Show, IsString)
424428
429+mkId :: Text -> Id a
430+mkId = Id
431+
425432instance FromJSON (Id a) where
426433 parseJSON = withText "id" (return . Id)
427434
@@ -469,7 +476,10 @@ instance QueryLike Empty where
469476 toQuery = const []
470477
471478newtype Address = Address Text
472− deriving (Eq, Show)
479+ deriving (Eq, Show, IsString)
480+
481+mkAddress :: Text -> Address
482+mkAddress = Address
473483
474484deriveJSON ''Address
475485makePrisms ''Address
src/Network/PagerDuty/REST.hs+10−16
@@ -16,19 +16,12 @@ module Network.PagerDuty.REST
1616
1717 -- * Sending requests
1818 send
19− , paginate
20−
21− -- * Configuration
22− -- ** Environment
23− , Env
24− , envDomain
25− , envAuth
26− , envManager
27− , envLogger
28−
29− -- ** Requests
3019 , sendWith
20+ , paginate
3121 , paginateWith
22+
23+ -- * Re-exported types
24+ , module Network.PagerDuty.Types
3225 ) where
3326
3427import Control.Applicative
@@ -36,20 +29,22 @@ import Control.Lens
3629import Control.Monad
3730import Control.Monad.IO.Class
3831import Control.Monad.Trans
39−import Data.Aeson (FromJSON)
32+import Data.Aeson (FromJSON)
4033import Data.Conduit
4134import Data.Default.Class
4235import Data.Monoid
43−import Network.HTTP.Client (Manager)
44−import qualified Network.HTTP.Client as Client
36+import Network.HTTP.Client (Manager)
37+import qualified Network.HTTP.Client as Client
4538import Network.HTTP.Types
4639import Network.PagerDuty.Internal.IO
4740import Network.PagerDuty.Internal.Types
41+import Network.PagerDuty.Types
4842
4943-- FIXME: verify correct actions are all paginated
5044-- FIXME: Ensure RequesterId parameter is always most significant param
5145-- FIXME: add smart constructors for all types, for testing purposes
5246
47+-- | /See:/ 'sendWith'
5348send :: (MonadIO m, FromJSON b)
5449 => SubDomain
5550 -> Auth s
@@ -58,13 +53,13 @@ send :: (MonadIO m, FromJSON b)
5853 -> m (Either Error b)
5954send d a m = sendWith (prod d a m)
6055
61−-- | /See:/ 'sendWith'
6256sendWith :: (MonadIO m, FromJSON b)
6357 => Env s
6458 -> Request a s b
6559 -> m (Either Error b)
6660sendWith e = liftM (fmap fst) . http e
6761
62+-- | /See:/ 'paginateWith'
6863paginate :: (MonadIO m, Paginate a, FromJSON b)
6964 => SubDomain
7065 -> Auth s
@@ -73,7 +68,6 @@ paginate :: (MonadIO m, Paginate a, FromJSON b)
7368 -> Source m (Either Error b)
7469paginate d a m = paginateWith (prod d a m)
7570
76−-- | /See:/ 'paginateWith'
7771paginateWith :: (MonadIO m, Paginate a, FromJSON b)
7872 => Env s
7973 -> Request a s b
src/Network/PagerDuty/Types.hsnew file+93
@@ -0,0 +1,93 @@
1+-- Module : Network.PagerDuty.Types
2+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
3+-- License : This Source Code Form is subject to the terms of
4+-- the Mozilla Public License, v. 2.0.
5+-- A copy of the MPL can be found in the LICENSE file or
6+-- you can obtain it at http://mozilla.org/MPL/2.0/.
7+-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
8+-- Stability : experimental
9+-- Portability : non-portable (GHC extensions)
10+
11+module Network.PagerDuty.Types
12+ (
13+ -- * Configuration
14+ -- ** Environment
15+ Env
16+ , envDomain
17+ , envAuth
18+ , envManager
19+ , envLogger
20+
21+ -- ** Logging
22+ , Logger (..)
23+ , debug
24+
25+ -- * Types
26+ -- ** Requests
27+ , Paginate
28+ , Request
29+
30+ -- ** Errors
31+ , Error
32+ , _Internal
33+ , _Integration
34+ , _REST
35+ -- *** Messages
36+ , HasMessage (..)
37+ -- *** Fields
38+ , HasErrors (..)
39+ -- *** Integration
40+ , IntegrationError
41+ , status
42+ -- *** REST
43+ , RESTError
44+ , Code
45+ , code
46+ , description
47+
48+ -- ** Authentication
49+ , Security (..)
50+ , Auth (..)
51+
52+ -- ** Keys
53+ , Key
54+ , mkKey
55+ -- *** Aliases
56+ , ServiceKey
57+ , IncidentKey
58+
59+ -- ** Identifiers
60+ , Id
61+ , mkId
62+ -- *** Aliases
63+ , AlertId
64+ , ContactId
65+ , EmailFilterId
66+ , EscalationPolicyId
67+ , EscalationRuleId
68+ , IncidentId
69+ , LogEntryId
70+ , NoteId
71+ , NotificationRuleId
72+ , OverrideId
73+ , RequesterId
74+ , ScheduleId
75+ , ServiceId
76+ , UserId
77+ , VendorId
78+ , WebhookId
79+ , WindowId
80+
81+ -- ** SubDomain
82+ , SubDomain
83+ , mkSubDomain
84+
85+ -- ** Address
86+ , Address
87+ , mkAddress
88+
89+ -- ** Miscellaneous
90+ , Empty (..)
91+ ) where
92+
93+import Network.PagerDuty.Internal.Types