@@ -0,0 +1,525 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE NoImplicitPrelude #-}
4+{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE RecordWildCards #-}
6+
7+{-# OPTIONS_GHC -fno-warn-unused-binds #-}
8+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
9+
10+-- |
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)
17+--
18+module Network.Google.Script.Types.Product where
19+
20+import Network.Google.Prelude
21+import Network.Google.Script.Types.Sum
22+
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.
26+--
27+-- /See:/ 'status' smart constructor.
28+data Status = Status
29+ { _sDetails :: !(Maybe [StatusDetailsItem])
30+ , _sCode :: !(Maybe (Textual Int32))
31+ , _sMessage :: !(Maybe Text)
32+ } deriving (Eq,Show,Data,Typeable,Generic)
33+
34+-- | Creates a value of 'Status' with the minimum fields required to make a request.
35+--
36+-- Use one of the following lenses to modify other fields as desired:
37+--
38+-- * 'sDetails'
39+--
40+-- * 'sCode'
41+--
42+-- * 'sMessage'
43+status
44+ :: Status
45+status =
46+ Status
47+ { _sDetails = Nothing
48+ , _sCode = Nothing
49+ , _sMessage = Nothing
50+ }
51+
52+-- | An array that contains a single \`ExecutionError\` object that provides
53+-- information about the nature of the error.
54+sDetails :: Lens' Status [StatusDetailsItem]
55+sDetails
56+ = lens _sDetails (\ s a -> s{_sDetails = a}) .
57+ _Default
58+ . _Coerce
59+
60+-- | The status code, which should be an enum value of google.rpc.Code.
61+sCode :: Lens' Status (Maybe Int32)
62+sCode
63+ = lens _sCode (\ s a -> s{_sCode = a}) .
64+ mapping _Coerce
65+
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})
71+
72+instance FromJSON Status where
73+ parseJSON
74+ = withObject "Status"
75+ (\ o ->
76+ Status <$>
77+ (o .:? "details" .!= mempty) <*> (o .:? "code") <*>
78+ (o .:? "message"))
79+
80+instance ToJSON Status where
81+ toJSON Status{..}
82+ = object
83+ (catMaybes
84+ [("details" .=) <$> _sDetails,
85+ ("code" .=) <$> _sCode,
86+ ("message" .=) <$> _sMessage])
87+
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.
102+--
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)
111+
112+-- | Creates a value of 'Operation' with the minimum fields required to make a request.
113+--
114+-- Use one of the following lenses to modify other fields as desired:
115+--
116+-- * 'oDone'
117+--
118+-- * 'oError'
119+--
120+-- * 'oResponse'
121+--
122+-- * 'oName'
123+--
124+-- * 'oMetadata'
125+operation
126+ :: Operation
127+operation =
128+ Operation
129+ { _oDone = Nothing
130+ , _oError = Nothing
131+ , _oResponse = Nothing
132+ , _oName = Nothing
133+ , _oMetadata = Nothing
134+ }
135+
136+-- | This field is not used.
137+oDone :: Lens' Operation (Maybe Bool)
138+oDone = lens _oDone (\ s a -> s{_oDone = a})
139+
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})
147+
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)
152+oResponse
153+ = lens _oResponse (\ s a -> s{_oResponse = a})
154+
155+-- | This field is not used.
156+oName :: Lens' Operation (Maybe Text)
157+oName = lens _oName (\ s a -> s{_oName = a})
158+
159+-- | This field is not used.
160+oMetadata :: Lens' Operation (Maybe OperationMetadata)
161+oMetadata
162+ = lens _oMetadata (\ s a -> s{_oMetadata = a})
163+
164+instance FromJSON Operation where
165+ parseJSON
166+ = withObject "Operation"
167+ (\ o ->
168+ Operation <$>
169+ (o .:? "done") <*> (o .:? "error") <*>
170+ (o .:? "response")
171+ <*> (o .:? "name")
172+ <*> (o .:? "metadata"))
173+
174+instance ToJSON Operation where
175+ toJSON Operation{..}
176+ = object
177+ (catMaybes
178+ [("done" .=) <$> _oDone, ("error" .=) <$> _oError,
179+ ("response" .=) <$> _oResponse,
180+ ("name" .=) <$> _oName,
181+ ("metadata" .=) <$> _oMetadata])
182+
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.
186+--
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)
194+
195+-- | Creates a value of 'ExecutionRequest' with the minimum fields required to make a request.
196+--
197+-- Use one of the following lenses to modify other fields as desired:
198+--
199+-- * 'erFunction'
200+--
201+-- * 'erSessionState'
202+--
203+-- * 'erDevMode'
204+--
205+-- * 'erParameters'
206+executionRequest
207+ :: ExecutionRequest
208+executionRequest =
209+ ExecutionRequest
210+ { _erFunction = Nothing
211+ , _erSessionState = Nothing
212+ , _erDevMode = Nothing
213+ , _erParameters = Nothing
214+ }
215+
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)
219+erFunction
220+ = lens _erFunction (\ s a -> s{_erFunction = a})
221+
222+-- | This field is not used.
223+erSessionState :: Lens' ExecutionRequest (Maybe Text)
224+erSessionState
225+ = lens _erSessionState
226+ (\ s a -> s{_erSessionState = a})
227+
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)
232+erDevMode
233+ = lens _erDevMode (\ s a -> s{_erDevMode = a})
234+
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]
241+erParameters
242+ = lens _erParameters (\ s a -> s{_erParameters = a})
243+ . _Default
244+ . _Coerce
245+
246+instance FromJSON ExecutionRequest where
247+ parseJSON
248+ = withObject "ExecutionRequest"
249+ (\ o ->
250+ ExecutionRequest <$>
251+ (o .:? "function") <*> (o .:? "sessionState") <*>
252+ (o .:? "devMode")
253+ <*> (o .:? "parameters" .!= mempty))
254+
255+instance ToJSON ExecutionRequest where
256+ toJSON ExecutionRequest{..}
257+ = object
258+ (catMaybes
259+ [("function" .=) <$> _erFunction,
260+ ("sessionState" .=) <$> _erSessionState,
261+ ("devMode" .=) <$> _erDevMode,
262+ ("parameters" .=) <$> _erParameters])
263+
264+--
265+-- /See:/ 'statusDetailsItem' smart constructor.
266+newtype StatusDetailsItem = StatusDetailsItem
267+ { _sdiAddtional :: HashMap Text JSONValue
268+ } deriving (Eq,Show,Data,Typeable,Generic)
269+
270+-- | Creates a value of 'StatusDetailsItem' with the minimum fields required to make a request.
271+--
272+-- Use one of the following lenses to modify other fields as desired:
273+--
274+-- * 'sdiAddtional'
275+statusDetailsItem
276+ :: HashMap Text JSONValue -- ^ 'sdiAddtional'
277+ -> StatusDetailsItem
278+statusDetailsItem pSdiAddtional_ =
279+ StatusDetailsItem
280+ { _sdiAddtional = _Coerce # pSdiAddtional_
281+ }
282+
283+-- | Properties of the object. Contains field \'ype with type URL.
284+sdiAddtional :: Lens' StatusDetailsItem (HashMap Text JSONValue)
285+sdiAddtional
286+ = lens _sdiAddtional (\ s a -> s{_sdiAddtional = a})
287+ . _Coerce
288+
289+instance FromJSON StatusDetailsItem where
290+ parseJSON
291+ = withObject "StatusDetailsItem"
292+ (\ o -> StatusDetailsItem <$> (parseJSONObject o))
293+
294+instance ToJSON StatusDetailsItem where
295+ toJSON = toJSON . _sdiAddtional
296+
297+-- | A stack trace through the script that shows where the execution failed.
298+--
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)
304+
305+-- | Creates a value of 'ScriptStackTraceElement' with the minimum fields required to make a request.
306+--
307+-- Use one of the following lenses to modify other fields as desired:
308+--
309+-- * 'ssteFunction'
310+--
311+-- * 'ssteLineNumber'
312+scriptStackTraceElement
313+ :: ScriptStackTraceElement
314+scriptStackTraceElement =
315+ ScriptStackTraceElement
316+ { _ssteFunction = Nothing
317+ , _ssteLineNumber = Nothing
318+ }
319+
320+-- | The name of the function that failed.
321+ssteFunction :: Lens' ScriptStackTraceElement (Maybe Text)
322+ssteFunction
323+ = lens _ssteFunction (\ s a -> s{_ssteFunction = a})
324+
325+-- | The line number where the script failed.
326+ssteLineNumber :: Lens' ScriptStackTraceElement (Maybe Int32)
327+ssteLineNumber
328+ = lens _ssteLineNumber
329+ (\ s a -> s{_ssteLineNumber = a})
330+ . mapping _Coerce
331+
332+instance FromJSON ScriptStackTraceElement where
333+ parseJSON
334+ = withObject "ScriptStackTraceElement"
335+ (\ o ->
336+ ScriptStackTraceElement <$>
337+ (o .:? "function") <*> (o .:? "lineNumber"))
338+
339+instance ToJSON ScriptStackTraceElement where
340+ toJSON ScriptStackTraceElement{..}
341+ = object
342+ (catMaybes
343+ [("function" .=) <$> _ssteFunction,
344+ ("lineNumber" .=) <$> _ssteLineNumber])
345+
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.
352+--
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)
359+
360+-- | Creates a value of 'ExecutionError' with the minimum fields required to make a request.
361+--
362+-- Use one of the following lenses to modify other fields as desired:
363+--
364+-- * 'eeScriptStackTraceElements'
365+--
366+-- * 'eeErrorType'
367+--
368+-- * 'eeErrorMessage'
369+executionError
370+ :: ExecutionError
371+executionError =
372+ ExecutionError
373+ { _eeScriptStackTraceElements = Nothing
374+ , _eeErrorType = Nothing
375+ , _eeErrorMessage = Nothing
376+ }
377+
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})
384+ . _Default
385+ . _Coerce
386+
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)
390+eeErrorType
391+ = lens _eeErrorType (\ s a -> s{_eeErrorType = a})
392+
393+-- | The error message thrown by Apps Script, usually localized into the
394+-- user\'s language.
395+eeErrorMessage :: Lens' ExecutionError (Maybe Text)
396+eeErrorMessage
397+ = lens _eeErrorMessage
398+ (\ s a -> s{_eeErrorMessage = a})
399+
400+instance FromJSON ExecutionError where
401+ parseJSON
402+ = withObject "ExecutionError"
403+ (\ o ->
404+ ExecutionError <$>
405+ (o .:? "scriptStackTraceElements" .!= mempty) <*>
406+ (o .:? "errorType")
407+ <*> (o .:? "errorMessage"))
408+
409+instance ToJSON ExecutionError where
410+ toJSON ExecutionError{..}
411+ = object
412+ (catMaybes
413+ [("scriptStackTraceElements" .=) <$>
414+ _eeScriptStackTraceElements,
415+ ("errorType" .=) <$> _eeErrorType,
416+ ("errorMessage" .=) <$> _eeErrorMessage])
417+
418+-- | This field is not used.
419+--
420+-- /See:/ 'operationMetadata' smart constructor.
421+newtype OperationMetadata = OperationMetadata
422+ { _omAddtional :: HashMap Text JSONValue
423+ } deriving (Eq,Show,Data,Typeable,Generic)
424+
425+-- | Creates a value of 'OperationMetadata' with the minimum fields required to make a request.
426+--
427+-- Use one of the following lenses to modify other fields as desired:
428+--
429+-- * 'omAddtional'
430+operationMetadata
431+ :: HashMap Text JSONValue -- ^ 'omAddtional'
432+ -> OperationMetadata
433+operationMetadata pOmAddtional_ =
434+ OperationMetadata
435+ { _omAddtional = _Coerce # pOmAddtional_
436+ }
437+
438+-- | Properties of the object. Contains field \'ype with type URL.
439+omAddtional :: Lens' OperationMetadata (HashMap Text JSONValue)
440+omAddtional
441+ = lens _omAddtional (\ s a -> s{_omAddtional = a}) .
442+ _Coerce
443+
444+instance FromJSON OperationMetadata where
445+ parseJSON
446+ = withObject "OperationMetadata"
447+ (\ o -> OperationMetadata <$> (parseJSONObject o))
448+
449+instance ToJSON OperationMetadata where
450+ toJSON = toJSON . _omAddtional
451+
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.
455+--
456+-- /See:/ 'operationResponse' smart constructor.
457+newtype OperationResponse = OperationResponse
458+ { _orAddtional :: HashMap Text JSONValue
459+ } deriving (Eq,Show,Data,Typeable,Generic)
460+
461+-- | Creates a value of 'OperationResponse' with the minimum fields required to make a request.
462+--
463+-- Use one of the following lenses to modify other fields as desired:
464+--
465+-- * 'orAddtional'
466+operationResponse
467+ :: HashMap Text JSONValue -- ^ 'orAddtional'
468+ -> OperationResponse
469+operationResponse pOrAddtional_ =
470+ OperationResponse
471+ { _orAddtional = _Coerce # pOrAddtional_
472+ }
473+
474+-- | Properties of the object. Contains field \'ype with type URL.
475+orAddtional :: Lens' OperationResponse (HashMap Text JSONValue)
476+orAddtional
477+ = lens _orAddtional (\ s a -> s{_orAddtional = a}) .
478+ _Coerce
479+
480+instance FromJSON OperationResponse where
481+ parseJSON
482+ = withObject "OperationResponse"
483+ (\ o -> OperationResponse <$> (parseJSONObject o))
484+
485+instance ToJSON OperationResponse where
486+ toJSON = toJSON . _orAddtional
487+
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.
492+--
493+-- /See:/ 'executionResponse' smart constructor.
494+newtype ExecutionResponse = ExecutionResponse
495+ { _erResult :: Maybe JSONValue
496+ } deriving (Eq,Show,Data,Typeable,Generic)
497+
498+-- | Creates a value of 'ExecutionResponse' with the minimum fields required to make a request.
499+--
500+-- Use one of the following lenses to modify other fields as desired:
501+--
502+-- * 'erResult'
503+executionResponse
504+ :: ExecutionResponse
505+executionResponse =
506+ ExecutionResponse
507+ { _erResult = Nothing
508+ }
509+
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})
517+
518+instance FromJSON ExecutionResponse where
519+ parseJSON
520+ = withObject "ExecutionResponse"
521+ (\ o -> ExecutionResponse <$> (o .:? "result"))
522+
523+instance ToJSON ExecutionResponse where
524+ toJSON ExecutionResponse{..}
525+ = object (catMaybes [("result" .=) <$> _erResult])