@@ -0,0 +1,54 @@
1+{-# LANGUAGE OverloadedStrings #-}
3+module Example.Sheets where
5+---------------------------------------------------------------------------------
6+import Network.Google.Resource.Sheets.Spreadsheets.Get
7+import Network.Google.Sheets
10+import Control.Lens ((.~), (<&>))
11+import Data.Text (Text)
12+import System.IO (stdout)
13+import Data.Aeson.Types
15+---------------------------------------------------------------------------------
18+-- This gets the Information about an spreadsheet.
19+-- In order to be able to run these examples you need to
20+-- create a service acount from google's developers console
21+-- and copy the dowloaded json file to ~/.config/gcloud/application_default_credentials.json.
23+-- you must also share with your service the spreadsheet that you want to get the info of.
24+-- In order to do this you must share the sheet with the email address of your service
25+-- which is in your downloaded service config file.
27+-- after doing above step just pass the sreadsheet id to the function.
28+exampleGetSheet :: Text -> IO Spreadsheet
29+exampleGetSheet sheetID = do
30+ lgr <- newLogger Debug stdout
31+ env <- newEnv <&> (envLogger .~ lgr) . (envScopes .~ spreadsheetsScope)
32+ runResourceT . runGoogle env $
33+ send (spreadsheetsGet sheetID )
36+-- you pass the sheet id and a range (eg. "sheet1!A1:C3") in that sheet
37+-- and it retreives the values in the specified range
38+exampleGetValue :: Text -> Text -> IO ValueRange
39+exampleGetValue sheetID range = do
40+ lgr <- newLogger Debug stdout
41+ env <- newEnv <&> (envLogger .~ lgr) . (envScopes .~ spreadsheetsScope)
42+ runResourceT . runGoogle env $
43+ send (spreadsheetsValuesGet sheetID range )
46+exampleAppendValue :: Text -> Text -> [[Value]] -> IO AppendValuesResponse
47+exampleAppendValue sheetID range val = do
48+ lgr <- newLogger Debug stdout
49+ env <- newEnv <&> (envLogger .~ lgr) . (envScopes .~ spreadsheetsScope)
50+ runResourceT . runGoogle env $
51+ send (svaValueInputOption .~ Just "USER_ENTERED" $ spreadsheetsValuesAppend
53+ ( vrMajorDimension .~ Just VRMDRows $ vrValues .~ val $ vrRange .~ Just range $ valueRange)