@@ -0,0 +1,525 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE NoImplicitPrelude #-}
4+{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE RecordWildCards #-}
7+{-# OPTIONS_GHC -fno-warn-unused-binds #-}
8+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
11+-- Module : Network.Google.Script.Types.Product
12+-- Copyright : (c) 2015 Brendan Hay
13+-- License : Mozilla Public License, v. 2.0.
14+-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
15+-- Stability : auto-generated
16+-- Portability : non-portable (GHC extensions)
18+module Network.Google.Script.Types.Product where
20+import Network.Google.Prelude
21+import Network.Google.Script.Types.Sum
23+-- | If a \`run\` call succeeds but the script function (or Apps Script
24+-- itself) throws an exception, the response body\'s \`error\` field will
25+-- contain this \`Status\` object.
27+-- /See:/ 'status' smart constructor.
29+ { _sDetails :: !(Maybe [StatusDetailsItem])
30+ , _sCode :: !(Maybe (Textual Int32))
31+ , _sMessage :: !(Maybe Text)
32+ } deriving (Eq,Show,Data,Typeable,Generic)
34+-- | Creates a value of 'Status' with the minimum fields required to make a request.
36+-- Use one of the following lenses to modify other fields as desired:
47+ { _sDetails = Nothing
49+ , _sMessage = Nothing
52+-- | An array that contains a single \`ExecutionError\` object that provides
53+-- information about the nature of the error.
54+sDetails :: Lens' Status [StatusDetailsItem]
56+ = lens _sDetails (\ s a -> s{_sDetails = a}) .
60+-- | The status code, which should be an enum value of google.rpc.Code.
61+sCode :: Lens' Status (Maybe Int32)
63+ = lens _sCode (\ s a -> s{_sCode = a}) .
66+-- | A developer-facing error message, which should be in English. Any
67+-- user-facing error message should be localized and sent in the
68+-- google.rpc.Status.details field, or localized by the client.
69+sMessage :: Lens' Status (Maybe Text)
70+sMessage = lens _sMessage (\ s a -> s{_sMessage = a})
72+instance FromJSON Status where
74+ = withObject "Status"
77+ (o .:? "details" .!= mempty) <*> (o .:? "code") <*>
80+instance ToJSON Status where
84+ [("details" .=) <$> _sDetails,
85+ ("code" .=) <$> _sCode,
86+ ("message" .=) <$> _sMessage])
88+-- | The response will not arrive until the function finishes executing. The
89+-- maximum runtime is listed in the guide to [limitations in Apps
90+-- Script](https:\/\/developers.google.com\/apps-script\/guides\/services\/quotas#current_limitations).
91+-- If the script function returns successfully, the \`response\` field will
92+-- contain an \`ExecutionResponse\` object with the function\'s return
93+-- value in the object\'s \`result\` field. If the script function (or Apps
94+-- Script itself) throws an exception, the \`error\` field will contain a
95+-- \`Status\` object. The \`Status\` object\'s \`details\` field will
96+-- contain an array with a single \`ExecutionError\` object that provides
97+-- information about the nature of the error. If the \`run\` call itself
98+-- fails (for example, because of a malformed request or an authorization
99+-- error), the method will return an HTTP response code in the 4XX range
100+-- with a different format for the response body. Client libraries will
101+-- automatically convert a 4XX response into an exception class.
103+-- /See:/ 'operation' smart constructor.
104+data Operation = Operation
105+ { _oDone :: !(Maybe Bool)
106+ , _oError :: !(Maybe Status)
107+ , _oResponse :: !(Maybe OperationResponse)
108+ , _oName :: !(Maybe Text)
109+ , _oMetadata :: !(Maybe OperationMetadata)
110+ } deriving (Eq,Show,Data,Typeable,Generic)
112+-- | Creates a value of 'Operation' with the minimum fields required to make a request.
114+-- Use one of the following lenses to modify other fields as desired:
131+ , _oResponse = Nothing
133+ , _oMetadata = Nothing
136+-- | This field is not used.
137+oDone :: Lens' Operation (Maybe Bool)
138+oDone = lens _oDone (\ s a -> s{_oDone = a})
140+-- | If a \`run\` call succeeds but the script function (or Apps Script
141+-- itself) throws an exception, this field will contain a \`Status\`
142+-- object. The \`Status\` object\'s \`details\` field will contain an array
143+-- with a single \`ExecutionError\` object that provides information about
144+-- the nature of the error.
145+oError :: Lens' Operation (Maybe Status)
146+oError = lens _oError (\ s a -> s{_oError = a})
148+-- | If the script function returns successfully, this field will contain an
149+-- \`ExecutionResponse\` object with the function\'s return value as the
150+-- object\'s \`result\` field.
151+oResponse :: Lens' Operation (Maybe OperationResponse)
153+ = lens _oResponse (\ s a -> s{_oResponse = a})
155+-- | This field is not used.
156+oName :: Lens' Operation (Maybe Text)
157+oName = lens _oName (\ s a -> s{_oName = a})
159+-- | This field is not used.
160+oMetadata :: Lens' Operation (Maybe OperationMetadata)
162+ = lens _oMetadata (\ s a -> s{_oMetadata = a})
164+instance FromJSON Operation where
166+ = withObject "Operation"
169+ (o .:? "done") <*> (o .:? "error") <*>
172+ <*> (o .:? "metadata"))
174+instance ToJSON Operation where
175+ toJSON Operation{..}
178+ [("done" .=) <$> _oDone, ("error" .=) <$> _oError,
179+ ("response" .=) <$> _oResponse,
180+ ("name" .=) <$> _oName,
181+ ("metadata" .=) <$> _oMetadata])
183+-- | A request to run the function in a script. The script is identified by
184+-- the specified \`script_id\`. Executing a function on a script will
185+-- return results based on the implementation of the script.
187+-- /See:/ 'executionRequest' smart constructor.
188+data ExecutionRequest = ExecutionRequest
189+ { _erFunction :: !(Maybe Text)
190+ , _erSessionState :: !(Maybe Text)
191+ , _erDevMode :: !(Maybe Bool)
192+ , _erParameters :: !(Maybe [JSONValue])
193+ } deriving (Eq,Show,Data,Typeable,Generic)
195+-- | Creates a value of 'ExecutionRequest' with the minimum fields required to make a request.
197+-- Use one of the following lenses to modify other fields as desired:
201+-- * 'erSessionState'
210+ { _erFunction = Nothing
211+ , _erSessionState = Nothing
212+ , _erDevMode = Nothing
213+ , _erParameters = Nothing
216+-- | The name of the function to execute in the given script. The name does
217+-- not include parentheses or parameters.
218+erFunction :: Lens' ExecutionRequest (Maybe Text)
220+ = lens _erFunction (\ s a -> s{_erFunction = a})
222+-- | This field is not used.
223+erSessionState :: Lens' ExecutionRequest (Maybe Text)
225+ = lens _erSessionState
226+ (\ s a -> s{_erSessionState = a})
228+-- | If \`true\` and the user is an owner of the script, the script runs at
229+-- the most recently saved version rather than the version deployed for use
230+-- with the Execution API. Optional; default is \`false\`.
231+erDevMode :: Lens' ExecutionRequest (Maybe Bool)
233+ = lens _erDevMode (\ s a -> s{_erDevMode = a})
235+-- | The parameters to be passed to the function being executed. The type for
236+-- each parameter should match the expected type in Apps Script. Parameters
237+-- cannot be Apps Script-specific objects (such as a \`Document\` or
238+-- \`Calendar\`); they can only be primitive types such as a \`string\`,
239+-- \`number\`, \`array\`, \`object\`, or \`boolean\`. Optional.
240+erParameters :: Lens' ExecutionRequest [JSONValue]
242+ = lens _erParameters (\ s a -> s{_erParameters = a})
246+instance FromJSON ExecutionRequest where
248+ = withObject "ExecutionRequest"
250+ ExecutionRequest <$>
251+ (o .:? "function") <*> (o .:? "sessionState") <*>
253+ <*> (o .:? "parameters" .!= mempty))
255+instance ToJSON ExecutionRequest where
256+ toJSON ExecutionRequest{..}
259+ [("function" .=) <$> _erFunction,
260+ ("sessionState" .=) <$> _erSessionState,
261+ ("devMode" .=) <$> _erDevMode,
262+ ("parameters" .=) <$> _erParameters])
265+-- /See:/ 'statusDetailsItem' smart constructor.
266+newtype StatusDetailsItem = StatusDetailsItem
267+ { _sdiAddtional :: HashMap Text JSONValue
268+ } deriving (Eq,Show,Data,Typeable,Generic)
270+-- | Creates a value of 'StatusDetailsItem' with the minimum fields required to make a request.
272+-- Use one of the following lenses to modify other fields as desired:
276+ :: HashMap Text JSONValue -- ^ 'sdiAddtional'
277+ -> StatusDetailsItem
278+statusDetailsItem pSdiAddtional_ =
280+ { _sdiAddtional = _Coerce # pSdiAddtional_
283+-- | Properties of the object. Contains field \'ype with type URL.
284+sdiAddtional :: Lens' StatusDetailsItem (HashMap Text JSONValue)
286+ = lens _sdiAddtional (\ s a -> s{_sdiAddtional = a})
289+instance FromJSON StatusDetailsItem where
291+ = withObject "StatusDetailsItem"
292+ (\ o -> StatusDetailsItem <$> (parseJSONObject o))
294+instance ToJSON StatusDetailsItem where
295+ toJSON = toJSON . _sdiAddtional
297+-- | A stack trace through the script that shows where the execution failed.
299+-- /See:/ 'scriptStackTraceElement' smart constructor.
300+data ScriptStackTraceElement = ScriptStackTraceElement
301+ { _ssteFunction :: !(Maybe Text)
302+ , _ssteLineNumber :: !(Maybe (Textual Int32))
303+ } deriving (Eq,Show,Data,Typeable,Generic)
305+-- | Creates a value of 'ScriptStackTraceElement' with the minimum fields required to make a request.
307+-- Use one of the following lenses to modify other fields as desired:
311+-- * 'ssteLineNumber'
312+scriptStackTraceElement
313+ :: ScriptStackTraceElement
314+scriptStackTraceElement =
315+ ScriptStackTraceElement
316+ { _ssteFunction = Nothing
317+ , _ssteLineNumber = Nothing
320+-- | The name of the function that failed.
321+ssteFunction :: Lens' ScriptStackTraceElement (Maybe Text)
323+ = lens _ssteFunction (\ s a -> s{_ssteFunction = a})
325+-- | The line number where the script failed.
326+ssteLineNumber :: Lens' ScriptStackTraceElement (Maybe Int32)
328+ = lens _ssteLineNumber
329+ (\ s a -> s{_ssteLineNumber = a})
332+instance FromJSON ScriptStackTraceElement where
334+ = withObject "ScriptStackTraceElement"
336+ ScriptStackTraceElement <$>
337+ (o .:? "function") <*> (o .:? "lineNumber"))
339+instance ToJSON ScriptStackTraceElement where
340+ toJSON ScriptStackTraceElement{..}
343+ [("function" .=) <$> _ssteFunction,
344+ ("lineNumber" .=) <$> _ssteLineNumber])
346+-- | An object that provides information about the nature of an error in the
347+-- Apps Script Execution API. If an \`run\` call succeeds but the script
348+-- function (or Apps Script itself) throws an exception, the response
349+-- body\'s \`error\` field will contain a \`Status\` object. The \`Status\`
350+-- object\'s \`details\` field will contain an array with a single one of
351+-- these \`ExecutionError\` objects.
353+-- /See:/ 'executionError' smart constructor.
354+data ExecutionError = ExecutionError
355+ { _eeScriptStackTraceElements :: !(Maybe [ScriptStackTraceElement])
356+ , _eeErrorType :: !(Maybe Text)
357+ , _eeErrorMessage :: !(Maybe Text)
358+ } deriving (Eq,Show,Data,Typeable,Generic)
360+-- | Creates a value of 'ExecutionError' with the minimum fields required to make a request.
362+-- Use one of the following lenses to modify other fields as desired:
364+-- * 'eeScriptStackTraceElements'
368+-- * 'eeErrorMessage'
373+ { _eeScriptStackTraceElements = Nothing
374+ , _eeErrorType = Nothing
375+ , _eeErrorMessage = Nothing
378+-- | An array of objects that provide a stack trace through the script to
379+-- show where the execution failed, with the deepest call first.
380+eeScriptStackTraceElements :: Lens' ExecutionError [ScriptStackTraceElement]
381+eeScriptStackTraceElements
382+ = lens _eeScriptStackTraceElements
383+ (\ s a -> s{_eeScriptStackTraceElements = a})
387+-- | The error type, for example \`TypeError\` or \`ReferenceError\`. If the
388+-- error type is unavailable, this field is not included.
389+eeErrorType :: Lens' ExecutionError (Maybe Text)
391+ = lens _eeErrorType (\ s a -> s{_eeErrorType = a})
393+-- | The error message thrown by Apps Script, usually localized into the
395+eeErrorMessage :: Lens' ExecutionError (Maybe Text)
397+ = lens _eeErrorMessage
398+ (\ s a -> s{_eeErrorMessage = a})
400+instance FromJSON ExecutionError where
402+ = withObject "ExecutionError"
405+ (o .:? "scriptStackTraceElements" .!= mempty) <*>
407+ <*> (o .:? "errorMessage"))
409+instance ToJSON ExecutionError where
410+ toJSON ExecutionError{..}
413+ [("scriptStackTraceElements" .=) <$>
414+ _eeScriptStackTraceElements,
415+ ("errorType" .=) <$> _eeErrorType,
416+ ("errorMessage" .=) <$> _eeErrorMessage])
418+-- | This field is not used.
420+-- /See:/ 'operationMetadata' smart constructor.
421+newtype OperationMetadata = OperationMetadata
422+ { _omAddtional :: HashMap Text JSONValue
423+ } deriving (Eq,Show,Data,Typeable,Generic)
425+-- | Creates a value of 'OperationMetadata' with the minimum fields required to make a request.
427+-- Use one of the following lenses to modify other fields as desired:
431+ :: HashMap Text JSONValue -- ^ 'omAddtional'
432+ -> OperationMetadata
433+operationMetadata pOmAddtional_ =
435+ { _omAddtional = _Coerce # pOmAddtional_
438+-- | Properties of the object. Contains field \'ype with type URL.
439+omAddtional :: Lens' OperationMetadata (HashMap Text JSONValue)
441+ = lens _omAddtional (\ s a -> s{_omAddtional = a}) .
444+instance FromJSON OperationMetadata where
446+ = withObject "OperationMetadata"
447+ (\ o -> OperationMetadata <$> (parseJSONObject o))
449+instance ToJSON OperationMetadata where
450+ toJSON = toJSON . _omAddtional
452+-- | If the script function returns successfully, this field will contain an
453+-- \`ExecutionResponse\` object with the function\'s return value as the
454+-- object\'s \`result\` field.
456+-- /See:/ 'operationResponse' smart constructor.
457+newtype OperationResponse = OperationResponse
458+ { _orAddtional :: HashMap Text JSONValue
459+ } deriving (Eq,Show,Data,Typeable,Generic)
461+-- | Creates a value of 'OperationResponse' with the minimum fields required to make a request.
463+-- Use one of the following lenses to modify other fields as desired:
467+ :: HashMap Text JSONValue -- ^ 'orAddtional'
468+ -> OperationResponse
469+operationResponse pOrAddtional_ =
471+ { _orAddtional = _Coerce # pOrAddtional_
474+-- | Properties of the object. Contains field \'ype with type URL.
475+orAddtional :: Lens' OperationResponse (HashMap Text JSONValue)
477+ = lens _orAddtional (\ s a -> s{_orAddtional = a}) .
480+instance FromJSON OperationResponse where
482+ = withObject "OperationResponse"
483+ (\ o -> OperationResponse <$> (parseJSONObject o))
485+instance ToJSON OperationResponse where
486+ toJSON = toJSON . _orAddtional
488+-- | An object that provides the return value of a function executed through
489+-- the Apps Script Execution API. If an \`run\` call succeeds and the
490+-- script function returns successfully, the response body\'s \`response\`
491+-- field will contain this \`ExecutionResponse\` object.
493+-- /See:/ 'executionResponse' smart constructor.
494+newtype ExecutionResponse = ExecutionResponse
495+ { _erResult :: Maybe JSONValue
496+ } deriving (Eq,Show,Data,Typeable,Generic)
498+-- | Creates a value of 'ExecutionResponse' with the minimum fields required to make a request.
500+-- Use one of the following lenses to modify other fields as desired:
504+ :: ExecutionResponse
507+ { _erResult = Nothing
510+-- | The return value of the script function. The type will match the type
511+-- returned in Apps Script. Functions called through the Execution API
512+-- cannot return Apps Script-specific objects (such as a \`Document\` or
513+-- \`Calendar\`); they can only return primitive types such as a
514+-- \`string\`, \`number\`, \`array\`, \`object\`, or \`boolean\`.
515+erResult :: Lens' ExecutionResponse (Maybe JSONValue)
516+erResult = lens _erResult (\ s a -> s{_erResult = a})
518+instance FromJSON ExecutionResponse where
520+ = withObject "ExecutionResponse"
521+ (\ o -> ExecutionResponse <$> (o .:? "result"))
523+instance ToJSON ExecutionResponse where
524+ toJSON ExecutionResponse{..}
525+ = object (catMaybes [("result" .=) <$> _erResult])