Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Created August 6, 2014 11:56
Show Gist options
  • Save wmakeev/674970c4242c64e14f2a to your computer and use it in GitHub Desktop.
Save wmakeev/674970c4242c64e14f2a to your computer and use it in GitHub Desktop.
Инициализации GoogleScript проекта для moysklad-client
var client = MoyskladClient.createClient();
var _ = MoyskladClient.require('lodash');
var userProperties = PropertiesService.getUserProperties();
client.options.filterLimit = 20;
// Auth
client.setAuth(
userProperties.getProperty('MOYSKLAD_LOGIN'),
userProperties.getProperty('MOYSKLAD_PASSWORD')
);
function onOpen() {
createMenu_();
}
// Do get
function doGet(e) {
var action = e.parameter.action;
if (this[action + 'Action_']) {
var actionResult;
try {
actionResult = this[action + 'Action_'](e);
// Возвращаем если HtmlResult
if ('setSandboxMode' in actionResult)
return actionResult;
} catch (e) {
actionResult = {
type: 'error',
title: 'Ошибка сервиса',
message: 'Внутренняя ошибка сервиса',
error: e
};
}
var output = ContentService.createTextOutput()
.setMimeType(ContentService.MimeType.JSON)
.setContent(JSON.stringify(actionResult));
return output;
} else {
throw new Error('[action] parameter not correct or not defined');
}
}
function authAction_(e) {
var tmpl = HtmlService.createTemplateFromFile('_auth-form');
tmpl.data = {
user: {
name: encodeURI(e.parameter.user || '')
}
}
return tmpl.evaluate().setTitle('Сохранение пароля');
}
function setAuth(login, password) {
if (login && password) {
userProperties.setProperties({
MOYSKLAD_LOGIN: login,
MOYSKLAD_PASSWORD: password
});
} else {
throw new Error('Логин и пароль указаны некорректно');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment