google-server-api 0.3.0.0 → 0.3.1.0
raw patch · 4 files changed
+102/−5 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Google.Form: data DateTime
+ Google.Client: getCalendarEventList :: Token -> Text -> Maybe Bool -> Maybe DateTime -> Maybe DateTime -> Maybe Text -> IO (Either ServantError CalendarEventList)
+ Google.Form: instance Web.Internal.HttpApiData.ToHttpApiData Google.Form.DateTime
+ Google.Form: newtype DateTime
+ Google.Response: Account :: Text -> Account
+ Google.Response: CalendarEventList :: Text -> Text -> [CalendarEvent] -> CalendarEventList
+ Google.Response: DateTime :: UTCTime -> DateTime
+ Google.Response: ZonedDateTime :: Maybe ZonedTime -> ZonedDateTime
+ Google.Response: [$sel:attendees:CalendarEvent] :: CalendarEvent -> Maybe [Account]
+ Google.Response: [$sel:creator:CalendarEvent] :: CalendarEvent -> Account
+ Google.Response: [$sel:dateTime:DateTime] :: DateTime -> UTCTime
+ Google.Response: [$sel:dateTime:ZonedDateTime] :: ZonedDateTime -> Maybe ZonedTime
+ Google.Response: [$sel:description:CalendarEvent] :: CalendarEvent -> Maybe Text
+ Google.Response: [$sel:email:Account] :: Account -> Text
+ Google.Response: [$sel:end:CalendarEvent] :: CalendarEvent -> Maybe ZonedDateTime
+ Google.Response: [$sel:items:CalendarEventList] :: CalendarEventList -> [CalendarEvent]
+ Google.Response: [$sel:kind:CalendarEventList] :: CalendarEventList -> Text
+ Google.Response: [$sel:start:CalendarEvent] :: CalendarEvent -> Maybe ZonedDateTime
+ Google.Response: [$sel:summary:CalendarEventList] :: CalendarEventList -> Text
+ Google.Response: [$sel:summary:CalendarEvent] :: CalendarEvent -> Maybe Text
+ Google.Response: data CalendarEventList
+ Google.Response: instance Data.Aeson.Types.FromJSON.FromJSON Google.Response.Account
+ Google.Response: instance Data.Aeson.Types.FromJSON.FromJSON Google.Response.CalendarEventList
+ Google.Response: instance Data.Aeson.Types.FromJSON.FromJSON Google.Response.DateTime
+ Google.Response: instance Data.Aeson.Types.FromJSON.FromJSON Google.Response.ZonedDateTime
+ Google.Response: instance Data.Aeson.Types.ToJSON.ToJSON Google.Response.Account
+ Google.Response: instance Data.Aeson.Types.ToJSON.ToJSON Google.Response.CalendarEventList
+ Google.Response: instance Data.Aeson.Types.ToJSON.ToJSON Google.Response.DateTime
+ Google.Response: instance Data.Aeson.Types.ToJSON.ToJSON Google.Response.ZonedDateTime
+ Google.Response: instance GHC.Classes.Eq Google.Response.Account
+ Google.Response: instance GHC.Classes.Eq Google.Response.CalendarEventList
+ Google.Response: instance GHC.Classes.Eq Google.Response.DateTime
+ Google.Response: instance GHC.Classes.Eq Google.Response.ZonedDateTime
+ Google.Response: instance GHC.Generics.Generic Google.Response.Account
+ Google.Response: instance GHC.Generics.Generic Google.Response.CalendarEventList
+ Google.Response: instance GHC.Generics.Generic Google.Response.DateTime
+ Google.Response: instance GHC.Generics.Generic Google.Response.ZonedDateTime
+ Google.Response: instance GHC.Show.Show Google.Response.Account
+ Google.Response: instance GHC.Show.Show Google.Response.CalendarEventList
+ Google.Response: instance GHC.Show.Show Google.Response.DateTime
+ Google.Response: instance GHC.Show.Show Google.Response.ZonedDateTime
+ Google.Response: instance Web.Internal.HttpApiData.FromHttpApiData Google.Response.Account
+ Google.Response: instance Web.Internal.HttpApiData.FromHttpApiData Google.Response.DateTime
+ Google.Response: instance Web.Internal.HttpApiData.FromHttpApiData Google.Response.ZonedDateTime
+ Google.Response: instance Web.Internal.HttpApiData.FromHttpApiData [Google.Response.Account]
+ Google.Response: instance Web.Internal.HttpApiData.ToHttpApiData Google.Response.Account
+ Google.Response: instance Web.Internal.HttpApiData.ToHttpApiData Google.Response.DateTime
+ Google.Response: instance Web.Internal.HttpApiData.ToHttpApiData Google.Response.ZonedDateTime
+ Google.Response: instance Web.Internal.HttpApiData.ToHttpApiData [Google.Response.Account]
+ Google.Response: newtype Account
+ Google.Response: newtype DateTime
+ Google.Response: newtype ZonedDateTime
- Google.Response: CalendarEvent :: Text -> CalendarEvent
+ Google.Response: CalendarEvent :: Text -> Account -> Maybe [Account] -> Maybe Text -> Maybe Text -> Maybe ZonedDateTime -> Maybe ZonedDateTime -> CalendarEvent
Files
- google-server-api.cabal +2/−2
- src/Google/Client.hs +41/−1
- src/Google/Form.hs +3/−2
- src/Google/Response.hs +56/−0
google-server-api.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: f103dcbf98029b7f6d92e1567345d75693b1ffe818a833de202c0c5225fb5777+-- hash: 5ac159e750a2b71f84690632c27ad9f6a2e84d8f1cb4a5889fb343356817ca12 name: google-server-api-version: 0.3.0.0+version: 0.3.1.0 synopsis: Google APIs for server to server applications description: This library provides a way to use Google API for server to server applications. category: Web
src/Google/Client.hs view
@@ -8,6 +8,7 @@ -} module Google.Client ( getToken+ , getCalendarEventList , postCalendarEvent , postGmailSend ) where@@ -31,9 +32,11 @@ , Capture , FormUrlEncoded , FromHttpApiData+ , Get , Header , JSON , Post+ , QueryParam , ReqBody , ToHttpApiData )@@ -74,6 +77,15 @@ Capture "calendarId" Text :> "events" :> Header "Authorization" Bearer :>+ QueryParam "singleEvents" Bool :>+ QueryParam "timeMin" Form.DateTime :>+ QueryParam "timeMax" Form.DateTime :>+ QueryParam "orderBy" Text :>+ Get '[ JSON] Response.CalendarEventList+ :<|> "calendar" :> "v3" :> "calendars" :>+ Capture "calendarId" Text :>+ "events" :>+ Header "Authorization" Bearer :> ReqBody '[ JSON] Form.CalendarEvent :> Post '[ JSON] Response.CalendarEvent :<|> "gmail" :> "v1" :> "users" :> "me" :> "messages" :> "send" :>@@ -85,13 +97,21 @@ api = Proxy getToken' :: Form.Token -> ClientM Response.Token+getCalendarEventList' ::+ Text+ -> Maybe Bearer+ -> Maybe Bool+ -> Maybe Form.DateTime+ -> Maybe Form.DateTime+ -> Maybe Text+ -> ClientM Response.CalendarEventList postCalendarEvent' :: Text -> Maybe Bearer -> Form.CalendarEvent -> ClientM Response.CalendarEvent postGmailSend' :: Maybe Bearer -> Form.GmailSend -> ClientM Response.GmailSend-getToken' :<|> postCalendarEvent' :<|> postGmailSend' = client api+getToken' :<|> getCalendarEventList' :<|> postCalendarEvent' :<|> postGmailSend' = client api getToken :: Maybe JWT.Email@@ -107,6 +127,26 @@ { grantType = googleGrantType , assertion = decodeUtf8 . JWT.unSignedJWT $ a })+ (mkClientEnv manager googleBaseUrl)++getCalendarEventList ::+ Response.Token+ -> Text+ -> Maybe Bool+ -> Maybe Form.DateTime+ -> Maybe Form.DateTime+ -> Maybe Text+ -> IO (Either ServantError Response.CalendarEventList)+getCalendarEventList token calendarId singleEvents timeMin timeMax orderBy = do+ manager <- newManager tlsManagerSettings+ runClientM+ (getCalendarEventList'+ calendarId+ (pure . toBearer $ token)+ singleEvents+ timeMin+ timeMax+ orderBy) (mkClientEnv manager googleBaseUrl) postCalendarEvent ::
src/Google/Form.hs view
@@ -27,6 +27,7 @@ import Network.Mail.Mime (Address(..), Mail(..), renderAddress, simpleMail) import Web.FormUrlEncoded (Form(..), ToForm(toForm)) import Web.Internal.HttpApiData (toQueryParam)+import Web.HttpApiData (ToHttpApiData(..)) import qualified Data.HashMap.Strict as HashMap @@ -39,9 +40,9 @@ instance IsString Account where fromString = Account . fromString -data DateTime = DateTime+newtype DateTime = DateTime { dateTime :: UTCTime- } deriving (Eq, Generic, Show, Typeable)+ } deriving (Eq, Generic, Show, Typeable, ToHttpApiData) deriveJSON defaultOptions ''DateTime
src/Google/Response.hs view
@@ -10,9 +10,13 @@ import Data.Aeson.Casing (snakeCase) import Data.Aeson.TH (Options(..), defaultOptions, deriveJSON) import Data.Text (Text)+import Data.Text (intercalate, splitOn) import Data.Typeable (Typeable) import GHC.Generics (Generic) import Web.FormUrlEncoded (FromForm, ToForm)+import Data.Time.Clock (UTCTime)+import Data.Time.LocalTime (ZonedTime, zonedTimeToUTC)+import Web.HttpApiData (FromHttpApiData(..), ToHttpApiData(..), parseUrlPieces, toUrlPieces) data Token = Token { accessToken :: Text@@ -26,8 +30,51 @@ instance ToForm Token +newtype Account = Account+ { email :: Text+ } deriving (Eq, Generic, Show, Typeable, FromHttpApiData, ToHttpApiData)++deriveJSON defaultOptions ''Account++instance FromHttpApiData [Account] where+ parseUrlPiece = parseUrlPieces . (splitOn ",")++instance ToHttpApiData [Account] where+ toUrlPiece = (intercalate ",") . toUrlPieces+++newtype DateTime = DateTime+ { dateTime :: UTCTime+ } deriving (Eq, Generic, Show, Typeable, FromHttpApiData, ToHttpApiData)++deriveJSON defaultOptions ''DateTime+++newtype ZonedDateTime = ZonedDateTime+ { dateTime :: Maybe ZonedTime+ } deriving (Generic, Show, Typeable, FromHttpApiData, ToHttpApiData)++deriveJSON defaultOptions ''ZonedDateTime++instance Eq ZonedDateTime where+ (==) =+ (\x y ->+ let+ toUTC :: ZonedDateTime -> Maybe UTCTime+ toUTC = (fmap zonedTimeToUTC) . (dateTime :: ZonedDateTime -> Maybe ZonedTime)+ in+ (toUTC x) == (toUTC y)+ )++ data CalendarEvent = CalendarEvent { status :: Text+ , creator :: Account+ , attendees :: Maybe [Account]+ , summary :: Maybe Text+ , description :: Maybe Text+ , start :: Maybe ZonedDateTime+ , end :: Maybe ZonedDateTime } deriving (Eq, Generic, Show, Typeable) deriveJSON defaultOptions ''CalendarEvent@@ -35,6 +82,15 @@ instance FromForm CalendarEvent instance ToForm CalendarEvent+++data CalendarEventList = CalendarEventList+ { kind :: Text+ , summary :: Text+ , items :: [CalendarEvent]+ } deriving (Eq, Generic, Show, Typeable)++deriveJSON defaultOptions ''CalendarEventList data GmailSend = GmailSend