@@ -2,8 +2,11 @@
2{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
5+{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE OverloadedStrings #-}
8{-# LANGUAGE OverloadedStrings #-}
9+{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE TypeFamilies #-}
8{-# LANGUAGE TypeOperators #-}
11{-# LANGUAGE TypeOperators #-}
@@ -21,50 +24,57 @@ module Network.Google.Prelude
23import Control.Lens as Export (Lens', lens, mapping,
26import Control.Lens as Export (Lens', lens, mapping,
24− _Just)
27+ (^.), _Just)
25import Control.Lens hiding (coerce)
28import Control.Lens hiding (coerce)
26import Control.Monad.Trans.Either as Export (EitherT)
29import Control.Monad.Trans.Either as Export (EitherT)
27−import Data.Aeson as Export
28import Data.Coerce
30import Data.Coerce
29import Data.Data as Export (Data, Typeable)
31import Data.Data as Export (Data, Typeable)
30import Data.Hashable as Export
32import Data.Hashable as Export
31import Data.Int as Export (Int32, Int64)
33import Data.Int as Export (Int32, Int64)
32import Data.Maybe as Export
34import Data.Maybe as Export
33import Data.Proxy as Export
36import Data.Proxy as Export
34import Data.Text as Export (Text)
37import Data.Text as Export (Text)
38+import qualified Data.Text as Text
35−import Data.Time as Export (UTCTime)
39+import Data.Time as Export
36import Data.Word as Export (Word32, Word64, Word8)
40import Data.Word as Export (Word32, Word64, Word8)
37import GHC.Generics as Export (Generic)
41import GHC.Generics as Export (Generic)
38import Network.Google.Data.JSON as Export
43import Network.Google.Data.JSON as Export
39import Network.Google.Data.Numeric as Export
44import Network.Google.Data.Numeric as Export
40−import Network.HTTP.Media
45+-- import Network.HTTP.Media
41import Numeric.Natural as Export (Natural)
46import Numeric.Natural as Export (Natural)
42import Servant.API as Export
47import Servant.API as Export
43import Servant.Client as Export
48import Servant.Client as Export
44import Servant.Common.Req as Export (Req, defReq)
49import Servant.Common.Req as Export (Req, defReq)
50+import Servant.Common.Req (appendToPath)
45import Servant.Utils.Links as Export
51import Servant.Utils.Links as Export
47_Coerce :: (Coercible a b, Coercible b a) => Iso' a b
53_Coerce :: (Coercible a b, Coercible b a) => Iso' a b
48_Coerce = iso coerce coerce
54_Coerce = iso coerce coerce
50−-- | Invalid Iso, should be a Prism but exists for ease of composition
56+-- | Invalid Iso, exists for ease of composition with the current 'Lens . Iso'
51−-- with the current 'Lens . Iso' chaining to hide internal types from the user.
57+-- chaining to hide internal types from the user.
52_Default :: Monoid a => Iso' (Maybe a) a
58_Default :: Monoid a => Iso' (Maybe a) a
53_Default = iso f Just
59_Default = iso f Just
55 f (Just x) = x
61 f (Just x) = x
56 f Nothing = mempty
62 f Nothing = mempty
58−newtype Time' = Time' Text
64+_Time = undefined
59− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
65+_Date = undefined
61−newtype Date' = Date' Text
68+newtype Time' = Time' Text -- TimeOfDay
62− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
69+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, FromText, ToText, FromJSON, ToJSON)
71+newtype Date' = Date' Text -- LocalTime
72+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, FromText, ToText, FromJSON, ToJSON)
64−newtype DateTime' = DateTime' Text
74+newtype DateTime' = DateTime' Text -- UTCTime
65− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
75+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, FromText, ToText, FromJSON, ToJSON)
67−data AltJSON = AltJSON
77+data AltJSON = AltJSON
68 deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
78 deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
70instance ToText AltJSON where
80instance ToText AltJSON where
@@ -105,8 +115,52 @@ instance GoogleAuth a => GoogleAuth (Download a) where
105data Body = Body -- MediaType
115data Body = Body -- MediaType
106 deriving (Eq, Show, Generic, Data, Typeable)
116 deriving (Eq, Show, Generic, Data, Typeable)
118+data Captures (capture :: Symbol) a
121+instance (KnownSymbol capture, ToText a, HasClient sublayout)
122+ => HasClient (Captures capture a :> sublayout) where
123+ type Client (Captures capture a :> sublayout) = [a] -> Client sublayout
125+ clientWithRoute Proxy req baseUrl xs =
126+ clientWithRoute (Proxy :: Proxy sublayout) (appendToPath vs req) baseUrl
128+ vs = Text.unpack $ Text.intercalate "/" (map toText xs)
130+data CaptureMode (capture :: Symbol) (mode :: Symbol) a
133+instance (KnownSymbol capture, KnownSymbol mode, ToText a, HasClient sublayout)
134+ => HasClient (CaptureMode capture mode a :> sublayout) where
135+ type Client (CaptureMode capture mode a :> sublayout) = a -> Client sublayout
137+ clientWithRoute Proxy req baseUrl val =
138+ clientWithRoute (Proxy :: Proxy sublayout) (appendToPath p req) baseUrl
140+ p = Text.unpack (toText val) <> m
141+ m = symbolVal (Proxy :: Proxy mode)
143+instance MimeUnrender OctetStream Body
109data MultipartRelated (metatypes :: [*]) meta media
145data MultipartRelated (metatypes :: [*]) meta media
148+instance (MimeUnrender ct a, HasClient sublayout)
149+ => HasClient (MultipartRelated (ct ': cts) a b :> sublayout) where
151+ type Client (MultipartRelated (ct ': cts) a b :> sublayout) =
152+ a -> b -> Client sublayout
154+ clientWithRoute Proxy req baseurl meta media = undefined
156+ -- clientWithRoute (Proxy :: Proxy sublayout)
157+ -- (let ctProxy = Proxy :: Proxy ct
158+ -- in setRQBody (mimeRender ctProxy body)
159+ -- (contentType ctProxy)
111-- IsElem sa (ReqBody y x :> sb) = IsElem sa sb
165-- IsElem sa (ReqBody y x :> sb) = IsElem sa sb