@@ -15,7 +15,7 @@
15{-# LANGUAGE ViewPatterns #-}
15{-# LANGUAGE ViewPatterns #-}
17-- Module : Network.PagerDuty.Internal.Types
17-- 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>
19-- License : This Source Code Form is subject to the terms of
19-- License : This Source Code Form is subject to the terms of
20-- the Mozilla Public License, v. 2.0.
20-- the Mozilla Public License, v. 2.0.
21-- A copy of the MPL can be found in the LICENSE file or
21-- A copy of the MPL can be found in the LICENSE file or
@@ -27,33 +27,35 @@
27module Network.PagerDuty.Internal.Types where
27module Network.PagerDuty.Internal.Types where
29import Control.Applicative
29import Control.Applicative
30−import Control.Lens hiding ((.=), Empty)
30+import Control.Lens hiding ((.=))
31import Control.Monad.IO.Class
31import Control.Monad.IO.Class
32−import Data.Aeson hiding (Error, Key)
32+import Data.Aeson hiding (Error)
33−import qualified Data.Aeson.KeyMap as Map
34import Data.Aeson.Types (Parser)
33import Data.Aeson.Types (Parser)
35import Data.ByteString (ByteString)
34import Data.ByteString (ByteString)
36import qualified Data.ByteString.Char8 as BS
35import qualified Data.ByteString.Char8 as BS
37import Data.ByteString.Conversion hiding (List)
36import Data.ByteString.Conversion hiding (List)
38import Data.Default.Class
37import Data.Default.Class
39import Data.Function (on)
38import Data.Function (on)
39+import qualified Data.HashMap.Strict as Map
40import Data.List (deleteBy, intersperse)
40import Data.List (deleteBy, intersperse)
41import Data.Monoid
41import Data.Monoid
42import Data.String
42import Data.String
43import Data.Text (Text)
43import Data.Text (Text)
44import qualified Data.Text as Text
44import qualified Data.Text as Text
45import qualified Data.Text.Encoding as Text
45import qualified Data.Text.Encoding as Text
46−import Data.Time (UTCTime, TimeZone, formatTime, utc, timeZoneName)
46+import Data.Time
47import GHC.TypeLits
47import GHC.TypeLits
48import Network.HTTP.Client (Manager)
48import Network.HTTP.Client (Manager)
49import Network.HTTP.Types
49import Network.HTTP.Types
50import Network.HTTP.Types.QueryLike
50import Network.HTTP.Types.QueryLike
51import Network.PagerDuty.Internal.Query
51import Network.PagerDuty.Internal.Query
52import Network.PagerDuty.Internal.TH
52import Network.PagerDuty.Internal.TH
53−import Data.Time.Locale.Compat
53+import System.Locale
55+-- FIXME: Verify IncidentId/IncidentKey .. *Id/*Key are actually different or needed
55newtype CSV a = CSV [a]
57newtype CSV a = CSV [a]
56− deriving (Eq, Show, Semigroup, Monoid)
58+ deriving (Eq, Show, Monoid)
58makePrisms ''CSV
60makePrisms ''CSV
@@ -70,7 +72,7 @@ instance ToByteString a => ToJSON (CSV a) where
70 toJSON = String . Text.decodeUtf8 . toByteString'
72 toJSON = String . Text.decodeUtf8 . toByteString'
72newtype List a = L [a]
74newtype List a = L [a]
73− deriving (Eq, Show, Semigroup, Monoid)
75+ deriving (Eq, Show, Monoid)
75deriveJSON ''List
77deriveJSON ''List
76makePrisms ''List
78makePrisms ''List
@@ -106,7 +108,7 @@ instance ToJSON Date where
107instance ToByteString Date where
109instance ToByteString Date where
108 builder (D d) = builder
110 builder (D d) = builder
109− (formatTime defaultTimeLocale ("%Y-%m-%dT%XZ") d)
111+ (formatTime defaultTimeLocale (iso8601DateFormat $ Just "%XZ") d)
111instance QueryValues Date
113instance QueryValues Date
@@ -133,17 +135,14 @@ data Security = Basic | Token
133 deriving (Eq, Show)
135 deriving (Eq, Show)
135data Auth (a :: Security) where
137data Auth (a :: Security) where
136− AuthBasic :: ByteString -> ByteString -> Auth 'Basic
138+ AuthBasic :: ByteString -> ByteString -> Auth Basic
137− AuthToken :: ByteString -> Auth 'Token
139+ AuthToken :: ByteString -> Auth Token
139deriving instance Eq (Auth a)
141deriving instance Eq (Auth a)
140deriving instance Show (Auth a)
142deriving instance Show (Auth a)
142newtype SubDomain = SubDomain { subDomain :: ByteString }
144newtype SubDomain = SubDomain { subDomain :: ByteString }
143− deriving (Eq, Show, IsString, ToByteString)
145+ deriving (Eq, Show, IsString)
145−mkSubDomain :: ByteString -> SubDomain
146−mkSubDomain = SubDomain
148domain :: SubDomain -> ByteString
147domain :: SubDomain -> ByteString
149domain (SubDomain s)
148domain (SubDomain s)
@@ -180,7 +179,7 @@ prod :: SubDomain -> Auth s -> Manager -> Env s
180prod d a m = Env d a m None
179prod d a m = Env d a m None
182newtype Code = Code Integer
181newtype Code = Code Integer
183− deriving (Eq, Show, Num)
182+ deriving (Eq, Show)
185deriveJSON ''Code
184deriveJSON ''Code
@@ -279,13 +278,8 @@ data Pager = Pager
280makeLenses ''Pager
279makeLenses ''Pager
282−data Page a = Page
281+instance FromJSON a => FromJSON (a, Maybe Pager) where
284− , _pgPager :: Maybe Pager
287−instance FromJSON a => FromJSON (Page a) where
288− parseJSON = withObject "paginated" $ \o -> Page
282+ parseJSON = withObject "paginated" $ \o -> (,)
289 <$> parseJSON (Object o)
283 <$> parseJSON (Object o)
290 <*> optional (parse o)
284 <*> optional (parse o)
@@ -310,13 +304,11 @@ data Path where
310 Path :: Path
304 Path :: Path
311 Seg :: ToByteString a => a -> Path
305 Seg :: ToByteString a => a -> Path
313−instance Semigroup Path where
316− Seg x <> Seg y = Seg (builder x <> "/" <> builder y)
318instance Monoid Path where
307instance Monoid Path where
319− mempty = Path
308+ mempty = Path
311+ mappend (Seg x) (Seg y) = Seg (builder x <> "/" <> builder y)
321instance IsString Path where
313instance IsString Path where
322 fromString = Seg
314 fromString = Seg
@@ -393,13 +385,13 @@ class Paginate a where
393 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
385 next :: Request a s b -> Maybe Pager -> Maybe (Request a s b)
394 next rq = maybe Nothing go
386 next rq = maybe Nothing go
396− go x | x ^. pgTotal == 0 = Nothing
388+ go x | x^.pgTotal == 0 = Nothing
397− | otherwise = Just $
389+ | otherwise = Just $
398− rq & pager ?~ (x & pgOffset +~ x ^. pgTotal)
390+ rq & pager ?~ (x & pgOffset +~ x^.pgTotal)
399 & query %~ (add . clear)
391 & query %~ (add . clear)
401 add :: Query -> Query
393 add :: Query -> Query
402− add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x ^. pgQuery)
394+ add = maybe id ((:) . (k,) . Just . Text.encodeUtf8) (x^.pgQuery)
404 clear :: Query -> Query
396 clear :: Query -> Query
405 clear = deleteBy ((==) `on` fst) (k, Nothing)
397 clear = deleteBy ((==) `on` fst) (k, Nothing)
@@ -410,9 +402,6 @@ class Paginate a where
410newtype Key (a :: Symbol) = Key Text
402newtype Key (a :: Symbol) = Key Text
411 deriving (Eq, Show, IsString)
403 deriving (Eq, Show, IsString)
413−mkKey :: Text -> Key a
416instance FromJSON (Key a) where
405instance FromJSON (Key a) where
417 parseJSON = withText "key" (return . Key)
406 parseJSON = withText "key" (return . Key)
@@ -433,9 +422,6 @@ type IncidentKey = Key "incident"
433newtype Id (a :: Symbol) = Id Text
422newtype Id (a :: Symbol) = Id Text
434 deriving (Eq, Show, IsString)
423 deriving (Eq, Show, IsString)
439instance FromJSON (Id a) where
425instance FromJSON (Id a) where
440 parseJSON = withText "id" (return . Id)
426 parseJSON = withText "id" (return . Id)
@@ -483,10 +469,7 @@ instance QueryLike Empty where
483 toQuery = const []
469 toQuery = const []
485newtype Address = Address Text
471newtype Address = Address Text
486− deriving (Eq, Show, IsString)
472+ deriving (Eq, Show)
488−mkAddress :: Text -> Address
491deriveJSON ''Address
474deriveJSON ''Address
492makePrisms ''Address
475makePrisms ''Address