forked from bernot-dev/starrez-google-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
58 lines (51 loc) · 1.94 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* exported configCredentials configEndpoint configEmail */
/**
* To set up your configuration:
* 1. Publish -> Deploy as Web App...
* 2. Choose options and deploy.
* 3. Navigate browser to Web App URL.
*/
/**
* Set up endpoint for StarRez REST API calls
* @param {string} shortName StarRez customer shortname
*/
function configEndpoint(shortName) {
var scriptProperties = PropertiesService.getScriptProperties();
var endpointPattern = /^\w{2,16}$/;
if (typeof shortName === "string" && endpointPattern.test(shortName)) {
scriptProperties.setProperty("STARREZ_API_ENDPOINT", "https://" + shortName + ".starrezhousing.com/StarRezRest");
Logger.log("Customer shortname updated");
return true;
}
throw new Error("Invalid Customer Shortname");
}
/**
* Set up credentials for StarRez REST API calls
* @param {string} username StarRez SecurityUser Username
* @param {string} token StarRez Web Services Token
*/
function configCredentials(username, token) {
var userProperties = PropertiesService.getUserProperties();
var usernamePattern = /^\w{1,100}$/;
var tokenPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
if (typeof username === "string" && usernamePattern.test(username) && typeof token === "string" && tokenPattern.test(token)) {
var credentials = Utilities.base64Encode(username + ":" + token, Utilities.Charset.UTF_8);
userProperties.setProperty("STARREZ_CREDENTIALS", "Basic " + credentials);
Logger.log("Credentials updated");
return true;
}
throw new Error("Invalid username or web services token.");
}
/**
* Set up e-mail for sending reports
* @param {string} email E-mail address of owner of script
*/
function configEmail(email) {
var userProperties = PropertiesService.getUserProperties();
if (typeof email === "string") {
userProperties.setProperty("EMAIL", email);
Logger.log("Email updated");
return true;
}
throw new Error("Invalid email");
}