git.iko.soy/typeable/pagerduty
on 4103feb help sign in
.gitignore−1
since splitsnapshots
unifiedsplit
@@ -9,7 +9,6 @@
9cabal.sandbox.config
9cabal.sandbox.config
10
10
11# Dirs
11# Dirs
12−.stack-work
13cabal-dev
12cabal-dev
14bin
13bin
15dist
14dist
.travis.ymldeleted−30
@@ -1,30 +0,0 @@
1−sudo: false
2−
3−cache:
4− apt: true
5− directories:
6− - ~/.stack
7−
8−branches:
9− only:
10− - master
11− - develop
12−
13−before_install:
14− - export PATH=/opt/ghc/$GHCVER/bin:$PATH
15− - export PATH=~/.local/bin:$PATH
16− - ./script/travis-lifecycle-before_install
17−
18−install:
19− - ./script/travis-lifecycle-install
20−
21−script:
22− - ./script/travis-lifecycle-script
23−
24−matrix:
25− fast_finish: true
26− include:
27− - env: GHCVER=8.0.1
28− addons: { apt: { packages: [ghc-8.0.1], sources: [hvr-ghc] } }
29− - env: GHCVER=7.10.3
30− addons: { apt: { packages: [ghc-7.10.3], sources: [hvr-ghc] } }
Makefilenew file+20
@@ -0,0 +1,20 @@
1+FLAGS := -j --disable-documentation --disable-library-coverage
2+
3+build:
4+ cabal build $(addprefix -,$(findstring j,$(MAKEFLAGS)))
5+
6+all:
7+ make clean; make install && make build
8+
9+install: cabal.sandbox.config
10+ cabal install $(FLAGS) --only-dependencies
11+
12+clean:
13+ cabal clean
14+ rm -rf cabal.sandbox.config .cabal-sandbox
15+
16+doc:
17+ cabal haddock
18+
19+cabal.sandbox.config:
20+ cabal sandbox init
README.md−14
@@ -1,14 +0,0 @@
1−# PagerDuty
2−
3−[![Build Status](https://travis-ci.org/brendanhay/amazonka.svg?branch=develop)](https://travis-ci.org/brendanhay/pagerduty)
4−
5−* [Contribute](#contribute)
6−* [Licence](#licence)
7−
8−## Contribute
9−
10−For any problems, comments, or feedback please create an issue [here on GitHub](https://github.com/brendanhay/pagerduty/issues).
11−
12−## Licence
13−
14−PagerDuty is released under the [Mozilla Public License Version 2.0](http://www.mozilla.org/MPL/).
pagerduty.cabal+21−32
@@ -1,32 +1,23 @@
1name: pagerduty
1name: pagerduty
2−version: 0.0.8
2+version: 0.0.0
3−synopsis: Client library for PagerDuty Integration and REST APIs.
3+synopsis: Pager Duty API Client
4homepage: http://github.com/brendanhay/pagerduty
4homepage: http://github.com/brendanhay/pagerduty
5license: OtherLicense
5license: OtherLicense
6license-file: LICENSE
6license-file: LICENSE
7author: Brendan Hay
7author: Brendan Hay
8maintainer: Brendan Hay <brendan.g.hay@gmail.com>
8maintainer: Brendan Hay <brendan.g.hay@gmail.com>
9−copyright: Copyright (c) 2013-2015 Brendan Hay, 2014 Kim Altintop
9+copyright: Copyright (c) 2013-2014 Brendan Hay, 2014 Kim Altintop
10−category: Network, PagerDuty, Monitoring
10+category: Network, Monitoring, Alerting
11build-type: Simple
11build-type: Simple
12cabal-version: >= 1.10
12cabal-version: >= 1.10
13
13
14description:
14description:
15− PagerDuty is an alerting system for IT professionals. PagerDuty connects
16− with a variety of systems (including monitoring tools and ticketing
17− systems) and dispatches alerts via automated phone call, SMS and email.
18−
19− This library implements the full PagerDuty Integration and REST APIs which
20− are documented here:
15+ Client library for the the PagerDuty REST APIs documented here:
21 .
16 .
22 * Integration API - <http://developer.pagerduty.com/documentation/integration>
17 * Integration API - <http://developer.pagerduty.com/documentation/integration>
23− .
24 * REST API - <http://developer.pagerduty.com/documentation/rest>
18 * REST API - <http://developer.pagerduty.com/documentation/rest>
25 .
19 .
26− /Warning:/ This is an experimental preview release which is still under
20+ /Warning:/ This is a /highly/ experimental preview release, caveat emptor!
27− heavy development and not intended for public consumption, caveat emptor!
28− .
29− /Note:/ An alternative source for Haddock documentation can be found <http://brendanhay.nz/pagerduty here>.
30
21
31extra-source-files:
22extra-source-files:
32 README.md
23 README.md
@@ -68,30 +59,28 @@ library
68 , Network.PagerDuty.Internal.Query
59 , Network.PagerDuty.Internal.Query
69 , Network.PagerDuty.Internal.TH
60 , Network.PagerDuty.Internal.TH
70 , Network.PagerDuty.Internal.Types
61 , Network.PagerDuty.Internal.Types
71− , Network.PagerDuty.Types
72
62
73 build-depends:
63 build-depends:
74− aeson >= 2.0
64+ aeson > 0.7 && <= 0.8
75− , base >= 4.7 && < 5
65+ , base >= 4.5 && < 5.0
76− , bifunctors >= 4.1
66+ , bifunctors >= 4
77 , bytestring >= 0.9
67 , bytestring >= 0.9
78 , bytestring-conversion >= 0.2.1
68 , bytestring-conversion >= 0.2.1
79− , conduit > 1.1
69+ , conduit >= 0.5.5
80 , data-default-class >= 0.0.1
70 , data-default-class >= 0.0.1
81 , exceptions >= 0.6
71 , exceptions >= 0.6
82− , generics-sop >= 0.5.0.0
72+ , generics-sop >= 0.1.0.2
83− , http-client >= 0.5 && < 1
73+ , http-client >= 0.3.6
84 , http-types >= 0.8
74 , http-types >= 0.8
85− , lens >= 4.4
75+ , lens >= 4.0
86− , lens-aeson >= 1
76+ , lens-aeson >= 1.0
87− , mmorph >= 1
77+ , mmorph >= 1.0
88− , monad-control >= 1
78+ , monad-control >= 0.3.2
89− , mtl >= 2.1.3.1
79+ , mtl >= 2.2.1
80+ , old-locale >= 1.0.0.5
90 , template-haskell >= 2.2
81 , template-haskell >= 2.2
91 , text >= 1.1
82 , text >= 1.1
92− , time >= 1.2
83+ , time == 1.4.*
93− , time-locale-compat >= 0.1.0.1
94− , transformers >= 0.2
84+ , transformers >= 0.4.1
95− , transformers-compat >= 0.3
96− , transformers-base >= 0.4.2
85+ , transformers-base >= 0.4.1
97 , unordered-containers >= 0.2.3
86 , unordered-containers >= 0.2.3
script/generate-pagesnew file+25
@@ -0,0 +1,25 @@
1+#!/usr/bin/env bash
2+
3+set -e
4+set -x
5+set -o errexit
6+
7+branch=$(git symbolic-ref -q HEAD)
8+branch=${branch##refs/heads/}
9+branch=${branch:-HEAD}
10+
11+cabal configure --disable-tests
12+
13+DOCDIR=`mktemp -d -t pages.XXXXXX`
14+cabal haddock --haddock-option=-o$DOCDIR
15+
16+HEAD=`git rev-parse HEAD`
17+
18+git checkout gh-pages
19+
20+mv $DOCDIR/* .
21+
22+git add *.html *.js *.css *.gif *.png
23+git commit -m "Generated documentation from $HEAD on $branch"
24+git push origin gh-pages
25+git checkout $branch
script/travis-lifecycle-before_installdeleted−11
@@ -1,11 +0,0 @@
1−#!/usr/bin/env bash
2−
3−set -e
4−
5−mkdir -p ~/.local/bin
6−
7−curl -L https://www.stackage.org/stack/linux-x86_64 | \
8− tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
9−
10−ghc --version
11−stack --version
script/travis-lifecycle-installdeleted−13
@@ -1,13 +0,0 @@
1−#!/usr/bin/env bash
2−
3−set -e
4−
5−GHCVER=${GHCVER?"GHCVER needs to be set."}
6−
7−path=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
8−
9−$path/travis-timeout \
10− stack --no-terminal --skip-ghc-check --stack-yaml stack-$GHCVER.yaml setup
11−
12−$path/travis-timeout \
13− stack --no-terminal --skip-ghc-check --stack-yaml stack-$GHCVER.yaml test pagerduty --only-snapshot
script/travis-lifecycle-scriptdeleted−9
@@ -1,9 +0,0 @@
1−#!/usr/bin/env bash
2−
3−set -e
4−
5−GHCVER=${GHCVER?"GHCVER needs to be set."}
6−
7−path=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
8−
9−stack --no-terminal --skip-ghc-check --stack-yaml stack-$GHCVER.yaml test pagerduty
script/travis-timeoutdeleted−15
@@ -1,15 +0,0 @@
1−#!/usr/bin/env bash
2−
3−$* &
4−pidA=$!
5−minutes=0
6−
7−while true; do sleep 60; ((minutes++)); echo -e "\033[0;32m$minutes minute(s) elapsed running '$*'\033[0m."; done &
8−pidB=$!
9−wait $pidA
10−resA=$?
11−
12−echo -e "\033[0;32m'$*' exited with status ${resA}.\033[0m"
13−kill -9 $pidB
14−
15−exit $resA
script/upload-documentationnew file+37
@@ -0,0 +1,37 @@
1+#!/usr/bin/env bash
2+
3+set -e
4+
5+package=${PWD##*/}
6+
7+echo "Package: ${package}"
8+read -p "Version: " version
9+read -p "Hackage user: " user
10+read -sp "Hackage password (not echoed): " password
11+
12+echo
13+echo "BUILDING"
14+echo
15+
16+cabal configure
17+cabal build
18+cabal haddock \
19+ --hyperlink-source \
20+ --html-location='/package/$pkg-$version/docs' \
21+ --contents-location='/package/$pkg'
22+
23+echo
24+echo "ARCHIVING"
25+echo
26+
27+cd dist/doc/html
28+DDIR="${package}-${version}-docs"
29+cp -r "${package}" "${DDIR}" && gtar -c -v -z -Hustar -f "${DDIR}.tar.gz" "${DDIR}"
30+
31+echo
32+echo "UPLOADING"
33+echo
34+
35+curl -X PUT -H 'Content-Type: application/x-tar' \
36+ -H 'Content-Encoding: gzip' --data-binary "@${DDIR}.tar.gz" \
37+ "http://${user}:${password}@hackage.haskell.org/package/${package}-${version}/docs"
src/Control/Monad/Trans/PagerDuty.hs+72−55
@@ -2,12 +2,15 @@
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+{-# LANGUAGE KindSignatures #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7+{-# LANGUAGE RecordWildCards #-}
8+{-# LANGUAGE TemplateHaskell #-}
6{-# LANGUAGE TypeFamilies #-}
9{-# LANGUAGE TypeFamilies #-}
7{-# LANGUAGE UndecidableInstances #-}
10{-# LANGUAGE UndecidableInstances #-}
8
11
9-- Module : Control.Monad.Trans.PagerDuty
12-- Module : Control.Monad.Trans.PagerDuty
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
13+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
14-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
15-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
16-- A copy of the MPL can be found in the LICENSE file or
@@ -19,50 +22,57 @@
19module Control.Monad.Trans.PagerDuty
22module Control.Monad.Trans.PagerDuty
20 (
23 (
21 -- * Transformer
24 -- * Transformer
22− PagerDuty
25+ PD
23− , PagerDutyT
26+ , PDT
24
27
25− -- * Running
28+ -- * Run
26− , runPagerDutyT
29+ , runPDT
27
30
31+ -- * Environment
32+ , Env
33+ , envDomain
34+ , envAuth
35+ , envManager
36+-- , envLogging
37+
28− -- * Integration events
38+ -- * Integration API
29 , submit
39 , submit
30− , submitCatch
31
40
32− -- * REST requests
41+ -- * REST API
33 , send
42 , send
34− , sendCatch
35 , paginate
43 , paginate
36− , paginateCatch
37−
38− -- ** Lifting errors
39− , hoistError
40−
41− , module Network.PagerDuty.Types
42 ) where
44 ) where
43
45
44import Control.Applicative
46import Control.Applicative
45−import Control.Monad
47+import Control.Lens
46import Control.Monad.Base
48import Control.Monad.Base
47import Control.Monad.Catch
49import Control.Monad.Catch
48−import Control.Monad.Except (MonadError (..))
50+import Control.Monad.Except
49import Control.Monad.Morph
51import Control.Monad.Morph
50import Control.Monad.Reader
52import Control.Monad.Reader
51import Control.Monad.Trans.Control
53import Control.Monad.Trans.Control
52−import Control.Monad.Trans.Except
53import Data.Aeson
54import Data.Aeson
54import Data.Conduit
55import Data.Conduit
56+import Network.HTTP.Client (Manager)
55−import Network.PagerDuty.Integration (Event, Response)
57+import Network.PagerDuty.Integration (Event, Response)
56−import qualified Network.PagerDuty.Integration as Int
58+import qualified Network.PagerDuty.Integration as Int
59+import qualified Network.PagerDuty.REST as REST
57import Network.PagerDuty.Internal.Types
60import Network.PagerDuty.Internal.Types
58−import qualified Network.PagerDuty.REST as REST
59−import Network.PagerDuty.Types
60
61
62+data Env (s :: Security) = Env
63+ { _envDomain :: SubDomain
64+ , _envAuth :: Auth s
65+ , _envManager :: Manager
66+-- , _envLogging ::
67+ }
68+
69+makeLenses ''Env
70+
61−-- | A convenient alias for 'PagerDutyT' 'IO'.
71+-- | A convenient alias for 'PDT' 'IO'.
62−type PagerDuty s = PagerDutyT s IO
72+type PD s = PDT s IO
63
73
64−newtype PagerDutyT s m a = PagerDutyT
74+newtype PDT s m a = PDT
65− { unPagerDutyT :: ReaderT (Env s) (ExceptT Error m) a
75+ { unPDT :: ReaderT (Env s) (ExceptT Error m) a
66 } deriving
76 } deriving
67 ( Functor
77 ( Functor
68 , Applicative
78 , Applicative
@@ -74,48 +84,50 @@ newtype PagerDutyT s m a = PagerDutyT
74 , MonadError Error
84 , MonadError Error
75 )
85 )
76
86
77−instance MonadTrans (PagerDutyT s) where
87+instance MonadTrans (PDT s) where
78− lift = PagerDutyT . lift . lift
88+ lift = PDT . lift . lift
79 {-# INLINE lift #-}
89 {-# INLINE lift #-}
80
90
81−instance MonadBase b m => MonadBase b (PagerDutyT s m) where
91+instance MonadBase b m => MonadBase b (PDT s m) where
82 liftBase = liftBaseDefault
92 liftBase = liftBaseDefault
83 {-# INLINE liftBase #-}
93 {-# INLINE liftBase #-}
84
94
85−instance MonadTransControl (PagerDutyT s) where
95+instance MonadTransControl (PDT s) where
96+ newtype StT (PDT s) a = StTAWS
86− type StT (PagerDutyT s) a = StT (ExceptT Error) (StT (ReaderT (Env s)) a)
97+ { unStTAWS :: StT (ExceptT Error) (StT (ReaderT (Env s)) a)
98+ }
87
99
88− liftWith f = PagerDutyT $
100+ liftWith f = PDT $
89 liftWith $ \g ->
101 liftWith $ \g ->
90− liftWith $ \h ->
102+ liftWith $ \h ->
91− f (h . g . unPagerDutyT)
103+ f (liftM StTAWS . h . g . unPDT)
92 {-# INLINE liftWith #-}
104 {-# INLINE liftWith #-}
93
105
94− restoreT = PagerDutyT . restoreT . restoreT
106+ restoreT = PDT . restoreT . restoreT . liftM unStTAWS
95 {-# INLINE restoreT #-}
107 {-# INLINE restoreT #-}
96
108
97−instance MonadBaseControl b m => MonadBaseControl b (PagerDutyT s m) where
109+instance MonadBaseControl b m => MonadBaseControl b (PDT s m) where
98− type StM (PagerDutyT s m) a = ComposeSt (PagerDutyT s) m a
110+ newtype StM (PDT s m) a = StMPDT { unStMPDT :: ComposeSt (PDT s) m a }
99
111
100− liftBaseWith = defaultLiftBaseWith
112+ liftBaseWith = defaultLiftBaseWith StMPDT
101 {-# INLINE liftBaseWith #-}
113 {-# INLINE liftBaseWith #-}
102
114
103− restoreM = defaultRestoreM
115+ restoreM = defaultRestoreM unStMPDT
104 {-# INLINE restoreM #-}
116 {-# INLINE restoreM #-}
105
117
106−instance MFunctor (PagerDutyT s) where
118+instance MFunctor (PDT s) where
107− hoist nat m = PagerDutyT (ReaderT (ExceptT . nat . runPagerDutyT m))
119+ hoist nat m = PDT (ReaderT (ExceptT . nat . runPDT m))
108 {-# INLINE hoist #-}
120 {-# INLINE hoist #-}
109
121
110−instance MMonad (PagerDutyT s) where
122+instance MMonad (PDT s) where
111− embed f m = ask >>= f . runPagerDutyT m >>= either throwError return
123+ embed f m = ask >>= f . runPDT m >>= either throwError return
112 {-# INLINE embed #-}
124 {-# INLINE embed #-}
113
125
114−runPagerDutyT :: PagerDutyT s m a -> Env s -> m (Either Error a)
126+runPDT :: PDT s m a -> Env s -> m (Either Error a)
115−runPagerDutyT (PagerDutyT k) = runExceptT . runReaderT k
127+runPDT (PDT k) = runExceptT . runReaderT k
116
128
117−hoistError :: (MonadError Error m) => Either Error a -> m a
129+hoistEither :: (MonadError Error m) => Either Error a -> m a
118−hoistError = either throwError return
130+hoistEither = either throwError return
119
131
120scoped :: MonadReader (Env s) m => (Env s -> m a) -> m a
132scoped :: MonadReader (Env s) m => (Env s -> m a) -> m a
121scoped f = ask >>= f
133scoped f = ask >>= f
@@ -123,17 +135,20 @@ scoped f = ask >>= f
123submit :: ( MonadIO m
135submit :: ( MonadIO m
124 , MonadReader (Env s) m
136 , MonadReader (Env s) m
125 , MonadError Error m
137 , MonadError Error m
138+ , Event a
126 )
139 )
127− => Event
140+ => a
128 -> m Response
141 -> m Response
129−submit = submitCatch >=> hoistError
142+submit = submitCatch >=> hoistEither
130
143
131submitCatch :: ( MonadIO m
144submitCatch :: ( MonadIO m
132 , MonadReader (Env s) m
145 , MonadReader (Env s) m
146+ , Event a
133 )
147 )
134− => Event
148+ => a
135 -> m (Either Error Response)
149 -> m (Either Error Response)
136−submitCatch x = scoped $ \e -> Int.submitWith (_envManager e) (_envLogger e) x
150+submitCatch x = scoped $ \e ->
151+ Int.submit (_envManager e) x
137
152
138send :: ( MonadIO m
153send :: ( MonadIO m
139 , MonadReader (Env s) m
154 , MonadReader (Env s) m
@@ -142,7 +157,7 @@ send :: ( MonadIO m
142 )
157 )
143 => Request a s b
158 => Request a s b
144 -> m b
159 -> m b
145−send = sendCatch >=> hoistError
160+send = sendCatch >=> hoistEither
146
161
147sendCatch :: ( MonadIO m
162sendCatch :: ( MonadIO m
148 , MonadReader (Env s) m
163 , MonadReader (Env s) m
@@ -150,7 +165,8 @@ sendCatch :: ( MonadIO m
150 )
165 )
151 => Request a s b
166 => Request a s b
152 -> m (Either Error b)
167 -> m (Either Error b)
153−sendCatch x = scoped (`REST.sendWith` x)
168+sendCatch x = scoped $ \Env{..} ->
169+ REST.send _envAuth _envDomain _envManager x
154
170
155paginate :: ( MonadIO m
171paginate :: ( MonadIO m
156 , MonadReader (Env s) m
172 , MonadReader (Env s) m
@@ -160,7 +176,7 @@ paginate :: ( MonadIO m
160 )
176 )
161 => Request a s b
177 => Request a s b
162 -> Source m b
178 -> Source m b
163−paginate x = paginateCatch x $= awaitForever (hoistError >=> yield)
179+paginate x = paginateCatch x $= awaitForever (hoistEither >=> yield)
164
180
165paginateCatch :: ( MonadIO m
181paginateCatch :: ( MonadIO m
166 , MonadReader (Env s) m
182 , MonadReader (Env s) m
@@ -169,4 +185,5 @@ paginateCatch :: ( MonadIO m
169 )
185 )
170 => Request a s b
186 => Request a s b
171 -> Source m (Either Error b)
187 -> Source m (Either Error b)
172−paginateCatch x = scoped (`REST.paginateWith` x)
188+paginateCatch x = scoped $ \Env{..} ->
189+ REST.paginate _envAuth _envDomain _envManager x
src/Network/PagerDuty/Integration.hs+147−187
@@ -1,12 +1,10 @@
1−{-# LANGUAGE FlexibleInstances #-}
1+{-# LANGUAGE GADTs #-}
2−{-# LANGUAGE FunctionalDependencies #-}
2+{-# LANGUAGE DefaultSignatures #-}
3−{-# LANGUAGE LambdaCase #-}
4−{-# LANGUAGE MultiParamTypeClasses #-}
5−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
6−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
7
5
8-- Module : Network.PagerDuty.Integration
6-- Module : Network.PagerDuty.Integration
9−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
7+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
10-- License : This Source Code Form is subject to the terms of
8-- License : This Source Code Form is subject to the terms of
11-- the Mozilla Public License, v. 2.0.
9-- the Mozilla Public License, v. 2.0.
12-- A copy of the MPL can be found in the LICENSE file or
10-- A copy of the MPL can be found in the LICENSE file or
@@ -38,57 +36,52 @@
38-- /See:/ <http://developer.pagerduty.com/documentation/integration/events>
36-- /See:/ <http://developer.pagerduty.com/documentation/integration/events>
39module Network.PagerDuty.Integration
37module Network.PagerDuty.Integration
40 (
38 (
41− -- * Sending events
39+ -- * Events
42 submit
40 submit
43− , submitWith
44
41
45 -- ** Trigger
42 -- ** Trigger
46 , Trigger
43 , Trigger
47 , trigger
44 , trigger
48− , client
45+ , tDescription
49− , clientUrl
46+ , tIncidentKey
47+ , tClient
48+ , tClientUrl
49+ , tDetails
50
50
51 -- ** Acknowledge
51 -- ** Acknowledge
52 , Acknowledge
52 , Acknowledge
53 , acknowledge
53 , acknowledge
54+ , aDescription
55+ , aDetails
54
56
55 -- ** Resolve
57 -- ** Resolve
56 , Resolve
58 , Resolve
57 , resolve
59 , resolve
58−
60+ , rDescription
59− -- * Fields
61+ , rDetails
60− , HasServiceKey (..)
61− , HasIncidentKey (..)
62− , HasDescription (..)
63− , HasDetails (..)
64
62
65 -- * Types
63 -- * Types
66− , Event (..)
64+ , Event
67− , _Trigger
65+ , AnyEvent (..)
68− , _Acknowledge
69− , _Resolve
70
66
71 , Response
67 , Response
72 , rsStatus
68 , rsStatus
73 , rsMessage
69 , rsMessage
74 , rsIncidentKey
70 , rsIncidentKey
75−
76− , Generic
77−
78− , module Network.PagerDuty.Types
79 ) where
71 ) where
80
72
81import Control.Lens
73import Control.Lens
82import Control.Monad.IO.Class
74import Control.Monad.IO.Class
83import Data.Aeson
75import Data.Aeson
76+import Data.Default.Class
84−import qualified Data.Aeson.KeyMap as Map
77+import qualified Data.HashMap.Strict as Map
85−import Data.Text (Text)
78+import Data.Monoid
79+import Data.Text (Text)
86−import Network.HTTP.Client (Manager)
80+import Network.HTTP.Client (Manager)
87−import qualified Network.HTTP.Client as Client
81+import qualified Network.HTTP.Client as Client
88import Network.PagerDuty.Internal.IO
82import Network.PagerDuty.Internal.IO
89import Network.PagerDuty.Internal.TH
83import Network.PagerDuty.Internal.TH
90import Network.PagerDuty.Internal.Types
84import Network.PagerDuty.Internal.Types
91−import Network.PagerDuty.Types hiding (description, message)
92
85
93data Response = Response
86data Response = Response
94 { _rsStatus :: Text
87 { _rsStatus :: Text
@@ -107,161 +100,128 @@ makeLens "_rsMessage" ''Response
107-- | The key of the incident that will be affected by the request.
100-- | The key of the incident that will be affected by the request.
108makeLens "_rsIncidentKey" ''Response
101makeLens "_rsIncidentKey" ''Response
109
102
110−class HasServiceKey s a | s -> a where
103+class Event a where
111− -- | The GUID of one of your "Generic API" services. This is the "service key"
104+ eventType :: a -> Text
112− -- listed on a Generic API's service detail page.
105+ eventPayload :: a -> Object
113− serviceKey :: Lens' s a
114−
115−class HasIncidentKey s a | s -> a where
116− -- | Identifies the incident to which this trigger event should be applied.
117− -- If there's no open (i.e. unresolved) incident with this key, a new one
118− -- will be created. If there's already an open incident with a matching key,
119− -- this event will be appended to that incident's log. The event key provides
120− -- an easy way to "de-dup" problem reports. If this field isn't provided,
121− -- PagerDuty will automatically open a new incident with a unique key.
122− incidentKey :: Lens' s a
123−
124−class HasDescription s a | s -> a where
125− -- | A short description of the problem that led to this trigger.
126− -- This field (or a truncated version) will be used when generating phone
127− -- calls, SMS messages and alert emails. It will also appear on the incidents
128− -- tables in the PagerDuty UI. The maximum length is 1024 characters.
129− description :: Lens' s a
130−
131−class HasDetails s a | s -> a where
132− -- | An arbitrary JSON object containing any data you'd like included
133− -- in the incident log.
134− details :: Lens' s a
135−
136−data Trigger = Trigger'
137− { _tServiceKey' :: ServiceKey
138− , _tIncidentKey' :: IncidentKey
139− , _tDescription' :: Text
140− , _tDetails' :: Maybe Object
141− , _tClient' :: Maybe Text
142− , _tClientUrl' :: Maybe Text
143− } deriving (Eq, Show)
144
106
145−deriveRecord ''Trigger
107+ default eventPayload :: ToJSON a => a -> Object
108+ eventPayload x = let Object o = toJSON x in o
146
109
147−instance HasServiceKey Trigger ServiceKey where serviceKey = tServiceKey'
110+data AnyEvent where
148−instance HasIncidentKey Trigger IncidentKey where incidentKey = tIncidentKey'
111+ Event :: Event a => a -> AnyEvent
149−instance HasDescription Trigger Text where description = tDescription'
150−instance HasDetails Trigger (Maybe Object) where details = tDetails'
151
112
152−-- | The name of the monitoring client that is triggering this event.
113+instance Event AnyEvent where
153−client :: Lens' Trigger (Maybe Text)
114+ eventType (Event x) = eventType x
154−client = tClient'
115+ eventPayload (Event x) = eventPayload x
155
116
156−-- | The URL of the monitoring client that is triggering this event.
157−clientUrl :: Lens' Trigger (Maybe Text)
158−clientUrl = tClientUrl'
159−
160−data Generic = Generic'
117+data Generic = Generic
161− { _gServiceKey' :: ServiceKey
118+ { _gServiceKey :: ServiceKey
119+ , _gDescription :: Maybe Text
162− , _gIncidentKey' :: IncidentKey
120+ , _gIncidentKey :: IncidentKey
163− , _gDescription' :: Maybe Text
164− , _gDetails' :: Maybe Object
121+ , _gDetails :: Object
165 } deriving (Eq, Show)
122 } deriving (Eq, Show)
166
123
167−deriveRecord ''Generic
124+deriveJSON ''Generic
168−
125+
169−instance HasServiceKey Generic ServiceKey where serviceKey = gServiceKey'
126+makeLens "_gDescription" ''Generic
170−instance HasIncidentKey Generic IncidentKey where incidentKey = gIncidentKey'
127+makeLens "_gDetails" ''Generic
171−instance HasDescription Generic (Maybe Text) where description = gDescription'
128+
172−instance HasDetails Generic (Maybe Object) where details = gDetails'
129+data Trigger = Trigger
173−
130+ { _tServiceKey :: ServiceKey
174−type Resolve = Generic
131+ , _tDescription :: Text
175−type Acknowledge = Generic
132+ , _tIncidentKey :: Maybe IncidentKey
176−
133+ , _tClient :: Maybe Text
177−data Event
134+ , _tClientUrl :: Maybe Text
178− = Trigger Trigger -- ^ /See:/ 'trigger'
135+ , _tDetails :: Object
179− | Acknowledge Generic -- ^ /See:/ 'acknowledge'
180− | Resolve Generic -- ^ /See:/ 'resolve'
181− deriving (Eq, Show)
136+ } deriving (Eq, Show)
182−
137+
183−makePrisms ''Event
138+deriveJSON ''Trigger
184−
139+
185−instance HasServiceKey Event ServiceKey where
140+instance Event Trigger where
186− serviceKey = lens f g
141+ eventType = const "trigger"
187− where
188− f (Trigger s) = _tServiceKey' s
189− f (Acknowledge s) = _gServiceKey' s
190− f (Resolve s) = _gServiceKey' s
191−
192− g (Trigger s) x = Trigger $ s { _tServiceKey' = x }
193− g (Acknowledge s) x = Acknowledge $ s { _gServiceKey' = x }
194− g (Resolve s) x = Resolve $ s { _gServiceKey' = x }
195−
196−instance HasIncidentKey Event IncidentKey where
197− incidentKey = lens f g
198− where
199− f (Trigger s) = _tIncidentKey' s
200− f (Acknowledge s) = _gIncidentKey' s
201− f (Resolve s) = _gIncidentKey' s
202−
203− g (Trigger s) x = Trigger $ s { _tIncidentKey' = x }
204− g (Acknowledge s) x = Acknowledge $ s { _gIncidentKey' = x }
205− g (Resolve s) x = Resolve $ s { _gIncidentKey' = x }
206−
207−instance HasDetails Event (Maybe Object) where
208− details = lens f g
209− where
210− f (Trigger s) = _tDetails' s
211− f (Acknowledge s) = _gDetails' s
212− f (Resolve s) = _gDetails' s
213−
214− g (Trigger s) x = Trigger $ s { _tDetails' = x }
215− g (Acknowledge s) x = Acknowledge $ s { _gDetails' = x }
216− g (Resolve s) x = Resolve $ s { _gDetails' = x }
217−
218−instance ToJSON Event where
219− toJSON = \case
220− Trigger x -> event "trigger" x
221− Acknowledge x -> event "acknowledge" x
222− Resolve x -> event "resolve" x
223− where
224− event k x =
225− case toJSON x of
226− Object o -> Object (Map.insert "event_type" (String k) o)
227− v -> v
228
142
229-- | Your monitoring tools should send PagerDuty a trigger event to report a new
143-- | Your monitoring tools should send PagerDuty a trigger event to report a new
230-- or ongoing problem. When PagerDuty receives a trigger event, it will either open
144-- or ongoing problem. When PagerDuty receives a trigger event, it will either open
231-- a new incident, or add a new trigger log entry to an existing incident,
145-- a new incident, or add a new trigger log entry to an existing incident,
232-- depending on the provided incident_key.
146-- depending on the provided incident_key.
233−trigger :: ServiceKey -- ^ 'serviceKey'
147+trigger :: ServiceKey
234− -> IncidentKey -- ^ 'incidentKey'
148+ -> Text -- ^ 'tDescription'
235− -> Text -- ^ 'description'
149+ -> Trigger
236− -> Event
237−trigger k i d =
150+trigger k d =
238− Trigger Trigger'
151+ Trigger
239− { _tServiceKey' = k
152+ { _tServiceKey = k
240− , _tDescription' = d
153+ , _tDescription = d
241− , _tIncidentKey' = i
154+ , _tIncidentKey = Nothing
242− , _tClient' = Nothing
155+ , _tClient = Nothing
243− , _tClientUrl' = Nothing
156+ , _tClientUrl = Nothing
244− , _tDetails' = Nothing
157+ , _tDetails = mempty
245 }
158 }
246
159
160+-- | A short description of the problem that led to this trigger.
161+-- This field (or a truncated version) will be used when generating phone
162+-- calls, SMS messages and alert emails. It will also appear on the incidents
163+-- tables in the PagerDuty UI. The maximum length is 1024 characters.
164+makeLens "_tDescription" ''Trigger
165+
166+-- | Identifies the incident to which this trigger event should be applied.
167+-- If there's no open (i.e. unresolved) incident with this key, a new one
168+-- will be created. If there's already an open incident with a matching key,
169+-- this event will be appended to that incident's log. The event key provides
170+-- an easy way to "de-dup" problem reports. If this field isn't provided,
171+-- PagerDuty will automatically open a new incident with a unique key.
172+makeLens "_tIncidentKey" ''Trigger
173+
174+-- | The name of the monitoring client that is triggering this event.
175+makeLens "_tClient" ''Trigger
176+
177+-- | The URL of the monitoring client that is triggering this event.
178+makeLens "_tClientUrl" ''Trigger
179+
180+-- | An arbitrary JSON object containing any data you'd like included
181+-- in the incident log.
182+makeLens "_tDetails" ''Trigger
183+
184+newtype Acknowledge = Acknowledge Generic
185+
186+deriveJSON ''Acknowledge
187+makePrisms ''Acknowledge
188+
189+instance Event Acknowledge where
190+ eventType = const "acknowledge"
191+
247-- | Acknowledge events cause the referenced incident to enter the acknowledged
192-- | Acknowledge events cause the referenced incident to enter the acknowledged
248-- state.
193-- state.
249--
194--
250-- While an incident is acknowledged, it won't generate any additional
195-- While an incident is acknowledged, it won't generate any additional
251-- notifications, even if it receives new trigger events. Your monitoring tools
196-- notifications, even if it receives new trigger events. Your monitoring tools
252−-- should send PagerDuty an acknowledge event when they know someone is
197+-- should send PagerDuty an acknowledge event when they know someone is presently
253−-- presently working on the problem.
198+-- working on the problem.
254−acknowledge :: ServiceKey -- ^ 'serviceKey'
199+acknowledge :: ServiceKey -> IncidentKey -> Acknowledge
255− -> IncidentKey -- ^ 'incidentKey'
256− -> Event
257acknowledge k i =
200acknowledge k i =
258− Acknowledge Generic'
201+ Acknowledge Generic
259− { _gServiceKey' = k
202+ { _gServiceKey = k
203+ , _gDescription = Nothing
260− , _gIncidentKey' = i
204+ , _gIncidentKey = i
261− , _gDescription' = Nothing
262− , _gDetails' = Nothing
205+ , _gDetails = mempty
263 }
206 }
264
207
208+-- | Text that will appear in the incident's log associated with this event.
209+aDescription :: Lens' Acknowledge (Maybe Text)
210+aDescription = _Acknowledge.gDescription
211+
212+-- | An arbitrary JSON object containing any data you'd like included
213+-- in the incident log.
214+aDetails :: Lens' Acknowledge Object
215+aDetails = _Acknowledge.gDetails
216+
217+newtype Resolve = Resolve Generic
218+
219+deriveJSON ''Resolve
220+makePrisms ''Resolve
221+
222+instance Event Resolve where
223+ eventType = const "acknowledge"
224+
265-- | Resolve events cause the referenced incident to enter the resolved state.
225-- | Resolve events cause the referenced incident to enter the resolved state.
266--
226--
267-- Once an incident is resolved, it won't generate any additional
227-- Once an incident is resolved, it won't generate any additional
@@ -269,30 +229,30 @@ acknowledge k i =
269-- incident won't re-open the incident. Instead, a new incident will be
229-- incident won't re-open the incident. Instead, a new incident will be
270-- created. Your monitoring tools should send PagerDuty a resolve event when the
230-- created. Your monitoring tools should send PagerDuty a resolve event when the
271-- problem that caused the initial trigger event has been fixed.
231-- problem that caused the initial trigger event has been fixed.
272−resolve :: ServiceKey -- ^ 'serviceKey'
232+resolve :: ServiceKey -> IncidentKey -> Resolve
273− -> IncidentKey -- ^ 'incidentKey'
274− -> Event
275resolve k i =
233resolve k i =
276− Resolve Generic'
234+ Resolve Generic
277− { _gServiceKey' = k
235+ { _gServiceKey = k
236+ , _gDescription = Nothing
278− , _gIncidentKey' = i
237+ , _gIncidentKey = i
279− , _gDescription' = Nothing
280− , _gDetails' = Nothing
238+ , _gDetails = mempty
281 }
239 }
282
240
241+-- | Text that will appear in the incident's log associated with this event.
242+rDescription :: Lens' Resolve (Maybe Text)
243+rDescription = _Resolve.gDescription
244+
245+-- | An arbitrary JSON object containing any data youd like included
246+-- in the incident log.
247+rDetails :: Lens' Resolve Object
248+rDetails = _Resolve.gDetails
249+
283-- | Send an event to the integration API.
250-- | Send an event to the integration API.
284−submit :: MonadIO m => Manager -> Event -> m (Either Error Response)
285−submit m = submitWith m None
286−
287−-- | /See:/ 'submit'
288−submitWith :: MonadIO m
289− => Manager
290− -> Logger
291− -> Event
292− -> m (Either Error Response)
251+submit :: (MonadIO m, Event a) => Manager -> a -> m (Either Error Response)
293−submitWith m l e = request m l e $
252+submit m x = request m payload $ def
294− Client.defaultRequest
295− { Client.host = "events.pagerduty.com"
253+ { Client.host = "events.pagerduty.com"
296− , Client.path = "/generic/2010-04-15/create_event.json"
254+ , Client.path = "/generic/2010-04-15/create_event.json"
297− , Client.method = "POST"
298− }
255+ }
256+ where
257+ payload = Object $
258+ Map.insert "event_type" (String (eventType x)) (eventPayload x)
src/Network/PagerDuty/Internal/IO.hs+17−27
@@ -1,8 +1,7 @@
1−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3
2
4-- Module : Network.PagerDuty.Internal.IO
3-- Module : Network.PagerDuty.Internal.IO
5−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
4+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
6-- License : This Source Code Form is subject to the terms of
5-- License : This Source Code Form is subject to the terms of
7-- the Mozilla Public License, v. 2.0.
6-- the Mozilla Public License, v. 2.0.
8-- A copy of the MPL can be found in the LICENSE file or
7-- A copy of the MPL can be found in the LICENSE file or
@@ -15,25 +14,20 @@ module Network.PagerDuty.Internal.IO where
15
14
16import Control.Monad
15import Control.Monad
17import Control.Monad.IO.Class
16import Control.Monad.IO.Class
18−import Data.Aeson hiding (Error)
17+import Data.Aeson hiding (Error)
19−import qualified Data.ByteString.Lazy as LBS
18+import qualified Data.ByteString.Lazy as LBS
20−import Data.Monoid
21−import qualified Data.Text as Text
22−import Network.HTTP.Client (Manager, httpLbs)
19+import Network.HTTP.Client (Manager, httpLbs)
23−import qualified Network.HTTP.Client as Client
20+import qualified Network.HTTP.Client as Client
24import Network.HTTP.Types
21import Network.HTTP.Types
25import Network.PagerDuty.Internal.Types
22import Network.PagerDuty.Internal.Types
26
23
27request :: (MonadIO m, ToJSON a, FromJSON b)
24request :: (MonadIO m, ToJSON a, FromJSON b)
28 => Manager
25 => Manager
29− -> Logger
30 -> a
26 -> a
31 -> Client.Request
27 -> Client.Request
32 -> m (Either Error b)
28 -> m (Either Error b)
33−request m l x rq = msg >> liftIO (httpLbs raw m) >>= response l
29+request m x rq = liftIO (httpLbs raw m) >>= response
34 where
30 where
35− msg = debug l ("[Raw Request]\n" <> Text.pack (show raw))
36−
37 raw = rq
31 raw = rq
38 { Client.secure = True
32 { Client.secure = True
39 , Client.port = 443
33 , Client.port = 443
@@ -46,11 +40,10 @@ request m l x rq = msg >> liftIO (httpLbs raw m) >>= response l
46 , ("Accept", "application/json")
40 , ("Accept", "application/json")
47 ]
41 ]
48
42
49−response :: forall m b. (MonadIO m, FromJSON b)
43+response :: (Monad m, FromJSON b)
50− => Logger
51− -> Client.Response LBS.ByteString
44+ => Client.Response LBS.ByteString
52 -> m (Either Error b)
45 -> m (Either Error b)
53−response l rs = case statusCode (Client.responseStatus rs) of
46+response rs = case statusCode (Client.responseStatus rs) of
54 200 -> success
47 200 -> success
55 201 -> success
48 201 -> success
56 400 -> failure
49 400 -> failure
@@ -60,17 +53,14 @@ response l rs = case statusCode (Client.responseStatus rs) of
60 success = maybe (Left unknown) Right `liftM` parse
53 success = maybe (Left unknown) Right `liftM` parse
61 failure = maybe (Left unknown) Left `liftM` parse
54 failure = maybe (Left unknown) Left `liftM` parse
62
55
63− unhandled n = Internal $
56+ unhandled n = Internal
64− "PagerDuty returned unhandled status code: "
57+ $ "PagerDuty returned unhandled status code: " ++ show n
65− <> Text.pack (show n)
66−
67− unknown = Internal $
68− "Unable to parse response into a PagerDuty API compatible type: "
69− <> Text.pack (show body)
70
58
71− parse :: FromJSON a => m (Maybe a)
59+ unknown = Internal
72− parse = msg >> return (decode body)
60+ $ "Unable to parse response into a PagerDuty API compatible type: "
61+ ++ show body
73
62
74− msg = debug l ("[Raw Response]\n" <> Text.pack (show rs))
63+ parse :: (Monad m, FromJSON a) => m (Maybe a)
64+ parse = return (decode body)
75
65
76 body = Client.responseBody rs
66 body = Client.responseBody rs
src/Network/PagerDuty/Internal/Options.hs+4−4
@@ -1,5 +1,5 @@
1-- Module : Network.PagerDuty.Internal.Options
1-- Module : Network.PagerDuty.Internal.Options
2−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
2+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
3-- License : This Source Code Form is subject to the terms of
3-- License : This Source Code Form is subject to the terms of
4-- the Mozilla Public License, v. 2.0.
4-- the Mozilla Public License, v. 2.0.
5-- A copy of the MPL can be found in the LICENSE file or
5-- A copy of the MPL can be found in the LICENSE file or
@@ -14,9 +14,9 @@ module Network.PagerDuty.Internal.Options
14 , underscored
14 , underscored
15 ) where
15 ) where
16
16
17−import Data.Aeson.Types
17+import Data.Aeson.Types
18−import Data.Char
18+import Data.Char
19−import Data.List
19+import Data.List
20
20
21dropped :: Int -> Options -> Options
21dropped :: Int -> Options -> Options
22dropped n o = o
22dropped n o = o
src/Network/PagerDuty/Internal/Query.hs+12−14
@@ -1,13 +1,12 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DefaultSignatures #-}
3−{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE GADTs #-}
3{-# LANGUAGE GADTs #-}
5{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TupleSections #-}
6{-# LANGUAGE TupleSections #-}
8
7
9-- Module : Network.PagerDuty.Internal.Query
8-- Module : Network.PagerDuty.Internal.Query
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
9+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
10-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
11-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
12-- A copy of the MPL can be found in the LICENSE file or
@@ -24,14 +23,14 @@ module Network.PagerDuty.Internal.Query
24
23
25import Data.Aeson.Types
24import Data.Aeson.Types
26import Data.Bifunctor
25import Data.Bifunctor
27−import Data.ByteString (ByteString)
26+import Data.ByteString (ByteString)
28−import qualified Data.ByteString.Char8 as BS
27+import qualified Data.ByteString.Char8 as BS
29import Data.ByteString.Conversion
28import Data.ByteString.Conversion
30−import Data.Function (on)
29+import Data.Function (on)
31−import Data.List (groupBy)
30+import Data.List (groupBy)
32−import Data.Monoid ((<>))
31+import Data.Monoid ((<>))
33−import Data.Text (Text)
32+import Data.Text (Text)
34−import qualified Data.Text.Encoding as Text
33+import qualified Data.Text.Encoding as Text
35import Generics.SOP
34import Generics.SOP
36import Network.HTTP.Types
35import Network.HTTP.Types
37import Network.PagerDuty.Internal.Options
36import Network.PagerDuty.Internal.Options
@@ -59,15 +58,14 @@ gqueryWith :: forall a. (Generic a, HasDatatypeInfo a, All2 QueryValues (Code a)
59 -> a
58 -> a
60 -> Query
59 -> Query
61gqueryWith o a = case datatypeInfo (Proxy :: Proxy a) of
60gqueryWith o a = case datatypeInfo (Proxy :: Proxy a) of
62− ADT _ _ cs _ -> go cs (from a)
61+ ADT _ _ cs -> go cs (from a)
63− Newtype _ _ c -> go (c :* Nil) (from a)
62+ Newtype _ _ c -> go (c :* Nil) (from a)
64 where
63 where
65− go :: (All2 QueryValues xss, SListI xss)
64+ go :: (All2 QueryValues xss, SingI xss)
66 => NP ConstructorInfo xss
65 => NP ConstructorInfo xss
67 -> SOP I xss
66 -> SOP I xss
68 -> Query
67 -> Query
69− go cs (SOP sop) =
70− group . hcollapse $ hcliftA2' p (gctor o) cs sop
68+ go cs (SOP sop) = group . unI . hcollapse $ hcliftA2' p (gctor o) cs sop
71
69
72 group :: [(ByteString, ByteString)] -> Query
70 group :: [(ByteString, ByteString)] -> Query
73 group = concatMap f . groupBy ((==) `on` fst)
71 group = concatMap f . groupBy ((==) `on` fst)
src/Network/PagerDuty/Internal/TH.hs+6−6
@@ -1,7 +1,7 @@
1{-# LANGUAGE TemplateHaskell #-}
1{-# LANGUAGE TemplateHaskell #-}
2
2
3-- Module : Network.PagerDuty.Internal.TH
3-- Module : Network.PagerDuty.Internal.TH
4−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
4+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
5-- License : This Source Code Form is subject to the terms of
5-- License : This Source Code Form is subject to the terms of
6-- the Mozilla Public License, v. 2.0.
6-- the Mozilla Public License, v. 2.0.
7-- A copy of the MPL can be found in the LICENSE file or
7-- A copy of the MPL can be found in the LICENSE file or
@@ -40,15 +40,15 @@ module Network.PagerDuty.Internal.TH
40
40
41import Control.Applicative
41import Control.Applicative
42import Control.Lens
42import Control.Lens
43−import qualified Data.Aeson.TH as Aeson
43+import qualified Data.Aeson.TH as Aeson
44import Data.Aeson.Types
44import Data.Aeson.Types
45−import Data.ByteString (ByteString)
45+import Data.ByteString (ByteString)
46−import qualified Data.Text.Encoding as Text
46+import qualified Data.Text.Encoding as Text
47import Generics.SOP.TH
47import Generics.SOP.TH
48import Language.Haskell.TH
48import Language.Haskell.TH
49import Network.HTTP.Types.QueryLike
49import Network.HTTP.Types.QueryLike
50−import Network.PagerDuty.Internal.Options
51import Network.PagerDuty.Internal.Query
50import Network.PagerDuty.Internal.Query
51+import Network.PagerDuty.Internal.Options
52
52
53jsonRequest :: Name -> Q [Dec]
53jsonRequest :: Name -> Q [Dec]
54jsonRequest n = concat <$> sequence
54jsonRequest n = concat <$> sequence
@@ -61,7 +61,7 @@ queryRequest :: Name -> Q [Dec]
61queryRequest n = concat <$> sequence
61queryRequest n = concat <$> sequence
62 [ deriveGeneric n
62 [ deriveGeneric n
63 , makeLenses n
63 , makeLenses n
64− , [d|instance ToJSON $(conT n) where toJSON = const emptyObject|]
64+ , [d|instance ToJSON $(conT n) where toJSON = const (toJSON (object []))|]
65 , [d|instance QueryLike $(conT n) where toQuery = gquery|]
65 , [d|instance QueryLike $(conT n) where toQuery = gquery|]
66 ]
66 ]
67
67
src/Network/PagerDuty/Internal/Types.hs+41−125
@@ -1,11 +1,9 @@
1{-# LANGUAGE BangPatterns #-}
1{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7{-# LANGUAGE KindSignatures #-}
6{-# LANGUAGE KindSignatures #-}
8−{-# LANGUAGE MultiParamTypeClasses #-}
9{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}
10{-# LANGUAGE PatternSynonyms #-}
8{-# LANGUAGE PatternSynonyms #-}
11{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE RankNTypes #-}
@@ -15,7 +13,7 @@
15{-# LANGUAGE ViewPatterns #-}
13{-# LANGUAGE ViewPatterns #-}
16
14
17-- Module : Network.PagerDuty.Internal.Types
15-- Module : Network.PagerDuty.Internal.Types
18−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
16+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
19-- License : This Source Code Form is subject to the terms of
17-- License : This Source Code Form is subject to the terms of
20-- the Mozilla Public License, v. 2.0.
18-- the Mozilla Public License, v. 2.0.
21-- A copy of the MPL can be found in the LICENSE file or
19-- A copy of the MPL can be found in the LICENSE file or
@@ -27,33 +25,33 @@
27module Network.PagerDuty.Internal.Types where
25module Network.PagerDuty.Internal.Types where
28
26
29import Control.Applicative
27import Control.Applicative
30−import Control.Lens hiding ((.=), Empty)
28+import Control.Lens hiding ((.=))
31−import Control.Monad.IO.Class
32−import Data.Aeson hiding (Error, Key)
29+import Data.Aeson hiding (Error)
33−import qualified Data.Aeson.KeyMap as Map
34−import Data.Aeson.Types (Parser)
30+import Data.Aeson.Types (Parser)
35−import Data.ByteString (ByteString)
31+import Data.ByteString (ByteString)
36−import qualified Data.ByteString.Char8 as BS
32+import qualified Data.ByteString.Char8 as BS
37−import Data.ByteString.Conversion hiding (List)
33+import Data.ByteString.Conversion hiding (List)
38import Data.Default.Class
34import Data.Default.Class
39−import Data.Function (on)
35+import Data.Function (on)
36+import qualified Data.HashMap.Strict as Map
40−import Data.List (deleteBy, intersperse)
37+import Data.List (deleteBy, intersperse)
41import Data.Monoid
38import Data.Monoid
42import Data.String
39import Data.String
43−import Data.Text (Text)
40+import Data.Text (Text)
44−import qualified Data.Text as Text
41+import qualified Data.Text as Text
45−import qualified Data.Text.Encoding as Text
42+import qualified Data.Text.Encoding as Text
46−import Data.Time (UTCTime, TimeZone, formatTime, utc, timeZoneName)
43+import Data.Time
47import GHC.TypeLits
44import GHC.TypeLits
48−import Network.HTTP.Client (Manager)
49import Network.HTTP.Types
45import Network.HTTP.Types
50import Network.HTTP.Types.QueryLike
46import Network.HTTP.Types.QueryLike
51import Network.PagerDuty.Internal.Query
47import Network.PagerDuty.Internal.Query
52import Network.PagerDuty.Internal.TH
48import Network.PagerDuty.Internal.TH
53−import Data.Time.Locale.Compat
49+import System.Locale
50+
51+-- FIXME: Verify IncidentId/IncidentKey .. *Id/*Key are actually different or needed
54
52
55newtype CSV a = CSV [a]
53newtype CSV a = CSV [a]
56− deriving (Eq, Show, Semigroup, Monoid)
54+ deriving (Eq, Show, Monoid)
57
55
58makePrisms ''CSV
56makePrisms ''CSV
59
57
@@ -70,7 +68,7 @@ instance ToByteString a => ToJSON (CSV a) where
70 toJSON = String . Text.decodeUtf8 . toByteString'
68 toJSON = String . Text.decodeUtf8 . toByteString'
71
69
72newtype List a = L [a]
70newtype List a = L [a]
73− deriving (Eq, Show, Semigroup, Monoid)
71+ deriving (Eq, Show, Monoid)
74
72
75deriveJSON ''List
73deriveJSON ''List
76makePrisms ''List
74makePrisms ''List
@@ -106,7 +104,7 @@ instance ToJSON Date where
106
104
107instance ToByteString Date where
105instance ToByteString Date where
108 builder (D d) = builder
106 builder (D d) = builder
109− (formatTime defaultTimeLocale ("%Y-%m-%dT%XZ") d)
107+ (formatTime defaultTimeLocale (iso8601DateFormat $ Just "%XZ") d)
110
108
111instance QueryValues Date
109instance QueryValues Date
112
110
@@ -133,17 +131,14 @@ data Security = Basic | Token
133 deriving (Eq, Show)
131 deriving (Eq, Show)
134
132
135data Auth (a :: Security) where
133data Auth (a :: Security) where
136− AuthBasic :: ByteString -> ByteString -> Auth 'Basic
134+ AuthBasic :: ByteString -> ByteString -> Auth Basic
137− AuthToken :: ByteString -> Auth 'Token
135+ AuthToken :: ByteString -> Auth Token
138
136
139deriving instance Eq (Auth a)
137deriving instance Eq (Auth a)
140deriving instance Show (Auth a)
138deriving instance Show (Auth a)
141
139
142−newtype SubDomain = SubDomain { subDomain :: ByteString }
140+newtype SubDomain = SubDomain ByteString
143− deriving (Eq, Show, IsString, ToByteString)
141+ deriving (Eq, Show, IsString)
144−
145−mkSubDomain :: ByteString -> SubDomain
146−mkSubDomain = SubDomain
147
142
148domain :: SubDomain -> ByteString
143domain :: SubDomain -> ByteString
149domain (SubDomain s)
144domain (SubDomain s)
@@ -152,35 +147,8 @@ domain (SubDomain s)
152 where
147 where
153 base = ".pagerduty.com"
148 base = ".pagerduty.com"
154
149
155−-- | The log level and associated logger function.
156−data Logger
157− = None
158− | Debug (Text -> IO ())
159−
160−-- | Log a message using the debug logger, or if none is specified noop.
161−debug :: MonadIO m => Logger -> Text -> m ()
162−debug None = const (return ())
163−debug (Debug f) = liftIO . f
164−
165−-- | The environment containing the parameters required to
166−-- make PagerDuty requests.
167−data Env (s :: Security) = Env
168− { _envDomain :: SubDomain
169− , _envAuth' :: Auth s
170− , _envManager :: Manager
171− , _envLogger :: Logger
172− }
173−
174−makeLenses ''Env
175−
176−envAuth :: forall s s'. Lens (Env s) (Env s') (Auth s) (Auth s')
177−envAuth = lens _envAuth' (\s x -> s { _envAuth' = x })
178−
179−prod :: SubDomain -> Auth s -> Manager -> Env s
180−prod d a m = Env d a m None
181−
182newtype Code = Code Integer
150newtype Code = Code Integer
183− deriving (Eq, Show, Num)
151+ deriving (Eq, Show)
184
152
185deriveJSON ''Code
153deriveJSON ''Code
186
154
@@ -202,15 +170,6 @@ description (Code c) =
202 2012 -> "Your account is expired and cannot use the API"
170 2012 -> "Your account is expired and cannot use the API"
203 _ -> "Unrecognised error code"
171 _ -> "Unrecognised error code"
204
172
205−class HasMessage s a | s -> a where
206− -- | A short human-readable message describing the error.
207− message :: Lens' s a
208−
209−class HasErrors s a | s -> a where
210− -- | A list of human-readable reasons for the error. These values,
211− -- and even their format, are subject to change.
212− errors :: Lens' s a
213−
214data IntegrationError = IntegrationError
173data IntegrationError = IntegrationError
215 { _ieStatus :: Text
174 { _ieStatus :: Text
216 , _ieMessage :: Text
175 , _ieMessage :: Text
@@ -219,53 +178,26 @@ data IntegrationError = IntegrationError
219
178
220deriveRecord ''IntegrationError
179deriveRecord ''IntegrationError
221
180
222−instance HasMessage IntegrationError Text where message = ieMessage
181+data RestError = RestError
223−instance HasErrors IntegrationError [Text] where errors = ieErrors
224−
225−status :: Lens' IntegrationError Text
226−status = ieStatus
227−
228−data RESTError = RESTError
229 { _reCode :: Code
182 { _reCode :: Code
230 , _reMessage :: Text
183 , _reMessage :: Text
231 , _reErrors :: [Text]
184 , _reErrors :: [Text]
232 } deriving (Eq, Show)
185 } deriving (Eq, Show)
233
186
234−deriveRecord ''RESTError
187+deriveRecord ''RestError
235−
236−instance HasMessage RESTError Text where message = reMessage
237−instance HasErrors RESTError [Text] where errors = reErrors
238−
239−-- | In the case of an error, the PagerDuty error code can give further details
240−-- on the nature of the error.
241−--
242−-- /See:/ 'description'
243−code :: Lens' RESTError Code
244−code = reCode
245
188
246data Error
189data Error
247− = Internal Text
190+ = Internal String
248 | Integration IntegrationError
191 | Integration IntegrationError
249− | REST RESTError
192+ | Rest RestError
250 deriving (Eq, Show)
193 deriving (Eq, Show)
251
194
252instance FromJSON Error where
195instance FromJSON Error where
253− parseJSON o = (REST <$> parseJSON o)
196+ parseJSON o = (Rest <$> parseJSON o)
254 <|> (Integration <$> parseJSON o)
197 <|> (Integration <$> parseJSON o)
255
198
256makePrisms ''Error
199makePrisms ''Error
257
200
258−instance HasMessage Error Text where
259− message = lens f g
260− where
261− f (Internal x) = x
262− f (Integration s) = _ieMessage s
263− f (REST s) = _reMessage s
264−
265− g (Internal _) x = Internal x
266− g (Integration s) x = Integration $ s { _ieMessage = x }
267− g (REST s) x = REST $ s { _reMessage = x }
268−
269data Pager = Pager
201data Pager = Pager
270 { _pgOffset :: !Int
202 { _pgOffset :: !Int
271 -- ^ The offset used in the execution of the query.
203 -- ^ The offset used in the execution of the query.
@@ -279,13 +211,8 @@ data Pager = Pager
279
211
280makeLenses ''Pager
212makeLenses ''Pager
281
213
282−data Page a = Page
214+instance FromJSON a => FromJSON (a, Maybe Pager) where
283− { _pgItem :: a
284− , _pgPager :: Maybe Pager
285− }
286−
287−instance FromJSON a => FromJSON (Page a) where
288− parseJSON = withObject "paginated" $ \o -> Page
215+ parseJSON = withObject "paginated" $ \o -> (,)
289 <$> parseJSON (Object o)
216 <$> parseJSON (Object o)
290 <*> optional (parse o)
217 <*> optional (parse o)
291 where
218 where
@@ -310,13 +237,11 @@ data Path where
310 Path :: Path
237 Path :: Path
311 Seg :: ToByteString a => a -> Path
238 Seg :: ToByteString a => a -> Path
312
239
313−instance Semigroup Path where
314− x <> Path = x
315− Path <> y = y
316− Seg x <> Seg y = Seg (builder x <> "/" <> builder y)
317−
318instance Monoid Path where
240instance Monoid Path where
319− mempty = Path
241+ mempty = Path
242+ mappend x Path = x
243+ mappend Path y = y
244+ mappend (Seg x) (Seg y) = Seg (builder x <> "/" <> builder y)
320
245
321instance IsString Path where
246instance IsString Path where
322 fromString = Seg
247 fromString = Seg
@@ -393,13 +318,13 @@ class Paginate a where
393 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
318 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
394 next rq = maybe Nothing go
319 next rq = maybe Nothing go
395 where
320 where
396− go x | x ^. pgTotal == 0 = Nothing
321+ go x | x^.pgTotal == 0 = Nothing
397− | otherwise = Just $
322+ | otherwise = Just $
398− rq & pager ?~ (x & pgOffset +~ x ^. pgTotal)
323+ rq & pager ?~ (x & pgOffset +~ x^.pgTotal)
399 & query %~ (add . clear)
324 & query %~ (add . clear)
400 where
325 where
401 add :: Query -> Query
326 add :: Query -> Query
402− add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x ^. pgQuery)
327+ add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x^.pgQuery)
403
328
404 clear :: Query -> Query
329 clear :: Query -> Query
405 clear = deleteBy ((==) `on` fst) (k, Nothing)
330 clear = deleteBy ((==) `on` fst) (k, Nothing)
@@ -410,9 +335,6 @@ class Paginate a where
410newtype Key (a :: Symbol) = Key Text
335newtype Key (a :: Symbol) = Key Text
411 deriving (Eq, Show, IsString)
336 deriving (Eq, Show, IsString)
412
337
413−mkKey :: Text -> Key a
414−mkKey = Key
415−
416instance FromJSON (Key a) where
338instance FromJSON (Key a) where
417 parseJSON = withText "key" (return . Key)
339 parseJSON = withText "key" (return . Key)
418
340
@@ -433,9 +355,6 @@ type IncidentKey = Key "incident"
433newtype Id (a :: Symbol) = Id Text
355newtype Id (a :: Symbol) = Id Text
434 deriving (Eq, Show, IsString)
356 deriving (Eq, Show, IsString)
435
357
436−mkId :: Text -> Id a
437−mkId = Id
438−
439instance FromJSON (Id a) where
358instance FromJSON (Id a) where
440 parseJSON = withText "id" (return . Id)
359 parseJSON = withText "id" (return . Id)
441
360
@@ -483,10 +402,7 @@ instance QueryLike Empty where
483 toQuery = const []
402 toQuery = const []
484
403
485newtype Address = Address Text
404newtype Address = Address Text
486− deriving (Eq, Show, IsString)
405+ deriving (Eq, Show)
487−
488−mkAddress :: Text -> Address
489−mkAddress = Address
490
406
491deriveJSON ''Address
407deriveJSON ''Address
492makePrisms ''Address
408makePrisms ''Address
src/Network/PagerDuty/REST.hs+29−41
@@ -2,7 +2,7 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3
3
4-- Module : Network.PagerDuty.REST
4-- Module : Network.PagerDuty.REST
5−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
5+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
6-- License : This Source Code Form is subject to the terms of
6-- License : This Source Code Form is subject to the terms of
7-- the Mozilla Public License, v. 2.0.
7-- the Mozilla Public License, v. 2.0.
8-- A copy of the MPL can be found in the LICENSE file or
8-- A copy of the MPL can be found in the LICENSE file or
@@ -15,11 +15,7 @@ module Network.PagerDuty.REST
15 (
15 (
16 -- * Sending requests
16 -- * Sending requests
17 send
17 send
18− , sendWith
19 , paginate
18 , paginate
20− , paginateWith
21−
22− , module Network.PagerDuty.Types
23 ) where
19 ) where
24
20
25import Control.Applicative
21import Control.Applicative
@@ -27,69 +23,61 @@ import Control.Lens
27import Control.Monad
23import Control.Monad
28import Control.Monad.IO.Class
24import Control.Monad.IO.Class
29import Control.Monad.Trans
25import Control.Monad.Trans
30−import Data.Aeson (FromJSON)
26+import Data.Aeson (FromJSON)
31import Data.Conduit
27import Data.Conduit
28+import Data.Default.Class
32import Data.Monoid
29import Data.Monoid
33−import Network.HTTP.Client (Manager)
30+import Network.HTTP.Client (Manager)
34−import qualified Network.HTTP.Client as Client
31+import qualified Network.HTTP.Client as Client
35import Network.HTTP.Types
32import Network.HTTP.Types
36import Network.PagerDuty.Internal.IO
33import Network.PagerDuty.Internal.IO
37import Network.PagerDuty.Internal.Types
34import Network.PagerDuty.Internal.Types
38−import Network.PagerDuty.Types
35+
36+-- Make the type names consistent, for example:
37+-- Suffix with *Details or *Info for results
38+-- No suffix for requests if necessary
39
39
40-- FIXME: verify correct actions are all paginated
40-- FIXME: verify correct actions are all paginated
41−-- FIXME: Ensure RequesterId parameter is always most significant param
42−-- FIXME: add smart constructors for all types, for testing purposes
43
41
44−-- | /See:/ 'sendWith'
42+-- FIXME: Ensure requesterid parameter is always first
43+
45send :: (MonadIO m, FromJSON b)
44send :: (MonadIO m, FromJSON b)
46− => SubDomain
45+ => Auth s
47− -> Auth s
46+ -> SubDomain
48 -> Manager
47 -> Manager
49 -> Request a s b
48 -> Request a s b
50 -> m (Either Error b)
49 -> m (Either Error b)
51−send d a m = sendWith (prod d a m)
50+send a s m = liftM (fmap fst) . http a s m
52
51
53−sendWith :: (MonadIO m, FromJSON b)
54− => Env s
55− -> Request a s b
56− -> m (Either Error b)
57−sendWith e = liftM (fmap _pgItem) . http e
58−
59−-- | /See:/ 'paginateWith'
60paginate :: (MonadIO m, Paginate a, FromJSON b)
52paginate :: (MonadIO m, Paginate a, FromJSON b)
61− => SubDomain
53+ => Auth s
62− -> Auth s
54+ -> SubDomain
63 -> Manager
55 -> Manager
64 -> Request a s b
56 -> Request a s b
65 -> Source m (Either Error b)
57 -> Source m (Either Error b)
66−paginate d a m = paginateWith (prod d a m)
58+paginate a d m = go
67−
68−paginateWith :: (MonadIO m, Paginate a, FromJSON b)
69− => Env s
70− -> Request a s b
71− -> Source m (Either Error b)
72−paginateWith e = go
73 where
59 where
74 go rq = do
60 go rq = do
75− rs <- lift (http e rq)
61+ rs <- lift (http a d m rq)
76− yield (_pgItem <$> rs)
62+ yield (fst <$> rs)
77 either (const (return ()))
63 either (const (return ()))
78− (maybe (return ()) go . next rq . _pgPager)
64+ (maybe (return ()) go . next rq . snd)
79 rs
65 rs
80
66
81http :: (MonadIO m, FromJSON b)
67http :: (MonadIO m, FromJSON b)
82− => Env s
68+ => Auth s
69+ -> SubDomain
70+ -> Manager
83 -> Request a s b
71 -> Request a s b
84− -> m (Either Error (Page b))
72+ -> m (Either Error (b, Maybe Pager))
85−http e rq = request (e ^. envManager) (e ^. envLogger) rq $ raw
73+http a (SubDomain h) m rq = request m rq $ raw
86− { Client.host = domain (e ^. envDomain)
74+ { Client.host = h
87 , Client.path = renderPath (rq ^. path)
75 , Client.path = renderPath (rq ^. path)
88 , Client.queryString = renderQuery False (rq ^. query)
76 , Client.queryString = renderQuery False (rq ^. query)
89 }
77 }
90 where
78 where
91− raw = case e ^. envAuth of
79+ raw = case a of
92− AuthBasic u p -> Client.applyBasicAuth u p Client.defaultRequest
80+ AuthBasic u p -> Client.applyBasicAuth u p def
93− AuthToken t -> Client.defaultRequest
81+ AuthToken t -> def
94 { Client.requestHeaders = [("Authorization", "Token token=" <> t)]
82 { Client.requestHeaders = [("Authorization", "Token token=" <> t)]
95 }
83 }
src/Network/PagerDuty/REST/Alerts.hs+7−7
@@ -4,7 +4,7 @@
4{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE TypeFamilies #-}
5
5
6-- Module : Network.PagerDuty.REST.Alerts
6-- Module : Network.PagerDuty.REST.Alerts
7−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
7+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
8-- License : This Source Code Form is subject to the terms of
8-- License : This Source Code Form is subject to the terms of
9-- the Mozilla Public License, v. 2.0.
9-- the Mozilla Public License, v. 2.0.
10-- A copy of the MPL can be found in the LICENSE file or
10-- A copy of the MPL can be found in the LICENSE file or
@@ -43,12 +43,12 @@ module Network.PagerDuty.REST.Alerts
43 , alertAddress
43 , alertAddress
44 ) where
44 ) where
45
45
46−import Control.Lens hiding (Empty)
46+import Control.Lens
47−import Data.Aeson.Lens
47+import Data.Aeson.Lens
48−import Data.Time
48+import Data.Time
49−import Network.PagerDuty.Internal.TH
50−import Network.PagerDuty.Internal.Types
51−import Network.PagerDuty.REST.Users (User)
49+import Network.PagerDuty.REST.Users (User)
50+import Network.PagerDuty.Internal.TH
51+import Network.PagerDuty.Internal.Types
52
52
53alerts :: Path
53alerts :: Path
54alerts = "alerts"
54alerts = "alerts"
src/Network/PagerDuty/REST/EscalationPolicies.hs+14−14
@@ -1,13 +1,13 @@
1+{-# LANGUAGE ExtendedDefaultRules #-}
1−{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeFamilies #-}
6
6
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
8
8
9-- Module : Network.PagerDuty.REST.EscalationPolicies
9-- Module : Network.PagerDuty.REST.EscalationPolicies
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
10+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
11-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
12-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
13-- A copy of the MPL can be found in the LICENSE file or
@@ -60,15 +60,15 @@ module Network.PagerDuty.REST.EscalationPolicies
60 , pServices
60 , pServices
61 ) where
61 ) where
62
62
63−import Control.Lens hiding (Empty)
63+import Control.Lens
64−import Data.Aeson.Lens
64+import Data.Aeson.Lens
65−import Data.Text (Text)
65+import Data.Text (Text)
66−import Network.HTTP.Types
66+import Network.HTTP.Types
67−import Network.PagerDuty.Internal.TH
68−import Network.PagerDuty.Internal.Types
69−import Network.PagerDuty.REST.Services (Service)
67+import Network.PagerDuty.REST.Services (Service)
68+import Network.PagerDuty.Internal.TH
69+import Network.PagerDuty.Internal.Types
70
70
71−import Network.PagerDuty.REST.EscalationPolicies.EscalationRules
71+import Network.PagerDuty.REST.EscalationPolicies.EscalationRules
72
72
73default (Path)
73default (Path)
74
74
src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs+10−10
@@ -1,12 +1,12 @@
1−{-# LANGUAGE ExtendedDefaultRules #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2−{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE FlexibleInstances #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5
5
6{-# OPTIONS_GHC -fno-warn-type-defaults #-}
6{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7
7
8-- Module : Network.PagerDuty.REST.EscalationPolicies.EscalationRules
8-- Module : Network.PagerDuty.REST.EscalationPolicies.EscalationRules
9−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
9+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
10-- License : This Source Code Form is subject to the terms of
10-- License : This Source Code Form is subject to the terms of
11-- the Mozilla Public License, v. 2.0.
11-- the Mozilla Public License, v. 2.0.
12-- A copy of the MPL can be found in the LICENSE file or
12-- A copy of the MPL can be found in the LICENSE file or
@@ -64,15 +64,15 @@ module Network.PagerDuty.REST.EscalationPolicies.EscalationRules
64 , rTargets
64 , rTargets
65 ) where
65 ) where
66
66
67−import Control.Applicative ((<$>))
67+import Control.Applicative ((<$>))
68−import Control.Lens hiding ((.=))
68+import Control.Lens hiding ((.=))
69import Data.Aeson
69import Data.Aeson
70−import qualified Data.Aeson.KeyMap as Map
70+import qualified Data.HashMap.Strict as Map
71−import Data.Text (Text)
71+import Data.Text (Text)
72import Network.HTTP.Types
72import Network.HTTP.Types
73+import Network.PagerDuty.REST.Users
73import Network.PagerDuty.Internal.TH
74import Network.PagerDuty.Internal.TH
74import Network.PagerDuty.Internal.Types
75import Network.PagerDuty.Internal.Types
75−import Network.PagerDuty.REST.Users
76
76
77default (Path)
77default (Path)
78
78
src/Network/PagerDuty/REST/Incidents.hs+24−20
@@ -10,7 +10,7 @@
10{-# OPTIONS_GHC -fno-warn-type-defaults #-}
10{-# OPTIONS_GHC -fno-warn-type-defaults #-}
11
11
12-- Module : Network.PagerDuty.REST.Incidents
12-- Module : Network.PagerDuty.REST.Incidents
13−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
13+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
14-- License : This Source Code Form is subject to the terms of
14-- License : This Source Code Form is subject to the terms of
15-- the Mozilla Public License, v. 2.0.
15-- the Mozilla Public License, v. 2.0.
16-- A copy of the MPL can be found in the LICENSE file or
16-- A copy of the MPL can be found in the LICENSE file or
@@ -129,16 +129,14 @@ module Network.PagerDuty.REST.Incidents
129 , Incident
129 , Incident
130 ) where
130 ) where
131
131
132−import Control.Applicative hiding (empty)
132+import Control.Applicative hiding (empty)
133−import Control.Lens hiding (Empty)
133+import Control.Lens
134import Data.Aeson
134import Data.Aeson
135−import Data.ByteString.Conversion (ToByteString (..),
135+import Data.ByteString.Conversion (ToByteString(..), toByteString')
136− toByteString')
137import Data.Default.Class
136import Data.Default.Class
138−import Data.Maybe
139−import Data.Monoid hiding (All)
137+import Data.Monoid hiding (All)
140−import Data.Text (Text)
138+import Data.Text (Text)
141−import qualified Data.Text.Encoding as Text
139+import qualified Data.Text.Encoding as Text
142import Data.Time
140import Data.Time
143import Network.HTTP.Types
141import Network.HTTP.Types
144import Network.PagerDuty.Internal.Query
142import Network.PagerDuty.Internal.Query
@@ -347,10 +345,13 @@ lsUntil = upd.lsUntil'.mapping _D
347-- | When set, the since and until parameters and defaults are
345-- | When set, the since and until parameters and defaults are
348-- ignored. Use this to get all incidents since the account was created.
346-- ignored. Use this to get all incidents since the account was created.
349lsDateRange :: Lens' (Request ListIncidents s b) Bool
347lsDateRange :: Lens' (Request ListIncidents s b) Bool
350−lsDateRange = upd.lens get_ (flip set_)
348+lsDateRange = upd . lens get_ set_
351 where
349 where
352− get_ = (Just All ==) . view lsDateRange'
350+ get_ x
353− set_ x = lsDateRange' .~ listToMaybe [All | x]
351+ | Just All <- _lsDateRange' x = True
352+ | otherwise = False
353+
354+ set_ l x = l { _lsDateRange' = if x then Just All else Nothing }
354
355
355-- | Returns only the incidents currently in the passed status(es).
356-- | Returns only the incidents currently in the passed status(es).
356lsStatus :: Lens' (Request ListIncidents s b) (Maybe [IncidentStatus])
357lsStatus :: Lens' (Request ListIncidents s b) (Maybe [IncidentStatus])
@@ -437,12 +438,12 @@ cSince = upd.cSince'.mapping _D
437
438
438-- | The end of the date range over which you want to search.
439-- | The end of the date range over which you want to search.
439--
440--
440−-- /Note:/ If you leave off either since or until, a 30 day default range is
441+-- /Note: If you leave off either since or until, a 30 day default range is
441-- applied to your open ended range. Not including the since parameter will set
442-- applied to your open ended range. Not including the since parameter will set
442−-- the date range to until @-30@ days. Likewise, if you leave off until,
443+-- the date range to until - 30 days. Likewise, if you leave off until,
443−-- it is set to since @+30@ days.
444+-- it is set to since + 30 days.
444--
445--
445−-- /Default:/ The last 30 days if you leave off both. The size of the date
446+-- Defaults to the last 30 days if you leave off both. The size of the date
446-- range must be less than 180 days.
447-- range must be less than 180 days.
447cUntil :: Lens' (Request CountIncidents s b) (Maybe UTCTime)
448cUntil :: Lens' (Request CountIncidents s b) (Maybe UTCTime)
448cUntil = upd.cUntil'.mapping _D
449cUntil = upd.cUntil'.mapping _D
@@ -450,10 +451,13 @@ cUntil = upd.cUntil'.mapping _D
450-- | When set, the since and until parameters and defaults are
451-- | When set, the since and until parameters and defaults are
451-- ignored. Use this to get all counts since the account was created.
452-- ignored. Use this to get all counts since the account was created.
452cDateRange :: Lens' (Request CountIncidents s b) Bool
453cDateRange :: Lens' (Request CountIncidents s b) Bool
453−cDateRange = upd.lens get_ (flip set_)
454+cDateRange = upd . lens get_ set_
454 where
455 where
455− get_ = (Just All ==) . view cDateRange'
456+ get_ x
456− set_ x = cDateRange' .~ listToMaybe [All | x]
457+ | Just All <- _cDateRange' x = True
458+ | otherwise = False
459+
460+ set_ l x = l { _cDateRange' = if x then Just All else Nothing }
457
461
458-- | Only counts the incidents currently in the passed status(es).
462-- | Only counts the incidents currently in the passed status(es).
459cStatus :: Lens' (Request CountIncidents s b) (Maybe [IncidentStatus])
463cStatus :: Lens' (Request CountIncidents s b) (Maybe [IncidentStatus])
@@ -567,7 +571,7 @@ updateIncidents r = auth updateIncidentsBasic & query .~ [("requester_id", r)]
567
571
568-- | A version of 'updateIncidents' which uses HTTP Basic authentication and
572-- | A version of 'updateIncidents' which uses HTTP Basic authentication and
569-- doesn't require a 'RequesterId'.
573-- doesn't require a 'RequesterId'.
570−updateIncidentsBasic :: Request UpdateIncidents 'Basic [UpdatedIncidents]
574+updateIncidentsBasic :: Request UpdateIncidents Basic [UpdatedIncidents]
571updateIncidentsBasic =
575updateIncidentsBasic =
572 mk UpdateIncidents
576 mk UpdateIncidents
573 { _uiIncidents' = []
577 { _uiIncidents' = []
src/Network/PagerDuty/REST/Incidents/Notes.hs+12−12
@@ -1,11 +1,11 @@
1−{-# LANGUAGE ExtendedDefaultRules #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
4
4
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
6
6
7-- Module : Network.PagerDuty.REST.Incidents.Notes
7-- Module : Network.PagerDuty.REST.Incidents.Notes
8−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
8+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
9-- License : This Source Code Form is subject to the terms of
9-- License : This Source Code Form is subject to the terms of
10-- the Mozilla Public License, v. 2.0.
10-- the Mozilla Public License, v. 2.0.
11-- A copy of the MPL can be found in the LICENSE file or
11-- A copy of the MPL can be found in the LICENSE file or
@@ -36,14 +36,14 @@ module Network.PagerDuty.REST.Incidents.Notes
36 , nContent
36 , nContent
37 ) where
37 ) where
38
38
39−import Control.Lens hiding ((.=))
39+import Control.Lens hiding ((.=))
40−import Data.Aeson
40+import Data.Aeson
41−import Data.Text (Text)
41+import Data.Text (Text)
42−import Data.Time
42+import Data.Time
43−import Network.HTTP.Types
43+import Network.HTTP.Types
44−import Network.PagerDuty.Internal.TH
45−import Network.PagerDuty.Internal.Types
46−import Network.PagerDuty.REST.Users
44+import Network.PagerDuty.REST.Users
45+import Network.PagerDuty.Internal.TH
46+import Network.PagerDuty.Internal.Types
47
47
48default (Path)
48default (Path)
49
49
src/Network/PagerDuty/REST/LogEntries.hs+7−6
@@ -5,7 +5,7 @@
5{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE TypeFamilies #-}
6
6
7-- Module : Network.PagerDuty.REST.LogEntries
7-- Module : Network.PagerDuty.REST.LogEntries
8−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
8+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
9-- License : This Source Code Form is subject to the terms of
9-- License : This Source Code Form is subject to the terms of
10-- the Mozilla Public License, v. 2.0.
10-- the Mozilla Public License, v. 2.0.
11-- A copy of the MPL can be found in the LICENSE file or
11-- A copy of the MPL can be found in the LICENSE file or
@@ -111,18 +111,19 @@ module Network.PagerDuty.REST.LogEntries
111 , nAddress
111 , nAddress
112 ) where
112 ) where
113
113
114−import Control.Lens hiding (Empty)
114+import Control.Applicative
115+import Control.Lens
115import Data.Aeson
116import Data.Aeson
116import Data.Aeson.Lens
117import Data.Aeson.Lens
117−import qualified Data.Aeson.KeyMap as Map
118import Data.Default.Class
118import Data.Default.Class
119+import qualified Data.HashMap.Strict as Map
119−import Data.Text (Text)
120+import Data.Text (Text)
120−import qualified Data.Text as Text
121+import qualified Data.Text as Text
121import Data.Time
122import Data.Time
122import Network.HTTP.Types
123import Network.HTTP.Types
124+import Network.PagerDuty.REST.Users (User)
123import Network.PagerDuty.Internal.TH
125import Network.PagerDuty.Internal.TH
124import Network.PagerDuty.Internal.Types
126import Network.PagerDuty.Internal.Types
125−import Network.PagerDuty.REST.Users (User)
126
127
127logs :: Path
128logs :: Path
128logs = "log_entries"
129logs = "log_entries"
src/Network/PagerDuty/REST/MaintenanceWindows.hs+10−10
@@ -4,7 +4,7 @@
4{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE TypeFamilies #-}
5
5
6-- Module : Network.PagerDuty.REST.MaintenanceWindows
6-- Module : Network.PagerDuty.REST.MaintenanceWindows
7−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
7+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
8-- License : This Source Code Form is subject to the terms of
8-- License : This Source Code Form is subject to the terms of
9-- the Mozilla Public License, v. 2.0.
9-- the Mozilla Public License, v. 2.0.
10-- A copy of the MPL can be found in the LICENSE file or
10-- A copy of the MPL can be found in the LICENSE file or
@@ -74,14 +74,14 @@ module Network.PagerDuty.REST.MaintenanceWindows
74 , mwServices
74 , mwServices
75 ) where
75 ) where
76
76
77−import Control.Lens hiding (Empty)
77+import Control.Lens
78−import Data.Monoid
78+import Data.Monoid
79−import Data.Text (Text)
79+import Data.Text (Text)
80−import Data.Time
80+import Data.Time
81−import Network.HTTP.Types
81+import Network.HTTP.Types
82−import Network.PagerDuty.Internal.TH
83−import Network.PagerDuty.Internal.Types
84−import Network.PagerDuty.REST.Users (User)
82+import Network.PagerDuty.REST.Users (User)
83+import Network.PagerDuty.Internal.TH
84+import Network.PagerDuty.Internal.Types
85
85
86windows :: Path
86windows :: Path
87windows = "maintenance_windows"
87windows = "maintenance_windows"
@@ -214,7 +214,7 @@ createWindow r s e xs =
214createWindowBasic :: UTCTime -- ^ 'cwStartTime'
214createWindowBasic :: UTCTime -- ^ 'cwStartTime'
215 -> UTCTime -- ^ 'cwEndTime'
215 -> UTCTime -- ^ 'cwEndTime'
216 -> [ServiceId] -- ^ 'cwServiceIds'
216 -> [ServiceId] -- ^ 'cwServiceIds'
217− -> Request CreateWindow 'Basic MaintenanceWindow
217+ -> Request CreateWindow Basic MaintenanceWindow
218createWindowBasic s e xs =
218createWindowBasic s e xs =
219 mk CreateWindow
219 mk CreateWindow
220 { _cwRequesterId' = Nothing
220 { _cwRequesterId' = Nothing
src/Network/PagerDuty/REST/Reports.hs+11−11
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeFamilies #-}
6
6
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
8
8
9-- Module : Network.PagerDuty.REST.Reports
9-- Module : Network.PagerDuty.REST.Reports
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
10+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
11-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
12-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
13-- A copy of the MPL can be found in the LICENSE file or
@@ -58,11 +58,11 @@ module Network.PagerDuty.REST.Reports
58 , irNumberOfIncidents
58 , irNumberOfIncidents
59 ) where
59 ) where
60
60
61−import Control.Lens hiding (Empty)
61+import Control.Lens
62−import Data.Aeson.Lens
62+import Data.Aeson.Lens
63−import Data.Time
63+import Data.Time
64−import Network.PagerDuty.Internal.TH
64+import Network.PagerDuty.Internal.TH
65−import Network.PagerDuty.Internal.Types
65+import Network.PagerDuty.Internal.Types
66
66
67default (Path)
67default (Path)
68
68
src/Network/PagerDuty/REST/Schedules.hs+14−14
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeFamilies #-}
6
6
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
8
8
9-- Module : Network.PagerDuty.REST.Schedules
9-- Module : Network.PagerDuty.REST.Schedules
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
10+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
11-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
12-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
13-- A copy of the MPL can be found in the LICENSE file or
@@ -110,14 +110,14 @@ module Network.PagerDuty.REST.Schedules
110 , sFinalSchedule
110 , sFinalSchedule
111 ) where
111 ) where
112
112
113−import Control.Lens hiding (Empty, (.=))
113+import Control.Lens hiding ((.=))
114−import Data.Aeson
114+import Data.Aeson
115−import Data.Text (Text)
115+import Data.Text (Text)
116−import Data.Time
116+import Data.Time
117−import Network.HTTP.Types
117+import Network.HTTP.Types
118−import Network.PagerDuty.Internal.TH
119−import Network.PagerDuty.Internal.Types
120−import Network.PagerDuty.REST.Users (User)
118+import Network.PagerDuty.REST.Users (User)
119+import Network.PagerDuty.Internal.TH
120+import Network.PagerDuty.Internal.Types
121
121
122default (Path)
122default (Path)
123
123
src/Network/PagerDuty/REST/Schedules/Overrides.hs+12−12
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeFamilies #-}
6
6
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
8
8
9-- Module : Network.PagerDuty.REST.Schedules
9-- Module : Network.PagerDuty.REST.Schedules
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
10+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
11-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
12-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
13-- A copy of the MPL can be found in the LICENSE file or
@@ -50,12 +50,12 @@ module Network.PagerDuty.REST.Schedules.Overrides
50 , oUser
50 , oUser
51 ) where
51 ) where
52
52
53−import Control.Lens
53+import Control.Lens
54−import Data.Time
54+import Data.Time
55−import Network.HTTP.Types
55+import Network.HTTP.Types
56−import Network.PagerDuty.Internal.TH
57−import Network.PagerDuty.Internal.Types
58−import Network.PagerDuty.REST.Users
56+import Network.PagerDuty.REST.Users
57+import Network.PagerDuty.Internal.TH
58+import Network.PagerDuty.Internal.Types
59
59
60overrides :: ScheduleId -> Path
60overrides :: ScheduleId -> Path
61overrides i = "schedules" % i % "overrides"
61overrides i = "schedules" % i % "overrides"
src/Network/PagerDuty/REST/Services.hs+16−16
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeFamilies #-}
6
6
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
8
8
9-- Module : Network.PagerDuty.REST.Services
9-- Module : Network.PagerDuty.REST.Services
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
10+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
11-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
12-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
13-- A copy of the MPL can be found in the LICENSE file or
@@ -106,14 +106,14 @@ module Network.PagerDuty.REST.Services
106 , svcSeverityFilter
106 , svcSeverityFilter
107 ) where
107 ) where
108
108
109−import Control.Lens hiding (Empty)
109+import Control.Lens
110−import Data.Aeson.Lens
110+import Data.Aeson.Lens
111−import Data.Text (Text)
111+import Data.Text (Text)
112−import Data.Time
112+import Data.Time
113−import Network.HTTP.Types
113+import Network.HTTP.Types
114−import Network.PagerDuty.Internal.TH
115−import Network.PagerDuty.Internal.Types
116−import Network.PagerDuty.REST.Services.EmailFilters
114+import Network.PagerDuty.REST.Services.EmailFilters
115+import Network.PagerDuty.Internal.TH
116+import Network.PagerDuty.Internal.Types
117
117
118default (Path)
118default (Path)
119
119
@@ -483,7 +483,7 @@ enableService r i =
483
483
484-- | A version of 'enableService' which uses HTTP Basic authentication and
484-- | A version of 'enableService' which uses HTTP Basic authentication and
485-- doesn't require a 'RequesterId'.
485-- doesn't require a 'RequesterId'.
486−enableServiceBasic :: ServiceId -> Request Empty 'Basic Empty
486+enableServiceBasic :: ServiceId -> Request Empty Basic Empty
487enableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "enable"
487enableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "enable"
488
488
489-- | Disable a service. Once a service is disabled, it will not be able to
489-- | Disable a service. Once a service is disabled, it will not be able to
@@ -498,7 +498,7 @@ disableService r i =
498
498
499-- | A version of 'disableService' which uses HTTP Basic authentication and
499-- | A version of 'disableService' which uses HTTP Basic authentication and
500-- doesn't require a 'RequesterId'.
500-- doesn't require a 'RequesterId'.
501−disableServiceBasic :: ServiceId -> Request Empty 'Basic Empty
501+disableServiceBasic :: ServiceId -> Request Empty Basic Empty
502disableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "disable"
502disableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "disable"
503
503
504-- | Regenerate a new service key for an existing service.
504-- | Regenerate a new service key for an existing service.
src/Network/PagerDuty/REST/Services/EmailFilters.hs+14−14
@@ -1,11 +1,11 @@
1−{-# LANGUAGE ExtendedDefaultRules #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
4
4
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
6
6
7-- Module : Network.PagerDuty.REST.Services.EmailFilters
7-- Module : Network.PagerDuty.REST.Services.EmailFilters
8−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
8+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
9-- License : This Source Code Form is subject to the terms of
9-- License : This Source Code Form is subject to the terms of
10-- the Mozilla Public License, v. 2.0.
10-- the Mozilla Public License, v. 2.0.
11-- A copy of the MPL can be found in the LICENSE file or
11-- A copy of the MPL can be found in the LICENSE file or
@@ -39,15 +39,15 @@ module Network.PagerDuty.REST.Services.EmailFilters
39 , efId
39 , efId
40 ) where
40 ) where
41
41
42−import Control.Applicative hiding (empty)
42+import Control.Applicative hiding (empty)
43−import Control.Lens hiding ((.=))
43+import Control.Lens hiding ((.=))
44−import Data.Aeson
44+import Data.Aeson
45−import Data.Default.Class
45+import Data.Default.Class
46−import Data.Monoid
46+import Data.Monoid
47−import Data.Text (Text)
47+import Data.Text (Text)
48−import Network.HTTP.Types
48+import Network.HTTP.Types
49−import Network.PagerDuty.Internal.TH
49+import Network.PagerDuty.Internal.TH
50−import Network.PagerDuty.Internal.Types
50+import Network.PagerDuty.Internal.Types
51
51
52default (Path)
52default (Path)
53
53
@@ -65,7 +65,7 @@ deriveNullaryWith hyphenated ''MatchMode
65-- FIXME: Tighten up this type! Make the regex required for match/no-match and
65-- FIXME: Tighten up this type! Make the regex required for match/no-match and
66-- encode the conditional invariants.
66-- encode the conditional invariants.
67data EmailFilterInfo = EmailFilterInfo
67data EmailFilterInfo = EmailFilterInfo
68− { _efSubjectMode' :: Maybe MatchMode
68+ { _efSubjectMode' :: Maybe MatchMode
69 , _efSubjectRegex' :: Maybe Text
69 , _efSubjectRegex' :: Maybe Text
70 , _efBodyMode' :: Maybe MatchMode
70 , _efBodyMode' :: Maybe MatchMode
71 , _efBodyRegex' :: Maybe Text
71 , _efBodyRegex' :: Maybe Text
src/Network/PagerDuty/REST/Users.hs+17−17
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TemplateHaskell #-}
5−{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeFamilies #-}
6
6
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
8
8
9-- Module : Network.PagerDuty.REST.Users
9-- Module : Network.PagerDuty.REST.Users
10−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
10+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
11-- License : This Source Code Form is subject to the terms of
11-- License : This Source Code Form is subject to the terms of
12-- the Mozilla Public License, v. 2.0.
12-- the Mozilla Public License, v. 2.0.
13-- A copy of the MPL can be found in the LICENSE file or
13-- A copy of the MPL can be found in the LICENSE file or
@@ -81,16 +81,16 @@ module Network.PagerDuty.REST.Users
81 , uJobTitle
81 , uJobTitle
82 ) where
82 ) where
83
83
84−import Control.Applicative hiding (empty)
84+import Control.Applicative hiding (empty)
85−import Control.Lens hiding (Empty, (.=))
85+import Control.Lens hiding ((.=))
86−import Data.Aeson
86+import Data.Aeson
87−import Data.Default.Class
87+import Data.Default.Class
88−import Data.Monoid
88+import Data.Monoid
89−import Data.Text (Text)
89+import Data.Text (Text)
90−import Data.Time
90+import Data.Time
91−import Network.HTTP.Types
91+import Network.HTTP.Types
92−import Network.PagerDuty.Internal.TH
92+import Network.PagerDuty.Internal.TH
93−import Network.PagerDuty.Internal.Types
93+import Network.PagerDuty.Internal.Types
94
94
95default (Path)
95default (Path)
96
96
@@ -315,7 +315,7 @@ createUser r n e = auth (createUserBasic n e) & query .~ [("requester_id", r)]
315-- doesn't require a 'RequesterId'.
315-- doesn't require a 'RequesterId'.
316createUserBasic :: Text -- ^ 'cuName'
316createUserBasic :: Text -- ^ 'cuName'
317 -> Address -- ^ 'cuEmail'
317 -> Address -- ^ 'cuEmail'
318− -> Request CreateUser 'Basic User
318+ -> Request CreateUser Basic User
319createUserBasic n e =
319createUserBasic n e =
320 mk CreateUser
320 mk CreateUser
321 { _cuName' = n
321 { _cuName' = n
src/Network/PagerDuty/REST/Users/ContactMethods.hs+10−10
@@ -1,11 +1,11 @@
1−{-# LANGUAGE ExtendedDefaultRules #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
4
4
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
6
6
7-- Module : Network.PagerDuty.REST.Users.ContactMethods
7-- Module : Network.PagerDuty.REST.Users.ContactMethods
8−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
8+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
9-- License : This Source Code Form is subject to the terms of
9-- License : This Source Code Form is subject to the terms of
10-- the Mozilla Public License, v. 2.0.
10-- the Mozilla Public License, v. 2.0.
11-- A copy of the MPL can be found in the LICENSE file or
11-- A copy of the MPL can be found in the LICENSE file or
@@ -56,12 +56,12 @@ module Network.PagerDuty.REST.Users.ContactMethods
56 , Contact
56 , Contact
57 ) where
57 ) where
58
58
59−import Control.Lens
59+import Control.Lens
60−import Data.Aeson.Lens
60+import Data.Aeson.Lens
61−import Data.Text (Text)
61+import Data.Text (Text)
62−import Network.HTTP.Types
62+import Network.HTTP.Types
63−import Network.PagerDuty.Internal.TH
63+import Network.PagerDuty.Internal.TH
64−import Network.PagerDuty.Internal.Types
64+import Network.PagerDuty.Internal.Types
65
65
66default (Path)
66default (Path)
67
67
src/Network/PagerDuty/REST/Users/NotificationRules.hs+10−10
@@ -1,11 +1,11 @@
1−{-# LANGUAGE ExtendedDefaultRules #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
4
4
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
5{-# OPTIONS_GHC -fno-warn-type-defaults #-}
6
6
7-- Module : Network.PagerDuty.REST.Users.NotificationRules
7-- Module : Network.PagerDuty.REST.Users.NotificationRules
8−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
8+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
9-- License : This Source Code Form is subject to the terms of
9-- License : This Source Code Form is subject to the terms of
10-- the Mozilla Public License, v. 2.0.
10-- the Mozilla Public License, v. 2.0.
11-- A copy of the MPL can be found in the LICENSE file or
11-- A copy of the MPL can be found in the LICENSE file or
@@ -51,12 +51,12 @@ module Network.PagerDuty.REST.Users.NotificationRules
51 , rContactMethod
51 , rContactMethod
52 ) where
52 ) where
53
53
54−import Control.Lens
54+import Control.Lens
55−import Data.Aeson.Lens
55+import Data.Aeson.Lens
56−import Network.HTTP.Types
56+import Network.HTTP.Types
57−import Network.PagerDuty.Internal.TH
58−import Network.PagerDuty.Internal.Types
59−import Network.PagerDuty.REST.Users.ContactMethods
57+import Network.PagerDuty.REST.Users.ContactMethods
58+import Network.PagerDuty.Internal.TH
59+import Network.PagerDuty.Internal.Types
60
60
61default (Path)
61default (Path)
62
62
src/Network/PagerDuty/REST/Webhooks.hs+3−4
@@ -3,7 +3,7 @@
3{-# LANGUAGE TemplateHaskell #-}
3{-# LANGUAGE TemplateHaskell #-}
4
4
5-- Module : Network.PagerDuty.REST.Webhooks
5-- Module : Network.PagerDuty.REST.Webhooks
6−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
6+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
7-- License : This Source Code Form is subject to the terms of
7-- License : This Source Code Form is subject to the terms of
8-- the Mozilla Public License, v. 2.0.
8-- the Mozilla Public License, v. 2.0.
9-- A copy of the MPL can be found in the LICENSE file or
9-- A copy of the MPL can be found in the LICENSE file or
@@ -35,14 +35,13 @@ module Network.PagerDuty.REST.Webhooks
35import Control.Applicative hiding (empty)
35import Control.Applicative hiding (empty)
36import Control.Lens
36import Control.Lens
37import Data.Aeson
37import Data.Aeson
38−import Data.ByteString.Conversion (ToByteString (..),
38+import Data.ByteString.Conversion (ToByteString(..), toByteString')
39− toByteString')
40import Data.Text (Text)
39import Data.Text (Text)
41import qualified Data.Text.Encoding as Text
40import qualified Data.Text.Encoding as Text
42import Data.Time
41import Data.Time
42+import Network.PagerDuty.REST.Incidents
43import Network.PagerDuty.Internal.TH
43import Network.PagerDuty.Internal.TH
44import Network.PagerDuty.Internal.Types
44import Network.PagerDuty.Internal.Types
45−import Network.PagerDuty.REST.Incidents
46
45
47data WebhookType
46data WebhookType
48 = WTrigger
47 = WTrigger
src/Network/PagerDuty/Types.hsdeleted−93
@@ -1,93 +0,0 @@
1−-- Module : Network.PagerDuty.Types
2−-- Copyright : (c) 2013-2015 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
stack.yamldeleted−7
@@ -1,7 +0,0 @@
1−resolver: lts-19.23
2−
3−packages:
4−- .
5−
6−nix:
7− packages: [zlib]