@@ -15,7 +15,7 @@
1515{-# LANGUAGE ViewPatterns #-}
1616
1717-- Module : Network.PagerDuty.Internal.Types
18−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
18+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
1919-- License : This Source Code Form is subject to the terms of
2020-- the Mozilla Public License, v. 2.0.
2121-- A copy of the MPL can be found in the LICENSE file or
@@ -27,33 +27,35 @@
2727module Network.PagerDuty.Internal.Types where
2828
2929import Control.Applicative
30−import Control.Lens hiding ((.=), Empty)
30+import Control.Lens hiding ((.=))
3131import Control.Monad.IO.Class
32−import Data.Aeson hiding (Error, Key)
33−import qualified Data.Aeson.KeyMap as Map
32+import Data.Aeson hiding (Error)
3433import Data.Aeson.Types (Parser)
3534import Data.ByteString (ByteString)
3635import qualified Data.ByteString.Char8 as BS
3736import Data.ByteString.Conversion hiding (List)
3837import Data.Default.Class
3938import Data.Function (on)
39+import qualified Data.HashMap.Strict as Map
4040import Data.List (deleteBy, intersperse)
4141import Data.Monoid
4242import Data.String
4343import Data.Text (Text)
4444import qualified Data.Text as Text
4545import qualified Data.Text.Encoding as Text
46−import Data.Time (UTCTime, TimeZone, formatTime, utc, timeZoneName)
46+import Data.Time
4747import GHC.TypeLits
4848import Network.HTTP.Client (Manager)
4949import Network.HTTP.Types
5050import Network.HTTP.Types.QueryLike
5151import Network.PagerDuty.Internal.Query
5252import Network.PagerDuty.Internal.TH
53−import Data.Time.Locale.Compat
53+import System.Locale
54+
55+-- FIXME: Verify IncidentId/IncidentKey .. *Id/*Key are actually different or needed
5456
5557newtype CSV a = CSV [a]
56− deriving (Eq, Show, Semigroup, Monoid)
58+ deriving (Eq, Show, Monoid)
5759
5860makePrisms ''CSV
5961
@@ -70,7 +72,7 @@ instance ToByteString a => ToJSON (CSV a) where
7072 toJSON = String . Text.decodeUtf8 . toByteString'
7173
7274newtype List a = L [a]
73− deriving (Eq, Show, Semigroup, Monoid)
75+ deriving (Eq, Show, Monoid)
7476
7577deriveJSON ''List
7678makePrisms ''List
@@ -106,7 +108,7 @@ instance ToJSON Date where
106108
107109instance ToByteString Date where
108110 builder (D d) = builder
109− (formatTime defaultTimeLocale ("%Y-%m-%dT%XZ") d)
111+ (formatTime defaultTimeLocale (iso8601DateFormat $ Just "%XZ") d)
110112
111113instance QueryValues Date
112114
@@ -133,17 +135,14 @@ data Security = Basic | Token
133135 deriving (Eq, Show)
134136
135137data Auth (a :: Security) where
136− AuthBasic :: ByteString -> ByteString -> Auth 'Basic
137− AuthToken :: ByteString -> Auth 'Token
138+ AuthBasic :: ByteString -> ByteString -> Auth Basic
139+ AuthToken :: ByteString -> Auth Token
138140
139141deriving instance Eq (Auth a)
140142deriving instance Show (Auth a)
141143
142144newtype SubDomain = SubDomain { subDomain :: ByteString }
143− deriving (Eq, Show, IsString, ToByteString)
144−
145−mkSubDomain :: ByteString -> SubDomain
146−mkSubDomain = SubDomain
145+ deriving (Eq, Show, IsString)
147146
148147domain :: SubDomain -> ByteString
149148domain (SubDomain s)
@@ -180,7 +179,7 @@ prod :: SubDomain -> Auth s -> Manager -> Env s
180179prod d a m = Env d a m None
181180
182181newtype Code = Code Integer
183− deriving (Eq, Show, Num)
182+ deriving (Eq, Show)
184183
185184deriveJSON ''Code
186185
@@ -279,13 +278,8 @@ data Pager = Pager
279278
280279makeLenses ''Pager
281280
282−data Page a = Page
283− { _pgItem :: a
284− , _pgPager :: Maybe Pager
285− }
286−
287−instance FromJSON a => FromJSON (Page a) where
288− parseJSON = withObject "paginated" $ \o -> Page
281+instance FromJSON a => FromJSON (a, Maybe Pager) where
282+ parseJSON = withObject "paginated" $ \o -> (,)
289283 <$> parseJSON (Object o)
290284 <*> optional (parse o)
291285 where
@@ -310,13 +304,11 @@ data Path where
310304 Path :: Path
311305 Seg :: ToByteString a => a -> Path
312306
313−instance Semigroup Path where
314− x <> Path = x
315− Path <> y = y
316− Seg x <> Seg y = Seg (builder x <> "/" <> builder y)
317−
318307instance Monoid Path where
319− mempty = Path
308+ mempty = Path
309+ mappend x Path = x
310+ mappend Path y = y
311+ mappend (Seg x) (Seg y) = Seg (builder x <> "/" <> builder y)
320312
321313instance IsString Path where
322314 fromString = Seg
@@ -393,13 +385,13 @@ class Paginate a where
393385 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
394386 next rq = maybe Nothing go
395387 where
396− go x | x ^. pgTotal == 0 = Nothing
397− | otherwise = Just $
398− rq & pager ?~ (x & pgOffset +~ x ^. pgTotal)
388+ go x | x^.pgTotal == 0 = Nothing
389+ | otherwise = Just $
390+ rq & pager ?~ (x & pgOffset +~ x^.pgTotal)
399391 & query %~ (add . clear)
400392 where
401393 add :: Query -> Query
402− add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x ^. pgQuery)
394+ add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x^.pgQuery)
403395
404396 clear :: Query -> Query
405397 clear = deleteBy ((==) `on` fst) (k, Nothing)
@@ -410,9 +402,6 @@ class Paginate a where
410402newtype Key (a :: Symbol) = Key Text
411403 deriving (Eq, Show, IsString)
412404
413−mkKey :: Text -> Key a
414−mkKey = Key
415−
416405instance FromJSON (Key a) where
417406 parseJSON = withText "key" (return . Key)
418407
@@ -433,9 +422,6 @@ type IncidentKey = Key "incident"
433422newtype Id (a :: Symbol) = Id Text
434423 deriving (Eq, Show, IsString)
435424
436−mkId :: Text -> Id a
437−mkId = Id
438−
439425instance FromJSON (Id a) where
440426 parseJSON = withText "id" (return . Id)
441427
@@ -483,10 +469,7 @@ instance QueryLike Empty where
483469 toQuery = const []
484470
485471newtype Address = Address Text
486− deriving (Eq, Show, IsString)
487−
488−mkAddress :: Text -> Address
489−mkAddress = Address
472+ deriving (Eq, Show)
490473
491474deriveJSON ''Address
492475makePrisms ''Address