on develop help sign in
added 3 examples for google sheets API
e367ff1milad
examples/gogol-examples.cabal+3
@@ -19,6 +19,7 @@ library
19
19
20 exposed-modules:
20 exposed-modules:
21 Example.Storage
21 Example.Storage
22+ , Example.Sheets
22
23
23 build-depends:
24 build-depends:
24 base >= 4.7
25 base >= 4.7
@@ -28,6 +29,8 @@ library
28 , gogol == 0.3.0.*
29 , gogol == 0.3.0.*
29 , gogol-core
30 , gogol-core
30 , gogol-storage
31 , gogol-storage
32+ , gogol-sheets
31 , lens
33 , lens
32 , resourcet
34 , resourcet
33 , text
35 , text
36+ , aeson
examples/src/Example/Sheets.hsnew file+54
@@ -0,0 +1,54 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module Example.Sheets where
4+
5+---------------------------------------------------------------------------------
6+import Network.Google.Resource.Sheets.Spreadsheets.Get
7+import Network.Google.Sheets
8+import Network.Google
9+
10+import Control.Lens ((.~), (<&>))
11+import Data.Text (Text)
12+import System.IO (stdout)
13+import Data.Aeson.Types
14+
15+---------------------------------------------------------------------------------
16+
17+-- |
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.
22+--
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.
26+--
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 )
34+
35+-- |
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 )
44+
45+
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
52+ sheetID
53+ ( vrMajorDimension .~ Just VRMDRows $ vrValues .~ val $ vrRange .~ Just range $ valueRange)
54+ range )