git.iko.soy/typeable/pagerduty
on develop help sign in
Ensuring newtype wrappers (Date etc) are not exposed via the lenses
commitea2e9c1f75232f8cef1aa4fe1b787240617cdef0 authorBrendan Hay <brendan.g.hay@gmail.com> dateThu 2 Oct 2014, 13:55 (12 years ago) parentf74da26
2 files changed+40−20
src/Network/PagerDuty/REST/LogEntries.hs+6−6 src/Network/PagerDuty/REST/Reports.hs+34−14
src/Network/PagerDuty/REST/LogEntries.hs+6−6
@@ -491,6 +491,12 @@ newtype GetLog = GetLog
491491
492492deriveQuery ''GetLog
493493
494+-- | Time zone in which dates in the result will be rendered.
495+--
496+-- Defaults to UTC.
497+glTimeZone :: Lens' (Request GetLog s b) TimeZone
498+glTimeZone = upd.glTimeZone'._TZ
499+
494500-- | Get details for a specific incident log entry. This method provides additional
495501-- information you can use to get at raw event data.
496502--
@@ -503,9 +509,3 @@ getLog l =
503509 { _glTimeZone' = def
504510 } & path .~ logs % l
505511 & query .~ includes
506−
507−-- | Time zone in which dates in the result will be rendered.
508−--
509−-- Defaults to UTC.
510−glTimeZone :: Lens' (Request GetLog s b) TimeZone
511−glTimeZone = upd.glTimeZone'._TZ
src/Network/PagerDuty/REST/Reports.hs+34−14
@@ -59,6 +59,7 @@ module Network.PagerDuty.REST.Reports
5959import Control.Lens
6060import Data.Aeson.Lens
6161import Data.ByteString.Builder (Builder)
62+import Data.Time
6263import Network.PagerDuty.TH
6364import Network.PagerDuty.Types
6465
@@ -85,13 +86,13 @@ deriveQuery ''Report
8586
8687-- | Start of the date range over which you want to search. The time element
8788-- is optional.
88−rSince :: Lens' (Request Report s b) Date
89−rSince = upd.rSince'
89+rSince :: Lens' (Request Report s b) UTCTime
90+rSince = upd.rSince'._Date
9091
9192-- | The end of the date range over which you want to search. This should be
9293-- in the same format as since.
93−rUntil :: Lens' (Request Report s b) Date
94−rUntil = upd.rUntil'
94+rUntil :: Lens' (Request Report s b) UTCTime
95+rUntil = upd.rUntil'._Date
9596
9697-- | Specifies the bucket duration for each summation.
9798--
@@ -112,7 +113,18 @@ data AlertReport = AlertReport
112113 , _arNumberOfEmailAlerts :: !Int
113114 } deriving (Eq, Show)
114115
115−deriveRecord ''AlertReport
116+deriveJSON ''AlertReport
117+
118+arStart :: Lens' AlertReport UTCTime
119+arStart = lens _arStart (\r x -> r { _arStart = x }) ._Date
120+
121+arEnd :: Lens' AlertReport UTCTime
122+arEnd = lens _arEnd (\r x -> r { _arEnd = x }) ._Date
123+
124+makeLens "_arNumberOfAlerts" ''AlertReport
125+makeLens "_arNumberOfPhoneAlerts" ''AlertReport
126+makeLens "_arNumberOfSmsAlerts" ''AlertReport
127+makeLens "_arNumberOfEmailAlerts" ''AlertReport
116128
117129data AlertTotals = AlertTotals
118130 { _atAlerts :: [AlertReport]
@@ -131,13 +143,13 @@ deriveRecord ''AlertTotals
131143-- @GET \/reports\/alerts_per_time@
132144--
133145-- See: <http://developer.pagerduty.com/documentation/rest/reports/alerts_per_time>
134−alertsPerTime :: Date -- ^ 'rSince'
135− -> Date -- ^ 'rUntil'
146+alertsPerTime :: UTCTime -- ^ 'rSince'
147+ -> UTCTime -- ^ 'rUntil'
136148 -> Request Report s AlertTotals
137149alertsPerTime s u =
138150 mk Report
139− { _rSince' = s
140− , _rUntil' = u
151+ { _rSince' = Date s
152+ , _rUntil' = Date u
141153 , _rRollup' = Monthly
142154 } & path .~ reports % "alerts_per_time"
143155
@@ -147,7 +159,15 @@ data IncidentReport = IncidentReport
147159 , _irNumberOfIncidents :: !Int
148160 } deriving (Eq, Show)
149161
150−deriveRecord ''IncidentReport
162+deriveJSON ''IncidentReport
163+
164+irStart :: Lens' IncidentReport UTCTime
165+irStart = lens _irStart (\r x -> r { _irStart = x }) . _Date
166+
167+irEnd :: Lens' IncidentReport UTCTime
168+irEnd = lens _irEnd (\r x -> r { _irEnd = x }) . _Date
169+
170+makeLens "_irNumberOfIncidents" ''IncidentReport
151171
152172-- | Get high level statistics about the number of incidents created for the
153173-- desired time period, summed daily, weekly or monthly.
@@ -155,13 +175,13 @@ deriveRecord ''IncidentReport
155175-- @GET \/reports\/incidents_per_time@
156176--
157177-- See: <http://developer.pagerduty.com/documentation/rest/reports/incidents_per_time>
158−incidentsPerTime :: Date -- ^ 'rSince'
159− -> Date -- ^ 'rUntil'
178+incidentsPerTime :: UTCTime -- ^ 'rSince'
179+ -> UTCTime -- ^ 'rUntil'
160180 -> Request Report s [IncidentReport]
161181incidentsPerTime s u =
162182 mk Report
163− { _rSince' = s
164− , _rUntil' = u
183+ { _rSince' = Date s
184+ , _rUntil' = Date u
165185 , _rRollup' = Monthly
166186 } & path .~ reports % "incidents_per_time"
167187 & unwrap .~ key "incidents"