git.iko.soy/typeable/pagerduty
on develop help sign in
Re-exporting needed types and constructors via a shallow module
68fe229Brendan Hay
src/Network/PagerDuty/Integration.hs+4
@@ -72,6 +72,9 @@ module Network.PagerDuty.Integration
72 , rsStatus
72 , rsStatus
73 , rsMessage
73 , rsMessage
74 , rsIncidentKey
74 , rsIncidentKey
75+
76+ -- * Re-exported types
77+ , module Network.PagerDuty.Types
75 ) where
78 ) where
76
79
77import Control.Lens
80import Control.Lens
@@ -85,6 +88,7 @@ import qualified Network.HTTP.Client as Client
85import Network.PagerDuty.Internal.IO
88import Network.PagerDuty.Internal.IO
86import Network.PagerDuty.Internal.TH
89import Network.PagerDuty.Internal.TH
87import Network.PagerDuty.Internal.Types
90import Network.PagerDuty.Internal.Types
91+import Network.PagerDuty.Types hiding (description, message)
88
92
89data Response = Response
93data Response = Response
90 { _rsStatus :: Text
94 { _rsStatus :: Text
src/Network/PagerDuty/Internal/Types.hs+19−9
@@ -52,8 +52,6 @@ import Network.PagerDuty.Internal.Query
52import Network.PagerDuty.Internal.TH
52import Network.PagerDuty.Internal.TH
53import System.Locale
53import System.Locale
54
54
55−-- FIXME: Verify IncidentId/IncidentKey .. *Id/*Key are actually different or needed
56−
57newtype CSV a = CSV [a]
55newtype CSV a = CSV [a]
58 deriving (Eq, Show, Monoid)
56 deriving (Eq, Show, Monoid)
59
57
@@ -142,7 +140,10 @@ deriving instance Eq (Auth a)
142deriving instance Show (Auth a)
140deriving instance Show (Auth a)
143
141
144newtype SubDomain = SubDomain { subDomain :: ByteString }
142newtype SubDomain = SubDomain { subDomain :: ByteString }
145− deriving (Eq, Show, IsString)
143+ deriving (Eq, Show, IsString, ToByteString)
144+
145+mkSubDomain :: ByteString -> SubDomain
146+mkSubDomain = SubDomain
146
147
147domain :: SubDomain -> ByteString
148domain :: SubDomain -> ByteString
148domain (SubDomain s)
149domain (SubDomain s)
@@ -179,7 +180,7 @@ prod :: SubDomain -> Auth s -> Manager -> Env s
179prod d a m = Env d a m None
180prod d a m = Env d a m None
180
181
181newtype Code = Code Integer
182newtype Code = Code Integer
182− deriving (Eq, Show)
183+ deriving (Eq, Show, Num)
183
184
184deriveJSON ''Code
185deriveJSON ''Code
185
186
@@ -385,13 +386,13 @@ class Paginate a where
385 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
386 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
386 next rq = maybe Nothing go
387 next rq = maybe Nothing go
387 where
388 where
388− go x | x^.pgTotal == 0 = Nothing
389+ go x | x ^. pgTotal == 0 = Nothing
389− | otherwise = Just $
390+ | otherwise = Just $
390− rq & pager ?~ (x & pgOffset +~ x^.pgTotal)
391+ rq & pager ?~ (x & pgOffset +~ x ^. pgTotal)
391 & query %~ (add . clear)
392 & query %~ (add . clear)
392 where
393 where
393 add :: Query -> Query
394 add :: Query -> Query
394− add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x^.pgQuery)
395+ add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x ^. pgQuery)
395
396
396 clear :: Query -> Query
397 clear :: Query -> Query
397 clear = deleteBy ((==) `on` fst) (k, Nothing)
398 clear = deleteBy ((==) `on` fst) (k, Nothing)
@@ -402,6 +403,9 @@ class Paginate a where
402newtype Key (a :: Symbol) = Key Text
403newtype Key (a :: Symbol) = Key Text
403 deriving (Eq, Show, IsString)
404 deriving (Eq, Show, IsString)
404
405
406+mkKey :: Text -> Key a
407+mkKey = Key
408+
405instance FromJSON (Key a) where
409instance FromJSON (Key a) where
406 parseJSON = withText "key" (return . Key)
410 parseJSON = withText "key" (return . Key)
407
411
@@ -422,6 +426,9 @@ type IncidentKey = Key "incident"
422newtype Id (a :: Symbol) = Id Text
426newtype Id (a :: Symbol) = Id Text
423 deriving (Eq, Show, IsString)
427 deriving (Eq, Show, IsString)
424
428
429+mkId :: Text -> Id a
430+mkId = Id
431+
425instance FromJSON (Id a) where
432instance FromJSON (Id a) where
426 parseJSON = withText "id" (return . Id)
433 parseJSON = withText "id" (return . Id)
427
434
@@ -469,7 +476,10 @@ instance QueryLike Empty where
469 toQuery = const []
476 toQuery = const []
470
477
471newtype Address = Address Text
478newtype Address = Address Text
472− deriving (Eq, Show)
479+ deriving (Eq, Show, IsString)
480+
481+mkAddress :: Text -> Address
482+mkAddress = Address
473
483
474deriveJSON ''Address
484deriveJSON ''Address
475makePrisms ''Address
485makePrisms ''Address
src/Network/PagerDuty/REST.hs+10−16
@@ -16,19 +16,12 @@ module Network.PagerDuty.REST
16
16
17 -- * Sending requests
17 -- * Sending requests
18 send
18 send
19− , paginate
20−
21− -- * Configuration
22− -- ** Environment
23− , Env
24− , envDomain
25− , envAuth
26− , envManager
27− , envLogger
28−
29− -- ** Requests
30 , sendWith
19 , sendWith
20+ , paginate
31 , paginateWith
21 , paginateWith
22+
23+ -- * Re-exported types
24+ , module Network.PagerDuty.Types
32 ) where
25 ) where
33
26
34import Control.Applicative
27import Control.Applicative
@@ -36,20 +29,22 @@ import Control.Lens
36import Control.Monad
29import Control.Monad
37import Control.Monad.IO.Class
30import Control.Monad.IO.Class
38import Control.Monad.Trans
31import Control.Monad.Trans
39−import Data.Aeson (FromJSON)
32+import Data.Aeson (FromJSON)
40import Data.Conduit
33import Data.Conduit
41import Data.Default.Class
34import Data.Default.Class
42import Data.Monoid
35import Data.Monoid
43−import Network.HTTP.Client (Manager)
36+import Network.HTTP.Client (Manager)
44−import qualified Network.HTTP.Client as Client
37+import qualified Network.HTTP.Client as Client
45import Network.HTTP.Types
38import Network.HTTP.Types
46import Network.PagerDuty.Internal.IO
39import Network.PagerDuty.Internal.IO
47import Network.PagerDuty.Internal.Types
40import Network.PagerDuty.Internal.Types
41+import Network.PagerDuty.Types
48
42
49-- FIXME: verify correct actions are all paginated
43-- FIXME: verify correct actions are all paginated
50-- FIXME: Ensure RequesterId parameter is always most significant param
44-- FIXME: Ensure RequesterId parameter is always most significant param
51-- FIXME: add smart constructors for all types, for testing purposes
45-- FIXME: add smart constructors for all types, for testing purposes
52
46
47+-- | /See:/ 'sendWith'
53send :: (MonadIO m, FromJSON b)
48send :: (MonadIO m, FromJSON b)
54 => SubDomain
49 => SubDomain
55 -> Auth s
50 -> Auth s
@@ -58,13 +53,13 @@ send :: (MonadIO m, FromJSON b)
58 -> m (Either Error b)
53 -> m (Either Error b)
59send d a m = sendWith (prod d a m)
54send d a m = sendWith (prod d a m)
60
55
61−-- | /See:/ 'sendWith'
62sendWith :: (MonadIO m, FromJSON b)
56sendWith :: (MonadIO m, FromJSON b)
63 => Env s
57 => Env s
64 -> Request a s b
58 -> Request a s b
65 -> m (Either Error b)
59 -> m (Either Error b)
66sendWith e = liftM (fmap fst) . http e
60sendWith e = liftM (fmap fst) . http e
67
61
62+-- | /See:/ 'paginateWith'
68paginate :: (MonadIO m, Paginate a, FromJSON b)
63paginate :: (MonadIO m, Paginate a, FromJSON b)
69 => SubDomain
64 => SubDomain
70 -> Auth s
65 -> Auth s
@@ -73,7 +68,6 @@ paginate :: (MonadIO m, Paginate a, FromJSON b)
73 -> Source m (Either Error b)
68 -> Source m (Either Error b)
74paginate d a m = paginateWith (prod d a m)
69paginate d a m = paginateWith (prod d a m)
75
70
76−-- | /See:/ 'paginateWith'
77paginateWith :: (MonadIO m, Paginate a, FromJSON b)
71paginateWith :: (MonadIO m, Paginate a, FromJSON b)
78 => Env s
72 => Env s
79 -> Request a s b
73 -> 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