@@ -2,8 +2,11 @@
22{-# LANGUAGE DeriveDataTypeable #-}
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE FlexibleContexts #-}
5+{-# LANGUAGE FlexibleInstances #-}
56{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE MultiParamTypeClasses #-}
68{-# LANGUAGE OverloadedStrings #-}
9+{-# LANGUAGE ScopedTypeVariables #-}
710{-# LANGUAGE TypeFamilies #-}
811{-# LANGUAGE TypeOperators #-}
912
@@ -21,50 +24,57 @@ module Network.Google.Prelude
2124 ) where
2225
2326import Control.Lens as Export (Lens', lens, mapping,
24− _Just)
27+ (^.), _Just)
2528import Control.Lens hiding (coerce)
2629import Control.Monad.Trans.Either as Export (EitherT)
27−import Data.Aeson as Export
2830import Data.Coerce
2931import Data.Data as Export (Data, Typeable)
3032import Data.Hashable as Export
3133import Data.Int as Export (Int32, Int64)
3234import Data.Maybe as Export
35+import Data.Monoid
3336import Data.Proxy as Export
3437import Data.Text as Export (Text)
35−import Data.Time as Export (UTCTime)
38+import qualified Data.Text as Text
39+import Data.Time as Export
3640import Data.Word as Export (Word32, Word64, Word8)
3741import GHC.Generics as Export (Generic)
42+import GHC.TypeLits
3843import Network.Google.Data.JSON as Export
3944import Network.Google.Data.Numeric as Export
40−import Network.HTTP.Media
45+-- import Network.HTTP.Media
4146import Numeric.Natural as Export (Natural)
4247import Servant.API as Export
4348import Servant.Client as Export
4449import Servant.Common.Req as Export (Req, defReq)
50+import Servant.Common.Req (appendToPath)
4551import Servant.Utils.Links as Export
4652
4753_Coerce :: (Coercible a b, Coercible b a) => Iso' a b
4854_Coerce = iso coerce coerce
4955
50−-- | Invalid Iso, should be a Prism but exists for ease of composition
51−-- with the current 'Lens . Iso' chaining to hide internal types from the user.
56+-- | Invalid Iso, exists for ease of composition with the current 'Lens . Iso'
57+-- chaining to hide internal types from the user.
5258_Default :: Monoid a => Iso' (Maybe a) a
5359_Default = iso f Just
5460 where
5561 f (Just x) = x
5662 f Nothing = mempty
5763
58−newtype Time' = Time' Text
59− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
64+_Time = undefined
65+_Date = undefined
66+_DateTime = undefined
6067
61−newtype Date' = Date' Text
62− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
68+newtype Time' = Time' Text -- TimeOfDay
69+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, FromText, ToText, FromJSON, ToJSON)
6370
64−newtype DateTime' = DateTime' Text
65− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
71+newtype Date' = Date' Text -- LocalTime
72+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, FromText, ToText, FromJSON, ToJSON)
73+
74+newtype DateTime' = DateTime' Text -- UTCTime
75+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, FromText, ToText, FromJSON, ToJSON)
6676
67−data AltJSON = AltJSON
77+data AltJSON = AltJSON
6878 deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
6979
7080instance ToText AltJSON where
@@ -105,8 +115,52 @@ instance GoogleAuth a => GoogleAuth (Download a) where
105115data Body = Body -- MediaType
106116 deriving (Eq, Show, Generic, Data, Typeable)
107117
118+data Captures (capture :: Symbol) a
119+ deriving (Typeable)
120+
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
124+
125+ clientWithRoute Proxy req baseUrl xs =
126+ clientWithRoute (Proxy :: Proxy sublayout) (appendToPath vs req) baseUrl
127+ where
128+ vs = Text.unpack $ Text.intercalate "/" (map toText xs)
129+
130+data CaptureMode (capture :: Symbol) (mode :: Symbol) a
131+ deriving (Typeable)
132+
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
136+
137+ clientWithRoute Proxy req baseUrl val =
138+ clientWithRoute (Proxy :: Proxy sublayout) (appendToPath p req) baseUrl
139+ where
140+ p = Text.unpack (toText val) <> m
141+ m = symbolVal (Proxy :: Proxy mode)
142+
143+instance MimeUnrender OctetStream Body
108144
109145data MultipartRelated (metatypes :: [*]) meta media
146+ deriving (Typeable)
147+
148+instance (MimeUnrender ct a, HasClient sublayout)
149+ => HasClient (MultipartRelated (ct ': cts) a b :> sublayout) where
150+
151+ type Client (MultipartRelated (ct ': cts) a b :> sublayout) =
152+ a -> b -> Client sublayout
153+
154+ clientWithRoute Proxy req baseurl meta media = undefined
155+
156+ -- clientWithRoute (Proxy :: Proxy sublayout)
157+ -- (let ctProxy = Proxy :: Proxy ct
158+ -- in setRQBody (mimeRender ctProxy body)
159+ -- (contentType ctProxy)
160+ -- req
161+ -- )
162+ -- baseurl
163+
110164
111165-- IsElem sa (ReqBody y x :> sb) = IsElem sa sb
112166