on develop help sign in
added 3 examples for google sheets API

these 3 minimalistic examples should demonstrate how to use google sheets APIs. There are also some explanations for each of the examples.

commite367ff170b5998ff4a28b261b4088f0eee5a6c54 authormilad <mza1989@gmail.com> dateWed 16 Aug 2017, 13:24 (9 years ago) parentc71b9a7
2 files changed+57
examples/gogol-examples.cabal+3 examples/src/Example/Sheets.hs+54
examples/gogol-examples.cabal+3
@@ -19,6 +19,7 @@ library
1919
2020 exposed-modules:
2121 Example.Storage
22+ , Example.Sheets
2223
2324 build-depends:
2425 base >= 4.7
@@ -28,6 +29,8 @@ library
2829 , gogol == 0.3.0.*
2930 , gogol-core
3031 , gogol-storage
32+ , gogol-sheets
3133 , lens
3234 , resourcet
3335 , 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 )