You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-08-15 20:13:31 +02:00
Обновление локализации
This commit is contained in:
14
.github/workflows/os/opi_translate.os
vendored
14
.github/workflows/os/opi_translate.os
vendored
@@ -1,10 +1,14 @@
|
||||
Перем ТаблицаСловаря;
|
||||
Перем СоответствиеИсключаемых;
|
||||
|
||||
Процедура ПриСозданииОбъекта()
|
||||
|
||||
КаталогСловарей = "./service/dictionaries";
|
||||
ФайлыСловарей = НайтиФайлы(КаталогСловарей, "*.json");
|
||||
|
||||
СоответствиеИсключаемых = Новый Соответствие();
|
||||
СоответствиеИсключаемых.Вставить("packagedef", Истина);
|
||||
|
||||
ТаблицаСловаря = Новый ТаблицаЗначений();
|
||||
ТаблицаСловаря.Колонки.Добавить("Ключ");
|
||||
ТаблицаСловаря.Колонки.Добавить("Значение");
|
||||
@@ -29,8 +33,8 @@
|
||||
|
||||
ПолучитьТаблицуСловаря(ПутьКСловарю);
|
||||
|
||||
КаталогИсточник = Новый Файл(".\src\ru\OPI");
|
||||
КаталогПриемник = Новый Файл(".\src\" + Язык + "\OPI");
|
||||
КаталогИсточник = Новый Файл(".\src\ru");
|
||||
КаталогПриемник = Новый Файл(".\src\" + Язык + "");
|
||||
|
||||
Если КаталогПриемник.Существует() Тогда
|
||||
УдалитьФайлы(КаталогПриемник.ПолноеИмя);
|
||||
@@ -55,7 +59,7 @@
|
||||
|
||||
Для Каждого ФайлЛокализации Из ВсеФайлыЛокализации Цикл
|
||||
|
||||
Если Не ФайлЛокализации.ЭтоКаталог() Тогда
|
||||
Если Не ФайлЛокализации.ЭтоКаталог() Или СоответствиеИсключаемых[ФайлЛокализации.Имя] <> Неопределено Тогда
|
||||
Продолжить;
|
||||
КонецЕсли;
|
||||
|
||||
@@ -179,6 +183,10 @@
|
||||
МассивФайлов = НайтиФайлы(КаталогИсточник, "*.*", Истина);
|
||||
|
||||
Для Каждого Файл Из МассивФайлов Цикл
|
||||
|
||||
Если СтрНайти(Файл.ПолноеИмя, "\cli") <> 0 Тогда
|
||||
Продолжить;
|
||||
КонецЕсли;
|
||||
ПолноеИмяИсточник = Файл.ПолноеИмя;
|
||||
ПолноеИмяПриемник = КаталогПриемник + СтрЗаменить(Файл.ПолноеИмя, КаталогИсточник, "");
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
"Знач":"Val",
|
||||
"И":"And",
|
||||
"Из":"In",
|
||||
"ИЛИ,Или":"Or",
|
||||
"Или":"Or",
|
||||
"Иначе":"Else",
|
||||
"ИначеЕсли":"ElsIf",
|
||||
"Исключение":"Except",
|
||||
@@ -22,7 +22,7 @@
|
||||
"Неопределено":"Undefined",
|
||||
"Перейти":"Goto",
|
||||
"Перем":"Var",
|
||||
"По":"For",
|
||||
"По":"To",
|
||||
"Пока":"WHile",
|
||||
"Попытка":"Try",
|
||||
"Процедура":"Procedure",
|
||||
@@ -46,5 +46,40 @@
|
||||
"Сервер":"Server",
|
||||
"ТолстыйКлиентОбычноеПриложение":"ThickClientOrdinaryApplication",
|
||||
"ТолстыйКлиентУправляемоеПриложение":"ThickClientManagedApplication",
|
||||
"ТонкийКлиент":"ThinClient"
|
||||
"ТонкийКлиент":"ThinClient",
|
||||
"Сообщить":"Message",
|
||||
"ТипЗнч":"TypeOf",
|
||||
"Соответствие":"Map",
|
||||
"Символы": "Chars",
|
||||
"СтрДлина": "StrLen",
|
||||
"вРег": "Upper",
|
||||
"нРег": "Lower",
|
||||
"ЗащищенноеСоединениеOpenSSL": "OpenSSLSecureConnection",
|
||||
"СтрЗаменить":"StrReplace",
|
||||
"ЧтениеJSON":"JSONReader",
|
||||
"ПараметрыЗаписиJSON":"JSONWriterSettings",
|
||||
"ЭкранированиеСимволовJSON":"JSONCharactersEscapeMode",
|
||||
"ЗаписьJSON":"JSONWriter",
|
||||
"МестноеВремя": "ToLocalTime",
|
||||
"Цел":"Int",
|
||||
"УникальныйИдентификатор": "UUID",
|
||||
"ЗаписьДанных":"DataWriter",
|
||||
"СтрСоединить":"StrConcat",
|
||||
"ЧтениеДанных":"DataReader",
|
||||
"ЧтениеZipФайла":"ZipFileReader",
|
||||
"ПодробноеПредставлениеОшибки":"DetailErrorDescription",
|
||||
"ИнформацияОбОшибке":"ErrorInfo",
|
||||
"РежимВосстановленияПутейФайловZIP":"ZIPRestoreFilePathsMode",
|
||||
"НеВосстанавливать":"DontRestore",
|
||||
"СокрЛП":"TrimAll",
|
||||
"СоединитьДвоичныеДанные":"ConcatBinaryData",
|
||||
"СтрНачинаетсяС":"StrStartsWith",
|
||||
"КопироватьФайл":"CopyFile",
|
||||
"ЧтениеТекста":"TextReader",
|
||||
"ПрограммныйИнтерфейс":"Public",
|
||||
"СлужебныйПрограммныйИнтерфейс":"Internal",
|
||||
"СлужебныеПроцедурыИФункции":"Private",
|
||||
"НачалоДня":"BegOfDay",
|
||||
"Вычислить":"Eval",
|
||||
"Сред":"Mid"
|
||||
}
|
681
src/en/OInt/core/Modules/OPI_Airtable.os
Normal file
681
src/en/OInt/core/Modules/OPI_Airtable.os
Normal file
@@ -0,0 +1,681 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Airtable.os
|
||||
// Library: Airtable
|
||||
// CLI Command: airtable
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region DatabaseWork
|
||||
|
||||
// Get list of bases
|
||||
// Gets the list of available bases
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Indent - String - Next page identifier of the base list from the previous request - offset
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetListOfBases(Val Token, Val Indent = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Indent);
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
Parameters = New Structure;
|
||||
|
||||
OPI_Tools.AddField("offset", Indent, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get base tables
|
||||
// Gets the schema of base tables
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier - base
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetDatabaseTables(Val Token, Val Base) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases/" + Base + "/tables";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create base
|
||||
// Creates a new database
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Workspace - String - Workspace identifier - ws
|
||||
// Name - String - New base name - title
|
||||
// TableCollection - Key-Value Pair - Table description: Key > name, Value > array of fields - tablesdata
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateDatabase(Val Token, Val Workspace, Val Name, Val TableCollection) Export
|
||||
|
||||
OPI_TypeConversion.GetCollection(TableCollection);
|
||||
|
||||
If Not TypeOf(TableCollection) = Type("Structure")
|
||||
And Not TypeOf(TableCollection) = Type("Map") Then
|
||||
|
||||
Raise "Error in table collection data";
|
||||
|
||||
EndIf;
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
TableArray = New Array;
|
||||
|
||||
For Each Table In TableCollection Do
|
||||
|
||||
Description = GenerateTableDescription(Table.TheKey, Table.Value);
|
||||
TableArray.Add(Description);
|
||||
|
||||
EndDo;
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("name" , Name , "String", Parameters);
|
||||
OPI_Tools.AddField("tables" , TableArray , "Array", Parameters);
|
||||
OPI_Tools.AddField("workspaceId", Workspace, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region TableManagement
|
||||
|
||||
// Create table
|
||||
// Creates a new table in the base
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier - base
|
||||
// Name - String - New table name - title
|
||||
// FieldArray - Array of Structure - Array of field descriptions - fieldsdata
|
||||
// Description - String - Table description - description
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateTable(Val Token, Val Base, Val Name, Val FieldArray, Val Description = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases/" + Base + "/tables";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
Parameters = GenerateTableDescription(Name, FieldArray, Description);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Modify table
|
||||
// Changes the name and/or description of the base
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Name - String - New name - title
|
||||
// Description - String - New description - description
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function ModifyTable(Val Token, Val Base, Val Table, Val Name = "", Val Description = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases/" + Base + "/tables/" + Table;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
Parameters = New Structure;
|
||||
|
||||
OPI_Tools.AddField("name" , Name, "String", Parameters);
|
||||
OPI_Tools.AddField("description", Description , "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Patch(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region FieldWork
|
||||
|
||||
// Create field
|
||||
// Creates a new field in the table
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// FieldStructure - Structure of Key-Value - Description of the new field - fielddata
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateField(Val Token, Val Base, Val Table, Val FieldStructure) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetCollection(FieldStructure);
|
||||
|
||||
If Not TypeOf(FieldStructure) = Type("Structure")
|
||||
And Not TypeOf(FieldStructure) = Type("Map") Then
|
||||
|
||||
Raise "Error in field description data";
|
||||
|
||||
EndIf;
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases/" + Base + "/tables/" + Table + "/fields";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, FieldStructure, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Modify field
|
||||
// Changes the name and/or description of an existing table field
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier Base - base
|
||||
// Table - String - Table identifier - table
|
||||
// Field - String - Field identifier - field
|
||||
// Name - String - New name - title
|
||||
// Description - String - New description - description
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function ModifyField(Val Token, Val Base, Val Table, Val Field, Val Name = "", Val Description = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetLine(Field);
|
||||
|
||||
URL = "https://api.airtable.com/v0/meta/bases/"
|
||||
+ Base
|
||||
+ "/tables/"
|
||||
+ Table
|
||||
+ "/fields/"
|
||||
+ Field;
|
||||
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure();
|
||||
OPI_Tools.AddField("name" , Name, "String", Parameters);
|
||||
OPI_Tools.AddField("description", Description , "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Patch(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get field (string)
|
||||
// Gets the description of a string field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - New field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetStringField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "richText");
|
||||
EndFunction
|
||||
|
||||
// Get field (numeric)
|
||||
// Gets the description of a numeric field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - New field name - title
|
||||
// Precision - Number, String - Number of decimal places - precision
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetNumberField(Val Name, Val Precision = 0) Export
|
||||
|
||||
OPI_TypeConversion.GetNumber(Precision);
|
||||
|
||||
OptionsStructure = New Structure("precision", Precision);
|
||||
Return PrimitiveFieldDescription(Name, "number", OptionsStructure);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get field (file)
|
||||
// Gets the description of a file field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetAttachmentField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "multipleAttachments");
|
||||
EndFunction
|
||||
|
||||
// Get field (checkbox)
|
||||
// Gets the description of a boolean field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetCheckboxField(Val Name) Export
|
||||
|
||||
OptionsStructure = New Structure("icon,color", "check", "yellowBright");
|
||||
Return PrimitiveFieldDescription(Name, "checkbox", OptionsStructure);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get field (date)
|
||||
// Gets the description of a date field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetDateField(Val Name) Export
|
||||
|
||||
FormatStructure = New Structure("format,name", "YYYY-MM-DD", "iso");
|
||||
OptionsStructure = New Structure("dateFormat", FormatStructure);
|
||||
|
||||
Return PrimitiveFieldDescription(Name, "date", OptionsStructure);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get field (email)
|
||||
// Gets the description of an email field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetEmailField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "email");
|
||||
EndFunction
|
||||
|
||||
// Get field (phone)
|
||||
// Gets the description of a phone number field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetPhoneField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "phoneNumber");
|
||||
EndFunction
|
||||
|
||||
// Get field (url)
|
||||
// Gets the description of a URL field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetLinkField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "url");
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region RecordManagement
|
||||
|
||||
// Get list of records
|
||||
// Gets the list of records of the selected table
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Indent - String - Next page identifier of data from the previous request - offset
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetListOfRecords(Val Token, Val Base, Val Table, Val Indent = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure();
|
||||
OPI_Tools.AddField("offset", Indent, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get record
|
||||
// Gets row data of the table by identifier
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Record - String - Record identifier in the table - record
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetRecord(Val Token, Val Base, Val Table, Val Record) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetLine(Record);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table + "/" + Record;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create records
|
||||
// Creates one or an array of records by description or an array of field value descriptions
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Data - Structure, Array of Structure - Set or array of sets of Key : Value pairs > Field : Indicator - data
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreatePosts(Val Token, Val Base, Val Table, Val Data) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetCollection(Data);
|
||||
|
||||
Parameters = New Structure();
|
||||
AddDataDescription(Data, Parameters);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete records
|
||||
// Deletes one or an array of records by identifiers
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Records - String, Array of String - Identifier or array of record identifiers - records
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function DeletePosts(Val Token, Val Base, Val Table, Val Records) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetArray(Records);
|
||||
|
||||
RecordString = "";
|
||||
|
||||
For Each Record In Records Do
|
||||
RecordString = RecordString
|
||||
+ ?(ValueIsFilled(RecordString), "&", "?")
|
||||
+ "records[]="
|
||||
+ OPI_Tools.NumberToString(Record);
|
||||
EndDo;
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table + RecordString;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region CommentManagement
|
||||
|
||||
// Get comments
|
||||
// Gets the list of comments for a record in the table
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Indent - String - Next page identifier of data from the previous request - offset
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetComments(Val Token, Val Base, Val Table, Val Record, Val Indent = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetLine(Record);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table + "/" + Record + "/comments";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure();
|
||||
OPI_Tools.AddField("offset", Indent, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create comment
|
||||
// Creates a comment for a record in the table
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Text - String - Comment text - text
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateComment(Val Token, Val Base, Val Table, Val Record, Val Text) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetLine(Record);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table + "/" + Record + "/comments";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure();
|
||||
OPI_Tools.AddField("text", Text, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Modify comment
|
||||
// Changes the text of an existing comment
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Comment - String - Comment identifier - comment
|
||||
// Text - String - New comment text - text
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function EditComment(Val Token, Val Base, Val Table, Val Record, Val Comment, Val Text) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetLine(Record);
|
||||
OPI_TypeConversion.GetLine(Comment);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table + "/" + Record + "/comments/" + Comment;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure();
|
||||
OPI_Tools.AddField("text", Text, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Patch(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete comment
|
||||
// Deletes a comment for a table record
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Comment - String - Comment identifier - comment
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function DeleteComment(Val Token, Val Base, Val Table, Val Record, Val Comment) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetLine(Record);
|
||||
OPI_TypeConversion.GetLine(Comment);
|
||||
|
||||
URL = "https://api.airtable.com/v0/" + Base + "/" + Table + "/" + Record + "/comments/" + Comment;
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function GetAuthorizationHeader(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "Bearer " + Token);
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GenerateTableDescription(Val Name, Val FieldArray, Val Description = "")
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetCollection(FieldArray);
|
||||
|
||||
TableDescription = New Structure("name,fields", Name, FieldArray);
|
||||
|
||||
OPI_Tools.AddField("description", Description, "String", TableDescription);
|
||||
|
||||
Return TableDescription;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function PrimitiveFieldDescription(Val Name, Val Type, Val Options = "")
|
||||
|
||||
FieldStructure = New Structure();
|
||||
OPI_Tools.AddField("name" , Name, "String" , FieldStructure);
|
||||
OPI_Tools.AddField("type" , Type , "String" , FieldStructure);
|
||||
OPI_Tools.AddField("options", Options , "Collection", FieldStructure);
|
||||
|
||||
Return FieldStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure AddDataDescription(Val Data, Parameters)
|
||||
|
||||
If TypeOf(Data) = Type("Array") Then
|
||||
|
||||
SendArray = New Array;
|
||||
|
||||
For Each RecordDescription In Data Do
|
||||
SendArray.Add(New Structure("fields", RecordDescription));
|
||||
EndDo;
|
||||
|
||||
OPI_Tools.AddField("records", SendArray, "Array", Parameters);
|
||||
|
||||
Else
|
||||
|
||||
OPI_Tools.AddField("fields", Data, "Collection", Parameters);
|
||||
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
961
src/en/OInt/core/Modules/OPI_Dropbox.os
Normal file
961
src/en/OInt/core/Modules/OPI_Dropbox.os
Normal file
@@ -0,0 +1,961 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Dropbox.os
|
||||
// Library: Dropbox
|
||||
// CLI Command: dropbox
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region AccountAndAuthorization
|
||||
|
||||
// Get authorization link
|
||||
// Generates an authorization link for browser transition
|
||||
//
|
||||
// Parameters:
|
||||
// AppKey - String - Application key - appkey
|
||||
//
|
||||
// Returns:
|
||||
// String - URL for browser transition
|
||||
Function GetAuthorizationLink(Val AppKey) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(AppKey);
|
||||
Return "https://www.dropbox.com/oauth2/authorize?client_id="
|
||||
+ AppKey
|
||||
+ "&response_type=code&token_access_type=offline";
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get token
|
||||
// Gets token based on the code from the GetAuthorizationLink page
|
||||
//
|
||||
// Parameters:
|
||||
// AppKey - String - Application key - appkey
|
||||
// AppSecret - String - Application secret - appsecret
|
||||
// Code - String - Code from the authorization page - code
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetToken(Val AppKey, Val AppSecret, Val Code) Export
|
||||
|
||||
URL = "https://api.dropbox.com/oauth2/token";
|
||||
DataType = "application/x-www-form-urlencoded; charset=utf-8";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("code" , Code , "String", Parameters);
|
||||
OPI_Tools.AddField("grant_type", "authorization_code", "String", Parameters);
|
||||
|
||||
URLStructure = OPI_Tools.SplitURL(URL);
|
||||
Server = URLStructure["Server"];
|
||||
Address = URLStructure["Address"];
|
||||
|
||||
Request = OPI_Tools.CreateRequest(Address, , DataType);
|
||||
Connection = OPI_Tools.CreateConnection(Server, AppKey, AppSecret);
|
||||
|
||||
ParameterString = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Data = Right(ParameterString, StrLen(ParameterString) - 1);
|
||||
|
||||
Request.SetBodyFromString(Data);
|
||||
|
||||
Response = Connection.CallHTTPMethod("POST", Request);
|
||||
OPI_Tools.ProcessResponse(Response);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Refresh token
|
||||
// Gets a new token based on the refresh token
|
||||
//
|
||||
// Parameters:
|
||||
// AppKey - String - Application key - appkey
|
||||
// AppSecret - String - Application secret - appsecret
|
||||
// RefreshToken - String - Refresh token - refresh
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function RefreshToken(Val AppKey, Val AppSecret, Val RefreshToken) Export
|
||||
|
||||
String_ = "String";
|
||||
URL = "https://api.dropbox.com/oauth2/token";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("refresh_token", RefreshToken , String_, Parameters);
|
||||
OPI_Tools.AddField("grant_type" , "refresh_token" , String_, Parameters);
|
||||
OPI_Tools.AddField("client_id" , AppKey , String_, Parameters);
|
||||
OPI_Tools.AddField("client_secret", AppSecret, String_, Parameters);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get account information
|
||||
// Gets account information
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Account - String - Account ID. Current token account if not filled - account
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetAccountInformation(Val Token, Val Account = "") Export
|
||||
|
||||
If ValueIsFilled(Account) Then
|
||||
Result = GetAccount(Token, Account);
|
||||
Else
|
||||
Result = GetOwnAccount(Token);
|
||||
EndIf;
|
||||
|
||||
Return Result;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get space usage data
|
||||
// Gets information on the amount of used disk space
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetSpaceUsageData(Val Token) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/users/get_space_usage";
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL
|
||||
, GetBinaryDataFromString("null")
|
||||
, Headers
|
||||
,
|
||||
, "text/plain; charset=dropbox-cors-hack");
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region FileAndDirectoryManagement
|
||||
|
||||
// Get object information
|
||||
// Gets information about a file or directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object - path
|
||||
// Detailed - Boolean - Adds additional information fields for media files - detail
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetObjectInformation(Val Token, Val Path, Val Detailed = False) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/get_metadata";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path" , Path , "String", Parameters);
|
||||
OPI_Tools.AddField("include_media_info", Detailed, "Boolean", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of folder files
|
||||
// Gets the list of the first files in the directory or continues getting the next ones when the cursor is specified
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the directory. Optional if the cursor is specified - path
|
||||
// Detailed - Boolean - Adds additional information fields for media files - detail
|
||||
// Cursor - String - Cursor from the previous request to get the next set of files - cursor
|
||||
//
|
||||
// Returns:
|
||||
// HTTPResponse - Get list of folder files
|
||||
Function GetListOfFolderFiles(Val Token, Val Path = "", Val Detailed = False, Val Cursor = "") Export
|
||||
|
||||
If Not ValueIsFilled(Cursor) Then
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/list_folder";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path" , Path , "String", Parameters);
|
||||
OPI_Tools.AddField("include_media_info", Detailed , "Boolean", Parameters);
|
||||
|
||||
Else
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/list_folder/continue";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("cursor", Cursor, "String", Parameters);
|
||||
|
||||
EndIf;
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get preview
|
||||
// Gets PDF or HTML preview of the object (for documents only)
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object - path
|
||||
//
|
||||
// Returns:
|
||||
// BinaryData - document preview
|
||||
Function GetPreview(Val Token, Val Path) Export
|
||||
|
||||
URL = "https://content.dropboxapi.com/2/files/get_preview";
|
||||
Response = ProcessObject(Token, URL, Path, True);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Upload file
|
||||
// Uploads a file to the cloud drive
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// File - String, BinaryData - Data file for upload - file
|
||||
// Path - String - Save path on Dropbox - path
|
||||
// Overwrite - Boolean - Overwrite file in case of path conflicts - overwrite
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function UploadFile(Val Token, Val File, Val Path, Val Overwrite = False) Export
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(File);
|
||||
OPI_TypeConversion.GetBoolean(Overwrite);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
|
||||
Mode = ?(Overwrite, "overwrite", "add");
|
||||
Size = File.Size();
|
||||
Border = 100000000;
|
||||
|
||||
If Size > Border Then
|
||||
Response = UploadLargeFile(Token, File, Path, Mode);
|
||||
Else
|
||||
Response = UploadSmallFile(Token, File, Path, Mode);
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Upload file by URL
|
||||
// Uploads a file to the cloud drive by fetching it from the specified URL
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FileURL - String - URL source of the file - url
|
||||
// Path - String - Save path on Dropbox - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function UploadFileByURL(Val Token, Val FileURL, Val Path) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/save_url";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path", Path , "String", Parameters);
|
||||
OPI_Tools.AddField("url" , FileURL , "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get upload status by URL
|
||||
// Gets the upload status of the file by URL
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// JobID - String - ID of the asynchronous job from the UploadFileByURL response - job
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetUploadStatusByURL(Val Token, Val JobID) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/save_url/check_job_status";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("async_job_id", JobID, "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete object
|
||||
// Deletes an object from the cloud drive
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object to delete - path
|
||||
// Irrecoverable - String - Delete object without the possibility of recovery - permanently
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function DeleteObject(Val Token, Val Path, Val Irrecoverable = False) Export
|
||||
|
||||
OPI_TypeConversion.GetBoolean(Irrecoverable);
|
||||
|
||||
If Irrecoverable Then
|
||||
URL = "https://api.dropboxapi.com/2/files/permanently_delete";
|
||||
Else
|
||||
URL = "https://api.dropboxapi.com/2/files/delete_v2";
|
||||
EndIf;
|
||||
|
||||
Response = ProcessObject(Token, URL, Path);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Copy object
|
||||
// Copies a file or directory to the selected path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// From - String - Path to the original object - form
|
||||
// Target - String - Target path for the new object - to
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CopyObject(Val Token, Val From, Val Target) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/copy_v2";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("from_path", From, "String", Parameters);
|
||||
OPI_Tools.AddField("to_path" , Target , "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Move object
|
||||
// Moves an object to the selected path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// From - String - Path to the original object - form
|
||||
// Target - String - Target path for the new object - to
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function MoveObject(Val Token, Val From, Val Target) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/move_v2";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("from_path", From, "String", Parameters);
|
||||
OPI_Tools.AddField("to_path" , Target , "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create folder
|
||||
// Creates an empty directory at the selected path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Target path for creating the directory - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CreateFolder(Val Token, Val Path) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/create_folder_v2";
|
||||
Response = ProcessObject(Token, URL, Path);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Download file
|
||||
// Downloads a file by the specified path or ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path or ID of the file - path
|
||||
//
|
||||
// Returns:
|
||||
// BinaryData - binary data of the file
|
||||
Function DownloadFile(Val Token, Val Path) Export
|
||||
|
||||
URL = "https://content.dropboxapi.com/2/files/download";
|
||||
Response = ProcessObject(Token, URL, Path, True);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Download folder
|
||||
// Downloads a zip archive with the contents of the specified directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path or ID of the directory - path
|
||||
//
|
||||
// Returns:
|
||||
// BinaryData - binary data of the zip archive with the contents of the directory
|
||||
Function DownloadFolder(Val Token, Val Path) Export
|
||||
|
||||
URL = "https://content.dropboxapi.com/2/files/download_zip";
|
||||
Response = ProcessObject(Token, URL, Path, True);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of object versions
|
||||
// Gets the list of versions (revisions) of the object
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object - path
|
||||
// Quantity - String, Number - Number of the latest versions of the object to display - amount
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetObjectVersionList(Val Token, Val Path, Val Quantity = 10) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/list_revisions";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path" , Path , "String", Parameters);
|
||||
OPI_Tools.AddField("limit", Quantity, "Number" , Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Restore object to version
|
||||
// Restores object state to required version (revision)
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object - path
|
||||
// Version - String - ID of the version (revision) for restoration - rev
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function RestoreObjectToVersion(Val Token, Val Path, Val Version) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/restore";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path", Path , "String", Parameters);
|
||||
OPI_Tools.AddField("rev" , Version, "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region TagWork
|
||||
|
||||
// Get list of tags
|
||||
// Gets the list of tags of the selected files
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Paths - String, Array of String - Path or set of paths to the files - paths
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetTagList(Val Token, Val Paths) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/tags/get";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("paths", Paths, "Array", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Add tag
|
||||
// Adds a new text tag to a file or directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object for which the tag needs to be created - path
|
||||
// Tag - String - Tag text - tag
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function AddTag(Val Token, Val Path, Val Tag) Export
|
||||
|
||||
Return ProcessTag(Token, Path, Tag);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete tag
|
||||
// Deletes the text tag of a file or directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object whose tag needs to be deleted - path
|
||||
// Tag - String - Tag text - tag
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function DeleteTag(Val Token, Val Path, Val Tag) Export
|
||||
|
||||
Return ProcessTag(Token, Path, Tag, True);
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region SharedAccessSettings
|
||||
|
||||
// Publish folder
|
||||
// Sets the directory to public access mode
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the target directory - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function PublishFolder(Val Token, Val Path) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/sharing/share_folder";
|
||||
Response = ProcessObject(Token, URL, Path);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Unpublish folder
|
||||
// Cancels the public access mode for the directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FolderID - String - ID of the public catalog (shared folder ID) - folder
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CancelFolderPublication(Val Token, Val FolderID) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/sharing/unshare_folder";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("shared_folder_id", FolderID, "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Add user to file
|
||||
// Defines access to the file for an external user
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FileID - String - ID of the file to be accessed - fileid
|
||||
// EmailAddresses - String, Array of String - List of email addresses of users being added - emails
|
||||
// ViewOnly - Boolean - Prohibits file editing for the external user - readonly
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function AddUsersToFile(Val Token, Val FileID, Val EmailAddresses, Val ViewOnly = True) Export
|
||||
|
||||
String_ = "String";
|
||||
|
||||
OPI_TypeConversion.GetArray(EmailAddresses);
|
||||
OPI_TypeConversion.GetLine(FileID);
|
||||
OPI_TypeConversion.GetBoolean(ViewOnly);
|
||||
|
||||
If Not StrStartsWith(FileID, "id:") Then
|
||||
FileID = "id:" + FileID;
|
||||
EndIf;
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/sharing/add_file_member";
|
||||
|
||||
ArrayOfUsers = New Array;
|
||||
|
||||
For Each Address In EmailAddresses Do
|
||||
|
||||
UserData = New Map;
|
||||
OPI_Tools.AddField(".tag" , "email", String_, UserData);
|
||||
OPI_Tools.AddField("email", Address , String_, UserData);
|
||||
|
||||
ArrayOfUsers.Add(UserData);
|
||||
|
||||
EndDo;
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("file" , FileID , String_, Parameters);
|
||||
OPI_Tools.AddField("members", ArrayOfUsers , "Array", Parameters);
|
||||
|
||||
Mode = ?(ViewOnly, "viewer", "editor");
|
||||
|
||||
OPI_Tools.AddField("access_level", Mode , String_, Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Add users to folder
|
||||
// Grants external users access to the directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FolderID - String - ID of the public catalog (shared folder ID) - folder
|
||||
// EmailAddresses - String, Array of String - List of email addresses of users being added - emails
|
||||
// ViewOnly - Boolean - Prohibits file editing for the external user - readonly
|
||||
//
|
||||
// Returns:
|
||||
// Undefined - empty response
|
||||
Function AddUsersToFolder(Val Token, Val FolderID, Val EmailAddresses, Val ViewOnly = True) Export
|
||||
|
||||
String_ = "String";
|
||||
|
||||
OPI_TypeConversion.GetArray(EmailAddresses);
|
||||
OPI_TypeConversion.GetBoolean(ViewOnly);
|
||||
Mode = ?(ViewOnly, "viewer", "editor");
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/sharing/add_folder_member";
|
||||
|
||||
ArrayOfUsers = New Array;
|
||||
|
||||
For Each Address In EmailAddresses Do
|
||||
|
||||
UserData = New Map;
|
||||
OPI_Tools.AddField(".tag" , "email", String_, UserData);
|
||||
OPI_Tools.AddField("email", Address , String_, UserData);
|
||||
|
||||
UserStructure = New Structure("member,access_level", UserData, Mode);
|
||||
|
||||
ArrayOfUsers.Add(UserStructure);
|
||||
|
||||
EndDo;
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("shared_folder_id", FolderID , String_, Parameters);
|
||||
OPI_Tools.AddField("members" , ArrayOfUsers , "Array", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get asynchronous change status
|
||||
// Gets the status of the asynchronous access change job
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// JobID - String - AsynchronousJobID - job
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetAsynchronousChangeStatus(Val Token, Val JobID) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/sharing/check_job_status";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("async_job_id", JobID, "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Unpublish file
|
||||
// Prohibits access to the file for external users
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FileID - String - ID of the file to be accessed - fileid
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CancelFilePublication(Val Token, Val FileID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(FileID);
|
||||
|
||||
If Not StrStartsWith(FileID, "id:") Then
|
||||
FileID = "id:" + FileID;
|
||||
EndIf;
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/sharing/unshare_file";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("file", FileID, "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function ProcessObject(Val Token, Val URL, Val Path, Val InHeaders = False)
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path", Path, "String", Parameters);
|
||||
|
||||
If InHeaders Then
|
||||
Headers = GetRequestHeaders(Token, Parameters);
|
||||
Response = OPI_Tools.PostBinary(URL, GetBinaryDataFromString(""), Headers);
|
||||
Else
|
||||
Headers = GetRequestHeaders(Token);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ProcessTag(Val Token, Val Path, Val Tag, Val ThisIsDeletion = False)
|
||||
|
||||
If ThisIsDeletion Then
|
||||
URL = "https://api.dropboxapi.com/2/files/tags/remove";
|
||||
Else
|
||||
URL = "https://api.dropboxapi.com/2/files/tags/add";
|
||||
EndIf;
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("path" , Path, "String", Parameters);
|
||||
OPI_Tools.AddField("tag_text" , Tag , "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetRequestHeaders(Val Token, Val Parameters = "")
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization" , "Bearer " + Token);
|
||||
|
||||
If ValueIsFilled(Parameters) Then
|
||||
|
||||
JSON = OPI_Tools.JSONString(Parameters, "No");
|
||||
JSON = StrReplace(JSON, Chars.VK + Chars.PS, "");
|
||||
|
||||
Headers.Insert("Dropbox-API-Arg", JSON);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UploadLargeFile(Val Token, Val File, Val Path, Val Mode)
|
||||
|
||||
URL = "https://content.dropboxapi.com/2/files/upload_session/append_v2";
|
||||
|
||||
ChunkSize = 100000000;
|
||||
CurrentPosition = 0;
|
||||
BytesRead = 0;
|
||||
TotalSize = File.Size();
|
||||
Session = OpenSession(Token);
|
||||
|
||||
WHile BytesRead < TotalSize Do
|
||||
|
||||
Indent = CurrentPosition;
|
||||
Cursor = New Structure("offset,session_id", Indent, Session);
|
||||
|
||||
Parameters = New Structure("cursor", Cursor);
|
||||
Headers = GetRequestHeaders(Token, Parameters);
|
||||
|
||||
DataReader = New DataReader(File);
|
||||
BytesRead = DataReader.Skip(CurrentPosition);
|
||||
Result = DataReader.Read(ChunkSize);
|
||||
CurrentData = Result.GetBinaryData();
|
||||
CurrentSize = CurrentData.Size();
|
||||
NextPosition = CurrentPosition + CurrentSize;
|
||||
|
||||
If Not ValueIsFilled(CurrentData) Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL, CurrentData, Headers);
|
||||
|
||||
CurrentPosition = NextPosition;
|
||||
|
||||
KBytes = 1024;
|
||||
MByte = KBytes * KBytes;
|
||||
Message(OPI_Tools.ProgressInformation(CurrentPosition, TotalSize, "MB", MByte));
|
||||
|
||||
PerformGarbageCollection();
|
||||
ReleaseObject(CurrentData);
|
||||
|
||||
EndDo;
|
||||
|
||||
Response = CloseSession(Token, Path, Mode, TotalSize, Session);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UploadSmallFile(Val Token, Val File, Val Path, Val Mode)
|
||||
|
||||
Boolean_ = "Boolean";
|
||||
String_ = "String";
|
||||
URL = "https://content.dropboxapi.com/2/files/upload";
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
OPI_Tools.AddField("autorename" , False , Boolean_, Parameters);
|
||||
OPI_Tools.AddField("mode" , Mode, String_, Parameters);
|
||||
OPI_Tools.AddField("mute" , False , Boolean_, Parameters);
|
||||
OPI_Tools.AddField("path" , Path , String_, Parameters);
|
||||
OPI_Tools.AddField("strict_conflict", False , Boolean_, Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token, Parameters);
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL, File, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function OpenSession(Val Token)
|
||||
|
||||
SessionId = "session_id";
|
||||
URL = "https://content.dropboxapi.com/2/files/upload_session/start";
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL, GetBinaryDataFromString(""), Headers);
|
||||
|
||||
Return Response[SessionId];
|
||||
|
||||
EndFunction
|
||||
|
||||
Function CloseSession(Val Token, Val Path, Val Mode, Val TotalSize, Val Session)
|
||||
|
||||
URL = "https://content.dropboxapi.com/2/files/upload_session/finish";
|
||||
|
||||
Commit = New Structure();
|
||||
OPI_Tools.AddField("mode", Mode, "String", Commit);
|
||||
OPI_Tools.AddField("path", Path, "String", Commit);
|
||||
|
||||
Cursor = New Structure("offset,session_id", TotalSize, Session);
|
||||
|
||||
Parameters = New Structure("commit,cursor", Commit, Cursor);
|
||||
Headers = GetRequestHeaders(Token, Parameters);
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL, GetBinaryDataFromString(""), Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetAccount(Val Token, Val Account)
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/users/get_account";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("account_id", Account, "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetOwnAccount(Val Token)
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/users/get_current_account";
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL
|
||||
, GetBinaryDataFromString("null")
|
||||
, Headers
|
||||
,
|
||||
, "text/plain; charset=dropbox-cors-hack");
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
631
src/en/OInt/core/Modules/OPI_GoogleCalendar.os
Normal file
631
src/en/OInt/core/Modules/OPI_GoogleCalendar.os
Normal file
@@ -0,0 +1,631 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleCalendar.os
|
||||
// Library: Google Calendar
|
||||
// CLI Command: gcalendar
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region CalendarMetadataManagement
|
||||
|
||||
// Create calendar
|
||||
// Creates an empty calendar
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Name - String - Name of the created calendar - title
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateCalendar(Val Token, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("summary" , Name);
|
||||
Parameters.Insert("timeZone", "Europe/Moscow");
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get calendar
|
||||
// Gets calendar information by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetCalendarMetadata(Val Token, Val Calendar) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/" + Calendar;
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Edit calendar
|
||||
// Edits properties of an existing calendar
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// Name - String - New name - title
|
||||
// Description - String - New calendar description - description
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditCalendarMetadata(Val Token
|
||||
, Val Calendar
|
||||
, Val Name = ""
|
||||
, Val Description = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Description);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/" + Calendar;
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Name) Then
|
||||
Parameters.Insert("summary", Name);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Description) Then
|
||||
Parameters.Insert("description", Description);
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Patch(URL, Parameters, Headers, True);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Clear primary calendar
|
||||
// Clears the event list of the primary calendar
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function ClearMainCalendar(Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/primary/clear";
|
||||
Response = OPI_Tools.Post(URL, , Headers, False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete calendar
|
||||
// Deletes a calendar by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteCalendar(Val Token, Val Calendar) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/" + Calendar;
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region CalendarListManagement
|
||||
|
||||
// Get list of calendars
|
||||
// Gets an array of account calendars
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of calendar data mappings
|
||||
Function GetCalendarList(Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
ArrayOfCalendars = New Array;
|
||||
|
||||
GetCalendarsListRecursively(Headers, ArrayOfCalendars);
|
||||
|
||||
Return ArrayOfCalendars;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Add calendar to list
|
||||
// Adds an existing calendar to the user's list
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function AddCalendarToList(Val Token, Val Calendar) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("id", Calendar);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list calendar
|
||||
// Gets a calendar from the user's list by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetListCalendar(Val Token, Val Calendar) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/users/me/calendarList/" + Calendar;
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Remove calendar from list
|
||||
// Removes a calendar from the user's list
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteCalendarFromList(Val Token, Val Calendar) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/users/me/calendarList/" + Calendar;
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Edit list calendar
|
||||
// Edits the properties of a calendar from the user's list
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// PrimaryColor - String - HEX primary color (#ffffff) - primary
|
||||
// SecondaryColor - String - HEX secondary color (#ffffff) - secondary
|
||||
// Hidden - Boolean - Hidden calendar - hidden
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditListCalendar(Val Token
|
||||
, Val Calendar
|
||||
, Val PrimaryColor
|
||||
, Val SecondaryColor
|
||||
, Val Hidden = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
OPI_TypeConversion.GetLine(PrimaryColor);
|
||||
OPI_TypeConversion.GetLine(SecondaryColor);
|
||||
OPI_TypeConversion.GetBoolean(Hidden);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/users/me/calendarList/" + Calendar + "?colorRgbFormat=true";
|
||||
|
||||
Parameters = New Map;
|
||||
Parameters.Insert("hidden" , Hidden);
|
||||
Parameters.Insert("foregroundColor", PrimaryColor);
|
||||
Parameters.Insert("backgroundColor", SecondaryColor);
|
||||
|
||||
Response = OPI_Tools.Put(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region EventManagement
|
||||
|
||||
// Get event description !NOCLI
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Empty event template
|
||||
Function GetEventDescription() Export
|
||||
|
||||
CurrentDate = OPI_Tools.GetCurrentDate();
|
||||
Hour = 3600;
|
||||
Event = New Map;
|
||||
|
||||
Event.Insert("Description" , ""); // Event description
|
||||
Event.Insert("Title" , "New event"); // Title events
|
||||
Event.Insert("Venue" , ""); // String description of the venue of the event
|
||||
Event.Insert("StartDate" , CurrentDate); // Date of start events
|
||||
Event.Insert("EndDate" , CurrentDate + Hour); // Date of end events
|
||||
Event.Insert("ArrayOfAttachmentURLs", New Map); // TheKey - name, Value - URL to file
|
||||
Event.Insert("SendNotifications" , True); // Indication of sending notifications to participants
|
||||
|
||||
Return Event;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of events
|
||||
// Gets the list of all calendar events
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of event mappings
|
||||
Function GetEventList(Val Token, Val Calendar) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
ArrayOfEvents = New Array;
|
||||
|
||||
GetEventsListRecursively(Headers, Calendar, ArrayOfEvents);
|
||||
|
||||
Return ArrayOfEvents;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get event
|
||||
// Gets an event by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// Event - String - Event ID - event
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetEvent(Val Token, Val Calendar, Val Event) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
OPI_TypeConversion.GetLine(Event);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/"
|
||||
+ Calendar
|
||||
+ "/events/"
|
||||
+ Event;
|
||||
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create event
|
||||
// Creates a new event
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// EventDescription - Key-Value Pair - Event description - props
|
||||
//
|
||||
// Returns:
|
||||
// String, Arbitrary, HTTPResponse, BinaryData, Undefined - Google server response
|
||||
Function CreateEvent(Val Token, Val Calendar, Val EventDescription) Export
|
||||
Return EventManagement(Token, Calendar, EventDescription);
|
||||
EndFunction
|
||||
|
||||
// Move event
|
||||
// Moves an event to another calendar
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// SourceCalendar - String - ID of the source calendar - from
|
||||
// TargetCalendar - String - ID of the target calendar - to
|
||||
// Event - String - ID of the source calendar event - event
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function MoveEvent(Val Token, Val SourceCalendar, Val TargetCalendar, Val Event) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(SourceCalendar);
|
||||
OPI_TypeConversion.GetLine(TargetCalendar);
|
||||
OPI_TypeConversion.GetLine(Event);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/"
|
||||
+ SourceCalendar
|
||||
+ "/events/"
|
||||
+ Event
|
||||
+ "/move?destination="
|
||||
+ TargetCalendar;
|
||||
|
||||
Response = OPI_Tools.Post(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Edit event
|
||||
// Edits an existing event
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// EventDescription - String - New event description - props
|
||||
// Event - String - Event ID - event
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditEvent(Val Token, Val Calendar, Val EventDescription, Val Event) Export
|
||||
Return EventManagement(Token, Calendar, EventDescription, Event);
|
||||
EndFunction
|
||||
|
||||
// Delete event
|
||||
// Deletes an event by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// Event - String - Event ID - event
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteEvent(Val Token, Val Calendar, Val Event) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
OPI_TypeConversion.GetLine(Event);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/"
|
||||
+ Calendar
|
||||
+ "/events/"
|
||||
+ Event;
|
||||
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function ConvertDate(Val Date)
|
||||
|
||||
OPI_TypeConversion.GetDate(Date);
|
||||
|
||||
DateStructure = New Structure;
|
||||
|
||||
If Not TypeOf(Date) = Type("Date") Then
|
||||
Return Undefined;
|
||||
EndIf;
|
||||
|
||||
If Date = BegOfDay(Date) Then
|
||||
DateFormat = "DF=yyyy-MM-dd";
|
||||
Field = "date";
|
||||
Else
|
||||
DateFormat = "DF=yyyy-MM-ddTHH:mm:ssZ";
|
||||
Field = "dateTime";
|
||||
EndIf;
|
||||
|
||||
Date = Format(Date, DateFormat);
|
||||
DateStructure.Insert(Field , Date);
|
||||
DateStructure.Insert("timeZone", "Europe/Moscow");
|
||||
|
||||
Return DateStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertAttachments(Val Attachments)
|
||||
|
||||
OPI_TypeConversion.GetCollection(Attachments);
|
||||
|
||||
AttachmentsArray = New Array;
|
||||
|
||||
If TypeOf(Attachments) = Type("Map") Or TypeOf(Attachments) = Type("Structure") Then
|
||||
|
||||
For Each Attachment In Attachments Do
|
||||
|
||||
CurrentAttachment = New Structure;
|
||||
CurrentAttachment.Insert("title" , Attachment.TheKey);
|
||||
CurrentAttachment.Insert("fileUrl", Attachment.Value);
|
||||
|
||||
AttachmentsArray.Add(CurrentAttachment);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndIf;
|
||||
|
||||
If AttachmentsArray.Quantity() > 0 Then
|
||||
Return AttachmentsArray;
|
||||
Else
|
||||
Return Undefined;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function EventManagement(Val Token, Val Calendar, Val EventDescription, Val Event = "")
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Calendar);
|
||||
OPI_TypeConversion.GetLine(Event);
|
||||
OPI_TypeConversion.GetCollection(EventDescription);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
Existing = ValueIsFilled(Event);
|
||||
URL = "https://www.googleapis.com/calendar/v3/calendars/"
|
||||
+ Calendar
|
||||
+ "/events"
|
||||
+ ?(Existing, "/" + Event, "");
|
||||
|
||||
Date0 = EventDescription["StartDate"];
|
||||
Date1 = EventDescription["EndDate"];
|
||||
Attachments = EventDescription["ArrayOfAttachmentURLs"];
|
||||
Attachments = ConvertAttachments(Attachments);
|
||||
Notifications = ?(EventDescription["SendNotifications"] = Undefined
|
||||
, False
|
||||
, EventDescription["SendNotifications"]);
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("summary" , EventDescription["Title"]);
|
||||
Parameters.Insert("description", EventDescription["Description"]);
|
||||
Parameters.Insert("location" , EventDescription["Venue"]);
|
||||
Parameters.Insert("start" , ConvertDate(Date0));
|
||||
Parameters.Insert("end" , ConvertDate(Date1));
|
||||
Parameters.Insert("attachments", Attachments);
|
||||
|
||||
URLParameters = New Structure;
|
||||
URLParameters.Insert("sendUpdates" , ?(Notifications, "all", "none"));
|
||||
URLParameters.Insert("supportsAttachments" , ?(ValueIsFilled(Attachments), "true", "false"));
|
||||
|
||||
URL = URL + OPI_Tools.RequestParametersToString(URLParameters);
|
||||
|
||||
OPI_Tools.RemoveEmptyCollectionFields(Parameters);
|
||||
|
||||
If Existing Then
|
||||
Response = OPI_Tools.Patch(URL, Parameters, Headers, True);
|
||||
Else
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers, True);
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure GetCalendarsListRecursively(Val Headers, ArrayOfCalendars, Page = "")
|
||||
|
||||
Items = "items";
|
||||
NPT = "nextPageToken";
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Page) Then
|
||||
Parameters.Insert("pageToken", Page);
|
||||
EndIf;
|
||||
|
||||
Result = OPI_Tools.Get("https://www.googleapis.com/calendar/v3/users/me/calendarList"
|
||||
, Parameters
|
||||
, Headers);
|
||||
|
||||
Calendars = Result[Items];
|
||||
Page = Result[NPT];
|
||||
|
||||
For Each Calendar In Calendars Do
|
||||
ArrayOfCalendars.Add(Calendar);
|
||||
EndDo;
|
||||
|
||||
If Calendars.Quantity() > 0 And ValueIsFilled(Page) Then
|
||||
GetCalendarsListRecursively(Headers, ArrayOfCalendars, Page);
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetEventsListRecursively(Val Headers, Val Calendar, ArrayOfEvents, Page = "")
|
||||
|
||||
Items = "items";
|
||||
NPT = "nextPageToken";
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Page) Then
|
||||
Parameters.Insert("pageToken", Page);
|
||||
EndIf;
|
||||
|
||||
Result = OPI_Tools.Get("https://www.googleapis.com/calendar/v3/calendars/" + Calendar + "/events"
|
||||
, Parameters
|
||||
, Headers);
|
||||
|
||||
Events = Result[Items];
|
||||
Page = Result[NPT];
|
||||
|
||||
For Each Event In Events Do
|
||||
ArrayOfEvents.Add(Event);
|
||||
EndDo;
|
||||
|
||||
If Events.Quantity() > 0 And ValueIsFilled(Page) Then
|
||||
GetEventsListRecursively(Headers, ArrayOfEvents, Page);
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
719
src/en/OInt/core/Modules/OPI_GoogleDrive.os
Normal file
719
src/en/OInt/core/Modules/OPI_GoogleDrive.os
Normal file
@@ -0,0 +1,719 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleDrive.os
|
||||
// Library: Google Drive
|
||||
// CLI Command: gdrive
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region FileAndDirectoryManagement
|
||||
|
||||
// Get object information
|
||||
// Gets information about a folder or file by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the file or folder - object
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetObjectInformation(Val Token, Val Identifier) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + Identifier;
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("fields", "*");
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of directories
|
||||
// Gets the list of drive directories
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// NameContains - String - Filter by name - querry
|
||||
// Detailed - Boolean - Adds a list of files to the directory fields - depth
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of directory mappings
|
||||
Function GetDirectoriesList(Val Token, Val NameContains = "", Val Detailed = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(NameContains);
|
||||
OPI_TypeConversion.GetBoolean(Detailed);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
ArrayOfObjects = New Array;
|
||||
Filter = New Array;
|
||||
|
||||
Filter.Add("mimeType = 'application/vnd.google-apps.folder'");
|
||||
|
||||
If ValueIsFilled(NameContains) Then
|
||||
Filter.Add("name contains '" + NameContains + "'");
|
||||
EndIf;
|
||||
|
||||
GetObjectsListRecursively(Headers, ArrayOfObjects, Detailed, Filter);
|
||||
|
||||
If Detailed Then
|
||||
BreakDownObjectsInDetail(Token, ArrayOfObjects);
|
||||
EndIf;
|
||||
|
||||
Return ArrayOfObjects;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of files
|
||||
// Gets the list of files
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// NameContains - String - Filter by name - querry
|
||||
// Directory - String - Filter by parent directory ID - catalog
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of file mappings
|
||||
Function GetFilesList(Val Token, Val NameContains = "", Val Directory = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(NameContains);
|
||||
OPI_TypeConversion.GetLine(Directory);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
ArrayOfObjects = New Array;
|
||||
Filter = New Array;
|
||||
|
||||
Filter.Add("mimeType != 'application/vnd.google-apps.folder'");
|
||||
|
||||
If ValueIsFilled(NameContains) Then
|
||||
Filter.Add("name contains '" + NameContains + "'");
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Directory) Then
|
||||
Filter.Add("'" + Directory + "' in parents");
|
||||
EndIf;
|
||||
|
||||
GetObjectsListRecursively(Headers, ArrayOfObjects, , Filter);
|
||||
|
||||
Return ArrayOfObjects;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Upload file
|
||||
// Uploads a file to the drive
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// File - BinaryData,String - File to be uploaded - file
|
||||
// Description - Key-Value Pair - See GetFileDescription - props - JSON description or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function UploadFile(Val Token, Val File, Val Description) Export
|
||||
Return FileManagement(Token, File, Description);
|
||||
EndFunction
|
||||
|
||||
// Create folder
|
||||
// Creates an empty directory on the drive
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Name - String - Folder name - title
|
||||
// Parent - String - Parent - catalog
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateFolder(Val Token, Val Name, Val Parent = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Parent);
|
||||
|
||||
Description = New Map;
|
||||
Description.Insert("MIME" , "application/vnd.google-apps.folder");
|
||||
Description.Insert("Name" , Name);
|
||||
Description.Insert("Description", "");
|
||||
Description.Insert("Parent", ?(ValueIsFilled(Parent), Parent, "root"));
|
||||
|
||||
Return FileManagement(Token, , Description);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Download file
|
||||
// Gets file by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - File identifier - object
|
||||
// SavePath - String - File save path - out
|
||||
//
|
||||
// Returns:
|
||||
// BinaryData,String - Binary data or file path when SavePath parameter is specified
|
||||
Function DownloadFile(Val Token, Val Identifier, Val SavePath = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + Identifier;
|
||||
|
||||
Parameters = New Map;
|
||||
Parameters.Insert("alt", "media");
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters , Headers, SavePath);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Copy object
|
||||
// Copies file or directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Object identifier - object
|
||||
// NewName - String - New object name - title
|
||||
// NewParent - String - New parent directory - catalog
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CopyObject(Val Token, Val Identifier, Val NewName = "", Val NewParent = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(NewName);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
OPI_TypeConversion.GetLine(NewParent);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + Identifier + "/copy";
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(NewName) Then
|
||||
Parameters.Insert("name", NewName);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(NewParent) Then
|
||||
|
||||
ArrayOfParents = New Array;
|
||||
ArrayOfParents.Add(NewParent);
|
||||
Parameters.Insert("parents", ArrayOfParents);
|
||||
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters , Headers, True);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Update file
|
||||
// Updates file binary data
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the object to update - object
|
||||
// File - BinaryData,String - File source for update - file
|
||||
// NewName - String - New file name (if necessary) - title
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function UpdateFile(Val Token, Val Identifier, Val File, Val NewName = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
OPI_TypeConversion.GetLine(NewName);
|
||||
OPI_TypeConversion.GetBinaryData(File);
|
||||
|
||||
If ValueIsFilled(NewName) Then
|
||||
Description = New Map;
|
||||
Description.Insert("Name", NewName);
|
||||
Else
|
||||
Description = "";
|
||||
EndIf;
|
||||
|
||||
Return FileManagement(Token, File, Description, Identifier);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete object
|
||||
// Deletes file or directory by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the object to delete - object
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteObject(Val Token, Val Identifier) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + Identifier;
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get file description !NOCLI
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - File description
|
||||
Function GetFileDescription() Export
|
||||
|
||||
Description = New Map;
|
||||
Description.Insert("MIME" , "image/jpeg"); // MIME-type uploading file
|
||||
Description.Insert("Name" , "New file.jpg"); // File name with extension
|
||||
Description.Insert("Description" , "This is a new file"); // File description
|
||||
Description.Insert("Parent" , "root"); // ID directory upload or "root" for upload in root
|
||||
|
||||
Return Description;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region CommentManagement
|
||||
|
||||
// Create comment
|
||||
// Creates a comment for a file or directory
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the object that needs a comment - object
|
||||
// Comment - String - Comment text - text
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateComment(Val Token, Val Identifier, Val Comment) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
OPI_TypeConversion.GetLine(Comment);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + Identifier + "/comments?fields=*";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("content", Comment);
|
||||
|
||||
Response = OPI_Tools.POST(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get comment
|
||||
// Gets comment by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// ObjectID - String - Identifier of the file or directory where the comment is located - object
|
||||
// CommentID - String - Comment identifier - comment
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetComment(Val Token, Val ObjectID, Val CommentID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(ObjectID);
|
||||
OPI_TypeConversion.GetLine(CommentID);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + ObjectID + "/comments/" + CommentID;
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("fields", "*");
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of comments
|
||||
// Gets the list of all comments of the object
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// ObjectID - String - Object identifier - object
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetCommentList(Val Token, Val ObjectID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(ObjectID);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + ObjectID + "/comments";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("fields", "*");
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete comment
|
||||
// Deletes comment by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// ObjectID - String - Identifier of the file or directory where the comment is located - object
|
||||
// CommentID - String - Comment identifier - comment
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteComment(Val Token, Val ObjectID, Val CommentID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(ObjectID);
|
||||
OPI_TypeConversion.GetLine(CommentID);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + ObjectID + "/comments/" + CommentID;
|
||||
|
||||
Response = OPI_Tools.Delete(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Procedure GetObjectsListRecursively(Val Headers, ArrayOfObjects, Detailed = False, Filter = "", Page = "")
|
||||
|
||||
URL = "https://www.googleapis.com/drive/v3/files";
|
||||
Files = "files";
|
||||
NPT = "nextPageToken";
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("fields", "*");
|
||||
|
||||
If ValueIsFilled(Page) Then
|
||||
Parameters.Insert("pageToken", Page);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Filter) And TypeOf(Filter) = Type("Array") Then
|
||||
FilterString = StrConcat(Filter, " and ");
|
||||
Parameters.Insert("q", FilterString);
|
||||
EndIf;
|
||||
|
||||
Result = OPI_Tools.Get(URL, Parameters, Headers);
|
||||
|
||||
Objects = Result[Files];
|
||||
Page = Result[NPT];
|
||||
|
||||
For Each CurrentObject In Objects Do
|
||||
ArrayOfObjects.Add(CurrentObject);
|
||||
EndDo;
|
||||
|
||||
If Objects.Quantity() > 0 And ValueIsFilled(Page) Then
|
||||
GetObjectsListRecursively(Headers, ArrayOfObjects, Detailed, Filter, Page);
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure BreakDownObjectsInDetail(Val Token, ArrayOfObjects)
|
||||
|
||||
For Each CurrentObject In ArrayOfObjects Do
|
||||
|
||||
ArrayOfFiles = New Array;
|
||||
CurrentID = CurrentObject["id"];
|
||||
|
||||
Result = GetFilesList(Token, , CurrentID);
|
||||
|
||||
For Each File In Result Do
|
||||
ArrayOfFiles.Add(File);
|
||||
EndDo;
|
||||
|
||||
CurrentObject.Insert("files", ArrayOfFiles);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure FormFileUploadParameters(Description)
|
||||
|
||||
FormedDescription = New Map;
|
||||
OPI_Tools.RemoveEmptyCollectionFields(Description);
|
||||
|
||||
FieldMapping = New Map;
|
||||
FieldMapping.Insert("MIME" , "mimeType");
|
||||
FieldMapping.Insert("Name" , "name");
|
||||
FieldMapping.Insert("Description" , "description");
|
||||
FieldMapping.Insert("Parent" , "parents");
|
||||
FieldMapping.Insert("Extension", "fileExtension");
|
||||
|
||||
For Each Element In Description Do
|
||||
|
||||
If Element.TheKey = "Parent" Then
|
||||
|
||||
CurrentValue = New Array;
|
||||
CurrentValue.Add(Element.Value);
|
||||
|
||||
Else
|
||||
|
||||
CurrentValue = Element.Value;
|
||||
|
||||
EndIf;
|
||||
|
||||
FieldName = FieldMapping.Get(Element.TheKey);
|
||||
FormedDescription.Insert(FieldName, CurrentValue);
|
||||
|
||||
EndDo;
|
||||
|
||||
Description = FormedDescription;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Function FileManagement(Val Token, Val File = "", Val Description = "", Val Identifier = "")
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
If ValueIsFilled(Description) Then
|
||||
OPI_TypeConversion.GetCollection(Description);
|
||||
EndIf;
|
||||
|
||||
MimeType = "mimeType";
|
||||
|
||||
If ValueIsFilled(Identifier) Then
|
||||
MIME = GetObjectInformation(Token, Identifier)[MimeType];
|
||||
Else
|
||||
MIME = Description["MIME"];
|
||||
EndIf;
|
||||
|
||||
If Not ValueIsFilled(Description) Then
|
||||
Description = New Map;
|
||||
EndIf;
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
FormFileUploadParameters(Description);
|
||||
JSONDescription = OPI_Tools.JSONString(Description);
|
||||
|
||||
FileMapping = New Map;
|
||||
|
||||
If ValueIsFilled(File) Then
|
||||
|
||||
ChunkSize = 268435457;
|
||||
Size = OPI_Tools.ConvertDataWithSizeRetrieval(File, ChunkSize);
|
||||
|
||||
FileMapping.Insert(File, MIME);
|
||||
|
||||
If Size < ChunkSize And TypeOf(File) = Type("BinaryData") Then
|
||||
Response = UploadSmallFile(JSONDescription, FileMapping, Headers, Identifier);
|
||||
Else
|
||||
Response = UploadLargeFile(Description, FileMapping, Headers, Identifier);
|
||||
EndIf;
|
||||
|
||||
Else
|
||||
Response = UploadSmallFile(JSONDescription, FileMapping, Headers, Identifier);
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UploadSmallFile(Val Description, Val FileMapping, Val Headers, Val Identifier = "")
|
||||
|
||||
URL = "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart";
|
||||
|
||||
If ValueIsFilled(Identifier) Then
|
||||
URL = StrReplace(URL, "/files", "/files/" + Identifier);
|
||||
Response = OPI_Tools.PatchMultipartRelated(URL, Description, FileMapping, Headers);
|
||||
Else
|
||||
Response = OPI_Tools.PostMultipartRelated(URL, Description, FileMapping, Headers);
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UploadLargeFile(Val Description, Val FileMapping, Val Headers, Val Identifier = "")
|
||||
|
||||
For Each File In FileMapping Do
|
||||
Binary = File.TheKey;
|
||||
Break;
|
||||
EndDo;
|
||||
|
||||
URL = "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable";
|
||||
|
||||
If ValueIsFilled(Identifier) Then
|
||||
URL = StrReplace(URL, "/files", "/files/" + Identifier);
|
||||
Response = OPI_Tools.Patch(URL, Description, Headers, True, True);
|
||||
Else
|
||||
Response = OPI_Tools.Post(URL, Description, Headers, True, True);
|
||||
EndIf;
|
||||
|
||||
UploadURL = Response.Headers["Location"];
|
||||
|
||||
If Not ValueIsFilled(UploadURL) Then
|
||||
OPI_Tools.ProcessResponse(Response);
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
UploadResponse = UploadFileInParts(Binary, UploadURL);
|
||||
Response = ?(ValueIsFilled(UploadResponse), UploadResponse, Response);
|
||||
|
||||
OPI_Tools.ProcessResponse(Response);
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UploadFileInParts(Val Binary, Val UploadURL)
|
||||
|
||||
Response = "";
|
||||
ChunkSize = 268435456;
|
||||
BytesRead = 0;
|
||||
CurrentPosition = 0;
|
||||
TotalSize = Binary.Size();
|
||||
StrTotalSize = OPI_Tools.NumberToString(TotalSize);
|
||||
DataReader = New DataReader(Binary);
|
||||
SourceStream = DataReader.SourceStream();
|
||||
|
||||
WHile BytesRead < TotalSize Do
|
||||
|
||||
BytesRead = SourceStream.CurrentPosition();
|
||||
Result = DataReader.Read(ChunkSize);
|
||||
CurrentData = Result.GetBinaryData();
|
||||
CurrentSize = CurrentData.Size();
|
||||
NextPosition = CurrentPosition + CurrentSize - 1;
|
||||
|
||||
If Not ValueIsFilled(CurrentData) Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
StreamHeader = "bytes "
|
||||
+ OPI_Tools.NumberToString(CurrentPosition)
|
||||
+ "-"
|
||||
+ OPI_Tools.NumberToString(NextPosition)
|
||||
+ "/"
|
||||
+ StrTotalSize;
|
||||
|
||||
AdditionalHeaders = New Map;
|
||||
AdditionalHeaders.Insert("Content-Length", OPI_Tools.NumberToString(CurrentSize));
|
||||
AdditionalHeaders.Insert("Content-Range" , StreamHeader);
|
||||
AdditionalHeaders.Insert("Content-Type" , "application/octet-stream");
|
||||
|
||||
Response = OPI_Tools.Put(UploadURL, CurrentData, AdditionalHeaders, False, True);
|
||||
|
||||
CheckResult = CheckPartUpload(Response, StrTotalSize, AdditionalHeaders, UploadURL, CurrentPosition);
|
||||
|
||||
If ValueIsFilled(CheckResult) Then
|
||||
Return CheckResult;
|
||||
EndIf;
|
||||
|
||||
KBytes = 1024;
|
||||
MByte = KBytes * KBytes;
|
||||
Message(OPI_Tools.ProgressInformation(CurrentPosition, TotalSize, "MB", MByte));
|
||||
|
||||
PerformGarbageCollection();
|
||||
ReleaseObject(CurrentData);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function CheckPartUpload(Response, StrTotalSize, AdditionalHeaders, UploadURL, CurrentPosition)
|
||||
|
||||
StartOfErrorCodes = 400;
|
||||
EndOfFailureCodes = 600;
|
||||
StartOfSuccessCodes = 200;
|
||||
EndOfSuccessCodes = 300;
|
||||
Redirection = 308;
|
||||
|
||||
If Response.StatusCode >= StartOfErrorCodes And Response.StatusCode < EndOfFailureCodes Then
|
||||
|
||||
StreamHeader = "bytes */" + StrTotalSize;
|
||||
AdditionalHeaders.Insert("Content-Range" , StreamHeader);
|
||||
|
||||
CheckResponse = OPI_Tools.Put(UploadURL, "", AdditionalHeaders, False, True);
|
||||
|
||||
If CheckResponse.StatusCode >= StartOfSuccessCodes And CheckResponse.StatusCode < EndOfSuccessCodes Then
|
||||
|
||||
OPI_Tools.ProcessResponse(CheckResponse);
|
||||
Return CheckResponse;
|
||||
|
||||
ElsIf CheckResponse.StatusCode = Redirection Then
|
||||
|
||||
UploadedData = Response.Headers["Range"];
|
||||
|
||||
Else
|
||||
|
||||
OPI_Tools.ProcessResponse(Response);
|
||||
Return Response;
|
||||
|
||||
EndIf;
|
||||
|
||||
Else
|
||||
UploadedData = Response.Headers["Range"];
|
||||
EndIf;
|
||||
|
||||
If Not ValueIsFilled(UploadedData) Then
|
||||
OPI_Tools.ProcessResponse(Response);
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
UploadedData = StrReplace(UploadedData, "bytes=", "");
|
||||
ArrayOfInformation = StrSplit(UploadedData, "-", False);
|
||||
PartsRequired = 2;
|
||||
|
||||
If Not ArrayOfInformation.Quantity() = PartsRequired Then
|
||||
OPI_Tools.ProcessResponse(Response);
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
CurrentPosition = Number(ArrayOfInformation[1]) + 1;
|
||||
|
||||
Return "";
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
409
src/en/OInt/core/Modules/OPI_GoogleSheets.os
Normal file
409
src/en/OInt/core/Modules/OPI_GoogleSheets.os
Normal file
@@ -0,0 +1,409 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleSheets.os
|
||||
// Library: Google Sheets
|
||||
// CLI Command: gsheets
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region BookWork
|
||||
|
||||
// CreateBook
|
||||
// Creates a new book
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Name - String - Name - title
|
||||
// ArrayOfSheetNames - Array of String - Array of names to add new sheets to the book - sheets
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateBook(Val Token, Val Name, Val ArrayOfSheetNames) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetCollection(ArrayOfSheetNames);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets";
|
||||
|
||||
Properties = New Structure("title" , Name);
|
||||
Sheets = New Array;
|
||||
|
||||
FillSheetArray(ArrayOfSheetNames, Sheets);
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("properties", Properties, "Collection", Parameters);
|
||||
OPI_Tools.AddField("sheets" , Sheets , "Collection", Parameters);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// GetBook
|
||||
// Gets information about the book by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - BookIdentifier - spreadsheet
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetBook(Val Token, Val Identifier) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Identifier;
|
||||
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// ChangeBookName
|
||||
// Changes the name of the existing book
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// Name - String - New name - title
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditBookTitle(Val Token, Val Book, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + ":batchUpdate";
|
||||
|
||||
Change = New Structure("title", Name);
|
||||
ChangeRequest = New Structure("properties,fields", Change, "title");
|
||||
Request = New Structure("updateSpreadsheetProperties", ChangeRequest);
|
||||
|
||||
ArrayOfRequests = New Array;
|
||||
ArrayOfRequests.Add(Request);
|
||||
|
||||
Parameters = New Structure("requests", ArrayOfRequests);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region SheetWork
|
||||
|
||||
// AddSheet
|
||||
// Adds a new sheet to the book
|
||||
//
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookIdentifier - spreadsheet
|
||||
// Name - String - NewSheetName - title
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function AddSheet(Val Token, Val Book, Val Name) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + ":batchUpdate";
|
||||
Sheet = CreateSheet(Name);
|
||||
|
||||
Requests = New Array;
|
||||
Change = New Structure("addSheet", Sheet);
|
||||
Requests.Add(Change);
|
||||
|
||||
Parameters = New Structure("requests", Requests);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// DeleteSheet
|
||||
// Deletes a sheet from the book
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookIdentifier - spreadsheet
|
||||
// Sheet - String - IdentifierOfSheetToDelete - sheet
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteSheet(Val Token, Val Book, Val Sheet) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + ":batchUpdate";
|
||||
|
||||
Requests = New Array;
|
||||
Sheet = New Structure("sheetId" , Sheet);
|
||||
Change = New Structure("deleteSheet", Sheet);
|
||||
Requests.Add(Change);
|
||||
|
||||
Parameters = New Structure("requests", Requests);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// CopySheet
|
||||
// Copies a sheet from one book to another
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// From - String - SourceBookID - from
|
||||
// Target - String - DestinationBookID - to
|
||||
// Sheet - String - CopiedSheetID - sheet
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CopySheet(Val Token, Val From, Val Target, Val Sheet) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(From);
|
||||
OPI_TypeConversion.GetLine(Target);
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/"
|
||||
+ From
|
||||
+ "/sheets/"
|
||||
+ Sheet
|
||||
+ ":copyTo";
|
||||
|
||||
Parameters = New Structure("destinationSpreadsheetId", Target);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region DataWork
|
||||
|
||||
// SetCellValues
|
||||
// Sets sheet cell values
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// ValueMapping - Key-Value Pair - Fill data where the key is the cell name like A1 - data
|
||||
// Sheet - String - Sheet name (first sheet by default) - sheetname
|
||||
// MajorDimension - String - Main dimension when filling the array range - dim
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function SetCellValues(Val Token
|
||||
, Val Book
|
||||
, Val ValueMapping
|
||||
, Val Sheet = ""
|
||||
, Val MajorDimension = "COLUMNS") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
OPI_TypeConversion.GetCollection(ValueMapping);
|
||||
|
||||
If Not TypeOf(ValueMapping) = Type("Structure")
|
||||
And Not TypeOf(ValueMapping) = Type("Map") Then
|
||||
Return "Failed to convert the structure of values to a collection";
|
||||
EndIf;
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchUpdate";
|
||||
DataArray = FormCellDataArray(ValueMapping, MajorDimension, Sheet);
|
||||
|
||||
Parameters = New Structure("data,valueInputOption", DataArray, "USER_ENTERED");
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Clear cells
|
||||
// Clears the value in cells
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// CellsArray - Array of String - Array of cells like A1 to be cleared - cells
|
||||
// Sheet - String - Sheet name (first sheet by default) - sheetname
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function ClearCells(Val Token, Val Book, Val CellsArray, Val Sheet = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
OPI_TypeConversion.GetCollection(CellsArray);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchClear";
|
||||
|
||||
FormCellNameArray(CellsArray, Sheet);
|
||||
|
||||
Parameters = New Structure("ranges", CellsArray);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get cell values
|
||||
// Gets cell values of the table
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// CellsArray - Array of String - Array of A1-type cells to get (whole sheet if not filled) - cells
|
||||
// Sheet - String - Sheet name (first sheet by default) - sheetname
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetCellValues(Val Token, Val Book, Val CellsArray = "", Val Sheet = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchGet";
|
||||
|
||||
If ValueIsFilled(CellsArray) Then
|
||||
OPI_TypeConversion.GetCollection(CellsArray);
|
||||
FormCellNameArray(CellsArray, Sheet);
|
||||
|
||||
First = True;
|
||||
For Each Cell In CellsArray Do
|
||||
Delimiter = ?(First, "?", "&");
|
||||
URL = URL + Delimiter + "ranges=" + Cell;
|
||||
First = False;
|
||||
EndDo;
|
||||
Else
|
||||
URL = URL + "?ranges='" + Sheet + "'";
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(URL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Procedure FillSheetArray(Val ArrayOfNames, SheetArray)
|
||||
|
||||
For Each SheetName In ArrayOfNames Do
|
||||
|
||||
Sheet = CreateSheet(SheetName);
|
||||
SheetArray.Add(Sheet);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddSheetName(Cell, Val Sheet)
|
||||
|
||||
If ValueIsFilled(Sheet) Then
|
||||
Cell = "'" + Sheet + "'!" + Cell;
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Function CreateSheet(Val Name)
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
SheetProperties = New Structure("title" , Name);
|
||||
Sheet = New Structure("properties", SheetProperties);
|
||||
|
||||
Return Sheet;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormCellDataArray(Val ValueStructure, Val MajorDimension, Val Sheet)
|
||||
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
DataArray = New Array;
|
||||
|
||||
For Each CellData In ValueStructure Do
|
||||
|
||||
CurrentValue = CellData.Value;
|
||||
CurrentKey = CellData.TheKey;
|
||||
|
||||
AddSheetName(CurrentKey, Sheet);
|
||||
|
||||
OPI_TypeConversion.GetArray(CurrentValue);
|
||||
|
||||
CurrentData = New Map;
|
||||
CurrentArray = New Array;
|
||||
|
||||
CurrentArray.Add(CurrentValue);
|
||||
|
||||
OPI_Tools.AddField("range" , CurrentKey , "String", CurrentData);
|
||||
OPI_Tools.AddField("values" , CurrentArray , "Array", CurrentData);
|
||||
OPI_Tools.AddField("majorDimension", MajorDimension, "String", CurrentData);
|
||||
|
||||
DataArray.Add(CurrentData);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return DataArray;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure FormCellNameArray(Val ArrayOfNames, Val Sheet)
|
||||
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
For N = 0 To ArrayOfNames.WithinBoundary() Do
|
||||
AddSheetName(ArrayOfNames[N], Sheet);
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
173
src/en/OInt/core/Modules/OPI_GoogleWorkspace.os
Normal file
173
src/en/OInt/core/Modules/OPI_GoogleWorkspace.os
Normal file
@@ -0,0 +1,173 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleWorkspace.os
|
||||
// Library: Google Workspace
|
||||
// CLI command: google
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
// Generate code retrieval link
|
||||
// Returns URL for browser authorization
|
||||
//
|
||||
// Parameters:
|
||||
// ClientID - String - Client ID - id
|
||||
// Calendar - Boolean - Calendar methods permission - calendar
|
||||
// Drive - Boolean - Drive methods permission - drive
|
||||
// Sheets - Boolean - Sheets methods permission - sheets
|
||||
//
|
||||
// Returns:
|
||||
// String - Code retrieval link
|
||||
Function FormCodeRetrievalLink(Val ClientID
|
||||
, Val Calendar = True
|
||||
, Val Drive = True
|
||||
, Val Sheets = True) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ClientID);
|
||||
OPI_TypeConversion.GetBoolean(Calendar);
|
||||
OPI_TypeConversion.GetBoolean(Sheets);
|
||||
OPI_TypeConversion.GetBoolean(Drive);
|
||||
|
||||
URL = "https://accounts.google.com/o/oauth2/auth";
|
||||
|
||||
URLParameters = New Structure;
|
||||
URLParameters.Insert("response_type", "code");
|
||||
URLParameters.Insert("client_id" , ClientID);
|
||||
URLParameters.Insert("redirect_uri" , "http://localhost");
|
||||
URLParameters.Insert("access_type" , "offline");
|
||||
URLParameters.Insert("scope" , GetPermissionsList(Calendar, Drive, Sheets));
|
||||
|
||||
URL = URL + OPI_Tools.RequestParametersToString(URLParameters);
|
||||
|
||||
Return URL;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get token by code
|
||||
// Gets token by code from browser authorization
|
||||
//
|
||||
// Parameters:
|
||||
// ClientID - String - Client ID - id
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// Code - String - Code from browser - code
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetTokenByCode(Val ClientID, Val ClientSecret, Val Code) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ClientID);
|
||||
OPI_TypeConversion.GetLine(ClientSecret);
|
||||
OPI_TypeConversion.GetLine(Code);
|
||||
|
||||
URL = "https://accounts.google.com/o/oauth2/token";
|
||||
|
||||
URLParameters = New Structure;
|
||||
URLParameters.Insert("grant_type" , "authorization_code");
|
||||
URLParameters.Insert("client_id" , ClientID);
|
||||
URLParameters.Insert("client_secret", ClientSecret);
|
||||
URLParameters.Insert("redirect_uri" , "http://localhost");
|
||||
URLParameters.Insert("code" , Code);
|
||||
|
||||
Response = OPI_Tools.Post(URL, URLParameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Refresh token
|
||||
// Updates token by Refresh token
|
||||
//
|
||||
// Parameters:
|
||||
// ClientID - String - Client ID - id
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// RefreshToken - String - Refresh token - refresh
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function RefreshToken(Val ClientID, Val ClientSecret, Val RefreshToken) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ClientID);
|
||||
OPI_TypeConversion.GetLine(ClientSecret);
|
||||
OPI_TypeConversion.GetLine(RefreshToken);
|
||||
|
||||
URL = "https://accounts.google.com/o/oauth2/token";
|
||||
|
||||
URLParameters = New Structure;
|
||||
URLParameters.Insert("grant_type" , "refresh_token");
|
||||
URLParameters.Insert("client_id" , ClientID);
|
||||
URLParameters.Insert("client_secret", ClientSecret);
|
||||
URLParameters.Insert("refresh_token", RefreshToken);
|
||||
|
||||
Response = OPI_Tools.Post(URL, URLParameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Internal
|
||||
|
||||
Function GetAuthorizationHeader(Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "Bearer " + Token);
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
|
||||
Function GetPermissionsList(Calendar, Drive, Sheets)
|
||||
|
||||
PermissionsArray = New Array;
|
||||
|
||||
If Calendar Then
|
||||
PermissionsArray.Add("https://www.googleapis.com/auth/calendar");
|
||||
EndIf;
|
||||
|
||||
If Drive Then
|
||||
PermissionsArray.Add("https://www.googleapis.com/auth/drive");
|
||||
EndIf;
|
||||
|
||||
If Sheets Then
|
||||
PermissionsArray.Add("https://www.googleapis.com/auth/spreadsheets");
|
||||
EndIf;
|
||||
|
||||
Return StrConcat(PermissionsArray, " ");
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
889
src/en/OInt/core/Modules/OPI_Notion.os
Normal file
889
src/en/OInt/core/Modules/OPI_Notion.os
Normal file
@@ -0,0 +1,889 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Notion.os
|
||||
// Library: Notion
|
||||
// CLI command: notion
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
// @skip-check method-too-many-params
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region PageManagement
|
||||
|
||||
// Create page
|
||||
// Creates a child page above another parent page
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Parent - String - Parent ID - page
|
||||
// Title - String - Page title - title
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreatePage(Val Token, Val Parent, Val Title) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Parent);
|
||||
OPI_TypeConversion.GetLine(Title);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Properties = New Structure;
|
||||
Parameters = New Structure;
|
||||
|
||||
AddPageHeader(Title, Properties);
|
||||
AddPageParent(Parent, False, Parameters);
|
||||
|
||||
Parameters.Insert("properties", Properties);
|
||||
|
||||
Response = OPI_Tools.Post("https://api.notion.com/v1/pages", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create page in database
|
||||
// Creates a page in the parent database
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Parent - String - Parent database ID - base
|
||||
// Data - Key-Value Pair - Properties match - data
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreatePageInDatabase(Val Token, Val Parent, Val Data) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Parent);
|
||||
OPI_TypeConversion.GetCollection(Data);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Parameters = New Structure;
|
||||
|
||||
AddPageParent(Parent, True, Parameters);
|
||||
|
||||
Properties = FillDataBySchema(Parent, Data, Token);
|
||||
Parameters.Insert("properties", Properties);
|
||||
|
||||
Response = OPI_Tools.Post("https://api.notion.com/v1/pages", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get page
|
||||
// Gets information about the page by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Page - String - Page ID - page
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function GetPage(Val Token, Val Page) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Page);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
ConvertID(Page);
|
||||
|
||||
Response = OPI_Tools.Get("https://api.notion.com/v1/pages/" + Page, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Edit page properties.
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Page - String - ID of the page being modified - page
|
||||
// Data - Key-Value Pair - Matching of editable parameters - data
|
||||
// Icon - String - URL of the page icon image - icon
|
||||
// Cover - String - URL of the page cover image - cover
|
||||
// Archived - Boolean - Archive page or not (boolean) - archive
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function EditPageProperties(Val Token
|
||||
, Val Page
|
||||
, Val Data = ""
|
||||
, Val Icon = ""
|
||||
, Val Cover = ""
|
||||
, Val Archived = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Page);
|
||||
OPI_TypeConversion.GetLine(Icon);
|
||||
OPI_TypeConversion.GetLine(Cover);
|
||||
OPI_TypeConversion.GetBoolean(Archived);
|
||||
OPI_TypeConversion.GetCollection(Data);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Parameters = New Structure;
|
||||
Files = "files";
|
||||
|
||||
If ValueIsFilled(Data)
|
||||
And (TypeOf(Data) = Type("Map") Or TypeOf(Data) = Type("Structure")) Then
|
||||
Properties = FillDataBySchema(Page, Data, Token, False);
|
||||
Else
|
||||
Properties = New Map;
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Icon) Then
|
||||
IconMap = New Map;
|
||||
IconMap.Insert("Icon", Icon);
|
||||
|
||||
IconObject = ConvertValueByType(Files, IconMap);
|
||||
IconObject = IconObject[Files][0];
|
||||
IconObject.Delete("name");
|
||||
|
||||
Parameters.Insert("icon", IconObject);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Cover) Then
|
||||
CoverMap = New Map;
|
||||
CoverMap.Insert("Cover", Cover);
|
||||
|
||||
CoverObject = ConvertValueByType(Files, CoverMap);
|
||||
CoverObject = CoverObject[Files][0];
|
||||
CoverObject.Delete("name");
|
||||
|
||||
Parameters.Insert("cover", CoverObject);
|
||||
EndIf;
|
||||
|
||||
Parameters.Insert("properties", Properties);
|
||||
Parameters.Insert("archived" , Archived);
|
||||
|
||||
ConvertID(Page);
|
||||
|
||||
Response = OPI_Tools.Patch("https://api.notion.com/v1/pages/" + Page, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region DatabaseManagement
|
||||
|
||||
// Create database
|
||||
// Creates a database
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Parent - String - Parent page ID - page
|
||||
// Title - String - Database title - title
|
||||
// Properties - Structure Of String - Database properties - props
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreateDatabase(Val Token, Val Parent, Val Title, Val Properties = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Parent);
|
||||
OPI_TypeConversion.GetLine(Title);
|
||||
OPI_TypeConversion.GetCollection(Properties);
|
||||
|
||||
// Example structure/property map
|
||||
|
||||
// Name : title
|
||||
// Description : rich_text
|
||||
// InProgress : checkbox
|
||||
// Quantity : number
|
||||
// Date : date
|
||||
// Status : Map
|
||||
// Аtoтиinный : green
|
||||
// Inactive : red
|
||||
// Архиin : yellow
|
||||
|
||||
// All pages created as children must have parent base properties
|
||||
|
||||
If Not TypeOf(Properties) = Type("Structure") And Not TypeOf(Properties) = Type("Map") Then
|
||||
Properties = New Structure("Name", "title");
|
||||
EndIf;
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Parameters = New Structure;
|
||||
|
||||
AddDatabaseParent(Parent, False, Parameters);
|
||||
AddDatabaseHeader(Title, Parameters);
|
||||
AddDatabaseProperties(Properties, Parameters);
|
||||
|
||||
Response = OPI_Tools.Post("https://api.notion.com/v1/databases", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get database
|
||||
// Get database information
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database ID - base
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function GetDatabase(Val Token, Val Base) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
ConvertID(Base);
|
||||
|
||||
Response = OPI_Tools.Get("https://api.notion.com/v1/databases/" + Base, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Edit database properties
|
||||
// Edits properties of an existing database
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Target database ID - base
|
||||
// Properties - Map of KeyAndValue - New or modified database properties - props
|
||||
// Title - String - New database title - title
|
||||
// Description - String - New database description - description
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function EditDatabaseProperties(Val Token, Val Base, Val Properties = "", Val Title = "", Val Description = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Base);
|
||||
OPI_TypeConversion.GetLine(Title);
|
||||
OPI_TypeConversion.GetLine(Description);
|
||||
OPI_TypeConversion.GetCollection(Properties);
|
||||
|
||||
Parameters = New Structure;
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
ConvertID(Base);
|
||||
|
||||
If ValueIsFilled(Title) Then
|
||||
AddDatabaseHeader(Title, Parameters);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Description) Then
|
||||
AddDatabaseDescription(Description, Parameters);
|
||||
EndIf;
|
||||
|
||||
If TypeOf(Properties) = Type("Structure") Or TypeOf(Properties) = Type("Map") Then
|
||||
AddDatabaseProperties(Properties, Parameters);
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Patch("https://api.notion.com/v1/databases/" + Base, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region BlockWork
|
||||
|
||||
// Create block
|
||||
// Creates a new block based on an existing block
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Parent - String - Parent block or page ID - page
|
||||
// Block - String, Map Of KeyAndValue - Block ID or block sample itself - block
|
||||
// InsertAfter - String - Block ID after which to insert the new one - prev
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreateBlock(Val Token, Val Parent, Val Block, Val InsertAfter = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Parent);
|
||||
OPI_TypeConversion.GetLine(InsertAfter);
|
||||
OPI_TypeConversion.GetCollection(Block);
|
||||
|
||||
If TypeOf(Block) = Type("Array") Then
|
||||
Block = Block[0];
|
||||
EndIf;
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
ConvertID(Parent);
|
||||
|
||||
If TypeOf(Block) = Type("String") Then
|
||||
ConvertID(Block);
|
||||
Block = ReturnBlock(Token, Block);
|
||||
EndIf;
|
||||
|
||||
BlockArray = New Array;
|
||||
BlockArray.Add(Block);
|
||||
|
||||
Parameters = New Map;
|
||||
Parameters.Insert("children", BlockArray);
|
||||
|
||||
If ValueIsFilled(InsertAfter) Then
|
||||
Parameters.Insert("after", InsertAfter);
|
||||
EndIf;
|
||||
|
||||
URL = "https://api.notion.com/v1/blocks/" + Parent + "/children";
|
||||
Response = OPI_Tools.Patch(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Return block.
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// BlockID - String - Block ID - block
|
||||
// OnlyBase - Boolean - True > service fields are deleted, only the block itself remains - core
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function ReturnBlock(Val Token, Val BlockID, Val OnlyBase = True) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(BlockID);
|
||||
OPI_TypeConversion.GetBoolean(OnlyBase);
|
||||
|
||||
ConvertID(BlockID);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Response = OPI_Tools.Get("https://api.notion.com/v1/blocks/" + BlockID, , Headers);
|
||||
|
||||
If OnlyBase Then
|
||||
RemoveExtraBlockFields(Response);
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Return child blocks
|
||||
// Returns list of child blocks of parent block
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// BlockID - String - Parent block ID - block
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function ReturnChildBlocks(Val Token, Val BlockID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(BlockID);
|
||||
|
||||
ConvertID(BlockID);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Response = OPI_Tools.Get("https://api.notion.com/v1/blocks/" + BlockID + "/children", , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete block
|
||||
// Deletes block by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// BlockID - String - Block ID - block
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function DeleteBlock(Val Token, Val BlockID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(BlockID);
|
||||
|
||||
ConvertID(BlockID);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Response = OPI_Tools.Delete("https://api.notion.com/v1/blocks/" + BlockID, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Users
|
||||
|
||||
// User list
|
||||
// Returns a list of workspace users
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function UserList(Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Response = OPI_Tools.Get("https://api.notion.com/v1/users", , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get user data
|
||||
// Gets user data by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// UserID - String - Target user ID - user
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function GetUserData(Val Token, Val UserID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(UserID);
|
||||
|
||||
ConvertID(UserID);
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
Response = OPI_Tools.Get("https://api.notion.com/v1/users/" + UserID, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function CreateRequestHeaders(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization" , "Bearer " + Token);
|
||||
Headers.Insert("Notion-Version", "2022-06-28");
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure ConvertID(Identifier)
|
||||
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
Identifier = StrReplace(Identifier, "-", "");
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddPageParent(Val Parent, Val ParentBase, MainStructure)
|
||||
|
||||
OPI_TypeConversion.GetLine(ParentBase);
|
||||
|
||||
ConvertID(Parent);
|
||||
|
||||
IdentifierField = ?(ParentBase, "database_id", "page_id");
|
||||
ParentStructure = New Structure(IdentifierField, Parent);
|
||||
|
||||
MainStructure.Insert("parent", ParentStructure);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddDatabaseParent(Val Parent, Val ParentBase, MainStructure)
|
||||
|
||||
OPI_TypeConversion.GetLine(ParentBase);
|
||||
|
||||
ConvertID(Parent);
|
||||
|
||||
IdentifierField = ?(ParentBase, "database_id", "page_id");
|
||||
|
||||
ParentStructure = New Structure();
|
||||
ParentStructure.Insert("type" , IdentifierField);
|
||||
ParentStructure.Insert(IdentifierField, Parent);
|
||||
|
||||
MainStructure.Insert("parent", ParentStructure);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddPageHeader(Val Title, MainStructure)
|
||||
|
||||
OPI_TypeConversion.GetLine(Title);
|
||||
|
||||
SubordinateStructure = New Structure;
|
||||
DataStructure = New Structure;
|
||||
TextStructure = New Structure;
|
||||
DataArray = New Array;
|
||||
Title = "title";
|
||||
|
||||
TextStructure.Insert("content", Title);
|
||||
TextStructure.Insert("link" , Undefined);
|
||||
|
||||
DataStructure.Insert("text", TextStructure);
|
||||
DataStructure.Insert("type", "text");
|
||||
|
||||
DataArray.Add(DataStructure);
|
||||
|
||||
SubordinateStructure.Insert("id" , Title);
|
||||
SubordinateStructure.Insert("type" , Title);
|
||||
SubordinateStructure.Insert(Title , DataArray);
|
||||
|
||||
MainStructure.Insert(Title, SubordinateStructure);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddDatabaseHeader(Val Title, MainStructure)
|
||||
|
||||
OPI_TypeConversion.GetLine(Title);
|
||||
|
||||
Title = ConvertHeader(Title);
|
||||
MainStructure.Insert("title", Title["title"]);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddDatabaseDescription(Val Description, MainStructure)
|
||||
|
||||
OPI_TypeConversion.GetLine(Description);
|
||||
|
||||
Title = ConvertHeader(Description);
|
||||
MainStructure.Insert("description", Title["title"]);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure AddDatabaseProperties(Val Properties, MainStructure)
|
||||
|
||||
If Properties.Quantity() = 0 Then
|
||||
MainStructure.Insert("properties", New Structure);
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
ParameterMap = New Map;
|
||||
|
||||
For Each Property In Properties Do
|
||||
|
||||
If TypeOf(Property.Value) = Type("String") Then
|
||||
|
||||
ParameterMap.Insert(Property.TheKey, New Structure(Property.Value, New Structure));
|
||||
|
||||
ElsIf TypeOf(Property.Value) = Type("Structure")
|
||||
Or TypeOf(Property.Value) = Type("Map") Then
|
||||
|
||||
ValueSelection = FormSelectionValues(Property.Value);
|
||||
ParameterMap.Insert(Property.TheKey, New Structure("select", ValueSelection));
|
||||
|
||||
Else
|
||||
|
||||
ParameterMap.Insert(Property.TheKey, Property.Value);
|
||||
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
MainStructure.Insert("properties", ParameterMap);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Function FormSelectionValues(Val VariantStructure)
|
||||
|
||||
OptionArray = New Array;
|
||||
|
||||
For Each Option In VariantStructure Do
|
||||
|
||||
OptionMap = New Map;
|
||||
OptionMap.Insert("name" , Option.TheKey);
|
||||
OptionMap.Insert("color", Option.Value);
|
||||
|
||||
OptionArray.Add(OptionMap);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return New Structure("options", OptionArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FillDataBySchema(Val Scheme, Val Data, Val Token, Val ThisIsBase = True)
|
||||
|
||||
If ThisIsBase Then
|
||||
SchemaData = GetDatabase(Token, Scheme);
|
||||
Else
|
||||
SchemaData = GetPage(Token, Scheme);
|
||||
EndIf;
|
||||
|
||||
BaseFields = SchemaData["properties"];
|
||||
Properties = New Map;
|
||||
|
||||
If ValueIsFilled(BaseFields) Then
|
||||
|
||||
For Each Field In BaseFields Do
|
||||
|
||||
FieldData = Field.Value;
|
||||
FieldType = FieldData["type"];
|
||||
|
||||
FillableData = Data.Get(Field.TheKey);
|
||||
|
||||
If FillableData = Undefined Then
|
||||
Continue;
|
||||
EndIf;
|
||||
|
||||
ConvertedData = ConvertValueByType(FieldType, FillableData);
|
||||
|
||||
If ConvertedData = Undefined Then
|
||||
Continue;
|
||||
EndIf;
|
||||
|
||||
Properties.Insert(FieldData["id"], ConvertedData);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Properties;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure RemoveExtraBlockFields(Val Block)
|
||||
|
||||
ExtraArray = New Array;
|
||||
ExtraArray.Add("request_id");
|
||||
ExtraArray.Add("archived");
|
||||
ExtraArray.Add("created_by");
|
||||
ExtraArray.Add("last_edited_time");
|
||||
ExtraArray.Add("created_time");
|
||||
ExtraArray.Add("has_children");
|
||||
ExtraArray.Add("parrent");
|
||||
ExtraArray.Add("last_edited_by");
|
||||
ExtraArray.Add("id");
|
||||
|
||||
For Each Field In ExtraArray Do
|
||||
|
||||
If Not Block.Get(Field) = Undefined Then
|
||||
Block.Delete(Field);
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#Region TypeConversion
|
||||
|
||||
Function ConvertValueByType(Val Type, Val Value)
|
||||
|
||||
If Type = "title" Then
|
||||
Return ConvertHeader(Value);
|
||||
ElsIf Type = "rich_text" Then
|
||||
Return ConvertText(Value);
|
||||
ElsIf Type = "number" Then
|
||||
Return ConvertNumber(Value);
|
||||
ElsIf Type = "select" Then
|
||||
Return ConvertSelectionOption(Value);
|
||||
ElsIf Type = "multi_select" Then
|
||||
Return ConvertMultipleChoice(Value);
|
||||
ElsIf Type = "status" Then
|
||||
Return ConvertStatus(Value);
|
||||
ElsIf Type = "date" Then
|
||||
Return ConvertDate(Value);
|
||||
ElsIf Type = "relation" Then
|
||||
Return ConvertLink(Value);
|
||||
ElsIf Type = "people" Then
|
||||
Return ConvertUsers(Value);
|
||||
ElsIf Type = "files" Then
|
||||
Return ConvertFiles(Value);
|
||||
ElsIf Type = "checkbox" Then
|
||||
Return ConvertBoolean(Value);
|
||||
ElsIf Type = "url" Then
|
||||
Return ConvertURL(Value);
|
||||
ElsIf Type = "email" Then
|
||||
Return ConvertEmail(Value);
|
||||
ElsIf Type = "phone_number" Then
|
||||
Return ConvertPhone(Value);
|
||||
Else
|
||||
Return Undefined;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertHeader(Val Title)
|
||||
|
||||
DataStructure = New Structure;
|
||||
TextStructure = New Structure;
|
||||
DataArray = New Array;
|
||||
|
||||
TextStructure.Insert("content", Title);
|
||||
TextStructure.Insert("link" , Undefined);
|
||||
|
||||
DataStructure.Insert("type", "text");
|
||||
DataStructure.Insert("text", TextStructure);
|
||||
|
||||
DataArray.Add(DataStructure);
|
||||
|
||||
Return New Structure("title", DataArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertText(Val Text)
|
||||
|
||||
TextArray = New Array;
|
||||
TextStructure = New Structure;
|
||||
|
||||
TextStructure.Insert("type", "text");
|
||||
TextStructure.Insert("text", New Structure("content", Text));
|
||||
|
||||
TextArray.Add(TextStructure);
|
||||
|
||||
Return New Structure("rich_text", TextArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertNumber(Val Number)
|
||||
Return New Structure("number", Number);
|
||||
EndFunction
|
||||
|
||||
Function ConvertSelectionOption(Val Option)
|
||||
|
||||
ChoiceStructure = New Structure;
|
||||
ChoiceStructure.Insert("select", New Structure("name", Option));
|
||||
|
||||
Return ChoiceStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertStatus(Val Status)
|
||||
|
||||
StatusStructure = New Structure;
|
||||
StatusStructure.Insert("status", New Structure("name", Status));
|
||||
|
||||
Return StatusStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertMultipleChoice(Val OptionArray)
|
||||
|
||||
ChoiceOptionArray = New Array;
|
||||
|
||||
For Each Option In OptionArray Do
|
||||
ChoiceOptionArray.Add(New Structure("name", Option));
|
||||
EndDo;
|
||||
|
||||
Return New Structure("multi_select", ChoiceOptionArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertDate(Val Date)
|
||||
|
||||
DateStructure = New Structure;
|
||||
|
||||
If Date = BegOfDay(Date) Then
|
||||
DateFormat = "DF=yyyy-MM-dd";
|
||||
Else
|
||||
DateFormat = "ISO8601Datetime";
|
||||
EndIf;
|
||||
|
||||
Date = Format(Date, DateFormat);
|
||||
DateStructure.Insert("start", Date);
|
||||
|
||||
Return New Structure("date", DateStructure);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertLink(Val Identifier)
|
||||
|
||||
LinkArray = New Array;
|
||||
LinkArray.Add(New Structure("id", Identifier));
|
||||
|
||||
Return New Structure("relation", LinkArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertUsers(Val IDArray)
|
||||
|
||||
If Not TypeOf(IDArray) = Type("Array") Then
|
||||
ArrayID_ = New Array;
|
||||
ArrayID_.Add(IDArray);
|
||||
IDArray = ArrayID_;
|
||||
EndIf;
|
||||
|
||||
ArrayOfUsers = New Array;
|
||||
|
||||
For Each Identifier In IDArray Do
|
||||
|
||||
UserStructure = New Structure;
|
||||
UserStructure.Insert("object", "user");
|
||||
UserStructure.Insert("id" , Identifier);
|
||||
ArrayOfUsers.Add(UserStructure);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return New Structure("people", ArrayOfUsers);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertFiles(Val FileMapping)
|
||||
|
||||
ArrayOfFiles = New Array;
|
||||
|
||||
For Each File In FileMapping Do
|
||||
|
||||
FileStructure = New Structure;
|
||||
FileStructure.Insert("type" , "external");
|
||||
FileStructure.Insert("name" , File.TheKey);
|
||||
FileStructure.Insert("external", New Structure("url", File.Value));
|
||||
|
||||
ArrayOfFiles.Add(FileStructure);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return New Structure("files", ArrayOfFiles);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConvertBoolean(Val Boolean)
|
||||
Return New Structure("checkbox", Boolean);
|
||||
EndFunction
|
||||
|
||||
Function ConvertURL(Val URL)
|
||||
Return New Structure("url", URL);
|
||||
EndFunction
|
||||
|
||||
Function ConvertEmail(Val Email)
|
||||
Return New Structure("email", Email);
|
||||
EndFunction
|
||||
|
||||
Function ConvertPhone(Val Phone)
|
||||
Return New Structure("phone_number", Phone);
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
1055
src/en/OInt/core/Modules/OPI_Slack.os
Normal file
1055
src/en/OInt/core/Modules/OPI_Slack.os
Normal file
File diff suppressed because it is too large
Load Diff
1253
src/en/OInt/core/Modules/OPI_Telegram.os
Normal file
1253
src/en/OInt/core/Modules/OPI_Telegram.os
Normal file
File diff suppressed because it is too large
Load Diff
682
src/en/OInt/core/Modules/OPI_Twitter.os
Normal file
682
src/en/OInt/core/Modules/OPI_Twitter.os
Normal file
@@ -0,0 +1,682 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Twitter.os
|
||||
// Library: Twitter
|
||||
// CLI Command: twitter
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
// If you don't know where to start, you should find the method GetStandardParameters()
|
||||
// and read comments
|
||||
|
||||
// BSLLS:Typo-off
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region DataAndSettings
|
||||
|
||||
// Get authorization link
|
||||
// Forms a link for authorization via the browser
|
||||
//
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// String - URL for browser transition
|
||||
Function GetAuthorizationLink(Parameters = "") Export
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
|
||||
URLParameters = New Structure;
|
||||
|
||||
URLParameters.Insert("response_type" , "code");
|
||||
URLParameters.Insert("client_id" , Parameters_["client_id"]);
|
||||
URLParameters.Insert("redirect_uri" , Parameters_["redirect_uri"]);
|
||||
URLParameters.Insert("scope" , Parameters_["scope"]);
|
||||
URLParameters.Insert("state" , "state");
|
||||
URLParameters.Insert("code_challenge" , "challenge");
|
||||
URLParameters.Insert("code_challenge_method", "plain");
|
||||
|
||||
URLParameters = OPI_Tools.RequestParametersToString(URLParameters);
|
||||
Link = "https://twitter.com/i/oauth2/authorize" + URLParameters;
|
||||
|
||||
Return Link;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get token
|
||||
// Gets the token by the code obtained during authorization via the link from GetAuthorizationLink
|
||||
//
|
||||
// Parameters:
|
||||
// Code - String - Code obtained from authorization See GetAuthorizationLink - code
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function GetToken(Val Code, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Code);
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
|
||||
RequestParameters = New Structure;
|
||||
RequestParameters.Insert("code" , Code);
|
||||
RequestParameters.Insert("grant_type" , "authorization_code");
|
||||
RequestParameters.Insert("client_id" , Parameters_["client_id"]);
|
||||
RequestParameters.Insert("redirect_uri" , Parameters_["redirect_uri"]);
|
||||
RequestParameters.Insert("code_verifier", "challenge");
|
||||
|
||||
Response = OPI_Tools.Post("https://api.twitter.com/2/oauth2/token"
|
||||
, RequestParameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Refresh token
|
||||
// Updates the v2 token using the refresh_token
|
||||
//
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function RefreshToken(Val Parameters = "") Export
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
Refresh = "refresh_token";
|
||||
|
||||
RequestParameters = New Structure;
|
||||
RequestParameters.Insert(Refresh , Parameters_[Refresh]);
|
||||
RequestParameters.Insert("grant_type" , Refresh);
|
||||
RequestParameters.Insert("client_id" , Parameters_["client_id"]);
|
||||
|
||||
Response = OPI_Tools.Post("https://api.twitter.com/2/oauth2/token"
|
||||
, RequestParameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// !NOCLI
|
||||
// Method for insertion into an http service, the address of which is specified in redirect_uri
|
||||
// Calls the token acquisition method, as for obtaining a token from the code received
|
||||
// on redirect_uri after authorization via the browser is only 30 seconds
|
||||
//
|
||||
// Parameters:
|
||||
// Request - HTTPServiceRequest - Request coming to the http service
|
||||
//
|
||||
// Returns:
|
||||
// HTTPResponse, Arbitrary, BinaryData - Result of reading the JSON response from the server
|
||||
Function HandleIncomingRequestAfterAuthorization(Request) Export
|
||||
|
||||
Code = Request.RequestParameters["code"];
|
||||
TokenResponse = GetToken(Code);
|
||||
|
||||
// BSLLS:CommentedCode-off
|
||||
// Preferred token storage
|
||||
// Constants.TwitterRefresh.Set(ResponseToken["refresh_token"]);
|
||||
// Constants.TwitterToken.Set(ResponseToken["access_token"]);
|
||||
// BSLLS:CommentedCode-on
|
||||
|
||||
Return TokenResponse;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Tweets
|
||||
|
||||
// !NOCLI
|
||||
// Create custom tweet
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text
|
||||
// MediaArray - Array of String, BinaryData - Array of binary data or file paths
|
||||
// PollOptionsArray - Array of String - Array of poll options, if necessary
|
||||
// PollDuration - String, Number - Poll duration if necessary (poll without duration is not created)
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateCustomTweet(Val Text = ""
|
||||
, Val MediaArray = ""
|
||||
, Val PollOptionsArray = ""
|
||||
, Val PollDuration = ""
|
||||
, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Text);
|
||||
OPI_TypeConversion.GetLine(PollDuration);
|
||||
|
||||
If ValueIsFilled(MediaArray) Then
|
||||
OPI_TypeConversion.GetCollection(MediaArray);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(PollOptionsArray) Then
|
||||
OPI_TypeConversion.GetCollection(PollOptionsArray);
|
||||
EndIf;
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
URL = "https://api.twitter.com/2/tweets";
|
||||
Array = "Array";
|
||||
Fields = New Map;
|
||||
|
||||
If ValueIsFilled(Text) Then
|
||||
Fields.Insert("text", Text);
|
||||
EndIf;
|
||||
|
||||
If TypeOf(PollOptionsArray) = Type(Array) And ValueIsFilled(PollDuration) Then
|
||||
|
||||
PollDuration = Number(PollDuration);
|
||||
|
||||
If PollOptionsArray.Quantity() > 0 Then
|
||||
|
||||
OptionStructure = New Structure("options,duration_minutes", PollOptionsArray, PollDuration);
|
||||
Fields.Insert("poll", OptionStructure);
|
||||
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
If TypeOf(MediaArray) = Type(Array) Then
|
||||
If MediaArray.Quantity() > 0 Then
|
||||
Fields.Insert("media", New Structure("media_ids", MediaArray));
|
||||
EndIf;
|
||||
EndIf;
|
||||
|
||||
Authorization = CreateAuthorizationHeaderV2(Parameters_);
|
||||
Response = OPI_Tools.Post(URL, Fields, Authorization);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create text tweet
|
||||
// Creates a tweet without attachments
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateTextTweet(Val Text, Val Parameters = "") Export
|
||||
Return CreateCustomTweet(Text, , , , Parameters);
|
||||
EndFunction
|
||||
|
||||
// Create image tweet
|
||||
// Creates a tweet with an image attachment
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// ImageArray - Array of String, BinaryData - Image files array - pictures
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateImageTweet(Val Text, Val ImageArray, Val Parameters = "") Export
|
||||
|
||||
MediaArray = UploadAttachmentsArray(ImageArray, "tweet_image", Parameters);
|
||||
Return CreateCustomTweet(Text, MediaArray, , , Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create gif tweet
|
||||
// Creates a tweet with a gif attachment
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// GifsArray - Array of String, BinaryData - Gif files array - gifs
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateGifTweet(Val Text, Val GifsArray, Val Parameters = "") Export
|
||||
|
||||
MediaArray = UploadAttachmentsArray(GifsArray, "tweet_gif", Parameters);
|
||||
Return CreateCustomTweet(Text, MediaArray, , , Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create video tweet
|
||||
// Creates a tweet with a video attachment
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// VideosArray - Array of String, BinaryData - Video files array - videos
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateVideoTweet(Val Text, Val VideosArray, Val Parameters = "") Export
|
||||
|
||||
MediaArray = UploadAttachmentsArray(VideosArray, "tweet_video", Parameters);
|
||||
Return CreateCustomTweet(Text, MediaArray, , , Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create poll tweet
|
||||
// Creates a tweet with a poll
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// OptionArray - Array of String - Poll options array - options
|
||||
// Duration - String, Number - Poll duration - duration
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreatePollTweet(Val Text, Val OptionArray, Val Duration, Val Parameters = "") Export
|
||||
Return CreateCustomTweet(Text, , OptionArray, Duration, Parameters);
|
||||
EndFunction
|
||||
|
||||
// Upload attachments array !NOCLI
|
||||
// Uploads files to the server and returns their IDs
|
||||
//
|
||||
// Parameters:
|
||||
// ArrayOfFiles - Array of String, BinaryData - Files array
|
||||
// AttachmentsType - String - Attachments type
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Returns:
|
||||
// Array Of String - Media ID array
|
||||
Function UploadAttachmentsArray(Val ArrayOfFiles, Val AttachmentsType, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(AttachmentsType);
|
||||
OPI_TypeConversion.GetCollection(ArrayOfFiles);
|
||||
|
||||
MediaArray = New Array;
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
MIS = "media_id_string";
|
||||
|
||||
If ValueIsFilled(ArrayOfFiles) Then
|
||||
|
||||
For Each SendingFile In ArrayOfFiles Do
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(SendingFile);
|
||||
|
||||
Response = UploadMediaFile(SendingFile, AttachmentsType, Parameters_);
|
||||
MediaID = Response[MIS];
|
||||
|
||||
If Not ValueIsFilled(MediaID) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
MediaArray.Add(MediaID);
|
||||
|
||||
EndDo;
|
||||
|
||||
EndIf;
|
||||
|
||||
Return MediaArray;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function UploadMediaFile(Val File, Val Type, Val Parameters)
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(File);
|
||||
|
||||
RequestType = "POST";
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
URL = "https://upload.twitter.com/1.1/media/upload.json";
|
||||
|
||||
If Type = "tweet_image" Then
|
||||
|
||||
Fields = New Structure;
|
||||
Fields.Insert("media_data" , Base64String(File));
|
||||
Fields.Insert("media_category", Type);
|
||||
|
||||
Authorization = CreateAuthorizationHeaderV1(Parameters_, Fields, RequestType, URL);
|
||||
Response = OPI_Tools.Post(URL, Fields, Authorization, False);
|
||||
|
||||
Else
|
||||
|
||||
Response = UploadMediaInParts(File, Type, RequestType, URL, Parameters_);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UploadMediaInParts(Val File, Val Type, Val RequestType, Val URL, Parameters)
|
||||
|
||||
Unit = 1024;
|
||||
Quantity = 4;
|
||||
MediaKey = "media_key";
|
||||
MIS = "media_id_string";
|
||||
Command = "command";
|
||||
Size = File.Size();
|
||||
|
||||
MIMETypeMapping = New Map;
|
||||
MIMETypeMapping.Insert("tweet_image", "image/jpeg");
|
||||
MIMETypeMapping.Insert("tweet_video", "video/mp4");
|
||||
MIMETypeMapping.Insert("tweet_gif" , "image/gif");
|
||||
|
||||
ChunkSize = Quantity * Unit * Unit;
|
||||
ArrayReading = SplitBinaryData(File, ChunkSize);
|
||||
|
||||
Fields = New Structure;
|
||||
Fields.Insert(Command , "INIT");
|
||||
Fields.Insert("total_bytes" , OPI_Tools.NumberToString(Size));
|
||||
Fields.Insert("media_type" , MIMETypeMapping.Get(Type));
|
||||
Fields.Insert("media_category" , Type);
|
||||
|
||||
Authorization = CreateAuthorizationHeaderV1(Parameters, Fields, RequestType, URL);
|
||||
|
||||
InitializationResponse = OPI_Tools.Post(URL, Fields, Authorization, False);
|
||||
InitializationKey = InitializationResponse[MediaKey];
|
||||
InitializationID = InitializationResponse[MIS];
|
||||
|
||||
If Not ValueIsFilled(InitializationKey) Or Not ValueIsFilled(InitializationID) Then
|
||||
Return InitializationResponse;
|
||||
EndIf;
|
||||
|
||||
Counter = 0;
|
||||
|
||||
For Each Part In ArrayReading Do
|
||||
|
||||
Fields = New Structure;
|
||||
Fields.Insert(Command , "APPEND");
|
||||
Fields.Insert("media_key" , InitializationKey);
|
||||
Fields.Insert("segment_index" , OPI_Tools.NumberToString(Counter));
|
||||
Fields.Insert("media" , Part);
|
||||
|
||||
Authorization = CreateAuthorizationHeaderV1(Parameters, New Structure, RequestType, URL);
|
||||
|
||||
OPI_Tools.PostMultipart(URL, Fields, , , Authorization);
|
||||
|
||||
Counter = Counter + 1;
|
||||
|
||||
EndDo;
|
||||
|
||||
Fields = New Structure;
|
||||
Fields.Insert(Command , "FINALIZE");
|
||||
Fields.Insert("media_id", InitializationID);
|
||||
|
||||
ProcessingStatus = GetProcessingStatus(Parameters, Fields, URL);
|
||||
|
||||
If Not TypeOf(ProcessingStatus) = Type("String") Then
|
||||
Return ProcessingStatus;
|
||||
EndIf;
|
||||
|
||||
Response = WaitForProcessingCompletion(ProcessingStatus, InitializationID, URL, Parameters);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function WaitForProcessingCompletion(Val ProcessingStatus, Val InitializationID, Val URL, Val Parameters)
|
||||
|
||||
ProcessingInfo = "processing_info";
|
||||
Command = "command";
|
||||
Fields = New Structure;
|
||||
|
||||
Fields.Insert(Command , "STATUS");
|
||||
Fields.Insert("media_id", InitializationID);
|
||||
|
||||
WHile String(ProcessingStatus) = "pending" Or String(ProcessingStatus) = "in_progress" Do
|
||||
|
||||
Authorization = CreateAuthorizationHeaderV1(Parameters, Fields, "GET", URL);
|
||||
Response = OPI_Tools.Get(URL, Fields, Authorization);
|
||||
Information = Response[ProcessingInfo];
|
||||
|
||||
If Not ValueIsFilled(Information) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
ProcessingStatus = Information["state"];
|
||||
|
||||
If Not ValueIsFilled(ProcessingStatus) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If ProcessingStatus = "failed" Then
|
||||
Raise "Twitter could not process the video you uploaded";
|
||||
EndIf;
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetStandardParameters(Val Parameters = "")
|
||||
|
||||
// Here is the definition of the data needed for work.
|
||||
// For Twitter, this is quite a significant set, which is due to the presence of 2 APIs at once,
|
||||
// which, at the same time, are not created for different tasks, but are simply versions of each other.
|
||||
// The current version of the API is v2 and it requires obtaining temporary tokens. Despite the fact,
|
||||
// that Twitter insists on using this latest version, they somehow managed not to transfer
|
||||
// file upload mechanism and some others from the old version - v1.1. Therefore, something needs to be done
|
||||
// on version 1.1, and something on 2: up to the point that they removed the ability to post tweets from v1.1,
|
||||
// but only through it you can add a picture to the tweet. At the same time, their authentication methods and tokens are different
|
||||
|
||||
// The world gigacorporation of Elon Musk, by the way, a reminder ;)
|
||||
|
||||
// P.S The "Twitter Developer settings page" is often mentioned further" - this
|
||||
// https://developer.twitter.com/en/portal/dashboard и inыбор toонtoретного проеtoта from withпиwithtoа (зtoчеto c toлючем)
|
||||
|
||||
Parameters_ = New Map;
|
||||
Permissions = "tweet.read tweet.write tweet.moderate.write users.read "
|
||||
+ "follows.read follows.write offline.access space.read mute.read "
|
||||
+ "mute.write like.read like.write list.read list.write block.read "
|
||||
+ "block.write bookmark.read bookmark.write";
|
||||
|
||||
// Data for API v2
|
||||
|
||||
// redirect_uri - URL of your http service (or other request handler) for authorization
|
||||
// scope - a set of permissions for the received key. Can be any, but offline.access is mandatory
|
||||
// client_id - From OAuth 2.0 Client ID and Client Secret settings page of Twitter Developer
|
||||
// client_secret - From OAuth 2.0 Client ID and Client Secret settings page of Twitter Developer
|
||||
// access_token - GetAuthorizationLink() -> Browser -> code will come to redirect_uri -> GetToken(code)
|
||||
// refresh_token - Comes together with access_token and is used to refresh it (access_token lifetime - 2 hr)
|
||||
// The update is done using the UpdateToken method with new access_token and refresh_token.
|
||||
// For the next update, you need to use a new refresh_token, so hardcode
|
||||
// won't work (access_token won't work either)
|
||||
|
||||
// |--> RefreshToken() ->|access_token --> Andwithпользуетwithя in т-нии 2-х чаwithоin for запроwithоin
|
||||
// | |refresh_token --|
|
||||
// |--------[after 2 hrs.]-------------------|
|
||||
|
||||
// Data for API v1.1
|
||||
|
||||
// oauth_token - From Authentication Tokens -> Access Token and Secret settings page of Twitter Developer
|
||||
// oauth_token_secret - From Authentication Tokens -> Access Token and Secret settings page of Twitter Developer
|
||||
// oauth_consumer_key - From Consumer Keys -> Access Token and Secret settings page of Twitter Developer
|
||||
// oauth_consumer_secret - From Consumer Keys -> Access Token and Secret settings page of Twitter Developer
|
||||
|
||||
// These tokens do not need to be updated
|
||||
|
||||
Parameters_.Insert("redirect_uri" , "");
|
||||
Parameters_.Insert("scope" , Permissions);
|
||||
Parameters_.Insert("client_id" , "");
|
||||
Parameters_.Insert("client_secret" , "");
|
||||
Parameters_.Insert("access_token" , ""); // Should be something like Constants.TwitterToken.Get()
|
||||
Parameters_.Insert("refresh_token" , ""); // Should be something like Constants.TwitterRefresh.Get()
|
||||
Parameters_.Insert("oauth_token" , "");
|
||||
Parameters_.Insert("oauth_token_secret" , "");
|
||||
Parameters_.Insert("oauth_consumer_key" , "");
|
||||
Parameters_.Insert("oauth_consumer_secret", "");
|
||||
|
||||
OPI_TypeConversion.GetCollection(Parameters);
|
||||
|
||||
If TypeOf(Parameters) = Type("Structure") Or TypeOf(Parameters) = Type("Map") Then
|
||||
For Each PassedParameter In Parameters Do
|
||||
Parameters_.Insert(PassedParameter.TheKey, OPI_Tools.NumberToString(PassedParameter.Value));
|
||||
EndDo;
|
||||
EndIf;
|
||||
|
||||
Return Parameters_;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function CreateAuthorizationHeaderV1(Val Parameters, Val Fields, Val RequestType, Val URL)
|
||||
|
||||
CurrentDate = OPI_Tools.GetCurrentDate();
|
||||
AuthorizationHeader = "";
|
||||
HashingMethod = "HMAC-SHA1";
|
||||
APIVersion = "1.0";
|
||||
SignatureString = "";
|
||||
Signature = "";
|
||||
OCK = "oauth_consumer_key";
|
||||
OTK = "oauth_token";
|
||||
CurrentUNIXDate = OPI_Tools.UNIXTime(CurrentDate);
|
||||
CurrentUNIXDate = OPI_Tools.NumberToString(CurrentUNIXDate);
|
||||
ParametersTable = New ValueTable;
|
||||
ParametersTable.Columns.Add("TheKey");
|
||||
ParametersTable.Columns.Add("Value");
|
||||
|
||||
For Each Field In Fields Do
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = Field.TheKey;
|
||||
NewLine.Value = Field.Value;
|
||||
|
||||
EndDo;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = OCK;
|
||||
NewLine.Value = Parameters[OCK];
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = OTK;
|
||||
NewLine.Value = Parameters[OTK];
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = "oauth_version";
|
||||
NewLine.Value = APIVersion;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = "oauth_signature_method";
|
||||
NewLine.Value = HashingMethod;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = "oauth_timestamp";
|
||||
NewLine.Value = CurrentUNIXDate;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.TheKey = "oauth_nonce";
|
||||
NewLine.Value = CurrentUNIXDate;
|
||||
|
||||
For Each TableRow In ParametersTable Do
|
||||
|
||||
TableRow.TheKey = EncodeString(TableRow.TheKey, StringEncodingMethod.URLencoding);
|
||||
TableRow.Value = EncodeString(TableRow.Value, StringEncodingMethod.URLencoding);
|
||||
|
||||
EndDo;
|
||||
|
||||
ParametersTable.Sort("TheKey");
|
||||
|
||||
For Each TableRow In ParametersTable Do
|
||||
|
||||
SignatureString = SignatureString
|
||||
+ TableRow.TheKey
|
||||
+ "="
|
||||
+ TableRow.Value
|
||||
+ "&";
|
||||
|
||||
EndDo;
|
||||
|
||||
SignatureString = Left(SignatureString, StrLen(SignatureString) - 1);
|
||||
SignatureString = Upper(RequestType)
|
||||
+ "&"
|
||||
+ EncodeString(URL, StringEncodingMethod.URLencoding)
|
||||
+ "&"
|
||||
+ EncodeString(SignatureString, StringEncodingMethod.URLencoding);
|
||||
|
||||
Signature = EncodeString(Parameters["oauth_consumer_secret"], StringEncodingMethod.URLencoding)
|
||||
+ "&"
|
||||
+ EncodeString(Parameters["oauth_token_secret"], StringEncodingMethod.URLencoding);
|
||||
|
||||
Signature = OPI_Cryptography.HMAC(GetBinaryDataFromString(Signature)
|
||||
, GetBinaryDataFromString(SignatureString)
|
||||
, HashFunction.SHA1
|
||||
, 64);
|
||||
|
||||
Signature = EncodeString(Base64String(Signature), StringEncodingMethod.URLencoding);
|
||||
|
||||
Delimiter = """,";
|
||||
AuthorizationHeader = AuthorizationHeader
|
||||
+ "OAuth "
|
||||
+ "oauth_consumer_key=""" + Parameters[OCK] + Delimiter
|
||||
+ "oauth_token=""" + Parameters[OTK] + Delimiter
|
||||
+ "oauth_signature_method=""" + HashingMethod + Delimiter
|
||||
+ "oauth_timestamp=""" + CurrentUNIXDate + Delimiter
|
||||
+ "oauth_nonce=""" + CurrentUNIXDate + Delimiter
|
||||
+ "oauth_version=""" + APIVersion + Delimiter
|
||||
+ "oauth_signature=""" + Signature;
|
||||
|
||||
HeaderMapping = New Map;
|
||||
HeaderMapping.Insert("authorization", AuthorizationHeader);
|
||||
|
||||
Return HeaderMapping;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function CreateAuthorizationHeaderV2(Val Parameters)
|
||||
|
||||
ReturnMapping = New Map;
|
||||
ReturnMapping.Insert("Authorization", "Bearer " + Parameters["access_token"]);
|
||||
|
||||
Return ReturnMapping;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetProcessingStatus(Val Parameters, Val Fields, Val URL)
|
||||
|
||||
ProcessingInfo = "processing_info";
|
||||
Authorization = CreateAuthorizationHeaderV1(Parameters, Fields, "POST", URL);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Fields, Authorization, False);
|
||||
Information = Response[ProcessingInfo];
|
||||
|
||||
If Not ValueIsFilled(Information) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
ProcessingStatus = Information["state"];
|
||||
|
||||
If Not ValueIsFilled(ProcessingStatus) Then
|
||||
Return Response;
|
||||
Else
|
||||
Return ProcessingStatus;
|
||||
EndIf;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
2190
src/en/OInt/core/Modules/OPI_VK.os
Normal file
2190
src/en/OInt/core/Modules/OPI_VK.os
Normal file
File diff suppressed because it is too large
Load Diff
414
src/en/OInt/core/Modules/OPI_Viber.os
Normal file
414
src/en/OInt/core/Modules/OPI_Viber.os
Normal file
@@ -0,0 +1,414 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Viber.os
|
||||
// Library: Viber
|
||||
// CLI Command: viber
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region SettingsAndInformation
|
||||
|
||||
// Set Webhook
|
||||
// IMPORTANT: Setting up Webhook is mandatory according to Viber rules. You need to have a free URL for this.,
|
||||
// which will return 200 and a genuine SSL certificate. If there is a certificate and the database is published
|
||||
// on the server - you can use an HTTP service. Information about new messages will also be sent there
|
||||
// Viber periodically knocks on the Webhook address, so if it is inactive, everything will stop working
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Viber Token - token
|
||||
// URL - String - URL for setting up Webhook - url
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SetWebhook(Val Token, Val URL) Export
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("url" , URL , "String", Parameters);
|
||||
OPI_Tools.AddField("auth_token" , Token, "String", Parameters);
|
||||
|
||||
Return OPI_Tools.Post("https://chatapi.viber.com/pa/set_webhook", Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get channel information
|
||||
// Here you can get the channel's user IDs. Bot IDs need to be obtained from the Webhook arrivals
|
||||
// The user ID from channel information is not suitable for sending messages through the bot - they are different
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function GetChannelInformation(Val Token) Export
|
||||
|
||||
URL = "https://chatapi.viber.com/pa/get_account_info";
|
||||
Return OPI_Tools.Get(URL, , TokenInHeaders(Token));
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get user data
|
||||
// Gets user information by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// UserID - String, Number - Viber User ID - user
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function GetUserData(Val Token, Val UserID) Export
|
||||
|
||||
URL = "https://chatapi.viber.com/pa/get_user_details";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("id", UserID, "String", Parameters);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, TokenInHeaders(Token));
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get online users
|
||||
// Gets the status of a user or several users by ID
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Viber Token - token
|
||||
// UserIDs - String,Number,Array of String,Number - Viber User(s) ID - users
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function GetOnlineUsers(Val Token, Val UserIDs) Export
|
||||
|
||||
URL = "https://chatapi.viber.com/pa/get_online";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("ids", UserIDs, "Collection", Parameters);
|
||||
|
||||
Response = OPI_Tools.Post(URL, Parameters, TokenInHeaders(Token));
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region MessageSending
|
||||
|
||||
// Send text message
|
||||
// Sends a text message to a chat or channel
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Text - String - Message text - text
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
// Keyboard - Structure Of String - See CreateKeyboardFromArrayButton - keyboard
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendTextMessage(Val Token
|
||||
, Val Text
|
||||
, Val UserID
|
||||
, Val SendingToChannel
|
||||
, Val Keyboard = "") Export
|
||||
|
||||
Return SendMessage(Token, "text", UserID, SendingToChannel, , Text, Keyboard);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Send image
|
||||
// Sends an image to a chat or channel
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - Image URL - picture
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - boolean - Sending to channel or bot chat - ischannel
|
||||
// Description - String - Image annotation - description
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendImage(Val Token, Val URL, Val UserID, Val SendingToChannel, Val Description = "") Export
|
||||
|
||||
Return SendMessage(Token, "picture", UserID, SendingToChannel, URL, Description);
|
||||
|
||||
EndFunction
|
||||
|
||||
// SendFile
|
||||
// Sends a file (document) to a chat or channel
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - File URL - file
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
// Extension - String - File extension - ext
|
||||
// Size - Number - File size. If not filled in > determined automatically by downloading the file - size
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendFile(Val Token
|
||||
, Val URL
|
||||
, Val UserID
|
||||
, Val SendingToChannel
|
||||
, Val Extension
|
||||
, Val Size = "") Export
|
||||
|
||||
If Not ValueIsFilled(Size) Then
|
||||
|
||||
Response = OPI_Tools.Get(URL);
|
||||
Size = Response.Size();
|
||||
|
||||
EndIf;
|
||||
|
||||
String_ = "String";
|
||||
Extension = StrReplace(Extension, ".", "");
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("URL" , URL , String_, Parameters);
|
||||
OPI_Tools.AddField("Size" , Size , String_, Parameters);
|
||||
OPI_Tools.AddField("Extension", Extension, String_, Parameters);
|
||||
|
||||
Return SendMessage(Token, "file", UserID, SendingToChannel, Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Send contact
|
||||
// Sends a contact with a phone number to a chat or channel
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// ContactName - String - Contact name - name
|
||||
// PhoneNumber - String - Phone number - phone
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendContact(Val Token
|
||||
, Val ContactName
|
||||
, Val PhoneNumber
|
||||
, Val UserID
|
||||
, Val SendingToChannel) Export
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("name" , ContactName , "String", Parameters);
|
||||
OPI_Tools.AddField("phone_number", PhoneNumber, "String", Parameters);
|
||||
|
||||
Return SendMessage(Token, "contact", UserID, SendingToChannel, Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// SendLocation
|
||||
// Sends geographic coordinates to a chat or channel
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Latitude - String, Number - Geographic latitude - lat
|
||||
// Longitude - String, Number - Geographic longitude - long
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendLocation(Val Token, Val Latitude, Val Longitude, Val UserID, Val SendingToChannel) Export
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("lat", Latitude , "String", Parameters);
|
||||
OPI_Tools.AddField("lon", Longitude, "String", Parameters);
|
||||
|
||||
Return SendMessage(Token, "location", UserID, SendingToChannel, Parameters);
|
||||
|
||||
EndFunction
|
||||
|
||||
// SendLink
|
||||
// Sends a URL with a preview to a chat or channel
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - SentLink - url
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendLink(Val Token, Val URL, Val UserID, Val SendingToChannel) Export
|
||||
|
||||
Return SendMessage(Token, "url", UserID, SendingToChannel, URL);
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create a keyboard from an array of buttons
|
||||
// Returns a keyboard structure for messages
|
||||
//
|
||||
// Parameters:
|
||||
// ButtonArray - Array of String - Array of buttons - buttons
|
||||
// ButtonColor - String - HEX color of buttons with # at the beginning - color
|
||||
//
|
||||
// Returns:
|
||||
// Structure - Create a keyboard from an array of buttons:
|
||||
// * Buttons - Array of Structure - Array of formed buttons
|
||||
// * Type - String - KeyboardType
|
||||
Function CreateKeyboardFromArrayButton(Val ButtonArray, Val ButtonColor = "#2db9b9") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ButtonColor);
|
||||
OPI_TypeConversion.GetCollection(ButtonArray);
|
||||
|
||||
ArrayOfButtonStructures = New Array;
|
||||
KeyboardStructure = New Structure;
|
||||
|
||||
For Each ButtonText In ButtonArray Do
|
||||
|
||||
ButtonStructure = New Structure;
|
||||
ButtonStructure.Insert("ActionType", "reply");
|
||||
ButtonStructure.Insert("ActionBody", ButtonText);
|
||||
ButtonStructure.Insert("Text" , ButtonText);
|
||||
ButtonStructure.Insert("BgColor" , ButtonColor);
|
||||
ButtonStructure.Insert("Coloumns" , 3);
|
||||
|
||||
ArrayOfButtonStructures.Add(ButtonStructure);
|
||||
|
||||
EndDo;
|
||||
|
||||
KeyboardStructure.Insert("Buttons", ArrayOfButtonStructures);
|
||||
KeyboardStructure.Insert("Type" , "keyboard");
|
||||
|
||||
Return KeyboardStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
// Send message.
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token
|
||||
// Type - String - TypeOfSentMessage
|
||||
// UserID - String, Number - Viber User ID
|
||||
// IsChannel - Boolean - Sending to channel or bot chat
|
||||
// Value - String, Structure - Value:
|
||||
// * URL - String - При отпраintoе URL
|
||||
// * Size - Number, String - File size in case of sending
|
||||
// * Extension - String - File extension in case of sending
|
||||
// Text - String - Message text
|
||||
// Keyboard - Structure Of String - Keyboard, if needed, see CreateKeyboardFromArrayButton
|
||||
//
|
||||
// Returns:
|
||||
// Arbitrary, HTTPResponse - Send message
|
||||
Function SendMessage(Val Token
|
||||
, Val Type
|
||||
, Val UserID
|
||||
, Val IsChannel
|
||||
, Val Value = ""
|
||||
, Val Text = ""
|
||||
, Val Keyboard = "")
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Type);
|
||||
OPI_TypeConversion.GetLine(UserID);
|
||||
OPI_TypeConversion.GetLine(Text);
|
||||
OPI_TypeConversion.GetBoolean(IsChannel);
|
||||
OPI_TypeConversion.GetCollection(Keyboard);
|
||||
|
||||
ParametersStructure = ReturnStandardParameters();
|
||||
ParametersStructure.Insert("type", Type);
|
||||
|
||||
If (Type = "text" Or Type = "picture") And ValueIsFilled(Text) Then
|
||||
ParametersStructure.Insert("text", Text);
|
||||
EndIf;
|
||||
|
||||
If TypeOf(Keyboard) = Type("Structure") Then
|
||||
ParametersStructure.Insert("keyboard", Keyboard);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Value) Then
|
||||
|
||||
If Type = "file" Then
|
||||
ParametersStructure.Insert("media" , Value["URL"]);
|
||||
ParametersStructure.Insert("size" , Value["Size"]);
|
||||
ParametersStructure.Insert("file_name", "File." + Value["Extension"]);
|
||||
ElsIf Type = "contact" Then
|
||||
ParametersStructure.Insert("contact" , Value);
|
||||
ElsIf Type = "location" Then
|
||||
ParametersStructure.Insert("location" , Value);
|
||||
Else
|
||||
ParametersStructure.Insert("media" , Value);
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
If IsChannel Then
|
||||
ParametersStructure.Insert("from", UserID);
|
||||
URL = "https://chatapi.viber.com/pa/post";
|
||||
Else
|
||||
ParametersStructure.Insert("receiver", UserID);
|
||||
URL = "https://chatapi.viber.com/pa/send_message";
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Post(URL, ParametersStructure, TokenInHeaders(Token));
|
||||
|
||||
Try
|
||||
Return OPI_Tools.JsonToStructure(Response.GetBodyAsBinaryData());
|
||||
Except
|
||||
Return Response;
|
||||
EndTry;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ReturnStandardParameters()
|
||||
|
||||
SenderStructure = New Structure;
|
||||
SenderStructure.Insert("name" , "Bot");
|
||||
SenderStructure.Insert("avatar", "");
|
||||
|
||||
ParametersStructure = New Structure;
|
||||
ParametersStructure.Insert("sender", SenderStructure);
|
||||
ParametersStructure.Insert("min_api_version", 1);
|
||||
|
||||
Return ParametersStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function TokenInHeaders(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
HeadersStructure = New Map;
|
||||
HeadersStructure.Insert("X-Viber-Auth-Token", Token);
|
||||
Return HeadersStructure;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
635
src/en/OInt/core/Modules/OPI_YandexDisk.os
Normal file
635
src/en/OInt/core/Modules/OPI_YandexDisk.os
Normal file
@@ -0,0 +1,635 @@
|
||||
// OS Location: ./OInt/core/Modules/OPI_YandexDisk.os
|
||||
// Library: Yandex Disk
|
||||
// CLI command: yadisk
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
#Region FileAndFolderManagement
|
||||
|
||||
// Get disk information
|
||||
// Gets information about the current disk
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetDiskInformation(Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk", , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create folder
|
||||
// Creates a directory on the disk
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the created folder - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function CreateFolder(Val Token, Val Path) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
URL = "https://cloud-api.yandex.net/v1/disk/resources";
|
||||
Href = "href";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("path", Path);
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Response = OPI_Tools.Put(URL + Parameters, , Headers, False);
|
||||
|
||||
ResponseURL = Response[Href];
|
||||
|
||||
If Not ValueIsFilled(ResponseURL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(ResponseURL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get object
|
||||
// Gets information about a disk object at the specified path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to folder or file - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetObject(Val Token, Val Path) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("path", Path);
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/resources", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Delete object
|
||||
// Deletes an object at the specified path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the folder or file to be deleted - path
|
||||
// ToCart - Boolean - To cart - can
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function DeleteObject(Val Token, Val Path, Val ToCart = True) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
OPI_TypeConversion.GetBoolean(ToCart);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("path" , Path);
|
||||
Parameters.Insert("permanently", Not ToCart);
|
||||
|
||||
Response = OPI_Tools.Delete("https://cloud-api.yandex.net/v1/disk/resources", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Create object copy
|
||||
// Creates a copy of the object at the specified path and path to the original
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Original - String - Path to the original file or directory - from
|
||||
// Path - String - Destination path for the copy - to
|
||||
// Overwrite - Boolean - Overwrite if a file with the same name already exists - rewrite
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function CreateObjectCopy(Val Token, Val Original, Val Path, Val Overwrite = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Original);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
OPI_TypeConversion.GetBoolean(Overwrite);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
URL = "https://cloud-api.yandex.net/v1/disk/resources/copy";
|
||||
Href = "href";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("from" , Original);
|
||||
Parameters.Insert("path" , Path);
|
||||
Parameters.Insert("overwrite" , Overwrite);
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Response = OPI_Tools.Post(URL + Parameters, , Headers, False);
|
||||
|
||||
ResponseURL = Response[Href];
|
||||
|
||||
If Not ValueIsFilled(ResponseURL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(ResponseURL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get download link
|
||||
// Gets a download link for the file
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the file for downloading - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetDownloadLink(Val Token, Val Path) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("path", Path);
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/resources/download", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Download file
|
||||
// Downloads a file at the specified path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the file for downloading - path
|
||||
// SavePath - String - File save path - out
|
||||
//
|
||||
// Returns:
|
||||
// BinaryData,String - Binary data or file path when SavePath parameter is specified
|
||||
Function DownloadFile(Val Token, Val Path, Val SavePath = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(SavePath);
|
||||
Response = GetDownloadLink(Token, Path);
|
||||
URL = Response["href"];
|
||||
|
||||
If Not ValueIsFilled(URL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(URL, , , SavePath);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get list of files
|
||||
// Gets a list of files with or without filtering by type
|
||||
// List of available types: audio, backup, book, compressed, data, development,
|
||||
// diskimage, document, encoded, executable, flash, font,
|
||||
// mage, settings, spreadsheet, text, unknown, video, web
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Quantity - Number, String - Number of returned objects - amount
|
||||
// OffsetFromStart - Number - Offset for getting objects not from the beginning of the list - offset
|
||||
// FilterByType - String - Filter by file type - type
|
||||
// SortByDate - Boolean - True > sort by date, False > alphabetically - datesort
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetFilesList(Val Token
|
||||
, Val Quantity = 0
|
||||
, Val OffsetFromStart = 0
|
||||
, Val FilterByType = ""
|
||||
, Val SortByDate = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Quantity);
|
||||
OPI_TypeConversion.GetLine(OffsetFromStart);
|
||||
OPI_TypeConversion.GetLine(FilterByType);
|
||||
OPI_TypeConversion.GetBoolean(SortByDate);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Quantity) Then
|
||||
Parameters.Insert("limit", OPI_Tools.NumberToString(Quantity));
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(OffsetFromStart) Then
|
||||
Parameters.Insert("offset", OPI_Tools.NumberToString(OffsetFromStart));
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(FilterByType) Then
|
||||
Parameters.Insert("media_type", FilterByType);
|
||||
EndIf;
|
||||
|
||||
If SortByDate Then
|
||||
Destination = "last-uploaded";
|
||||
Else
|
||||
Destination = "files";
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/resources/" + Destination, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Move object
|
||||
// Moves the object to the specified path and path to the original
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Original - String - Path to the original file or folder - from
|
||||
// Path - String - Destination path for moving - to
|
||||
// Overwrite - Boolean - Overwrite if a file with the same name already exists - rewrite
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function MoveObject(Val Token, Val Original, Val Path, Val Overwrite = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Original);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
OPI_TypeConversion.GetBoolean(Overwrite);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
URL = "https://cloud-api.yandex.net/v1/disk/resources/move";
|
||||
Href = "href";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("from" , Original);
|
||||
Parameters.Insert("path" , Path);
|
||||
Parameters.Insert("overwrite" , Overwrite);
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Response = OPI_Tools.Post(URL + Parameters, , Headers, False);
|
||||
ResponseURL = Response[Href];
|
||||
|
||||
If Not ValueIsFilled(ResponseURL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(ResponseURL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Upload file
|
||||
// Uploads a file to disk at the specified path
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path for saving the file to disk - path
|
||||
// File - String, BinaryData - File for upload - file
|
||||
// Overwrite - Boolean - Overwrite if a file with the same name already exists - rewrite
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function UploadFile(Val Token, Val Path, Val File, Val Overwrite = False) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
OPI_TypeConversion.GetBoolean(Overwrite);
|
||||
OPI_TypeConversion.GetBinaryData(File);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
Href = "href";
|
||||
File = New Structure("file", File);
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("path" , Path);
|
||||
Parameters.Insert("overwrite" , Overwrite);
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/resources/upload", Parameters, Headers);
|
||||
URL = Response[Href];
|
||||
|
||||
If Not ValueIsFilled(URL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.PutMultipart(URL, New Structure(), File, "multipart", Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Upload file by URL
|
||||
// Downloads a file to disk from the specified URL
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to place the downloaded file - path
|
||||
// Address - String - File URL - url
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function UploadFileByURL(Val Token, Val Path, Val Address) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
OPI_TypeConversion.GetLine(Address);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
URL = "https://cloud-api.yandex.net/v1/disk/resources/upload";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("url" , EncodeString(Address, StringEncodingMethod.URLInURLEncoding));
|
||||
Parameters.Insert("path", Path);
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Response = OPI_Tools.Post(URL + Parameters, , Headers, False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ManagePublicAccess
|
||||
|
||||
// Publish object
|
||||
// Publishes the disk object for public access
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object to be published - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function PublishObject(Val Token, Val Path) Export
|
||||
Return TogglePublicAccess(Token, Path, True);
|
||||
EndFunction
|
||||
|
||||
// Unpublish object
|
||||
// Unpublishes a previously published object
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the previously published object - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function CancelObjectPublication(Val Token, Val Path) Export
|
||||
Return TogglePublicAccess(Token, Path, False);
|
||||
EndFunction
|
||||
|
||||
// Get list of published objects.
|
||||
// Gets a list of published objects
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Quantity - Number - Number of returned objects - amount
|
||||
// OffsetFromStart - Number - Offset for getting objects not from the beginning of the list - offset
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetPublishedObjectsList(Val Token, Val Quantity = 0, Val OffsetFromStart = 0) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Quantity);
|
||||
OPI_TypeConversion.GetLine(OffsetFromStart);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Quantity) Then
|
||||
Parameters.Insert("limit", Quantity);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(OffsetFromStart) Then
|
||||
Parameters.Insert("offset", OffsetFromStart);
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/resources/public", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get public object
|
||||
// Gets information about the published object by its URL
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - Object address - url
|
||||
// Quantity - Number - Number of returned nested objects (for catalog) - amount
|
||||
// OffsetFromStart - Number - Offset for getting nested objects not from the beginning of the list - offset
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetPublicObject(Val Token, Val URL, Val Quantity = 0, Val OffsetFromStart = 0) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(URL);
|
||||
OPI_TypeConversion.GetLine(Quantity);
|
||||
OPI_TypeConversion.GetLine(OffsetFromStart);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Quantity) Then
|
||||
Parameters.Insert("limit", OPI_Tools.NumberToString(Quantity));
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(OffsetFromStart) Then
|
||||
Parameters.Insert("offset", OPI_Tools.NumberToString(OffsetFromStart));
|
||||
EndIf;
|
||||
|
||||
Parameters.Insert("public_key", URL);
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/public/resources", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get download link for public object
|
||||
// Gets a direct link to download the public object
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - Object address - url
|
||||
// Path - String - Path inside the object - path
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetDownloadLinkForPublicObject(Val Token, Val URL, Val Path = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(URL);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
|
||||
Parameters = New Structure;
|
||||
|
||||
If ValueIsFilled(Path) Then
|
||||
Parameters.Insert("path", Path);
|
||||
EndIf;
|
||||
|
||||
Parameters.Insert("public_key", URL);
|
||||
|
||||
Response = OPI_Tools.Get("https://cloud-api.yandex.net/v1/disk/public/resources/download", Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Save public object to disk
|
||||
// Saves the public object to your disk
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - Object address - url
|
||||
// From - String - Path within public catalog (folders only) - from
|
||||
// Target - String - File save path - to
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function SavePublicObjectToDisk(Val Token, Val URL, From = "", Target = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(URL);
|
||||
OPI_TypeConversion.GetLine(From);
|
||||
OPI_TypeConversion.GetLine(Target);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
Address = "https://cloud-api.yandex.net/v1/disk/public/resources/save-to-disk";
|
||||
Href = "href";
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("public_key", URL);
|
||||
|
||||
If ValueIsFilled(From) Then
|
||||
Parameters.Insert("path", From);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Target) Then
|
||||
Parameters.Insert("save_path", Target);
|
||||
EndIf;
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Response = OPI_Tools.Post(Address + Parameters, , Headers, False);
|
||||
|
||||
ResponseURL = Response[Href];
|
||||
|
||||
If Not ValueIsFilled(ResponseURL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(ResponseURL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function AuthorizationHeader(Val Token)
|
||||
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "OAuth " + Token);
|
||||
|
||||
Return Headers;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function TogglePublicAccess(Val Token, Val Path, Val PublicAccess)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(Path);
|
||||
OPI_TypeConversion.GetBoolean(PublicAccess);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
Destination = ?(PublicAccess, "publish", "unpublish");
|
||||
Href = "href";
|
||||
|
||||
URL = "https://cloud-api.yandex.net/v1/disk/resources/" + Destination;
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("path", Path);
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Response = OPI_Tools.Put(URL + Parameters, , Headers, False);
|
||||
|
||||
ResponseURL = Response[Href];
|
||||
|
||||
If Not ValueIsFilled(ResponseURL) Then
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.Get(ResponseURL, , Headers);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
112
src/en/OInt/core/Modules/OPI_YandexID.os
Normal file
112
src/en/OInt/core/Modules/OPI_YandexID.os
Normal file
@@ -0,0 +1,112 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_YandexID.os
|
||||
// Library: Yandex ID
|
||||
// CLI Command: yandex
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
#Use "../../tools"
|
||||
|
||||
#Region Public
|
||||
|
||||
// Get confirmation code
|
||||
// Gets the confirmation code and the address of the page where it needs to be entered
|
||||
//
|
||||
// Parameters:
|
||||
// ClientId - String - Client id - id
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetConfirmationCode(Val ClientId) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ClientId);
|
||||
|
||||
Parameters = New Structure("client_id", ClientId);
|
||||
Response = OPI_Tools.Post("https://oauth.yandex.ru/device/code", Parameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Convert code to token
|
||||
// Converts the code to a token after entering the code when executing GetConfirmationCode
|
||||
//
|
||||
// Parameters:
|
||||
// ClientId - String - Client id - id
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// DeviceCode - String - device_code from GetConfirmationCode() - device
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function ConvertCodeToToken(Val ClientId, Val ClientSecret, Val DeviceCode) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ClientId);
|
||||
OPI_TypeConversion.GetLine(ClientSecret);
|
||||
OPI_TypeConversion.GetLine(DeviceCode);
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("grant_type" , "device_code");
|
||||
Parameters.Insert("code" , DeviceCode);
|
||||
Parameters.Insert("client_id" , ClientId);
|
||||
Parameters.Insert("client_secret" , ClientSecret);
|
||||
|
||||
Response = OPI_Tools.Post("https://oauth.yandex.ru/token", Parameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
// Refresh token
|
||||
// Updates token by Refresh token
|
||||
//
|
||||
// Parameters:
|
||||
// ClientId - String - Client id - id
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// RefreshToken - String - Refresh token - refresh
|
||||
//
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function RefreshToken(Val ClientId, Val ClientSecret, Val RefreshToken) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ClientId);
|
||||
OPI_TypeConversion.GetLine(ClientSecret);
|
||||
OPI_TypeConversion.GetLine(RefreshToken);
|
||||
|
||||
Parameters = New Structure;
|
||||
Parameters.Insert("grant_type" , "refresh_token");
|
||||
Parameters.Insert("refresh_token" , RefreshToken);
|
||||
Parameters.Insert("client_id" , ClientId);
|
||||
Parameters.Insert("client_secret" , ClientSecret);
|
||||
|
||||
Response = OPI_Tools.Post("https://oauth.yandex.ru/token", Parameters, , False);
|
||||
|
||||
Return Response;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
27
src/en/OInt/coverage/Modules/Coverage_ОпределениеПокрытия.os
Normal file
27
src/en/OInt/coverage/Modules/Coverage_ОпределениеПокрытия.os
Normal file
@@ -0,0 +1,27 @@
|
||||
#Use 1commands
|
||||
#Use coverage
|
||||
#Use fs
|
||||
#Use oint
|
||||
|
||||
FS.EnsureEmptyDirectory("./OInt/coverage/data");
|
||||
PathToStat = FS.FullPath("./OInt/coverage/data/stat.json");
|
||||
|
||||
Command = New Command;
|
||||
Command.SetCommand("oscript");
|
||||
Command.AddParameter(StrTemplate("-codestat=%1", PathToStat));
|
||||
Command.AddParameter(FS.FullPath("./OInt/tests/Modules/Coverage_RunAllTests.os")); // File start tests
|
||||
Command.ShowOutputImmediately(True);
|
||||
|
||||
ReturnCode = Command.Execute();
|
||||
File_Stat = New File(PathToStat);
|
||||
PackageName = "oint";
|
||||
|
||||
GenerationProcessor = New CoverageReportGenerator();
|
||||
|
||||
Message(File_Stat.FullName);
|
||||
ProcessorObject = GenerationProcessor.StatisticsFile(File_Stat.FullName);
|
||||
ProcessorObject = ProcessorObject.SourceDirectory(FS.FullPath("./OInt"));
|
||||
ProcessorObject = ProcessorObject.WorkingDirectory(FS.FullPath("./OInt/coverage/data"));
|
||||
ProcessorObject = ProcessorObject.GenericCoverage();
|
||||
|
||||
ProcessorObject.Formulate();
|
2
src/en/OInt/coverage/data/genericCoverage.xml
Normal file
2
src/en/OInt/coverage/data/genericCoverage.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<coverage version="1"/>
|
20
src/en/OInt/lib.config
Normal file
20
src/en/OInt/lib.config
Normal file
@@ -0,0 +1,20 @@
|
||||
<package-def>
|
||||
<module name="OPI_GoogleCalendar" file="core/Modules/OPI_GoogleCalendar.os"/>
|
||||
<module name="OPI_Tools" file="tools/Modules/internal/Modules/OPI_Tools.os"/>
|
||||
<module name="OPI_Notion" file="core/Modules/OPI_Notion.os"/>
|
||||
<module name="OPI_Telegram" file="core/Modules/OPI_Telegram.os"/>
|
||||
<module name="OPI_GoogleDrive" file="core/Modules/OPI_GoogleDrive.os"/>
|
||||
<module name="OPI_TestDataRetrieval" file="tools/Modules/OPI_TestDataRetrieval.os"/>
|
||||
<module name="OPI_Twitter" file="core/Modules/OPI_Twitter.os"/>
|
||||
<module name="OPI_Viber" file="core/Modules/OPI_Viber.os"/>
|
||||
<module name="OPI_TypeConversion" file="tools/Modules/OPI_TypeConversion.os"/>
|
||||
<module name="OPI_GoogleWorkspace" file="core/Modules/OPI_GoogleWorkspace.os"/>
|
||||
<module name="OPI_YandexDisk" file="core/Modules/OPI_YandexDisk.os"/>
|
||||
<module name="OPI_Dropbox" file="core/Modules/OPI_Dropbox.os"/>
|
||||
<module name="OPI_Airtable" file="core/Modules/OPI_Airtable.os"/>
|
||||
<module name="OPI_Slack" file="core/Modules/OPI_Slack.os"/>
|
||||
<module name="OPI_GoogleSheets" file="core/Modules/OPI_GoogleSheets.os"/>
|
||||
<module name="OPI_YandexID" file="core/Modules/OPI_YandexID.os"/>
|
||||
<module name="OPI_VK" file="core/Modules/OPI_VK.os"/>
|
||||
<module name="OPI_Cryptography" file="tools/Modules/internal/Modules/OPI_Cryptography.os"/>
|
||||
</package-def>
|
13
src/en/OInt/packagedef
Normal file
13
src/en/OInt/packagedef
Normal file
@@ -0,0 +1,13 @@
|
||||
Description.Name("oint")
|
||||
.Version("1.9.0")
|
||||
.Author("bayselonarrend")
|
||||
.AddressAuthorа("bayselonarrend@gmail.com")
|
||||
.Description("Open integrations package with popular API aboard")
|
||||
.VersionMidы("1.0.7")
|
||||
.IntoлючитьFile("core")
|
||||
.IntoлючитьFile("tools")
|
||||
.IntoлючитьFile("tests")
|
||||
.IntoлючитьFile("lib.config")
|
||||
.IntoлючитьFile("../README.MD")
|
||||
.IntoлючитьFile("../LICENSE")
|
||||
.ЗаinиwithитОт("asserts", "1.3.0")
|
8
src/en/OInt/tests/Modules/Coverage_ЗапускВсехТестов.os
Normal file
8
src/en/OInt/tests/Modules/Coverage_ЗапускВсехТестов.os
Normal file
@@ -0,0 +1,8 @@
|
||||
#Use "./internal"
|
||||
#Use "../../tools"
|
||||
|
||||
Tests = OPI_TestDataRetrieval.FormAssertsTests();
|
||||
|
||||
For Each Test In Tests Do
|
||||
Execute("OPI_Tests." + Test + "()");
|
||||
EndDo;
|
5307
src/en/OInt/tests/Modules/internal/OPI_Tests.os
Normal file
5307
src/en/OInt/tests/Modules/internal/OPI_Tests.os
Normal file
File diff suppressed because it is too large
Load Diff
@@ -36,10 +36,10 @@
|
||||
//@skip-check use-non-recommended-method
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "./internal"
|
||||
// #Use asserts
|
||||
#Use "./internal"
|
||||
#Use asserts
|
||||
|
||||
#Region ServiceProgramInterface
|
||||
#Region Internal
|
||||
|
||||
Function GetTestingSectionMapping() Export
|
||||
|
||||
@@ -68,7 +68,7 @@ EndFunction
|
||||
Function GetTestTable() Export
|
||||
|
||||
Telegram = "Telegram";
|
||||
VK = "VK";
|
||||
VKontakte = "VK";
|
||||
YDisk = "YandexDisk";
|
||||
Calendar = "GoogleCalendar";
|
||||
Twitter = "Twitter";
|
||||
@@ -86,49 +86,49 @@ Function GetTestTable() Export
|
||||
TestTable.Columns.Add("Synonym");
|
||||
TestTable.Columns.Add("Section");
|
||||
|
||||
NewTest(TestTable, "Telegram_GetBotInfo" , "Get bot information" , Telegram);
|
||||
NewTest(TestTable, "Telegram_GetUpdates" , "Get updates" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SetWebhook" , "Set Webhook" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendTextMessage" , "Send text message" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendImage" , "Send image" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendVideo" , "Send video" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendAudio" , "Send audio" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendDocument" , "Send document" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendGIF" , "Send GIF" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendMediaGroup" , "Send media group" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendLocation" , "Send location" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendContact" , "Send contact" , Telegram);
|
||||
NewTest(TestTable, "Telegram_SendPoll" , "Send poll" , Telegram);
|
||||
NewTest(TestTable, "Telegram_ForwardMessage" , "Forward message" , Telegram);
|
||||
NewTest(TestTable, "Telegram_BanUnban" , "Ban/Unban" , Telegram);
|
||||
NewTest(TestTable, "Telegram_CreateInvitationLink" , "Create invitation link" , Telegram);
|
||||
NewTest(TestTable, "Telegram_PinUnpinMessage" , "Pin/Unpin message" , Telegram);
|
||||
NewTest(TestTable, "Telegram_GetMemberCount" , "Get participant count" , Telegram);
|
||||
NewTest(TestTable, "Telegram_GetForumAvatarsList", "Get forum avatars list", Telegram);
|
||||
NewTest(TestTable, "Telegram_CreateDeleteForumTopic" , "Create/Delete forum topic" , Telegram);
|
||||
NewTest(TestTable, "Telegram_ChangeMainTopicName" , "Change main topic name" , Telegram);
|
||||
NewTest(TestTable, "Telegram_HideShowMainTopic" , "Hide/Show main topic" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetBotInfo" , "Get bot information" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetUpdates" , "Get updates" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SetWebhook" , "Set Webhook" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendTextMessage" , "Send text message" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendImage" , "Send image" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendVideo" , "Send video" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendAudio" , "Send audio" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendDocument" , "Send document" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendGIF" , "Send GIF" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendMediaGroup" , "Send mediagroup" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendLocation" , "Send location" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendContact" , "Send contact" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendPoll" , "Send poll" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_ForwardMessage" , "Forward message" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_BanUnban" , "Ban/Unban" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_CreateInvitationLink" , "Create invitation link" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_PinUnpinMessage" , "Pin/Unpin message" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetMemberCount" , "Get participant count" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetForumAvatarsList", "Get forum avatars list", Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_CreateDeleteForumTopic" , "Create/Delete forum topic" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_ChangeMainTopicName" , "Change main topic name" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_HideShowMainTopic" , "Hide/Show main topic" , Telegram);
|
||||
|
||||
NewTest(TestTable, "VK_CreateTokenLink" , "Create token retrieval link", VK);
|
||||
NewTest(TestTable, "VK_CreateDeletePost" , "Create/Delete post" , VK);
|
||||
NewTest(TestTable, "VK_CreateCompositePost" , "Create/Delete composite post" , VK);
|
||||
NewTest(TestTable, "VK_CreatePoll" , "Create poll" , VK);
|
||||
NewTest(TestTable, "VK_SaveDeleteImage" , "Add/Delete image" , VK);
|
||||
NewTest(TestTable, "VK_CreateStory" , "Create story" , VK);
|
||||
NewTest(TestTable, "VK_DiscussionMethods" , "Actions with discussions" , VK);
|
||||
NewTest(TestTable, "VK_LikeRepostComment" , "Like/Repost/Comment" , VK);
|
||||
NewTest(TestTable, "VK_GetStatistics" , "Get statistics" , VK);
|
||||
NewTest(TestTable, "VK_GetPostStatistics" , "Get post statistics" , VK);
|
||||
NewTest(TestTable, "VK_CreateAdCampaign" , "Create advertising campaign" , VK);
|
||||
NewTest(TestTable, "VK_SendMessage" , "Send message" , VK);
|
||||
NewTest(TestTable, "VK_GetProductCategories" , "Get product categories" , VK);
|
||||
NewTest(TestTable, "VK_CreateProductSelection" , "Create product and selection" , VK);
|
||||
NewTest(TestTable, "VK_CreateProductWithProperties" , "Create product with properties" , VK);
|
||||
NewTest(TestTable, "VK_GetProductList" , "Get product list" , VK);
|
||||
NewTest(TestTable, "VK_GetSelectionList" , "Get selection list" , VK);
|
||||
NewTest(TestTable, "VK_GetPropertyList" , "Get property list" , VK);
|
||||
NewTest(TestTable, "VK_GetOrderList" , "Get order list" , VK);
|
||||
NewTest(TestTable, "VK_UploadVideo" , "Upload video" , VK);
|
||||
NewTest(TestTable, "VKAPI_CreateTokenLink" , "Create token retrieval link", VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateDeletePost" , "Create/Delete post" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateCompositePost" , "Create/Delete composite post" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreatePoll" , "Create poll" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_SaveDeleteImage" , "Add/Delete image" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateStory" , "Create story" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_DiscussionMethods" , "Actions with discussions" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_LikeRepostComment" , "Like/Repost/Comment" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetStatistics" , "Get statistics" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetPostStatistics" , "Get post statistics" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateAdCampaign" , "Create advertising campaign" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_SendMessage" , "Send message" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetProductCategories" , "Get product categories" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateProductSelection" , "Create product and selection" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateProductWithProperties" , "Create product with properties" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetProductList" , "Get product list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetSelectionList" , "Get selection list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetPropertyList" , "Get property list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetOrderList" , "Get order list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_UploadVideo" , "Upload video" , VKontakte);
|
||||
|
||||
NewTest(TestTable, "YDisk_GetDiskInfo" , "Get disk information" , YDisk);
|
||||
NewTest(TestTable, "YDisk_CreateFolder" , "Create folder" , YDisk);
|
||||
@@ -206,13 +206,13 @@ Function GetTestTable() Export
|
||||
NewTest(TestTable, "AT_CreateField" , "Create/Edit field" , AirT);
|
||||
NewTest(TestTable, "AT_CreateDeleteRecords" , "Create/Delete records" , AirT);
|
||||
|
||||
NewTest(TestTable, "Dropbox_GetUpdateToken" , "Get/Update token" , Dropbox);
|
||||
NewTest(TestTable, "Dropbox_UploadFile" , "Upload file" , Dropbox);
|
||||
NewTest(TestTable, "Dropbox_UploadFileByURL" , "Upload file by URL" , Dropbox);
|
||||
NewTest(TestTable, "Dropbox_CreateFolder" , "Create folder" , Dropbox);
|
||||
NewTest(TestTable, "Dropbox_CreateDeleteTag" , "Create/Delete tag" , Dropbox);
|
||||
NewTest(TestTable, "Dropbox_GetAccount" , "Get account data" , Dropbox);
|
||||
NewTest(TestTable, "Dropbox_AccessManagement" , "Access management" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_GetUpdateToken" , "Get/Update token" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_UploadFile" , "Upload file" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_UploadFileByURL" , "Upload file by URL" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_CreateFolder" , "Create folder" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_CreateDeleteTag" , "Create/Delete tag" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_GetAccount" , "Get account data" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_AccessManagement" , "Access management" , Dropbox);
|
||||
|
||||
Return TestTable;
|
||||
|
||||
@@ -223,7 +223,7 @@ Function ExpectsThat(Value) Export
|
||||
Try
|
||||
|
||||
Module = GetCommonModule("UTest");
|
||||
Awaiting = TypeValue(Module) = Type("CommonModule");
|
||||
Awaiting = TypeOf(Module) = Type("CommonModule");
|
||||
Return Module.ExpectsThat(Value);
|
||||
|
||||
Except
|
||||
@@ -240,7 +240,7 @@ Function FormYAXTests() Export
|
||||
|
||||
For Each Section In Sections Do
|
||||
|
||||
CurrentSection = Section.Key;
|
||||
CurrentSection = Section.TheKey;
|
||||
Filter = New Structure("Section", CurrentSection);
|
||||
SectionTests = TestTable.FindLines(Filter);
|
||||
|
||||
@@ -291,7 +291,7 @@ Function GetBinary(Parameter) Export
|
||||
Value = MainValue;
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Value) = Type("String") Then
|
||||
If TypeOf(Value) = Type("String") Then
|
||||
Value = GetFilePath(Value, LocalParameter);
|
||||
EndIf;
|
||||
|
||||
@@ -358,12 +358,12 @@ Procedure WriteLog(Val Result, Val Method, Val Library = "") Export
|
||||
|
||||
Data = " " + Data;
|
||||
|
||||
Notify(Header);
|
||||
Notify(Symbols.PS);
|
||||
Notify(Data);
|
||||
Notify(Symbols.PS);
|
||||
Notify("---------------------------------");
|
||||
Notify(Symbols.PS);
|
||||
Message(Header);
|
||||
Message(Chars.PS);
|
||||
Message(Data);
|
||||
Message(Chars.PS);
|
||||
Message("---------------------------------");
|
||||
Message(Chars.PS);
|
||||
|
||||
If ValueIsFilled(Library) Then
|
||||
WriteLogFile(Data, Method, Library);
|
||||
@@ -373,7 +373,7 @@ EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function GetValueFromFile(Parameter, Path)
|
||||
|
||||
@@ -405,9 +405,9 @@ Function DataFilePath()
|
||||
EndFunction
|
||||
|
||||
Function GetCommonModule(Val Name)
|
||||
SetSafeMode(True);
|
||||
Module = Calculate(Name);
|
||||
SetSafeMode(False);
|
||||
|
||||
Module = Eval(Name);
|
||||
|
||||
Return Module;
|
||||
EndFunction
|
||||
|
||||
@@ -425,9 +425,9 @@ Procedure WriteParameterToFile(Val Parameter, Val Value, Val Path)
|
||||
Values = OPI_Tools.ReadJSONFile(Path);
|
||||
Values.Insert(Parameter, Value);
|
||||
|
||||
Record = New WritingJSON;
|
||||
JSONWriteParameters = New JSONWriteParameters(JSONLineBreak.Auto, Symbols.Tab);
|
||||
Record.OpenFile(Path, , , JSONWriteParameters);
|
||||
Record = New JSONWriter;
|
||||
JSONWriterSettings = New JSONWriterSettings(JSONLineBreak.Auto, Chars.Tab);
|
||||
Record.OpenFile(Path, , , JSONWriterSettings);
|
||||
WriteJSON(Record, Values);
|
||||
Record.Close();
|
||||
|
||||
@@ -462,7 +462,7 @@ Procedure WriteLogFile(Val Data, Val Method, Val Library)
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
Notify("Failed to write log file!: " + ErrorDescription());
|
||||
Message("Failed to write log file!: " + ErrorDescription());
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
320
src/en/OInt/tools/Modules/OPI_TypeConversion.os
Normal file
320
src/en/OInt/tools/Modules/OPI_TypeConversion.os
Normal file
@@ -0,0 +1,320 @@
|
||||
// Location OS: ./OInt/tools/Modules/OPI_TypeConversion.os
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UnusedLocalVariable-off
|
||||
|
||||
#Use "./internal"
|
||||
|
||||
#Region Internal
|
||||
|
||||
Procedure GetBinaryData(Value) Export
|
||||
|
||||
If Value = Undefined Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Try
|
||||
|
||||
If TypeOf(Value) = Type("BinaryData") Then
|
||||
Return;
|
||||
Else
|
||||
|
||||
File = New File(Value);
|
||||
|
||||
If File.Exists() Then
|
||||
Value = New BinaryData(Value);
|
||||
|
||||
ElsIf StrFind(Value, "//") Then
|
||||
|
||||
Value = OPI_Tools.Get(Value);
|
||||
|
||||
Else
|
||||
|
||||
Value = Base64Value(Value);
|
||||
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
Raise "Error getting binary data from parameter: " + ErrorDescription();
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetBinaryOrStream(Value) Export
|
||||
|
||||
If Value = Undefined Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
If TypeOf(Value) <> Type("String") Then
|
||||
GetBinaryData(Value);
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
File = New File(Value);
|
||||
|
||||
If File.Exists() Then
|
||||
Value = New FileStream(Value, FileOpenMode.Open);
|
||||
Else
|
||||
GetBinaryData(Value);
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetCollection(Value) Export
|
||||
|
||||
If Value = Undefined Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Try
|
||||
|
||||
InitialValue = Value;
|
||||
|
||||
If ThisIsCollection(Value) Then
|
||||
Return;
|
||||
Else
|
||||
|
||||
If TypeOf(Value) = Type("BinaryData") Then
|
||||
Value = GetStringFromBinaryData(Value);
|
||||
Else
|
||||
Value = OPI_Tools.NumberToString(Value);
|
||||
EndIf;
|
||||
|
||||
File = New File(Value);
|
||||
JSONReader = New JSONReader;
|
||||
|
||||
If File.Exists() Then
|
||||
|
||||
JSONReader.OpenFile(Value);
|
||||
|
||||
ElsIf StrStartsWith(Lower(Value), "http") Then
|
||||
|
||||
AndVF = GetTempFileName();
|
||||
CopyFile(Value, AndVF);
|
||||
JSONReader.OpenFile(AndVF);
|
||||
JSONReader.Read();
|
||||
|
||||
DeleteFiles(AndVF);
|
||||
|
||||
Else
|
||||
|
||||
JSONReader.SetString(TrimAll(Value));
|
||||
|
||||
EndIf;
|
||||
|
||||
Value = ReadJSON(JSONReader, True, Undefined, JSONDateFormat.ISO);
|
||||
JSONReader.Close();
|
||||
|
||||
If (Not ThisIsCollection(Value)) Or Not ValueIsFilled(Value) Then
|
||||
|
||||
Value = InitialValue;
|
||||
GetArray(Value);
|
||||
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
|
||||
Value = InitialValue;
|
||||
GetArray(Value);
|
||||
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetArray(Value) Export
|
||||
|
||||
If TypeOf(Value) = Type("Array") Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
If TypeOf(Value) = Type("String")
|
||||
And StrStartsWith(Value, "[")
|
||||
And StrEndsWith(Value, "]") Then
|
||||
|
||||
CommaInQuotes = "','";
|
||||
|
||||
Value = StrReplace(Value, "['" , "");
|
||||
Value = StrReplace(Value, "']" , "");
|
||||
Value = StrReplace(Value, "', '" , CommaInQuotes);
|
||||
Value = StrReplace(Value, "' , '", CommaInQuotes);
|
||||
Value = StrReplace(Value, "' ,'" , CommaInQuotes);
|
||||
|
||||
Value = StrSplit(Value, CommaInQuotes, False);
|
||||
|
||||
For N = 0 To Value.WithinBoundary() Do
|
||||
Value[N] = TrimAll(Value[N]);
|
||||
EndDo;
|
||||
|
||||
Else
|
||||
|
||||
If TypeOf(Value) = Type("Number") Then
|
||||
Value = OPI_Tools.NumberToString(Value);
|
||||
EndIf;
|
||||
|
||||
OPI_Tools.ValueToArray(Value);
|
||||
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetBoolean(Value) Export
|
||||
|
||||
If Value = Undefined Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Try
|
||||
|
||||
If TypeOf(Value) = Type("Boolean") Then
|
||||
Return;
|
||||
Else
|
||||
Value = Boolean(Value);
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
Raise "Error getting boolean data from parameter";
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetLine(Value, Val FromSource = False) Export
|
||||
|
||||
If Value = Undefined Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Try
|
||||
|
||||
If ThisIsSymbolic(Value) Then
|
||||
|
||||
If Not FromSource Then
|
||||
Value = OPI_Tools.NumberToString(Value);
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Value = OPI_Tools.NumberToString(Value);
|
||||
File = New File(Value);
|
||||
|
||||
If File.Exists() Then
|
||||
|
||||
TextReader = New TextReader(Value);
|
||||
Value = TextReader.Read();
|
||||
TextReader.Close();
|
||||
|
||||
ElsIf StrStartsWith(Lower(Value), "http") Then
|
||||
|
||||
AndVF = GetTempFileName();
|
||||
CopyFile(Value, AndVF);
|
||||
|
||||
TextReader = New TextReader(AndVF);
|
||||
Value = TextReader.Read();
|
||||
TextReader.Close();
|
||||
|
||||
DeleteFiles(AndVF);
|
||||
|
||||
Else
|
||||
|
||||
Return;
|
||||
|
||||
EndIf;
|
||||
|
||||
ElsIf TypeOf(Value) = Type("BinaryData") Then
|
||||
|
||||
Value = GetStringFromBinaryData(Value);
|
||||
|
||||
ElsIf ThisIsCollection(Value) Then
|
||||
|
||||
Value = OPI_Tools.JSONString(Value);
|
||||
|
||||
Else
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
Value = String(Value);
|
||||
Return;
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetDate(Value) Export
|
||||
|
||||
If Value = Undefined Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
Date = "Date";
|
||||
|
||||
Try
|
||||
|
||||
If TypeOf(Value) = Type(Date) Then
|
||||
Return;
|
||||
Else
|
||||
Value = XMLValue(Type(Date), Value);
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
OOD = New TypeDescription(Date);
|
||||
Value = OOD.ConvertValue(Value);
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetNumber(Value) Export
|
||||
|
||||
TypeDescription = New TypeDescription("Number");
|
||||
Value = TypeDescription.ConvertValue(Value);
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function ThisIsCollection(Val Value)
|
||||
|
||||
Return TypeOf(Value) = Type("Array")
|
||||
Or TypeOf(Value) = Type("Structure")
|
||||
Or TypeOf(Value) = Type("Map");
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ThisIsSymbolic(Val Value)
|
||||
|
||||
Return TypeOf(Value) = Type("String")
|
||||
Or TypeOf(Value) = Type("Number")
|
||||
Or TypeOf(Value) = Type("Date");
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
110
src/en/OInt/tools/Modules/internal/Modules/OPI_Cryptography.os
Normal file
110
src/en/OInt/tools/Modules/internal/Modules/OPI_Cryptography.os
Normal file
@@ -0,0 +1,110 @@
|
||||
// Location OS: ./OInt/tools/Modules/internal/Modules/OPI_Cryptography.os
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UnusedLocalVariable-off
|
||||
|
||||
#Region Internal
|
||||
|
||||
#Region BSP
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (c) 2019, LLC 1C-Soft
|
||||
// All rights reserved. This program and accompanying materials are provided
|
||||
// under the terms of the Attribution 4.0 International (CC BY 4.0 license)
|
||||
// License text available at:
|
||||
// https://creativecommons.org/licenses/by/4.0/legalcode
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Function HMACSHA256(Val TheKey, Val Data) Export
|
||||
|
||||
Return HMAC(TheKey, Data, HashFunction.SHA256, 64);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function Hash(BinaryData, Type) Export
|
||||
|
||||
Hashing = New DataHashing(Type);
|
||||
Hashing.Add(BinaryData);
|
||||
|
||||
Return Hashing.HashSum;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function HMAC(Val TheKey, Val Data, Type, BlockSize) Export
|
||||
|
||||
Twice = 2;
|
||||
|
||||
If TheKey.Size() > BlockSize Then
|
||||
TheKey = Hash(TheKey, Type);
|
||||
EndIf;
|
||||
|
||||
If TheKey.Size() <= BlockSize Then
|
||||
TheKey = GetHexStringFromBinaryData(TheKey);
|
||||
TheKey = Left(TheKey + RepeatString("00", BlockSize), BlockSize * Twice);
|
||||
EndIf;
|
||||
|
||||
TheKey = GetBinaryDataBufferFromBinaryData(GetBinaryDataFromHexString(TheKey));
|
||||
|
||||
Ipad = GetBinaryDataBufferFromHexString(RepeatString("36", BlockSize));
|
||||
Opad = GetBinaryDataBufferFromHexString(RepeatString("5c", BlockSize));
|
||||
|
||||
Ipad.WriteBitwiseExclusiveOr(0, TheKey);
|
||||
Ikeypad = GetBinaryDataFromBinaryDataBuffer(ipad);
|
||||
|
||||
Opad.WriteBitwiseExclusiveOr(0, TheKey);
|
||||
Okeypad = GetBinaryDataFromBinaryDataBuffer(opad);
|
||||
|
||||
Return Hash(ConcatenateBinaryData(okeypad, Hash(ConcatenateBinaryData(ikeypad, Data), Type)), Type);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ConcatenateBinaryData(BinaryData1, BinaryData2) Export
|
||||
|
||||
BinaryDataArray = New Array;
|
||||
BinaryDataArray.Add(BinaryData1);
|
||||
BinaryDataArray.Add(BinaryData2);
|
||||
|
||||
Return ConcatBinaryData(BinaryDataArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function RepeatString(String, Quantity) Export
|
||||
|
||||
Parts = New Array(Quantity);
|
||||
|
||||
For K = 1 To Quantity Do
|
||||
Parts.Add(String);
|
||||
EndDo;
|
||||
|
||||
Return StrConcat(Parts, "");
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
1229
src/en/OInt/tools/Modules/internal/Modules/OPI_Tools.os
Normal file
1229
src/en/OInt/tools/Modules/internal/Modules/OPI_Tools.os
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Airtable.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Airtable.os
|
||||
// Library: Airtable
|
||||
// CLI Command: airtable
|
||||
|
||||
@@ -28,10 +28,14 @@
|
||||
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region DatabaseWork
|
||||
|
||||
@@ -42,7 +46,7 @@
|
||||
// Token - String - Token - token
|
||||
// Indent - String - Next page identifier of the base list from the previous request - offset
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetListOfBases(Val Token, Val Indent = "") Export
|
||||
|
||||
@@ -67,7 +71,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier - base
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetDatabaseTables(Val Token, Val Base) Export
|
||||
|
||||
@@ -91,14 +95,14 @@ EndFunction
|
||||
// Name - String - New base name - title
|
||||
// TableCollection - Key-Value Pair - Table description: Key > name, Value > array of fields - tablesdata
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateDatabase(Val Token, Val Workspace, Val Name, Val TableCollection) Export
|
||||
|
||||
OPI_TypeConversion.GetCollection(TableCollection);
|
||||
|
||||
If Not TypeValue(TableCollection) = Type("Structure")
|
||||
And Not TypeValue(TableCollection) = Type("Match") Then
|
||||
If Not TypeOf(TableCollection) = Type("Structure")
|
||||
And Not TypeOf(TableCollection) = Type("Map") Then
|
||||
|
||||
Raise "Error in table collection data";
|
||||
|
||||
@@ -110,7 +114,7 @@ Function CreateDatabase(Val Token, Val Workspace, Val Name, Val TableCollection)
|
||||
|
||||
For Each Table In TableCollection Do
|
||||
|
||||
Description = GenerateTableDescription(Table.Key, Table.Value);
|
||||
Description = GenerateTableDescription(Table.TheKey, Table.Value);
|
||||
TableArray.Add(Description);
|
||||
|
||||
EndDo;
|
||||
@@ -137,10 +141,10 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Base - String - Base identifier - base
|
||||
// Name - String - New table name - title
|
||||
// FieldArray - Array of Structures - Array of field descriptions - fieldsdata
|
||||
// FieldArray - Array of Structure - Array of field descriptions - fieldsdata
|
||||
// Description - String - Table description - description
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateTable(Val Token, Val Base, Val Name, Val FieldArray, Val Description = "") Export
|
||||
|
||||
@@ -166,7 +170,7 @@ EndFunction
|
||||
// Name - String - New name - title
|
||||
// Description - String - New description - description
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function ModifyTable(Val Token, Val Base, Val Table, Val Name = "", Val Description = "") Export
|
||||
|
||||
@@ -199,7 +203,7 @@ EndFunction
|
||||
// Table - String - Table identifier - table
|
||||
// FieldStructure - Structure of Key-Value - Description of the new field - fielddata
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateField(Val Token, Val Base, Val Table, Val FieldStructure) Export
|
||||
|
||||
@@ -207,8 +211,8 @@ Function CreateField(Val Token, Val Base, Val Table, Val FieldStructure) Export
|
||||
OPI_TypeConversion.GetLine(Table);
|
||||
OPI_TypeConversion.GetCollection(FieldStructure);
|
||||
|
||||
If Not TypeValue(FieldStructure) = Type("Structure")
|
||||
And Not TypeValue(FieldStructure) = Type("Match") Then
|
||||
If Not TypeOf(FieldStructure) = Type("Structure")
|
||||
And Not TypeOf(FieldStructure) = Type("Map") Then
|
||||
|
||||
Raise "Error in field description data";
|
||||
|
||||
@@ -234,7 +238,7 @@ EndFunction
|
||||
// Name - String - New name - title
|
||||
// Description - String - New description - description
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function ModifyField(Val Token, Val Base, Val Table, Val Field, Val Name = "", Val Description = "") Export
|
||||
|
||||
@@ -261,26 +265,26 @@ Function ModifyField(Val Token, Val Base, Val Table, Val Field, Val Name = "", V
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get поле (withтроtoоinое)
|
||||
// Get field (string)
|
||||
// Gets the description of a string field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - New field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetStringField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "richText");
|
||||
EndFunction
|
||||
|
||||
// Get поле (чиwithлоinое)
|
||||
// Get field (numeric)
|
||||
// Gets the description of a numeric field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - New field name - title
|
||||
// Precision - Number, String - Number of decimal places - precision
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetNumberField(Val Name, Val Precision = 0) Export
|
||||
|
||||
@@ -291,25 +295,25 @@ Function GetNumberField(Val Name, Val Precision = 0) Export
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get поле (file)
|
||||
// Get field (file)
|
||||
// Gets the description of a file field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetAttachmentField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "multipleAttachments");
|
||||
EndFunction
|
||||
|
||||
// Get поле (флажоto)
|
||||
// Get field (checkbox)
|
||||
// Gets the description of a boolean field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetCheckboxField(Val Name) Export
|
||||
|
||||
@@ -318,13 +322,13 @@ Function GetCheckboxField(Val Name) Export
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get поле (dата)
|
||||
// Get field (date)
|
||||
// Gets the description of a date field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetDateField(Val Name) Export
|
||||
|
||||
@@ -335,37 +339,37 @@ Function GetDateField(Val Name) Export
|
||||
|
||||
EndFunction
|
||||
|
||||
// Get поле (email)
|
||||
// Get field (email)
|
||||
// Gets the description of an email field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetEmailField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "email");
|
||||
EndFunction
|
||||
|
||||
// Get поле (телефон)
|
||||
// Get field (phone)
|
||||
// Gets the description of a phone number field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetPhoneField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "phoneNumber");
|
||||
EndFunction
|
||||
|
||||
// Get поле (url)
|
||||
// Get field (url)
|
||||
// Gets the description of a URL field
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Field name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Field description
|
||||
Function GetLinkField(Val Name) Export
|
||||
Return PrimitiveFieldDescription(Name, "url");
|
||||
@@ -384,7 +388,7 @@ EndFunction
|
||||
// Table - String - Table identifier - table
|
||||
// Indent - String - Next page identifier of data from the previous request - offset
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetListOfRecords(Val Token, Val Base, Val Table, Val Indent = "") Export
|
||||
|
||||
@@ -412,7 +416,7 @@ EndFunction
|
||||
// Table - String - Table identifier - table
|
||||
// Record - String - Record identifier in the table - record
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetRecord(Val Token, Val Base, Val Table, Val Record) Export
|
||||
|
||||
@@ -436,9 +440,9 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Data - Structure, Array of Structures - Set or array of sets of Key : Value pairs > Field : Indicator - data
|
||||
// Data - Structure, Array of Structure - Set or array of sets of Key : Value pairs > Field : Indicator - data
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreatePosts(Val Token, Val Base, Val Table, Val Data) Export
|
||||
|
||||
@@ -465,9 +469,9 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database identifier - base
|
||||
// Table - String - Table identifier - table
|
||||
// Records - String, Array of Strings - Identifier or array of record identifiers - records
|
||||
// Records - String, Array of String - Identifier or array of record identifiers - records
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function DeletePosts(Val Token, Val Base, Val Table, Val Records) Export
|
||||
|
||||
@@ -507,7 +511,7 @@ EndFunction
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Indent - String - Next page identifier of data from the previous request - offset
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function GetComments(Val Token, Val Base, Val Table, Val Record, Val Indent = "") Export
|
||||
|
||||
@@ -537,7 +541,7 @@ EndFunction
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Text - String - Comment text - text
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function CreateComment(Val Token, Val Base, Val Table, Val Record, Val Text) Export
|
||||
|
||||
@@ -568,7 +572,7 @@ EndFunction
|
||||
// Comment - String - Comment identifier - comment
|
||||
// Text - String - New comment text - text
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function EditComment(Val Token, Val Base, Val Table, Val Record, Val Comment, Val Text) Export
|
||||
|
||||
@@ -599,7 +603,7 @@ EndFunction
|
||||
// Record - String - Record identifier in the table - record
|
||||
// Comment - String - Comment identifier - comment
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Airtable
|
||||
Function DeleteComment(Val Token, Val Base, Val Table, Val Record, Val Comment) Export
|
||||
|
||||
@@ -621,13 +625,13 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function GetAuthorizationHeader(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "Bearer " + Token);
|
||||
|
||||
Return Headers;
|
||||
@@ -660,7 +664,7 @@ EndFunction
|
||||
|
||||
Procedure AddDataDescription(Val Data, Parameters)
|
||||
|
||||
If TypeValue(Data) = Type("Array") Then
|
||||
If TypeOf(Data) = Type("Array") Then
|
||||
|
||||
SendArray = New Array;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/tools/Modules/internal/Modules/OPI_Cryptography.os
|
||||
//
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -28,21 +28,25 @@
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UnusedLocalVariable-off
|
||||
|
||||
#Region ServiceProgramInterface
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
#Region Internal
|
||||
|
||||
#Region BSP
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (c) 2019, LLC 1C-Soft
|
||||
// All rights reserved. This program and accompanying materials are provided
|
||||
// in withоотinетwithтinии with уwithлоinиями лицензии Attribution 4.0 International (CC BY 4.0)
|
||||
// under the terms of the Attribution 4.0 International (CC BY 4.0 license)
|
||||
// License text available at:
|
||||
// https://creativecommons.org/licenses/by/4.0/legalcode
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Function HMACSHA256(Val Key, Val Data) Export
|
||||
Function HMACSHA256(Val TheKey, Val Data) Export
|
||||
|
||||
Return HMAC(Key, Data, HashFunction.SHA256, 64);
|
||||
Return HMAC(TheKey, Data, HashFunction.SHA256, 64);
|
||||
|
||||
EndFunction
|
||||
|
||||
@@ -55,28 +59,28 @@ Function Hash(BinaryData, Type) Export
|
||||
|
||||
EndFunction
|
||||
|
||||
Function HMAC(Val Key, Val Data, Type, BlockSize) Export
|
||||
Function HMAC(Val TheKey, Val Data, Type, BlockSize) Export
|
||||
|
||||
Twice = 2;
|
||||
|
||||
If Key.Size() > BlockSize Then
|
||||
Key = Hash(Key, Type);
|
||||
If TheKey.Size() > BlockSize Then
|
||||
TheKey = Hash(TheKey, Type);
|
||||
EndIf;
|
||||
|
||||
If Key.Size() <= BlockSize Then
|
||||
Key = GetHexStringFromBinaryData(Key);
|
||||
Key = Left(Key + RepeatString("00", BlockSize), BlockSize * Twice);
|
||||
If TheKey.Size() <= BlockSize Then
|
||||
TheKey = GetHexStringFromBinaryData(TheKey);
|
||||
TheKey = Left(TheKey + RepeatString("00", BlockSize), BlockSize * Twice);
|
||||
EndIf;
|
||||
|
||||
Key = GetBinaryDataBufferFromBinaryData(GetBinaryDataFromHexString(Key));
|
||||
TheKey = GetBinaryDataBufferFromBinaryData(GetBinaryDataFromHexString(TheKey));
|
||||
|
||||
Ipad = GetBinaryDataBufferFromHexString(RepeatString("36", BlockSize));
|
||||
Opad = GetBinaryDataBufferFromHexString(RepeatString("5c", BlockSize));
|
||||
|
||||
Ipad.WriteBitwiseExclusiveOr(0, Key);
|
||||
Ipad.WriteBitwiseExclusiveOr(0, TheKey);
|
||||
Ikeypad = GetBinaryDataFromBinaryDataBuffer(ipad);
|
||||
|
||||
Opad.WriteBitwiseExclusiveOr(0, Key);
|
||||
Opad.WriteBitwiseExclusiveOr(0, TheKey);
|
||||
Okeypad = GetBinaryDataFromBinaryDataBuffer(opad);
|
||||
|
||||
Return Hash(ConcatenateBinaryData(okeypad, Hash(ConcatenateBinaryData(ikeypad, Data), Type)), Type);
|
||||
@@ -89,7 +93,7 @@ Function ConcatenateBinaryData(BinaryData1, BinaryData2) Export
|
||||
BinaryDataArray.Add(BinaryData1);
|
||||
BinaryDataArray.Add(BinaryData2);
|
||||
|
||||
Return JoinBinaryData(BinaryDataArray);
|
||||
Return ConcatBinaryData(BinaryDataArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
@@ -97,11 +101,11 @@ Function RepeatString(String, Quantity) Export
|
||||
|
||||
Parts = New Array(Quantity);
|
||||
|
||||
For To = 1 For Quantity Do
|
||||
For K = 1 To Quantity Do
|
||||
Parts.Add(String);
|
||||
EndDo;
|
||||
|
||||
Return StrJoin(Parts, "");
|
||||
Return StrConcat(Parts, "");
|
||||
|
||||
EndFunction
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_Cryptography</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Toриптография (OPI)</value>
|
||||
<value>Cryptography (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Dropbox.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Dropbox.os
|
||||
// Library: Dropbox
|
||||
// CLI Command: dropbox
|
||||
|
||||
@@ -28,10 +28,14 @@
|
||||
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region AccountAndAuthorization
|
||||
|
||||
@@ -41,7 +45,7 @@
|
||||
// Parameters:
|
||||
// AppKey - String - Application key - appkey
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - URL for browser transition
|
||||
Function GetAuthorizationLink(Val AppKey) Export
|
||||
|
||||
@@ -60,7 +64,7 @@ EndFunction
|
||||
// AppSecret - String - Application secret - appsecret
|
||||
// Code - String - Code from the authorization page - code
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetToken(Val AppKey, Val AppSecret, Val Code) Export
|
||||
|
||||
@@ -79,7 +83,7 @@ Function GetToken(Val AppKey, Val AppSecret, Val Code) Export
|
||||
Connection = OPI_Tools.CreateConnection(Server, AppKey, AppSecret);
|
||||
|
||||
ParameterString = OPI_Tools.RequestParametersToString(Parameters);
|
||||
Data = Right(ParameterString, StrLength(ParameterString) - 1);
|
||||
Data = Right(ParameterString, StrLen(ParameterString) - 1);
|
||||
|
||||
Request.SetBodyFromString(Data);
|
||||
|
||||
@@ -98,7 +102,7 @@ EndFunction
|
||||
// AppSecret - String - Application secret - appsecret
|
||||
// RefreshToken - String - Refresh token - refresh
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function RefreshToken(Val AppKey, Val AppSecret, Val RefreshToken) Export
|
||||
|
||||
@@ -124,7 +128,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Account - String - Account ID. Current token account if not filled - account
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetAccountInformation(Val Token, Val Account = "") Export
|
||||
|
||||
@@ -144,7 +148,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetSpaceUsageData(Val Token) Export
|
||||
|
||||
@@ -173,7 +177,7 @@ EndFunction
|
||||
// Path - String - Path to the object - path
|
||||
// Detailed - Boolean - Adds additional information fields for media files - detail
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetObjectInformation(Val Token, Val Path, Val Detailed = False) Export
|
||||
|
||||
@@ -199,7 +203,7 @@ EndFunction
|
||||
// Detailed - Boolean - Adds additional information fields for media files - detail
|
||||
// Cursor - String - Cursor from the previous request to get the next set of files - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// HTTPResponse - Get list of folder files
|
||||
Function GetListOfFolderFiles(Val Token, Val Path = "", Val Detailed = False, Val Cursor = "") Export
|
||||
|
||||
@@ -229,13 +233,13 @@ Function GetListOfFolderFiles(Val Token, Val Path = "", Val Detailed = False, Va
|
||||
EndFunction
|
||||
|
||||
// Get preview
|
||||
// Forлучает PDF or HTML преinью объеtoта (тольtoо for тоtoументоin)
|
||||
// Gets PDF or HTML preview of the object (for documents only)
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// BinaryData - document preview
|
||||
Function GetPreview(Val Token, Val Path) Export
|
||||
|
||||
@@ -255,7 +259,7 @@ EndFunction
|
||||
// Path - String - Save path on Dropbox - path
|
||||
// Overwrite - Boolean - Overwrite file in case of path conflicts - overwrite
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function UploadFile(Val Token, Val File, Val Path, Val Overwrite = False) Export
|
||||
|
||||
@@ -265,7 +269,7 @@ Function UploadFile(Val Token, Val File, Val Path, Val Overwrite = False) Export
|
||||
|
||||
Mode = ?(Overwrite, "overwrite", "add");
|
||||
Size = File.Size();
|
||||
Boundary = 100000000;
|
||||
Border = 100000000;
|
||||
|
||||
If Size > Border Then
|
||||
Response = UploadLargeFile(Token, File, Path, Mode);
|
||||
@@ -285,7 +289,7 @@ EndFunction
|
||||
// FileURL - String - URL source of the file - url
|
||||
// Path - String - Save path on Dropbox - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function UploadFileByURL(Val Token, Val FileURL, Val Path) Export
|
||||
|
||||
@@ -309,7 +313,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// JobID - String - ID of the asynchronous job from the UploadFileByURL response - job
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetUploadStatusByURL(Val Token, Val JobID) Export
|
||||
|
||||
@@ -333,13 +337,13 @@ EndFunction
|
||||
// Path - String - Path to the object to delete - path
|
||||
// Irrecoverable - String - Delete object without the possibility of recovery - permanently
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function DeleteObject(Val Token, Val Path, Val Irretrievably = False) Export
|
||||
Function DeleteObject(Val Token, Val Path, Val Irrecoverable = False) Export
|
||||
|
||||
OPI_TypeConversion.GetBoolean(Irretrievably);
|
||||
OPI_TypeConversion.GetBoolean(Irrecoverable);
|
||||
|
||||
If Irretrievably Then
|
||||
If Irrecoverable Then
|
||||
URL = "https://api.dropboxapi.com/2/files/permanently_delete";
|
||||
Else
|
||||
URL = "https://api.dropboxapi.com/2/files/delete_v2";
|
||||
@@ -357,17 +361,17 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// From - String - Path to the original object - form
|
||||
// To - String - Target path for the new object - to
|
||||
// Target - String - Target path for the new object - to
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CopyObject(Val Token, Val From, Val To) Export
|
||||
Function CopyObject(Val Token, Val From, Val Target) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/copy_v2";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("from_path", From, "String", Parameters);
|
||||
OPI_Tools.AddField("to_path" , To , "String", Parameters);
|
||||
OPI_Tools.AddField("to_path" , Target , "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
@@ -383,17 +387,17 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// From - String - Path to the original object - form
|
||||
// To - String - Target path for the new object - to
|
||||
// Target - String - Target path for the new object - to
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function MoveObject(Val Token, Val From, Val To) Export
|
||||
Function MoveObject(Val Token, Val From, Val Target) Export
|
||||
|
||||
URL = "https://api.dropboxapi.com/2/files/move_v2";
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("from_path", From, "String", Parameters);
|
||||
OPI_Tools.AddField("to_path" , To , "String", Parameters);
|
||||
OPI_Tools.AddField("to_path" , Target , "String", Parameters);
|
||||
|
||||
Headers = GetRequestHeaders(Token);
|
||||
|
||||
@@ -410,7 +414,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Target path for creating the directory - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CreateFolder(Val Token, Val Path) Export
|
||||
|
||||
@@ -428,7 +432,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path or ID of the file - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// BinaryData - binary data of the file
|
||||
Function DownloadFile(Val Token, Val Path) Export
|
||||
|
||||
@@ -446,7 +450,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path or ID of the directory - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// BinaryData - binary data of the zip archive with the contents of the directory
|
||||
Function DownloadFolder(Val Token, Val Path) Export
|
||||
|
||||
@@ -465,7 +469,7 @@ EndFunction
|
||||
// Path - String - Path to the object - path
|
||||
// Quantity - String, Number - Number of the latest versions of the object to display - amount
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetObjectVersionList(Val Token, Val Path, Val Quantity = 10) Export
|
||||
|
||||
@@ -483,14 +487,14 @@ Function GetObjectVersionList(Val Token, Val Path, Val Quantity = 10) Export
|
||||
EndFunction
|
||||
|
||||
// Restore object to version
|
||||
// Inоwithwithтаtoinлиinает withоwithтояние объеtoта to необхоdимой inерwithии (реinfromии)
|
||||
// Restores object state to required version (revision)
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object - path
|
||||
// Version - String - ID of the version (revision) for restoration - rev
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function RestoreObjectToVersion(Val Token, Val Path, Val Version) Export
|
||||
|
||||
@@ -516,9 +520,9 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Paths - String, Array of Strings - Path or set of paths to the files - paths
|
||||
// Paths - String, Array of String - Path or set of paths to the files - paths
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetTagList(Val Token, Val Paths) Export
|
||||
|
||||
@@ -543,7 +547,7 @@ EndFunction
|
||||
// Path - String - Path to the object for which the tag needs to be created - path
|
||||
// Tag - String - Tag text - tag
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function AddTag(Val Token, Val Path, Val Tag) Export
|
||||
|
||||
@@ -559,7 +563,7 @@ EndFunction
|
||||
// Path - String - Path to the object whose tag needs to be deleted - path
|
||||
// Tag - String - Tag text - tag
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function DeleteTag(Val Token, Val Path, Val Tag) Export
|
||||
|
||||
@@ -578,7 +582,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the target directory - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function PublishFolder(Val Token, Val Path) Export
|
||||
|
||||
@@ -594,9 +598,9 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FolderID - String - ID публичного directory (shared folder ID) - folder
|
||||
// FolderID - String - ID of the public catalog (shared folder ID) - folder
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CancelFolderPublication(Val Token, Val FolderID) Export
|
||||
|
||||
@@ -618,10 +622,10 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FileID - String - ID of the file to be accessed - fileid
|
||||
// EmailAddresses - String, Array of Strings - List of email addresses of users being added - emails
|
||||
// EmailAddresses - String, Array of String - List of email addresses of users being added - emails
|
||||
// ViewOnly - Boolean - Prohibits file editing for the external user - readonly
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function AddUsersToFile(Val Token, Val FileID, Val EmailAddresses, Val ViewOnly = True) Export
|
||||
|
||||
@@ -631,7 +635,7 @@ Function AddUsersToFile(Val Token, Val FileID, Val EmailAddresses, Val ViewOnly
|
||||
OPI_TypeConversion.GetLine(FileID);
|
||||
OPI_TypeConversion.GetBoolean(ViewOnly);
|
||||
|
||||
If Not StringStartsWith(FileID, "id:") Then
|
||||
If Not StrStartsWith(FileID, "id:") Then
|
||||
FileID = "id:" + FileID;
|
||||
EndIf;
|
||||
|
||||
@@ -641,7 +645,7 @@ Function AddUsersToFile(Val Token, Val FileID, Val EmailAddresses, Val ViewOnly
|
||||
|
||||
For Each Address In EmailAddresses Do
|
||||
|
||||
UserData = New Match;
|
||||
UserData = New Map;
|
||||
OPI_Tools.AddField(".tag" , "email", String_, UserData);
|
||||
OPI_Tools.AddField("email", Address , String_, UserData);
|
||||
|
||||
@@ -670,11 +674,11 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// FolderID - String - ID публичного directory (shared folder ID) - folder
|
||||
// EmailAddresses - String, Array of Strings - List of email addresses of users being added - emails
|
||||
// FolderID - String - ID of the public catalog (shared folder ID) - folder
|
||||
// EmailAddresses - String, Array of String - List of email addresses of users being added - emails
|
||||
// ViewOnly - Boolean - Prohibits file editing for the external user - readonly
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Undefined - empty response
|
||||
Function AddUsersToFolder(Val Token, Val FolderID, Val EmailAddresses, Val ViewOnly = True) Export
|
||||
|
||||
@@ -690,7 +694,7 @@ Function AddUsersToFolder(Val Token, Val FolderID, Val EmailAddresses, Val ViewO
|
||||
|
||||
For Each Address In EmailAddresses Do
|
||||
|
||||
UserData = New Match;
|
||||
UserData = New Map;
|
||||
OPI_Tools.AddField(".tag" , "email", String_, UserData);
|
||||
OPI_Tools.AddField("email", Address , String_, UserData);
|
||||
|
||||
@@ -719,7 +723,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// JobID - String - AsynchronousJobID - job
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function GetAsynchronousChangeStatus(Val Token, Val JobID) Export
|
||||
|
||||
@@ -742,13 +746,13 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// FileID - String - ID of the file to be accessed - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Dropbox
|
||||
Function CancelFilePublication(Val Token, Val FileID) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(FileID);
|
||||
|
||||
If Not StringStartsWith(FileID, "id:") Then
|
||||
If Not StrStartsWith(FileID, "id:") Then
|
||||
FileID = "id:" + FileID;
|
||||
EndIf;
|
||||
|
||||
@@ -768,7 +772,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function ProcessObject(Val Token, Val URL, Val Path, Val InHeaders = False)
|
||||
|
||||
@@ -811,13 +815,13 @@ Function GetRequestHeaders(Val Token, Val Parameters = "")
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization" , "Bearer " + Token);
|
||||
|
||||
If ValueIsFilled(Parameters) Then
|
||||
|
||||
JSON = OPI_Tools.JSONString(Parameters, "No");
|
||||
JSON = StringReplace(JSON, Symbols.VK + Symbols.PS, "");
|
||||
JSON = StrReplace(JSON, Chars.VK + Chars.PS, "");
|
||||
|
||||
Headers.Insert("Dropbox-API-Arg", JSON);
|
||||
|
||||
@@ -845,27 +849,27 @@ Function UploadLargeFile(Val Token, Val File, Val Path, Val Mode)
|
||||
Parameters = New Structure("cursor", Cursor);
|
||||
Headers = GetRequestHeaders(Token, Parameters);
|
||||
|
||||
ReadingData = New ReadingData(File);
|
||||
BytesRead = ReadingData.Skip(CurrentPosition);
|
||||
Result = ReadingData.Read(ChunkSize);
|
||||
Current data = Result.GetBinaryData();
|
||||
CurrentSize = Current data.Size();
|
||||
DataReader = New DataReader(File);
|
||||
BytesRead = DataReader.Skip(CurrentPosition);
|
||||
Result = DataReader.Read(ChunkSize);
|
||||
CurrentData = Result.GetBinaryData();
|
||||
CurrentSize = CurrentData.Size();
|
||||
NextPosition = CurrentPosition + CurrentSize;
|
||||
|
||||
If Not ValueIsFilled(Current data) Then
|
||||
If Not ValueIsFilled(CurrentData) Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
Response = OPI_Tools.PostBinary(URL, Current data, Headers);
|
||||
Response = OPI_Tools.PostBinary(URL, CurrentData, Headers);
|
||||
|
||||
CurrentPosition = NextPosition;
|
||||
|
||||
// !OInt KBytes = 1024;
|
||||
// !OInt MByte = KBytes * KBytes;
|
||||
// !OInt Notify(OPI_Tools.ProgressInformation(CurrentPosition, TotalSize, "MB", MByte));
|
||||
// !OInt KB = 1024;
|
||||
// !OInt MB = KB * KB;
|
||||
// !OInt Message(OPI_Tools.ProgressInfo(CurrentPosition, TotalSize, "MB", MB));
|
||||
|
||||
// !OInt PerformGarbageCollection();
|
||||
// !OInt ReleaseObject(Current data);
|
||||
// !OInt ReleaseObject(CurrentData);
|
||||
|
||||
EndDo;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleCalendar.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleCalendar.os
|
||||
// Library: Google Calendar
|
||||
// CLI Command: gcalendar
|
||||
|
||||
@@ -29,10 +29,14 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region CalendarMetadataManagement
|
||||
|
||||
@@ -43,7 +47,7 @@
|
||||
// Token - String - Token - token
|
||||
// Name - String - Name of the created calendar - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateCalendar(Val Token, Val Name) Export
|
||||
|
||||
@@ -70,7 +74,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetCalendarMetadata(Val Token, Val Calendar) Export
|
||||
|
||||
@@ -94,7 +98,7 @@ EndFunction
|
||||
// Name - String - New name - title
|
||||
// Description - String - New calendar description - description
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditCalendarMetadata(Val Token
|
||||
, Val Calendar
|
||||
@@ -131,7 +135,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function ClearMainCalendar(Val Token) Export
|
||||
|
||||
@@ -152,7 +156,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteCalendar(Val Token, Val Calendar) Export
|
||||
|
||||
@@ -177,7 +181,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of calendar data mappings
|
||||
Function GetCalendarList(Val Token) Export
|
||||
|
||||
@@ -199,7 +203,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function AddCalendarToList(Val Token, Val Calendar) Export
|
||||
|
||||
@@ -225,7 +229,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetListCalendar(Val Token, Val Calendar) Export
|
||||
|
||||
@@ -247,7 +251,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteCalendarFromList(Val Token, Val Calendar) Export
|
||||
|
||||
@@ -268,11 +272,11 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// PrimaryColor - String - HEX mainоinного цinета (#ffffff) - primary
|
||||
// SecondaryColor - String - HEX addолнительного цinета (#ffffff) - secondary
|
||||
// PrimaryColor - String - HEX primary color (#ffffff) - primary
|
||||
// SecondaryColor - String - HEX secondary color (#ffffff) - secondary
|
||||
// Hidden - Boolean - Hidden calendar - hidden
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditListCalendar(Val Token
|
||||
, Val Calendar
|
||||
@@ -289,7 +293,7 @@ Function EditListCalendar(Val Token
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/calendar/v3/users/me/calendarList/" + Calendar + "?colorRgbFormat=true";
|
||||
|
||||
Parameters = New Match;
|
||||
Parameters = New Map;
|
||||
Parameters.Insert("hidden" , Hidden);
|
||||
Parameters.Insert("foregroundColor", PrimaryColor);
|
||||
Parameters.Insert("backgroundColor", SecondaryColor);
|
||||
@@ -306,20 +310,20 @@ EndFunction
|
||||
|
||||
// Get event description !NOCLI
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Empty event template
|
||||
Function GetEventDescription() Export
|
||||
|
||||
CurrentDate = OPI_Tools.GetCurrentDate();
|
||||
Hour = 3600;
|
||||
Event = New Match;
|
||||
Event = New Map;
|
||||
|
||||
Event.Insert("Description" , ""); // Event description
|
||||
Event.Insert("Title" , "New event"); // Title events
|
||||
Event.Insert("Venue" , ""); // String description of the venue of the event
|
||||
Event.Insert("StartDate" , CurrentDate); // Date of start events
|
||||
Event.Insert("EndDate" , CurrentDate + Hour); // Date of end events
|
||||
Event.Insert("ArrayOfAttachmentURLs", New Match); // Key - name, Value - URL to file
|
||||
Event.Insert("ArrayOfAttachmentURLs", New Map); // TheKey - name, Value - URL to file
|
||||
Event.Insert("SendNotifications" , True); // Indication of sending notifications to participants
|
||||
|
||||
Return Event;
|
||||
@@ -333,7 +337,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of event mappings
|
||||
Function GetEventList(Val Token, Val Calendar) Export
|
||||
|
||||
@@ -357,7 +361,7 @@ EndFunction
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// Event - String - Event ID - event
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetEvent(Val Token, Val Calendar, Val Event) Export
|
||||
|
||||
@@ -385,7 +389,7 @@ EndFunction
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// EventDescription - Key-Value Pair - Event description - props
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String, Arbitrary, HTTPResponse, BinaryData, Undefined - Google server response
|
||||
Function CreateEvent(Val Token, Val Calendar, Val EventDescription) Export
|
||||
Return EventManagement(Token, Calendar, EventDescription);
|
||||
@@ -400,7 +404,7 @@ EndFunction
|
||||
// TargetCalendar - String - ID of the target calendar - to
|
||||
// Event - String - ID of the source calendar event - event
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function MoveEvent(Val Token, Val SourceCalendar, Val TargetCalendar, Val Event) Export
|
||||
|
||||
@@ -432,7 +436,7 @@ EndFunction
|
||||
// EventDescription - String - New event description - props
|
||||
// Event - String - Event ID - event
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditEvent(Val Token, Val Calendar, Val EventDescription, Val Event) Export
|
||||
Return EventManagement(Token, Calendar, EventDescription, Event);
|
||||
@@ -446,7 +450,7 @@ EndFunction
|
||||
// Calendar - String - Calendar ID - calendar
|
||||
// Event - String - Event ID - event
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteEvent(Val Token, Val Calendar, Val Event) Export
|
||||
|
||||
@@ -470,7 +474,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function ConvertDate(Val Date)
|
||||
|
||||
@@ -478,11 +482,11 @@ Function ConvertDate(Val Date)
|
||||
|
||||
DateStructure = New Structure;
|
||||
|
||||
If Not TypeValue(Date) = Type("Date") Then
|
||||
If Not TypeOf(Date) = Type("Date") Then
|
||||
Return Undefined;
|
||||
EndIf;
|
||||
|
||||
If Date = StartOfDay(Date) Then
|
||||
If Date = BegOfDay(Date) Then
|
||||
DateFormat = "DF=yyyy-MM-dd";
|
||||
Field = "date";
|
||||
Else
|
||||
@@ -504,12 +508,12 @@ Function ConvertAttachments(Val Attachments)
|
||||
|
||||
AttachmentsArray = New Array;
|
||||
|
||||
If TypeValue(Attachments) = Type("Match") Or TypeValue(Attachments) = Type("Structure") Then
|
||||
If TypeOf(Attachments) = Type("Map") Or TypeOf(Attachments) = Type("Structure") Then
|
||||
|
||||
For Each Attachment In Attachments Do
|
||||
|
||||
CurrentAttachment = New Structure;
|
||||
CurrentAttachment.Insert("title" , Attachment.Key);
|
||||
CurrentAttachment.Insert("title" , Attachment.TheKey);
|
||||
CurrentAttachment.Insert("fileUrl", Attachment.Value);
|
||||
|
||||
AttachmentsArray.Add(CurrentAttachment);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleDrive.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleDrive.os
|
||||
// Library: Google Drive
|
||||
// CLI Command: gdrive
|
||||
|
||||
@@ -29,10 +29,14 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region FileAndDirectoryManagement
|
||||
|
||||
@@ -43,7 +47,7 @@
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the file or folder - object
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetObjectInformation(Val Token, Val Identifier) Export
|
||||
|
||||
@@ -70,7 +74,7 @@ EndFunction
|
||||
// NameContains - String - Filter by name - querry
|
||||
// Detailed - Boolean - Adds a list of files to the directory fields - depth
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of directory mappings
|
||||
Function GetDirectoriesList(Val Token, Val NameContains = "", Val Detailed = False) Export
|
||||
|
||||
@@ -106,7 +110,7 @@ EndFunction
|
||||
// NameContains - String - Filter by name - querry
|
||||
// Directory - String - Filter by parent directory ID - catalog
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of file mappings
|
||||
Function GetFilesList(Val Token, Val NameContains = "", Val Directory = "") Export
|
||||
|
||||
@@ -142,7 +146,7 @@ EndFunction
|
||||
// File - BinaryData,String - File to be uploaded - file
|
||||
// Description - Key-Value Pair - See GetFileDescription - props - JSON description or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function UploadFile(Val Token, Val File, Val Description) Export
|
||||
Return FileManagement(Token, File, Description);
|
||||
@@ -156,7 +160,7 @@ EndFunction
|
||||
// Name - String - Folder name - title
|
||||
// Parent - String - Parent - catalog
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateFolder(Val Token, Val Name, Val Parent = "") Export
|
||||
|
||||
@@ -164,7 +168,7 @@ Function CreateFolder(Val Token, Val Name, Val Parent = "") Export
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Parent);
|
||||
|
||||
Description = New Match;
|
||||
Description = New Map;
|
||||
Description.Insert("MIME" , "application/vnd.google-apps.folder");
|
||||
Description.Insert("Name" , Name);
|
||||
Description.Insert("Description", "");
|
||||
@@ -182,7 +186,7 @@ EndFunction
|
||||
// Identifier - String - File identifier - object
|
||||
// SavePath - String - File save path - out
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// BinaryData,String - Binary data or file path when SavePath parameter is specified
|
||||
Function DownloadFile(Val Token, Val Identifier, Val SavePath = "") Export
|
||||
|
||||
@@ -192,7 +196,7 @@ Function DownloadFile(Val Token, Val Identifier, Val SavePath = "") Export
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://www.googleapis.com/drive/v3/files/" + Identifier;
|
||||
|
||||
Parameters = New Match;
|
||||
Parameters = New Map;
|
||||
Parameters.Insert("alt", "media");
|
||||
|
||||
Response = OPI_Tools.Get(URL, Parameters , Headers, SavePath);
|
||||
@@ -210,7 +214,7 @@ EndFunction
|
||||
// NewName - String - New object name - title
|
||||
// NewParent - String - New parent directory - catalog
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CopyObject(Val Token, Val Identifier, Val NewName = "", Val NewParent = "") Export
|
||||
|
||||
@@ -249,9 +253,9 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the object to update - object
|
||||
// File - BinaryData,String - File source for update - file
|
||||
// NewName - String - Nоinое имя file (еwithли необхоdимо) - title
|
||||
// NewName - String - New file name (if necessary) - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function UpdateFile(Val Token, Val Identifier, Val File, Val NewName = "") Export
|
||||
|
||||
@@ -261,7 +265,7 @@ Function UpdateFile(Val Token, Val Identifier, Val File, Val NewName = "") Expor
|
||||
OPI_TypeConversion.GetBinaryData(File);
|
||||
|
||||
If ValueIsFilled(NewName) Then
|
||||
Description = New Match;
|
||||
Description = New Map;
|
||||
Description.Insert("Name", NewName);
|
||||
Else
|
||||
Description = "";
|
||||
@@ -278,7 +282,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - Identifier of the object to delete - object
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteObject(Val Token, Val Identifier) Export
|
||||
|
||||
@@ -295,11 +299,11 @@ EndFunction
|
||||
|
||||
// Get file description !NOCLI
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - File description
|
||||
Function GetFileDescription() Export
|
||||
|
||||
Description = New Match;
|
||||
Description = New Map;
|
||||
Description.Insert("MIME" , "image/jpeg"); // MIME-type uploading file
|
||||
Description.Insert("Name" , "New file.jpg"); // File name with extension
|
||||
Description.Insert("Description" , "This is a new file"); // File description
|
||||
@@ -321,7 +325,7 @@ EndFunction
|
||||
// Identifier - String - Identifier of the object that needs a comment - object
|
||||
// Comment - String - Comment text - text
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateComment(Val Token, Val Identifier, Val Comment) Export
|
||||
|
||||
@@ -349,7 +353,7 @@ EndFunction
|
||||
// ObjectID - String - Identifier of the file or directory where the comment is located - object
|
||||
// CommentID - String - Comment identifier - comment
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetComment(Val Token, Val ObjectID, Val CommentID) Export
|
||||
|
||||
@@ -376,7 +380,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// ObjectID - String - Object identifier - object
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetCommentList(Val Token, Val ObjectID) Export
|
||||
|
||||
@@ -403,7 +407,7 @@ EndFunction
|
||||
// ObjectID - String - Identifier of the file or directory where the comment is located - object
|
||||
// CommentID - String - Comment identifier - comment
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteComment(Val Token, Val ObjectID, Val CommentID) Export
|
||||
|
||||
@@ -424,7 +428,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Procedure GetObjectsListRecursively(Val Headers, ArrayOfObjects, Detailed = False, Filter = "", Page = "")
|
||||
|
||||
@@ -438,8 +442,8 @@ Procedure GetObjectsListRecursively(Val Headers, ArrayOfObjects, Detailed = Fals
|
||||
Parameters.Insert("pageToken", Page);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Filter) And TypeValue(Filter) = Type("Array") Then
|
||||
FilterString = StrJoin(Filter, " and ");
|
||||
If ValueIsFilled(Filter) And TypeOf(Filter) = Type("Array") Then
|
||||
FilterString = StrConcat(Filter, " and ");
|
||||
Parameters.Insert("q", FilterString);
|
||||
EndIf;
|
||||
|
||||
@@ -479,10 +483,10 @@ EndProcedure
|
||||
|
||||
Procedure FormFileUploadParameters(Description)
|
||||
|
||||
FormedDescription = New Match;
|
||||
FormedDescription = New Map;
|
||||
OPI_Tools.RemoveEmptyCollectionFields(Description);
|
||||
|
||||
FieldMapping = New Match;
|
||||
FieldMapping = New Map;
|
||||
FieldMapping.Insert("MIME" , "mimeType");
|
||||
FieldMapping.Insert("Name" , "name");
|
||||
FieldMapping.Insert("Description" , "description");
|
||||
@@ -491,7 +495,7 @@ Procedure FormFileUploadParameters(Description)
|
||||
|
||||
For Each Element In Description Do
|
||||
|
||||
If Element.Key = "Parent" Then
|
||||
If Element.TheKey = "Parent" Then
|
||||
|
||||
CurrentValue = New Array;
|
||||
CurrentValue.Add(Element.Value);
|
||||
@@ -502,7 +506,7 @@ Procedure FormFileUploadParameters(Description)
|
||||
|
||||
EndIf;
|
||||
|
||||
FieldName = FieldMapping.Get(Element.Key);
|
||||
FieldName = FieldMapping.Get(Element.TheKey);
|
||||
FormedDescription.Insert(FieldName, CurrentValue);
|
||||
|
||||
EndDo;
|
||||
@@ -529,14 +533,14 @@ Function FileManagement(Val Token, Val File = "", Val Description = "", Val Iden
|
||||
EndIf;
|
||||
|
||||
If Not ValueIsFilled(Description) Then
|
||||
Description = New Match;
|
||||
Description = New Map;
|
||||
EndIf;
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
FormFileUploadParameters(Description);
|
||||
JSONDescription = OPI_Tools.JSONString(Description);
|
||||
|
||||
FileMapping = New Match;
|
||||
FileMapping = New Map;
|
||||
|
||||
If ValueIsFilled(File) Then
|
||||
|
||||
@@ -545,7 +549,7 @@ Function FileManagement(Val Token, Val File = "", Val Description = "", Val Iden
|
||||
|
||||
FileMapping.Insert(File, MIME);
|
||||
|
||||
If Size < ChunkSize And TypeValue(File) = Type("BinaryData") Then
|
||||
If Size < ChunkSize And TypeOf(File) = Type("BinaryData") Then
|
||||
Response = UploadSmallFile(JSONDescription, FileMapping, Headers, Identifier);
|
||||
Else
|
||||
Response = UploadLargeFile(Description, FileMapping, Headers, Identifier);
|
||||
@@ -564,7 +568,7 @@ Function UploadSmallFile(Val Description, Val FileMapping, Val Headers, Val Iden
|
||||
URL = "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart";
|
||||
|
||||
If ValueIsFilled(Identifier) Then
|
||||
URL = StringReplace(URL, "/files", "/files/" + Identifier);
|
||||
URL = StrReplace(URL, "/files", "/files/" + Identifier);
|
||||
Response = OPI_Tools.PatchMultipartRelated(URL, Description, FileMapping, Headers);
|
||||
Else
|
||||
Response = OPI_Tools.PostMultipartRelated(URL, Description, FileMapping, Headers);
|
||||
@@ -577,14 +581,14 @@ EndFunction
|
||||
Function UploadLargeFile(Val Description, Val FileMapping, Val Headers, Val Identifier = "")
|
||||
|
||||
For Each File In FileMapping Do
|
||||
Binary = File.Key;
|
||||
Binary = File.TheKey;
|
||||
Break;
|
||||
EndDo;
|
||||
|
||||
URL = "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable";
|
||||
|
||||
If ValueIsFilled(Identifier) Then
|
||||
URL = StringReplace(URL, "/files", "/files/" + Identifier);
|
||||
URL = StrReplace(URL, "/files", "/files/" + Identifier);
|
||||
Response = OPI_Tools.Patch(URL, Description, Headers, True, True);
|
||||
Else
|
||||
Response = OPI_Tools.Post(URL, Description, Headers, True, True);
|
||||
@@ -613,18 +617,18 @@ Function UploadFileInParts(Val Binary, Val UploadURL)
|
||||
CurrentPosition = 0;
|
||||
TotalSize = Binary.Size();
|
||||
StrTotalSize = OPI_Tools.NumberToString(TotalSize);
|
||||
ReadingData = New ReadingData(Binary);
|
||||
SourceStream = ReadingData.SourceStream();
|
||||
DataReader = New DataReader(Binary);
|
||||
SourceStream = DataReader.SourceStream();
|
||||
|
||||
WHile BytesRead < TotalSize Do
|
||||
|
||||
BytesRead = SourceStream.CurrentPosition();
|
||||
Result = ReadingData.Read(ChunkSize);
|
||||
Current data = Result.GetBinaryData();
|
||||
CurrentSize = Current data.Size();
|
||||
Result = DataReader.Read(ChunkSize);
|
||||
CurrentData = Result.GetBinaryData();
|
||||
CurrentSize = CurrentData.Size();
|
||||
NextPosition = CurrentPosition + CurrentSize - 1;
|
||||
|
||||
If Not ValueIsFilled(Current data) Then
|
||||
If Not ValueIsFilled(CurrentData) Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
@@ -635,12 +639,12 @@ Function UploadFileInParts(Val Binary, Val UploadURL)
|
||||
+ "/"
|
||||
+ StrTotalSize;
|
||||
|
||||
AdditionalHeaders = New Match;
|
||||
AdditionalHeaders = New Map;
|
||||
AdditionalHeaders.Insert("Content-Length", OPI_Tools.NumberToString(CurrentSize));
|
||||
AdditionalHeaders.Insert("Content-Range" , StreamHeader);
|
||||
AdditionalHeaders.Insert("Content-Type" , "application/octet-stream");
|
||||
|
||||
Response = OPI_Tools.Put(UploadURL, Current data, AdditionalHeaders, False, True);
|
||||
Response = OPI_Tools.Put(UploadURL, CurrentData, AdditionalHeaders, False, True);
|
||||
|
||||
CheckResult = CheckPartUpload(Response, StrTotalSize, AdditionalHeaders, UploadURL, CurrentPosition);
|
||||
|
||||
@@ -648,12 +652,12 @@ Function UploadFileInParts(Val Binary, Val UploadURL)
|
||||
Return CheckResult;
|
||||
EndIf;
|
||||
|
||||
// !OInt KBytes = 1024;
|
||||
// !OInt MByte = KBytes * KBytes;
|
||||
// !OInt Notify(OPI_Tools.ProgressInformation(CurrentPosition, TotalSize, "MB", MByte));
|
||||
// !OInt KB = 1024;
|
||||
// !OInt MB = KB * KB;
|
||||
// !OInt Message(OPI_Tools.ProgressInfo(CurrentPosition, TotalSize, "MB", MB));
|
||||
|
||||
// !OInt PerformGarbageCollection();
|
||||
// !OInt ReleaseObject(Current data);
|
||||
// !OInt ReleaseObject(CurrentData);
|
||||
|
||||
EndDo;
|
||||
|
||||
@@ -701,7 +705,7 @@ Function CheckPartUpload(Response, StrTotalSize, AdditionalHeaders, UploadURL, C
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
UploadedData = StringReplace(UploadedData, "bytes=", "");
|
||||
UploadedData = StrReplace(UploadedData, "bytes=", "");
|
||||
ArrayOfInformation = StrSplit(UploadedData, "-", False);
|
||||
PartsRequired = 2;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleSheets.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleSheets.os
|
||||
// Library: Google Sheets
|
||||
// CLI Command: gsheets
|
||||
|
||||
@@ -29,10 +29,14 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region BookWork
|
||||
|
||||
@@ -42,9 +46,9 @@
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Name - String - Name - title
|
||||
// ArrayOfSheetNames - Array of Strings - Array of names to add new sheets to the book - sheets
|
||||
// ArrayOfSheetNames - Array of String - Array of names to add new sheets to the book - sheets
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CreateBook(Val Token, Val Name, Val ArrayOfSheetNames) Export
|
||||
|
||||
@@ -76,7 +80,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Identifier - String - BookIdentifier - spreadsheet
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetBook(Val Token, Val Identifier) Export
|
||||
|
||||
@@ -99,7 +103,7 @@ EndFunction
|
||||
// Book - String - BookID - spreadsheet
|
||||
// Name - String - New name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function EditBookTitle(Val Token, Val Book, Val Name) Export
|
||||
|
||||
@@ -137,7 +141,7 @@ EndFunction
|
||||
// Book - String - BookIdentifier - spreadsheet
|
||||
// Name - String - NewSheetName - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function AddSheet(Val Token, Val Book, Val Name) Export
|
||||
|
||||
@@ -167,7 +171,7 @@ EndFunction
|
||||
// Book - String - BookIdentifier - spreadsheet
|
||||
// Sheet - String - IdentifierOfSheetToDelete - sheet
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function DeleteSheet(Val Token, Val Book, Val Sheet) Export
|
||||
|
||||
@@ -196,15 +200,15 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// From - String - SourceBookID - from
|
||||
// To - String - DestinationBookID - to
|
||||
// Target - String - DestinationBookID - to
|
||||
// Sheet - String - CopiedSheetID - sheet
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function CopySheet(Val Token, Val From, Val To, Val Sheet) Export
|
||||
Function CopySheet(Val Token, Val From, Val Target, Val Sheet) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(From);
|
||||
OPI_TypeConversion.GetLine(To);
|
||||
OPI_TypeConversion.GetLine(Target);
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
@@ -214,7 +218,7 @@ Function CopySheet(Val Token, Val From, Val To, Val Sheet) Export
|
||||
+ Sheet
|
||||
+ ":copyTo";
|
||||
|
||||
Parameters = New Structure("destinationSpreadsheetId", To);
|
||||
Parameters = New Structure("destinationSpreadsheetId", Target);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
@@ -232,10 +236,10 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// ValueMapping - Key-Value Pair - Fill data where the key is the cell name like A1 - data
|
||||
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
|
||||
// Sheet - String - Sheet name (first sheet by default) - sheetname
|
||||
// MajorDimension - String - Main dimension when filling the array range - dim
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function SetCellValues(Val Token
|
||||
, Val Book
|
||||
@@ -246,16 +250,16 @@ Function SetCellValues(Val Token
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
OPI_TypeConversion.GetCollection(ValueMapping);
|
||||
|
||||
If Not TypeValue(ValueMapping) = Type("Structure")
|
||||
And Not TypeValue(ValueMapping) = Type("Match") Then
|
||||
If Not TypeOf(ValueMapping) = Type("Structure")
|
||||
And Not TypeOf(ValueMapping) = Type("Map") Then
|
||||
Return "Failed to convert the structure of values to a collection";
|
||||
EndIf;
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchUpdate";
|
||||
Data array = FormCellDataArray(ValueMapping, MajorDimension, Sheet);
|
||||
DataArray = FormCellDataArray(ValueMapping, MajorDimension, Sheet);
|
||||
|
||||
Parameters = New Structure("data,valueInputOption", Data array, "USER_ENTERED");
|
||||
Parameters = New Structure("data,valueInputOption", DataArray, "USER_ENTERED");
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
@@ -268,22 +272,22 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// Cell array - Array of Strings - Array of cells like A1 to be cleared - cells
|
||||
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
|
||||
// CellsArray - Array of String - Array of cells like A1 to be cleared - cells
|
||||
// Sheet - String - Sheet name (first sheet by default) - sheetname
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function ClearCells(Val Token, Val Book, Val Cell array, Val Sheet = "") Export
|
||||
Function ClearCells(Val Token, Val Book, Val CellsArray, Val Sheet = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
OPI_TypeConversion.GetCollection(Cell array);
|
||||
OPI_TypeConversion.GetCollection(CellsArray);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchClear";
|
||||
|
||||
FormCellNameArray(Cell array, Sheet);
|
||||
FormCellNameArray(CellsArray, Sheet);
|
||||
|
||||
Parameters = New Structure("ranges", Cell array);
|
||||
Parameters = New Structure("ranges", CellsArray);
|
||||
Response = OPI_Tools.Post(URL, Parameters, Headers);
|
||||
|
||||
Return Response;
|
||||
@@ -296,24 +300,24 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Book - String - BookID - spreadsheet
|
||||
// Cell array - Array of Strings - Array ячееto inиdа А1 for получения (inеwithь лиwithт, еwithли не заполнено) - cells
|
||||
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
|
||||
// CellsArray - Array of String - Array of A1-type cells to get (whole sheet if not filled) - cells
|
||||
// Sheet - String - Sheet name (first sheet by default) - sheetname
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetCellValues(Val Token, Val Book, Val Cell array = "", Val Sheet = "") Export
|
||||
Function GetCellValues(Val Token, Val Book, Val CellsArray = "", Val Sheet = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Book);
|
||||
|
||||
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
|
||||
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchGet";
|
||||
|
||||
If ValueIsFilled(Cell array) Then
|
||||
OPI_TypeConversion.GetCollection(Cell array);
|
||||
FormCellNameArray(Cell array, Sheet);
|
||||
If ValueIsFilled(CellsArray) Then
|
||||
OPI_TypeConversion.GetCollection(CellsArray);
|
||||
FormCellNameArray(CellsArray, Sheet);
|
||||
|
||||
First = True;
|
||||
For Each Cell In Cell array Do
|
||||
For Each Cell In CellsArray Do
|
||||
Delimiter = ?(First, "?", "&");
|
||||
URL = URL + Delimiter + "ranges=" + Cell;
|
||||
First = False;
|
||||
@@ -332,7 +336,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Procedure FillSheetArray(Val ArrayOfNames, SheetArray)
|
||||
|
||||
@@ -357,8 +361,8 @@ Function CreateSheet(Val Name)
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
|
||||
Sheet properties = New Structure("title" , Name);
|
||||
Sheet = New Structure("properties", Sheet properties);
|
||||
SheetProperties = New Structure("title" , Name);
|
||||
Sheet = New Structure("properties", SheetProperties);
|
||||
|
||||
Return Sheet;
|
||||
|
||||
@@ -368,31 +372,31 @@ Function FormCellDataArray(Val ValueStructure, Val MajorDimension, Val Sheet)
|
||||
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
Data array = New Array;
|
||||
DataArray = New Array;
|
||||
|
||||
For Each CellData In ValueStructure Do
|
||||
|
||||
CurrentValue = CellData.Value;
|
||||
Current key = CellData.Key;
|
||||
CurrentKey = CellData.TheKey;
|
||||
|
||||
AddSheetName(Current key, Sheet);
|
||||
AddSheetName(CurrentKey, Sheet);
|
||||
|
||||
OPI_TypeConversion.GetArray(CurrentValue);
|
||||
|
||||
Current data = New Match;
|
||||
Current array = New Array;
|
||||
CurrentData = New Map;
|
||||
CurrentArray = New Array;
|
||||
|
||||
Current array.Add(CurrentValue);
|
||||
CurrentArray.Add(CurrentValue);
|
||||
|
||||
OPI_Tools.AddField("range" , Current key , "String", Current data);
|
||||
OPI_Tools.AddField("values" , Current array , "Array", Current data);
|
||||
OPI_Tools.AddField("majorDimension", MajorDimension, "String", Current data);
|
||||
OPI_Tools.AddField("range" , CurrentKey , "String", CurrentData);
|
||||
OPI_Tools.AddField("values" , CurrentArray , "Array", CurrentData);
|
||||
OPI_Tools.AddField("majorDimension", MajorDimension, "String", CurrentData);
|
||||
|
||||
Data array.Add(Current data);
|
||||
DataArray.Add(CurrentData);
|
||||
|
||||
EndDo;
|
||||
|
||||
Return Data array;
|
||||
Return DataArray;
|
||||
|
||||
EndFunction
|
||||
|
||||
@@ -400,7 +404,7 @@ Procedure FormCellNameArray(Val ArrayOfNames, Val Sheet)
|
||||
|
||||
OPI_TypeConversion.GetLine(Sheet);
|
||||
|
||||
For N = 0 For ArrayOfNames.WithinBoundary() Do
|
||||
For N = 0 To ArrayOfNames.WithinBoundary() Do
|
||||
AddSheetName(ArrayOfNames[N], Sheet);
|
||||
EndDo;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_GoogleWorkspace.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleWorkspace.os
|
||||
// Library: Google Workspace
|
||||
// CLI command: google
|
||||
|
||||
@@ -29,10 +29,14 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
// Generate code retrieval link
|
||||
// Returns URL for browser authorization
|
||||
@@ -43,7 +47,7 @@
|
||||
// Drive - Boolean - Drive methods permission - drive
|
||||
// Sheets - Boolean - Sheets methods permission - sheets
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - Code retrieval link
|
||||
Function FormCodeRetrievalLink(Val ClientID
|
||||
, Val Calendar = True
|
||||
@@ -78,7 +82,7 @@ EndFunction
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// Code - String - Code from browser - code
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function GetTokenByCode(Val ClientID, Val ClientSecret, Val Code) Export
|
||||
|
||||
@@ -109,7 +113,7 @@ EndFunction
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// RefreshToken - String - Refresh token - refresh
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Google
|
||||
Function RefreshToken(Val ClientID, Val ClientSecret, Val RefreshToken) Export
|
||||
|
||||
@@ -133,13 +137,13 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProgramInterface
|
||||
#Region Internal
|
||||
|
||||
Function GetAuthorizationHeader(Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "Bearer " + Token);
|
||||
|
||||
Return Headers;
|
||||
@@ -152,21 +156,21 @@ EndFunction
|
||||
|
||||
Function GetPermissionsList(Calendar, Drive, Sheets)
|
||||
|
||||
Permissions array = New Array;
|
||||
PermissionsArray = New Array;
|
||||
|
||||
If Calendar Then
|
||||
Permissions array.Add("https://www.googleapis.com/auth/calendar");
|
||||
PermissionsArray.Add("https://www.googleapis.com/auth/calendar");
|
||||
EndIf;
|
||||
|
||||
If Drive Then
|
||||
Permissions array.Add("https://www.googleapis.com/auth/drive");
|
||||
PermissionsArray.Add("https://www.googleapis.com/auth/drive");
|
||||
EndIf;
|
||||
|
||||
If Sheets Then
|
||||
Permissions array.Add("https://www.googleapis.com/auth/spreadsheets");
|
||||
PermissionsArray.Add("https://www.googleapis.com/auth/spreadsheets");
|
||||
EndIf;
|
||||
|
||||
Return StrJoin(Permissions array, " ");
|
||||
Return StrConcat(PermissionsArray, " ");
|
||||
|
||||
EndFunction
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Notion.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Notion.os
|
||||
// Library: Notion
|
||||
// CLI command: notion
|
||||
|
||||
@@ -31,12 +31,15 @@
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
// @skip-check method-too-many-params
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region PageManagement
|
||||
|
||||
@@ -48,7 +51,7 @@
|
||||
// Parent - String - Parent ID - page
|
||||
// Title - String - Page title - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreatePage(Val Token, Val Parent, Val Title) Export
|
||||
|
||||
@@ -79,7 +82,7 @@ EndFunction
|
||||
// Parent - String - Parent database ID - base
|
||||
// Data - Key-Value Pair - Properties match - data
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreatePageInDatabase(Val Token, Val Parent, Val Data) Export
|
||||
|
||||
@@ -108,7 +111,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Page - String - Page ID - page
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function GetPage(Val Token, Val Page) Export
|
||||
|
||||
@@ -132,9 +135,9 @@ EndFunction
|
||||
// Data - Key-Value Pair - Matching of editable parameters - data
|
||||
// Icon - String - URL of the page icon image - icon
|
||||
// Cover - String - URL of the page cover image - cover
|
||||
// Archived - Boolean - Archive page or нет (boolean) - archive
|
||||
// Archived - Boolean - Archive page or not (boolean) - archive
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function EditPageProperties(Val Token
|
||||
, Val Page
|
||||
@@ -155,32 +158,32 @@ Function EditPageProperties(Val Token
|
||||
Files = "files";
|
||||
|
||||
If ValueIsFilled(Data)
|
||||
And (TypeValue(Data) = Type("Match") Or TypeValue(Data) = Type("Structure")) Then
|
||||
And (TypeOf(Data) = Type("Map") Or TypeOf(Data) = Type("Structure")) Then
|
||||
Properties = FillDataBySchema(Page, Data, Token, False);
|
||||
Else
|
||||
Properties = New Match;
|
||||
Properties = New Map;
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Icon) Then
|
||||
Icon match = New Match;
|
||||
Icon match.Insert("Icon", Icon);
|
||||
IconMap = New Map;
|
||||
IconMap.Insert("Icon", Icon);
|
||||
|
||||
Icon object = ConvertValueByType(Files, Icon match);
|
||||
Icon object = Icon object[Files][0];
|
||||
Icon object.Delete("name");
|
||||
IconObject = ConvertValueByType(Files, IconMap);
|
||||
IconObject = IconObject[Files][0];
|
||||
IconObject.Delete("name");
|
||||
|
||||
Parameters.Insert("icon", Icon object);
|
||||
Parameters.Insert("icon", IconObject);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(Cover) Then
|
||||
Cover match = New Match;
|
||||
Cover match.Insert("Cover", Cover);
|
||||
CoverMap = New Map;
|
||||
CoverMap.Insert("Cover", Cover);
|
||||
|
||||
Cover object = ConvertValueByType(Files, Cover match);
|
||||
Cover object = Cover object[Files][0];
|
||||
Cover object.Delete("name");
|
||||
CoverObject = ConvertValueByType(Files, CoverMap);
|
||||
CoverObject = CoverObject[Files][0];
|
||||
CoverObject.Delete("name");
|
||||
|
||||
Parameters.Insert("cover", Cover object);
|
||||
Parameters.Insert("cover", CoverObject);
|
||||
EndIf;
|
||||
|
||||
Parameters.Insert("properties", Properties);
|
||||
@@ -207,7 +210,7 @@ EndFunction
|
||||
// Title - String - Database title - title
|
||||
// Properties - Structure Of String - Database properties - props
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreateDatabase(Val Token, Val Parent, Val Title, Val Properties = "") Export
|
||||
|
||||
@@ -223,14 +226,14 @@ Function CreateDatabase(Val Token, Val Parent, Val Title, Val Properties = "") E
|
||||
// InProgress : checkbox
|
||||
// Quantity : number
|
||||
// Date : date
|
||||
// Status : Match
|
||||
// Status : Map
|
||||
// Аtoтиinный : green
|
||||
// Inactive : red
|
||||
// Архиin : yellow
|
||||
|
||||
// All pages created as children must have parent base properties
|
||||
|
||||
If Not TypeValue(Properties) = Type("Structure") And Not TypeValue(Properties) = Type("Match") Then
|
||||
If Not TypeOf(Properties) = Type("Structure") And Not TypeOf(Properties) = Type("Map") Then
|
||||
Properties = New Structure("Name", "title");
|
||||
EndIf;
|
||||
|
||||
@@ -254,7 +257,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Base - String - Database ID - base
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function GetDatabase(Val Token, Val Base) Export
|
||||
|
||||
@@ -276,11 +279,11 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Base - String - Target database ID - base
|
||||
// Properties - Map from KeyAndValue - New or modified database properties - props
|
||||
// Properties - Map of KeyAndValue - New or modified database properties - props
|
||||
// Title - String - New database title - title
|
||||
// Description - String - New database description - description
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function EditDatabaseProperties(Val Token, Val Base, Val Properties = "", Val Title = "", Val Description = "") Export
|
||||
|
||||
@@ -302,7 +305,7 @@ Function EditDatabaseProperties(Val Token, Val Base, Val Properties = "", Val Ti
|
||||
AddDatabaseDescription(Description, Parameters);
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Properties) = Type("Structure") Or TypeValue(Properties) = Type("Match") Then
|
||||
If TypeOf(Properties) = Type("Structure") Or TypeOf(Properties) = Type("Map") Then
|
||||
AddDatabaseProperties(Properties, Parameters);
|
||||
EndIf;
|
||||
|
||||
@@ -322,10 +325,10 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// Parent - String - Parent block or page ID - page
|
||||
// Block - String, Map From KeyAndValue - Block ID or block sample itself - block
|
||||
// Block - String, Map Of KeyAndValue - Block ID or block sample itself - block
|
||||
// InsertAfter - String - Block ID after which to insert the new one - prev
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function CreateBlock(Val Token, Val Parent, Val Block, Val InsertAfter = "") Export
|
||||
|
||||
@@ -334,14 +337,14 @@ Function CreateBlock(Val Token, Val Parent, Val Block, Val InsertAfter = "") Exp
|
||||
OPI_TypeConversion.GetLine(InsertAfter);
|
||||
OPI_TypeConversion.GetCollection(Block);
|
||||
|
||||
If TypeValue(Block) = Type("Array") Then
|
||||
If TypeOf(Block) = Type("Array") Then
|
||||
Block = Block[0];
|
||||
EndIf;
|
||||
|
||||
Headers = CreateRequestHeaders(Token);
|
||||
ConvertID(Parent);
|
||||
|
||||
If TypeValue(Block) = Type("String") Then
|
||||
If TypeOf(Block) = Type("String") Then
|
||||
ConvertID(Block);
|
||||
Block = ReturnBlock(Token, Block);
|
||||
EndIf;
|
||||
@@ -349,7 +352,7 @@ Function CreateBlock(Val Token, Val Parent, Val Block, Val InsertAfter = "") Exp
|
||||
BlockArray = New Array;
|
||||
BlockArray.Add(Block);
|
||||
|
||||
Parameters = New Match;
|
||||
Parameters = New Map;
|
||||
Parameters.Insert("children", BlockArray);
|
||||
|
||||
If ValueIsFilled(InsertAfter) Then
|
||||
@@ -363,14 +366,14 @@ Function CreateBlock(Val Token, Val Parent, Val Block, Val InsertAfter = "") Exp
|
||||
|
||||
EndFunction
|
||||
|
||||
// Inернуть блоto.
|
||||
// Return block.
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// BlockID - String - Block ID - block
|
||||
// OnlyBase - Boolean - True > service fields are deleted, only the block itself remains - core
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function ReturnBlock(Val Token, Val BlockID, Val OnlyBase = True) Export
|
||||
|
||||
@@ -398,7 +401,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// BlockID - String - Parent block ID - block
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function ReturnChildBlocks(Val Token, Val BlockID) Export
|
||||
|
||||
@@ -421,7 +424,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// BlockID - String - Block ID - block
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function DeleteBlock(Val Token, Val BlockID) Export
|
||||
|
||||
@@ -447,7 +450,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function UserList(Val Token) Export
|
||||
|
||||
@@ -467,7 +470,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// UserID - String - Target user ID - user
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Notion
|
||||
Function GetUserData(Val Token, Val UserID) Export
|
||||
|
||||
@@ -487,13 +490,13 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function CreateRequestHeaders(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization" , "Bearer " + Token);
|
||||
Headers.Insert("Notion-Version", "2022-06-28");
|
||||
|
||||
@@ -505,7 +508,7 @@ Procedure ConvertID(Identifier)
|
||||
|
||||
OPI_TypeConversion.GetLine(Identifier);
|
||||
|
||||
Identifier = StringReplace(Identifier, "-", "");
|
||||
Identifier = StrReplace(Identifier, "-", "");
|
||||
|
||||
EndProcedure
|
||||
|
||||
@@ -545,7 +548,7 @@ Procedure AddPageHeader(Val Title, MainStructure)
|
||||
SubordinateStructure = New Structure;
|
||||
DataStructure = New Structure;
|
||||
TextStructure = New Structure;
|
||||
Data array = New Array;
|
||||
DataArray = New Array;
|
||||
Title = "title";
|
||||
|
||||
TextStructure.Insert("content", Title);
|
||||
@@ -554,11 +557,11 @@ Procedure AddPageHeader(Val Title, MainStructure)
|
||||
DataStructure.Insert("text", TextStructure);
|
||||
DataStructure.Insert("type", "text");
|
||||
|
||||
Data array.Add(DataStructure);
|
||||
DataArray.Add(DataStructure);
|
||||
|
||||
SubordinateStructure.Insert("id" , Title);
|
||||
SubordinateStructure.Insert("type" , Title);
|
||||
SubordinateStructure.Insert(Title , Data array);
|
||||
SubordinateStructure.Insert(Title , DataArray);
|
||||
|
||||
MainStructure.Insert(Title, SubordinateStructure);
|
||||
|
||||
@@ -589,23 +592,23 @@ Procedure AddDatabaseProperties(Val Properties, MainStructure)
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
ParameterMap = New Match;
|
||||
ParameterMap = New Map;
|
||||
|
||||
For Each Property In Properties Do
|
||||
|
||||
If TypeValue(Property.Value) = Type("String") Then
|
||||
If TypeOf(Property.Value) = Type("String") Then
|
||||
|
||||
ParameterMap.Insert(Property.Key, New Structure(Property.Value, New Structure));
|
||||
ParameterMap.Insert(Property.TheKey, New Structure(Property.Value, New Structure));
|
||||
|
||||
ElsIf TypeValue(Property.Value) = Type("Structure")
|
||||
Or TypeValue(Property.Value) = Type("Match") Then
|
||||
ElsIf TypeOf(Property.Value) = Type("Structure")
|
||||
Or TypeOf(Property.Value) = Type("Map") Then
|
||||
|
||||
ValueSelection = FormSelectionValues(Property.Value);
|
||||
ParameterMap.Insert(Property.Key, New Structure("select", ValueSelection));
|
||||
ParameterMap.Insert(Property.TheKey, New Structure("select", ValueSelection));
|
||||
|
||||
Else
|
||||
|
||||
ParameterMap.Insert(Property.Key, Property.Value);
|
||||
ParameterMap.Insert(Property.TheKey, Property.Value);
|
||||
|
||||
EndIf;
|
||||
|
||||
@@ -621,8 +624,8 @@ Function FormSelectionValues(Val VariantStructure)
|
||||
|
||||
For Each Option In VariantStructure Do
|
||||
|
||||
OptionMap = New Match;
|
||||
OptionMap.Insert("name" , Option.Key);
|
||||
OptionMap = New Map;
|
||||
OptionMap.Insert("name" , Option.TheKey);
|
||||
OptionMap.Insert("color", Option.Value);
|
||||
|
||||
OptionArray.Add(OptionMap);
|
||||
@@ -642,7 +645,7 @@ Function FillDataBySchema(Val Scheme, Val Data, Val Token, Val ThisIsBase = True
|
||||
EndIf;
|
||||
|
||||
BaseFields = SchemaData["properties"];
|
||||
Properties = New Match;
|
||||
Properties = New Map;
|
||||
|
||||
If ValueIsFilled(BaseFields) Then
|
||||
|
||||
@@ -651,7 +654,7 @@ Function FillDataBySchema(Val Scheme, Val Data, Val Token, Val ThisIsBase = True
|
||||
FieldData = Field.Value;
|
||||
FieldType = FieldData["type"];
|
||||
|
||||
FillableData = Data.Get(Field.Key);
|
||||
FillableData = Data.Get(Field.TheKey);
|
||||
|
||||
If FillableData = Undefined Then
|
||||
Continue;
|
||||
@@ -723,7 +726,7 @@ Function ConvertValueByType(Val Type, Val Value)
|
||||
ElsIf Type = "checkbox" Then
|
||||
Return ConvertBoolean(Value);
|
||||
ElsIf Type = "url" Then
|
||||
Return ConvertLink(Value);
|
||||
Return ConvertURL(Value);
|
||||
ElsIf Type = "email" Then
|
||||
Return ConvertEmail(Value);
|
||||
ElsIf Type = "phone_number" Then
|
||||
@@ -738,7 +741,7 @@ Function ConvertHeader(Val Title)
|
||||
|
||||
DataStructure = New Structure;
|
||||
TextStructure = New Structure;
|
||||
Data array = New Array;
|
||||
DataArray = New Array;
|
||||
|
||||
TextStructure.Insert("content", Title);
|
||||
TextStructure.Insert("link" , Undefined);
|
||||
@@ -746,9 +749,9 @@ Function ConvertHeader(Val Title)
|
||||
DataStructure.Insert("type", "text");
|
||||
DataStructure.Insert("text", TextStructure);
|
||||
|
||||
Data array.Add(DataStructure);
|
||||
DataArray.Add(DataStructure);
|
||||
|
||||
Return New Structure("title", Data array);
|
||||
Return New Structure("title", DataArray);
|
||||
|
||||
EndFunction
|
||||
|
||||
@@ -804,7 +807,7 @@ Function ConvertDate(Val Date)
|
||||
|
||||
DateStructure = New Structure;
|
||||
|
||||
If Date = StartOfDay(Date) Then
|
||||
If Date = BegOfDay(Date) Then
|
||||
DateFormat = "DF=yyyy-MM-dd";
|
||||
Else
|
||||
DateFormat = "ISO8601Datetime";
|
||||
@@ -828,7 +831,7 @@ EndFunction
|
||||
|
||||
Function ConvertUsers(Val IDArray)
|
||||
|
||||
If Not TypeValue(IDArray) = Type("Array") Then
|
||||
If Not TypeOf(IDArray) = Type("Array") Then
|
||||
ArrayID_ = New Array;
|
||||
ArrayID_.Add(IDArray);
|
||||
IDArray = ArrayID_;
|
||||
@@ -857,7 +860,7 @@ Function ConvertFiles(Val FileMapping)
|
||||
|
||||
FileStructure = New Structure;
|
||||
FileStructure.Insert("type" , "external");
|
||||
FileStructure.Insert("name" , File.Key);
|
||||
FileStructure.Insert("name" , File.TheKey);
|
||||
FileStructure.Insert("external", New Structure("url", File.Value));
|
||||
|
||||
ArrayOfFiles.Add(FileStructure);
|
||||
@@ -872,7 +875,7 @@ Function ConvertBoolean(Val Boolean)
|
||||
Return New Structure("checkbox", Boolean);
|
||||
EndFunction
|
||||
|
||||
Function ConvertLink(Val URL)
|
||||
Function ConvertURL(Val URL)
|
||||
Return New Structure("url", URL);
|
||||
EndFunction
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_Notion</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы work with Notion (OPI)</value>
|
||||
<value>Notion methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Slack.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Slack.os
|
||||
// Library: Slack
|
||||
// CLI command: slack
|
||||
|
||||
@@ -29,10 +29,14 @@
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:Typo-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region ManagementAndSettings
|
||||
|
||||
@@ -42,7 +46,7 @@
|
||||
// Parameters:
|
||||
// Token - String - Bot token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetBotInformation(Val Token) Export
|
||||
|
||||
@@ -62,7 +66,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetWorkspaceList(Val Token, Val Cursor = "") Export
|
||||
|
||||
@@ -80,7 +84,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetUserList(Val Token, Val Cursor = "") Export
|
||||
|
||||
@@ -102,23 +106,23 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Channel - String - Channel ID - channel
|
||||
// Text - String - Message text - text
|
||||
// Sending date - Date - Sending date for delayed message - date
|
||||
// Blocks - Array of Structures - Array of block descriptions - blocks - JSON array of block descriptions
|
||||
// SendingDate - Date - Sending date for delayed message - date
|
||||
// Blocks - Array of Structure - Array of block descriptions - blocks - JSON array of block descriptions
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function SendMessage(Val Token, Val Channel, Val Text = "", Val Sending date = "", Val Blocks = "") Export
|
||||
Function SendMessage(Val Token, Val Channel, Val Text = "", Val SendingDate = "", Val Blocks = "") Export
|
||||
|
||||
String_ = "String";
|
||||
HasDate = ValueIsFilled(Sending date);
|
||||
HasDate = ValueIsFilled(SendingDate);
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
If ValueIsFilled(Blocks) And TypeValue(Blocks) = Type(String_) Then
|
||||
If ValueIsFilled(Blocks) And TypeOf(Blocks) = Type(String_) Then
|
||||
OPI_TypeConversion.GetCollection(Blocks);
|
||||
|
||||
If TypeValue(Blocks) = Type("Array") Then
|
||||
If TypeOf(Blocks) = Type("Array") Then
|
||||
|
||||
For N = 0 For Blocks.WithinBoundary() Do
|
||||
For N = 0 To Blocks.WithinBoundary() Do
|
||||
OPI_TypeConversion.GetCollection(Blocks[N]);
|
||||
EndDo;
|
||||
|
||||
@@ -134,7 +138,7 @@ Function SendMessage(Val Token, Val Channel, Val Text = "", Val Sending date = "
|
||||
If HasDate Then
|
||||
|
||||
URL = "https://slack.com/api/chat.scheduleMessage";
|
||||
OPI_Tools.AddField("post_at", Sending date, "Date", Parameters);
|
||||
OPI_Tools.AddField("post_at", SendingDate, "Date", Parameters);
|
||||
|
||||
Else
|
||||
|
||||
@@ -157,9 +161,9 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Text - String - Message text - text
|
||||
// User - String - User ID - user
|
||||
// Blocks - Array of Structures - Array of block descriptions - blocks - JSON array of block descriptions
|
||||
// Blocks - Array of Structure - Array of block descriptions - blocks - JSON array of block descriptions
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function SendEphemeralMessage(Val Token
|
||||
, Val Channel
|
||||
@@ -169,7 +173,7 @@ Function SendEphemeralMessage(Val Token
|
||||
|
||||
String_ = "String";
|
||||
|
||||
If ValueIsFilled(Blocks) And Not TypeValue(Blocks) = Type(String_) Then
|
||||
If ValueIsFilled(Blocks) And Not TypeOf(Blocks) = Type(String_) Then
|
||||
OPI_TypeConversion.GetArray(Blocks);
|
||||
EndIf;
|
||||
|
||||
@@ -197,9 +201,9 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Timestamp - String - Message timestamp - stamp
|
||||
// Text - String - New message text - text
|
||||
// BlockArray - Array of Structures - Array of block descriptions - blocks - JSON array of block descriptions
|
||||
// BlockArray - Array of Structure - Array of block descriptions - blocks - JSON array of block descriptions
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function EditMessage(Val Token, Val Channel, Val Timestamp, Val Text = "", Val BlockArray = "") Export
|
||||
|
||||
@@ -228,7 +232,7 @@ EndFunction
|
||||
// Timestamp - String - Timestamp or message ID - stamp
|
||||
// IsDelayed - Boolean - Indicator of deleting a delayed message - issheduled
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function DeleteMessage(Val Token, Val Channel, Val Timestamp, Val IsDelayed = False) Export
|
||||
|
||||
@@ -262,7 +266,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetDelayedMessageList(Val Token, Val Channel, Val Cursor = "") Export
|
||||
|
||||
@@ -287,7 +291,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Timestamp - String - Timestamp or message ID - stamp
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetMessageLink(Val Token, Val Channel, Val Timestamp) Export
|
||||
|
||||
@@ -313,7 +317,7 @@ EndFunction
|
||||
// Timestamp - String - Timestamp or message ID - stamp
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetMessageReplyList(Val Token, Val Channel, Val Timestamp, Val Cursor = "") Export
|
||||
|
||||
@@ -344,7 +348,7 @@ EndFunction
|
||||
// ExcludeArchived - Boolean - Indicator of excluding archived channels - notarchived
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetChannelList(Val Token, Val ExcludeArchived = False, Val Cursor = "") Export
|
||||
|
||||
@@ -369,7 +373,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetChannelUserList(Val Token, Val Channel, Val Cursor = "") Export
|
||||
|
||||
@@ -394,7 +398,7 @@ EndFunction
|
||||
// Name - String - Channel name - title
|
||||
// Private - Boolean - Create channel as private - private
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function CreateChannel(Val Token, Val Name, Val Private = False) Export
|
||||
|
||||
@@ -418,7 +422,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Channel - String - Channel ID - channel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function ArchiveChannel(Val Token, Val Channel) Export
|
||||
|
||||
@@ -435,7 +439,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Channel - String - Channel ID - channel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetChannel(Val Token, Val Channel) Export
|
||||
|
||||
@@ -452,7 +456,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Channel - String - Channel ID - channel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetChannelHistory(Val Token, Val Channel) Export
|
||||
|
||||
@@ -470,7 +474,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// ArrayOfUsers - Array Of String - User ID Array - users
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function InviteUsersToChannel(Val Token, Val Channel, Val ArrayOfUsers) Export
|
||||
|
||||
@@ -478,7 +482,7 @@ Function InviteUsersToChannel(Val Token, Val Channel, Val ArrayOfUsers) Export
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
OPI_TypeConversion.GetCollection(ArrayOfUsers);
|
||||
ArrayOfUsers = StrJoin(ArrayOfUsers, ",");
|
||||
ArrayOfUsers = StrConcat(ArrayOfUsers, ",");
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("channel", Channel , "String", Parameters);
|
||||
@@ -498,7 +502,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// User - String - User ID - user
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function KickUserFromChannel(Val Token, Val Channel, Val User) Export
|
||||
|
||||
@@ -522,7 +526,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Channel - String - Channel ID - channel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function JoinChannel(Val Token, Val Channel) Export
|
||||
|
||||
@@ -539,7 +543,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Channel - String - Channel ID - channel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function LeaveChannel(Val Token, Val Channel) Export
|
||||
|
||||
@@ -557,7 +561,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Topic - String - Channel topic - theme
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function SetChannelTopic(Val Token, Val Channel, Val Topic) Export
|
||||
|
||||
@@ -582,7 +586,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Purpose - String - Channel purpose - purpose
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function SetChannelGoal(Val Token, Val Channel, Val Purpose) Export
|
||||
|
||||
@@ -607,7 +611,7 @@ EndFunction
|
||||
// Channel - String - Channel ID - channel
|
||||
// Name - String - New channel name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function RenameChannel(Val Token, Val Channel, Val Name) Export
|
||||
|
||||
@@ -633,9 +637,9 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Bot token - token
|
||||
// ArrayOfUsers - Array of Strings - User ID Array - users
|
||||
// ArrayOfUsers - Array of String - User ID Array - users
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function OpenDialog(Val Token, Val ArrayOfUsers) Export
|
||||
|
||||
@@ -643,7 +647,7 @@ Function OpenDialog(Val Token, Val ArrayOfUsers) Export
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
OPI_TypeConversion.GetCollection(ArrayOfUsers);
|
||||
ArrayOfUsers = StrJoin(ArrayOfUsers, ",");
|
||||
ArrayOfUsers = StrConcat(ArrayOfUsers, ",");
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("users", ArrayOfUsers, "String", Parameters);
|
||||
@@ -661,7 +665,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// Dialog - String - Dialog ID - conv
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function CloseDialog(Val Token, Val Dialog) Export
|
||||
|
||||
@@ -683,7 +687,7 @@ EndFunction
|
||||
// Channel - String - Channel for selection - channel
|
||||
// PageNumber - Number, String - Page number - page
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetFilesList(Val Token, Val Channel = "", Val PageNumber = 1) Export
|
||||
|
||||
@@ -710,7 +714,7 @@ EndFunction
|
||||
// Title - String - File name in Slack - title
|
||||
// Channel - String - Channel ID - channel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function UploadFile(Val Token, Val File, Val FileName, Val Title, Val Channel = "") Export
|
||||
|
||||
@@ -737,7 +741,7 @@ Function UploadFile(Val Token, Val File, Val FileName, Val Title, Val Channel =
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Files = New Match;
|
||||
Files = New Map;
|
||||
Files.Insert(FileName, File);
|
||||
|
||||
Response = OPI_Tools.PostMultipart(URL, , Files, , Headers);
|
||||
@@ -762,7 +766,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// FileID - String - File identifier - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetFileData(Val Token, Val FileID) Export
|
||||
|
||||
@@ -780,7 +784,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// FileID - String - File identifier - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function DeleteFile(Val Token, Val FileID) Export
|
||||
|
||||
@@ -798,7 +802,7 @@ EndFunction
|
||||
// Token - String - User token - token
|
||||
// FileID - String - File identifier - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function MakeFilePublic(Val Token, Val FileID) Export
|
||||
|
||||
@@ -816,7 +820,7 @@ EndFunction
|
||||
// Token - String - User token - token
|
||||
// FileID - String - File identifier - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function MakeFilePrivate(Val Token, Val FileID) Export
|
||||
|
||||
@@ -839,7 +843,7 @@ EndFunction
|
||||
// Channel - String - Channel for selection - channel
|
||||
// Cursor - String - Pointer from the previous request, if the result rows > 100 - cursor
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetExternalFileList(Val Token, Val Channel = "", Val Cursor = "") Export
|
||||
|
||||
@@ -863,7 +867,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// FileID - String - File identifier - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function GetExternalFile(Val Token, Val FileID) Export
|
||||
|
||||
@@ -882,14 +886,14 @@ EndFunction
|
||||
// URL - String - URL to external file - url
|
||||
// Title - String - File title for Slack - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function AddExternalFile(Val Token, Val URL, Val Title) Export
|
||||
|
||||
String_ = "String";
|
||||
URL = "https://slack.com/api/files.remote.add";
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
UID = String(New UniqueIdentifier());
|
||||
UID = String(New UUID());
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("external_url", URL , String_, Parameters);
|
||||
@@ -910,7 +914,7 @@ EndFunction
|
||||
// FileID - String - File identifier - fileid
|
||||
// ChannelArray - Array Of String - Array of channels for sending - channels
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function SendExternalFile(Val Token, Val FileID, Val ChannelArray) Export
|
||||
|
||||
@@ -918,7 +922,7 @@ Function SendExternalFile(Val Token, Val FileID, Val ChannelArray) Export
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
|
||||
OPI_TypeConversion.GetCollection(ChannelArray);
|
||||
ChannelArray = StrJoin(ChannelArray, ",");
|
||||
ChannelArray = StrConcat(ChannelArray, ",");
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("file" , FileID , "String", Parameters);
|
||||
@@ -937,7 +941,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// FileID - String - File identifier - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Slack
|
||||
Function DeleteExternalFile(Val Token, Val FileID) Export
|
||||
|
||||
@@ -959,13 +963,13 @@ EndFunction
|
||||
// URL - String - Image URL - picture
|
||||
// AlternateText - String - Alternate text of the image - alt
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Image block
|
||||
Function GenerateImageBlock(Val URL, Val AlternateText = "") Export
|
||||
|
||||
String_ = "String";
|
||||
|
||||
Block = New Match;
|
||||
Block = New Map;
|
||||
OPI_Tools.AddField("type" , "image" , String_, Block);
|
||||
OPI_Tools.AddField("image_url", URL , String_, Block);
|
||||
OPI_Tools.AddField("alt_text" , AlternateText , String_, Block);
|
||||
@@ -978,13 +982,13 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function GetAuthorizationHeader(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "Bearer " + Token);
|
||||
Return Headers;
|
||||
|
||||
@@ -993,7 +997,7 @@ EndFunction
|
||||
Function DialogManagement(Val Token, Val Channel, Val URL, Val RequestType = "POST")
|
||||
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
RequestType = inReg(RequestType);
|
||||
RequestType = Upper(RequestType);
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("channel", Channel, "String", Parameters);
|
||||
@@ -1011,7 +1015,7 @@ EndFunction
|
||||
Function FileManagement(Val Token, Val FileID, Val URL, Val RequestType = "POST")
|
||||
|
||||
Headers = GetAuthorizationHeader(Token);
|
||||
RequestType = inReg(RequestType);
|
||||
RequestType = Upper(RequestType);
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("file", FileID , "String", Parameters);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Telegram.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Telegram.os
|
||||
// Library: Telegram
|
||||
// CLI command: telegram
|
||||
|
||||
@@ -32,20 +32,24 @@
|
||||
// BSLLS:UnreachableCode-off
|
||||
// BSLLS:CommentedCode-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region DataRetrievalAndSettings
|
||||
|
||||
// Get bot information
|
||||
// Inыполняет запроwith /getMe, inозinращающий базоinую информацию о боте: имя, id, inозможноwithть dобаinлять бота in группы и т.d.
|
||||
// Executes the /getMe request, returning basic bot information: name, id, ability to add the bot to groups, etc..
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Bot token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function GetBotInformation(Val Token) Export
|
||||
|
||||
@@ -66,7 +70,7 @@ EndFunction
|
||||
// Timeout - String, Number - Waiting time for new events - timeout
|
||||
// Offset - String, Number - Offset in the list of received messages - offset
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function GetUpdates(Val Token, Val Timeout = 0, Val Offset = "") Export
|
||||
|
||||
@@ -88,9 +92,9 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Token - String - Bot token - token
|
||||
// URL - String - Address processing запроwithоin от Telegram (with https:) - url
|
||||
// URL - String - Request handling address from Telegram (with https:) - url
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SetWebhook(Val Token, Val URL) Export
|
||||
|
||||
@@ -112,7 +116,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Bot token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function DeleteWebhook(Val Token) Export
|
||||
|
||||
@@ -132,7 +136,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// FileID - String - File ID for downloading - fileid
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function DownloadFile(Val Token, Val FileID) Export
|
||||
|
||||
@@ -166,8 +170,8 @@ EndFunction
|
||||
// DataString - String - Query from Telegram.WebApp.initData
|
||||
// Token - String - Bot token
|
||||
//
|
||||
// Return value:
|
||||
// Map from String - Map of data with the result of verification in the passed field
|
||||
// Returns:
|
||||
// Map of String - Map of data with the result of verification in the passed field
|
||||
Function ProcessTMAData(Val DataString, Val Token) Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
@@ -175,46 +179,46 @@ Function ProcessTMAData(Val DataString, Val Token) Export
|
||||
|
||||
DataString = DecodeString(DataString, StringEncodingMethod.URLencoding);
|
||||
DataStructure = OPI_Tools.RequestParametersToMatch(DataString);
|
||||
Key = "WebAppData";
|
||||
TheKey = "WebAppData";
|
||||
Hash = "";
|
||||
BinaryKey = GetBinaryDataFromString(Key);
|
||||
BinaryKey = GetBinaryDataFromString(TheKey);
|
||||
|
||||
Result = OPI_Cryptography.HMACSHA256(BinaryKey, GetBinaryDataFromString(Token));
|
||||
|
||||
TValue = New ValueTable;
|
||||
TValue.Columns.Add("Key");
|
||||
TValue.Columns.Add("TheKey");
|
||||
TValue.Columns.Add("Value");
|
||||
|
||||
For Each Data In DataStructure Do
|
||||
|
||||
NewLine = TValue.Add();
|
||||
NewLine.Key = Data.Key;
|
||||
NewLine.TheKey = Data.TheKey;
|
||||
NewLine.Value = Data.Value;
|
||||
|
||||
EndDo;
|
||||
|
||||
TValue.Sort("Key");
|
||||
TValue.Sort("TheKey");
|
||||
|
||||
ReturnMapping = New Match;
|
||||
ReturnMapping = New Map;
|
||||
DCS = "";
|
||||
|
||||
For Each DataString In TValue Do
|
||||
|
||||
If DataString.Key <> "hash" Then
|
||||
DCS = DCS + DataString.Key + "=" + DataString.Value + Symbols.PS;
|
||||
ReturnMapping.Insert(DataString.Key, DataString.Value);
|
||||
If DataString.TheKey <> "hash" Then
|
||||
DCS = DCS + DataString.TheKey + "=" + DataString.Value + Chars.PS;
|
||||
ReturnMapping.Insert(DataString.TheKey, DataString.Value);
|
||||
Else
|
||||
Hash = DataString.Value;
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
DCS = Left(DCS, StrLength(DCS) - 1);
|
||||
DCS = Left(DCS, StrLen(DCS) - 1);
|
||||
Signature = OPI_Cryptography.HMACSHA256(Result, GetBinaryDataFromString(DCS));
|
||||
|
||||
Final = GetHexStringFromBinaryData(Signature);
|
||||
|
||||
If Final = inReg(Hash) Then
|
||||
If Final = Upper(Hash) Then
|
||||
Response = True;
|
||||
Else
|
||||
Response = False;
|
||||
@@ -238,9 +242,9 @@ EndFunction
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// Text - String - Message text - text
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendTextMessage(Val Token
|
||||
, Val ChatID
|
||||
@@ -274,9 +278,9 @@ EndFunction
|
||||
// Text - String - Message text - text
|
||||
// Image - BinaryData,String - Image file - picture
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendImage(Val Token
|
||||
, Val ChatID
|
||||
@@ -298,9 +302,9 @@ EndFunction
|
||||
// Text - String - Message text - text
|
||||
// Video - BinaryData,String - Video file - video
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendVideo(Val Token
|
||||
, Val ChatID
|
||||
@@ -322,9 +326,9 @@ EndFunction
|
||||
// Text - String - Message text - text
|
||||
// Audio - BinaryData,String - Audio file - audio
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendAudio(Val Token
|
||||
, Val ChatID
|
||||
@@ -346,9 +350,9 @@ EndFunction
|
||||
// Text - String - Message text - text
|
||||
// Document - BinaryData,String - Document file - doc
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendDocument(Val Token
|
||||
, Val ChatID
|
||||
@@ -370,9 +374,9 @@ EndFunction
|
||||
// Text - String - Message text - text
|
||||
// GIF - BinaryData,String - GIF file - gif
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendGif(Val Token
|
||||
, Val ChatID
|
||||
@@ -392,11 +396,11 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// Text - String - Message text - text
|
||||
// FileMapping - Map from String - File collection - media - File JSON or path to .json
|
||||
// FileMapping - Map of String - File collection - media - File JSON or path to .json
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
// Markup - String - View processing textа (HTML, Markdown, MarkdownV2) - parsemode
|
||||
// Markup - String - Text processing type (HTML, Markdown, MarkdownV2) - parsemode
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendMediaGroup(Val Token
|
||||
, Val ChatID
|
||||
@@ -406,7 +410,7 @@ Function SendMediaGroup(Val Token
|
||||
, Val Markup = "Markdown") Export
|
||||
|
||||
// FileMapping
|
||||
// Key - File, Value - Type
|
||||
// TheKey - File, Value - Type
|
||||
// Types: audio, document, photo, video
|
||||
// Different types cannot be mixed!
|
||||
|
||||
@@ -447,7 +451,7 @@ EndFunction
|
||||
// Longitude - String, Number - Geographic longitude - long
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendLocation(Val Token, Val ChatID, Val Latitude, Val Longitude, Val Keyboard = "") Export
|
||||
|
||||
@@ -478,13 +482,13 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// Name - String - Contact name - name
|
||||
// Last name - String - Contact last name - surname
|
||||
// LastName - String - Contact last name - surname
|
||||
// Phone - String - Contact phone number - phone
|
||||
// Keyboard - String - See GenerateKeyboardFromArray - keyboard - Keyboard JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendContact(Val Token, Val ChatID, Val Name, Val Last name, Val Phone, Val Keyboard = "") Export
|
||||
Function SendContact(Val Token, Val ChatID, Val Name, Val LastName, Val Phone, Val Keyboard = "") Export
|
||||
|
||||
String_ = "String";
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
@@ -495,7 +499,7 @@ Function SendContact(Val Token, Val ChatID, Val Name, Val Last name, Val Phone,
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("parse_mode" , "Markdown", String_ , Parameters);
|
||||
OPI_Tools.AddField("first_name" , Name , String_ , Parameters);
|
||||
OPI_Tools.AddField("last_name" , Last name , String_ , Parameters);
|
||||
OPI_Tools.AddField("last_name" , LastName , String_ , Parameters);
|
||||
OPI_Tools.AddField("phone_number", Phone , String_ , Parameters);
|
||||
OPI_Tools.AddField("reply_markup", Keyboard, "FileString", Parameters);
|
||||
|
||||
@@ -514,10 +518,10 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// Question - String - Poll question - question
|
||||
// AnswersArray - Array of Strings - Array of answer options - options
|
||||
// AnswersArray - Array of String - Array of answer options - options
|
||||
// Anonymous - Boolean - Poll anonymity - anonymous
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function SendPoll(Val Token, Val ChatID, Val Question, Val AnswersArray, Val Anonymous = True) Export
|
||||
|
||||
@@ -552,7 +556,7 @@ EndFunction
|
||||
// FromID - String, Number - Chat ID of the original message - from
|
||||
// ToID - String, Number - Target chat ID or ChatID*TopicID - to
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function ForwardMessage(Val Token, Val OriginalID, Val FromID, Val ToID) Export
|
||||
|
||||
@@ -579,11 +583,11 @@ EndFunction
|
||||
// Generates a simple JSON keyboard from an array of buttons for a message or bottom panel
|
||||
//
|
||||
// Parameters:
|
||||
// ButtonArray - Array of Strings - Array of buttons - buttons
|
||||
// ButtonArray - Array of String - Array of buttons - buttons
|
||||
// UnderMessage - Boolean - Keyboard under the message or on the bottom panel - under
|
||||
// OneByOne - Boolean - True > buttons are displayed in a column, False > in a row - column
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - Keyboard JSON
|
||||
Function FormKeyboardFromButtonArray(Val ButtonArray
|
||||
, Val UnderMessage = False
|
||||
@@ -623,7 +627,7 @@ EndFunction
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// UserID - String, Number - Target user ID - user
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function Ban(Val Token, Val ChatID, Val UserID) Export
|
||||
|
||||
@@ -651,7 +655,7 @@ EndFunction
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// UserID - String, Number - Target user ID - user
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function Unban(Val Token, Val ChatID, Val UserID) Export
|
||||
|
||||
@@ -679,10 +683,10 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
|
||||
// Title - String - Invitation title - title
|
||||
// ExpirationDate - Date - Date of end жfromни withwithылtoи (withoutwithрочно, еwithли не уtoазано) - expire
|
||||
// UserLimit - Number - Limit пользоinателей (беwithtoонечно, еwithли не уtoазано) - limit
|
||||
// ExpirationDate - Date - Link expiration date (permanent if not specified) - expire
|
||||
// UserLimit - Number - User limit (infinite if not specified) - limit
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function CreateInvitationLink(Val Token
|
||||
, Val ChatID
|
||||
@@ -716,7 +720,7 @@ EndFunction
|
||||
// ChatID - String, Number - Target chat ID - chat
|
||||
// MessageID - String, Number - Target message ID - message
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function PinMessage(Val Token, Val ChatID, Val MessageID) Export
|
||||
|
||||
@@ -745,7 +749,7 @@ EndFunction
|
||||
// ChatID - String, Number - Target chat ID - chat
|
||||
// MessageID - String, Number - Target message ID - message
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function UnpinMessage(Val Token, Val ChatID, Val MessageID) Export
|
||||
|
||||
@@ -772,7 +776,7 @@ EndFunction
|
||||
// Token - String - Bot token - token
|
||||
// ChatID - String, Number - Target chat ID - chat
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function GetParticipantCount(Val Token, Val ChatID) Export
|
||||
|
||||
@@ -800,7 +804,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Key > ID, Value > Emoji
|
||||
Function GetAvatarIconList(Val Token) Export
|
||||
|
||||
@@ -815,7 +819,7 @@ Function GetAvatarIconList(Val Token) Export
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
Collection = New Match;
|
||||
Collection = New Map;
|
||||
|
||||
For Each Icon In Icons Do
|
||||
Collection.Insert(Icon["custom_emoji_id"], Icon["emoji"]);
|
||||
@@ -834,7 +838,7 @@ EndFunction
|
||||
// Title - String - Thread title - title
|
||||
// IconID - String - See GetAvatarIconList - icon
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function CreateForumThread(Val Token, Val ChatID, Val Title, Val IconID = "") Export
|
||||
Return ForumTopicManagement(Token, ChatID, Title, IconID);
|
||||
@@ -850,7 +854,7 @@ EndFunction
|
||||
// Title - String - New title - title
|
||||
// IconID - String - See GetAvatarIconList - icon
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function EditForumTopic(Val Token
|
||||
, Val ChatID
|
||||
@@ -869,7 +873,7 @@ EndFunction
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
// ThreadID - String, Number - Thread ID - topic
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function CloseForumThread(Val Token, Val ChatID, Val ThreadID = "") Export
|
||||
Return ManageForumThreadState(Token, ChatID, 2, ThreadID);
|
||||
@@ -883,7 +887,7 @@ EndFunction
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
// ThreadID - String, Number - Thread ID - topic
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function OpenForumThread(Val Token, Val ChatID, Val ThreadID = "") Export
|
||||
Return ManageForumThreadState(Token, ChatID, 1, ThreadID);
|
||||
@@ -897,7 +901,7 @@ EndFunction
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
// ThreadID - String, Number - Thread ID - topic
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function DeleteForumTopic(Val Token, Val ChatID, Val ThreadID) Export
|
||||
Return ManageForumThreadState(Token, ChatID, 3, ThreadID);
|
||||
@@ -910,7 +914,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function HideMainForumTopic(Val Token, Val ChatID) Export
|
||||
Return ManageMainTopicVisibility(Token, ChatID, True);
|
||||
@@ -923,7 +927,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function ShowMainForumTopic(Val Token, Val ChatID) Export
|
||||
Return ManageMainTopicVisibility(Token, ChatID, False);
|
||||
@@ -937,7 +941,7 @@ EndFunction
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
// Title - String - New main thread name - title
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function EditMainForumTopicName(Val Token, Val ChatID, Val Title) Export
|
||||
|
||||
@@ -963,7 +967,7 @@ EndFunction
|
||||
// ChatID - String, Number - Thread chat ID - forum
|
||||
// ThreadID - String, Number - Thread ID. Main if not filled - topic
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from Telegram
|
||||
Function ClearThreadPinnedMessagesList(Val Token, Val ChatID, Val ThreadID = "") Export
|
||||
|
||||
@@ -992,7 +996,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function SendFile(Val Token, Val ChatID, Val Text, Val File, Val View, Val Keyboard, Val Markup)
|
||||
|
||||
@@ -1154,27 +1158,27 @@ Procedure FormMediaArray(Val FileMapping, Val Text, FileStructure, Media)
|
||||
OPI_TypeConversion.GetCollection(FileMapping);
|
||||
OPI_TypeConversion.GetLine(Text);
|
||||
|
||||
If TypeValue(FileMapping) <> Type("Match") Then
|
||||
// !OInt Raise("Failed to Retrieve Information from JSON media!");
|
||||
If TypeOf(FileMapping) <> Type("Map") Then
|
||||
// !OInt RaiseException("Failed to get information from json media!");
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
For Each CurrentFile In FileMapping Do
|
||||
|
||||
If Not TypeValue(CurrentFile.Key) = Type("BinaryData") Then
|
||||
If Not TypeOf(CurrentFile.TheKey) = Type("BinaryData") Then
|
||||
|
||||
Binary = CurrentFile.Key;
|
||||
Binary = CurrentFile.TheKey;
|
||||
OPI_TypeConversion.GetBinaryData(Binary);
|
||||
|
||||
ThisFile = New File(CurrentFile.Key);
|
||||
ThisFile = New File(CurrentFile.TheKey);
|
||||
MediaName = CurrentFile.Value
|
||||
+ String(Counter)
|
||||
+ ?(CurrentFile.Value = "document", ThisFile.Extension, "");
|
||||
|
||||
FullMediaName = StringReplace(MediaName, ".", "___");
|
||||
FullMediaName = StrReplace(MediaName, ".", "___");
|
||||
|
||||
Else
|
||||
Binary = CurrentFile.Key;
|
||||
Binary = CurrentFile.TheKey;
|
||||
MediaName = CurrentFile.Value + String(Counter);
|
||||
FullMediaName = MediaName;
|
||||
EndIf;
|
||||
@@ -1238,7 +1242,7 @@ EndProcedure
|
||||
|
||||
Procedure ConvertFileData(File, Extension, View)
|
||||
|
||||
If Not TypeValue(File) = Type("BinaryData") Then
|
||||
If Not TypeOf(File) = Type("BinaryData") Then
|
||||
|
||||
CurrentFile = New File(File);
|
||||
Extension = ?(View = "document", CurrentFile.Extension, Extension);
|
||||
@@ -1246,7 +1250,7 @@ Procedure ConvertFileData(File, Extension, View)
|
||||
|
||||
EndIf;
|
||||
|
||||
Extension = StringReplace(Extension, ".", "___");
|
||||
Extension = StrReplace(Extension, ".", "___");
|
||||
|
||||
EndProcedure
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_Telegram</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы интеграции with Telegram (OPI)</value>
|
||||
<value>Telegram integration methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
474
src/en/OPI/src/CommonModules/OPI_TestDataRetrieval/Module.bsl
Normal file
474
src/en/OPI/src/CommonModules/OPI_TestDataRetrieval/Module.bsl
Normal file
@@ -0,0 +1,474 @@
|
||||
//
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2023 Anton Tsitavets
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UsingHardcodePath-off
|
||||
// BSLLS:Typo-off
|
||||
// BSLLS:DeprecatedMessage-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
// BSLLS:ExecuteExternalCodeInCommonModule-off
|
||||
// BSLLS:DuplicateStringLiteral-off
|
||||
|
||||
//@skip-check use-non-recommended-method
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check undefined-function-or-procedure
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "./internal"
|
||||
// #Use asserts
|
||||
|
||||
#Region Internal
|
||||
|
||||
Function GetTestingSectionMapping() Export
|
||||
|
||||
StandardDependencies = "[Decode, Build]";
|
||||
GoogleDependencies = "Testing-GoogleWorkspace";
|
||||
|
||||
Sections = New Structure;
|
||||
Sections.Insert("Telegram" , StandardDependencies);
|
||||
Sections.Insert("VK" , StandardDependencies);
|
||||
Sections.Insert("Viber" , StandardDependencies);
|
||||
Sections.Insert("Twitter" , StandardDependencies);
|
||||
Sections.Insert("YandexDisk" , StandardDependencies);
|
||||
Sections.Insert("GoogleWorkspace", StandardDependencies);
|
||||
Sections.Insert("GoogleCalendar" , GoogleDependencies);
|
||||
Sections.Insert("GoogleDrive" , GoogleDependencies);
|
||||
Sections.Insert("GoogleSheets" , GoogleDependencies);
|
||||
Sections.Insert("Notion" , StandardDependencies);
|
||||
Sections.Insert("Slack" , StandardDependencies);
|
||||
Sections.Insert("Airtable" , StandardDependencies);
|
||||
Sections.Insert("Dropbox" , StandardDependencies);
|
||||
|
||||
Return Sections;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetTestTable() Export
|
||||
|
||||
Telegram = "Telegram";
|
||||
VKontakte = "VK";
|
||||
YDisk = "YandexDisk";
|
||||
Calendar = "GoogleCalendar";
|
||||
Twitter = "Twitter";
|
||||
Viber = "Viber";
|
||||
Drive = "GoogleDrive";
|
||||
VSpace = "GoogleWorkspace";
|
||||
Notion = "Notion";
|
||||
Slack = "Slack";
|
||||
Tables = "GoogleSheets";
|
||||
AirT = "Airtable";
|
||||
Dropbox = "Dropbox";
|
||||
|
||||
TestTable = New ValueTable;
|
||||
TestTable.Columns.Add("Method");
|
||||
TestTable.Columns.Add("Synonym");
|
||||
TestTable.Columns.Add("Section");
|
||||
|
||||
NewTest(TestTable, "TelegramAPI_GetBotInfo" , "Get bot information" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetUpdates" , "Get updates" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SetWebhook" , "Set Webhook" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendTextMessage" , "Send text message" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendImage" , "Send image" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendVideo" , "Send video" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendAudio" , "Send audio" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendDocument" , "Send document" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendGIF" , "Send GIF" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendMediaGroup" , "Send mediagroup" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendLocation" , "Send location" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendContact" , "Send contact" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_SendPoll" , "Send poll" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_ForwardMessage" , "Forward message" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_BanUnban" , "Ban/Unban" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_CreateInvitationLink" , "Create invitation link" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_PinUnpinMessage" , "Pin/Unpin message" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetMemberCount" , "Get participant count" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_GetForumAvatarsList", "Get forum avatars list", Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_CreateDeleteForumTopic" , "Create/Delete forum topic" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_ChangeMainTopicName" , "Change main topic name" , Telegram);
|
||||
NewTest(TestTable, "TelegramAPI_HideShowMainTopic" , "Hide/Show main topic" , Telegram);
|
||||
|
||||
NewTest(TestTable, "VKAPI_CreateTokenLink" , "Create token retrieval link", VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateDeletePost" , "Create/Delete post" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateCompositePost" , "Create/Delete composite post" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreatePoll" , "Create poll" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_SaveDeleteImage" , "Add/Delete image" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateStory" , "Create story" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_DiscussionMethods" , "Actions with discussions" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_LikeRepostComment" , "Like/Repost/Comment" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetStatistics" , "Get statistics" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetPostStatistics" , "Get post statistics" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateAdCampaign" , "Create advertising campaign" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_SendMessage" , "Send message" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetProductCategories" , "Get product categories" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateProductSelection" , "Create product and selection" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_CreateProductWithProperties" , "Create product with properties" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetProductList" , "Get product list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetSelectionList" , "Get selection list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetPropertyList" , "Get property list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_GetOrderList" , "Get order list" , VKontakte);
|
||||
NewTest(TestTable, "VKAPI_UploadVideo" , "Upload video" , VKontakte);
|
||||
|
||||
NewTest(TestTable, "YDisk_GetDiskInfo" , "Get disk information" , YDisk);
|
||||
NewTest(TestTable, "YDisk_CreateFolder" , "Create folder" , YDisk);
|
||||
NewTest(TestTable, "YDisk_UploadByUrlAndGetObject", "Upload by URL and get" , YDisk);
|
||||
NewTest(TestTable, "YDisk_UploadDeleteFile" , "Upload/Delete file" , YDisk);
|
||||
NewTest(TestTable, "YDisk_CreateObjectCopy" , "Create object copy" , YDisk);
|
||||
NewTest(TestTable, "YDisk_GetDownloadLink" , "Get download link" , YDisk);
|
||||
NewTest(TestTable, "YDisk_GetFileList" , "Get list of files" , YDisk);
|
||||
NewTest(TestTable, "YDisk_MoveObject" , "Move object" , YDisk);
|
||||
NewTest(TestTable, "YDisk_PublicObjectActions" , "Actions with public objects", YDisk);
|
||||
NewTest(TestTable, "YDisk_GetPublishedList" , "Get published list" , YDisk);
|
||||
|
||||
NewTest(TestTable, "GV_GetAuthorizationLink" , "Get authorization link" , VSpace);
|
||||
NewTest(TestTable, "GV_GetToken" , "Get token" , VSpace);
|
||||
NewTest(TestTable, "GV_UpdateToken" , "Refresh token" , VSpace);
|
||||
|
||||
NewTest(TestTable, "GC_GetCalendarList" , "Get list of calendars" , Calendar);
|
||||
NewTest(TestTable, "GC_CreateDeleteCalendar" , "Create/Delete calendar" , Calendar);
|
||||
NewTest(TestTable, "GC_CreateDeleteEvent" , "Create/Delete event" , Calendar);
|
||||
NewTest(TestTable, "GC_GetEventList" , "Get list of events" , Calendar);
|
||||
|
||||
NewTest(TestTable, "GD_GetCatalogList" , "Get list of directories" , Drive);
|
||||
NewTest(TestTable, "GD_UploadDeleteFile" , "Upload/Delete file" , Drive);
|
||||
NewTest(TestTable, "GD_CreateDeleteComment" , "Create/Delete Comment" , Drive);
|
||||
NewTest(TestTable, "GD_CreateCatalog" , "Create/Delete catalog" , Drive);
|
||||
|
||||
NewTest(TestTable, "GT_CreateTable" , "Create table" , Tables);
|
||||
NewTest(TestTable, "GT_GetTable" , "Get table" , Tables);
|
||||
NewTest(TestTable, "GT_FillClearCells" , "Fill/Clear cells" , Tables);
|
||||
|
||||
NewTest(TestTable, "Twitter_GetAuthorizationLink" , "Get authorization link" , Twitter);
|
||||
NewTest(TestTable, "Twitter_UpdateToken" , "Refresh token" , Twitter);
|
||||
NewTest(TestTable, "Twitter_CreateTextTweet" , "Text tweet" , Twitter);
|
||||
NewTest(TestTable, "Twitter_CreateTweetWithImage" , "Tweet with image" , Twitter);
|
||||
NewTest(TestTable, "Twitter_CreateTweetWithVideo" , "Tweet with video" , Twitter);
|
||||
NewTest(TestTable, "Twitter_CreateTweetWithGif" , "Tweet with gif" , Twitter);
|
||||
NewTest(TestTable, "Twitter_CreateTweetWithPoll" , "Tweet with poll" , Twitter);
|
||||
|
||||
NewTest(TestTable, "Viber_GetChannelInfo" , "Get channel info" , Viber);
|
||||
NewTest(TestTable, "Viber_GetUserData" , "Get user data" , Viber);
|
||||
NewTest(TestTable, "Viber_GetOnlineUsers" , "Get online users" , Viber);
|
||||
NewTest(TestTable, "Viber_SendTextMessage" , "Send text message" , Viber);
|
||||
NewTest(TestTable, "Viber_SendImage" , "Send image" , Viber);
|
||||
NewTest(TestTable, "Viber_SendFile" , "SendFile" , Viber);
|
||||
NewTest(TestTable, "Viber_SendContact" , "Send contact" , Viber);
|
||||
NewTest(TestTable, "Viber_SendLocation" , "SendLocation" , Viber);
|
||||
NewTest(TestTable, "Viber_SendLink" , "SendLink" , Viber);
|
||||
|
||||
NewTest(TestTable, "Notion_CreatePage" , "Create page" , Notion);
|
||||
NewTest(TestTable, "Notion_CreateEditDatabase" , "Create/Edit database" , Notion);
|
||||
NewTest(TestTable, "Notion_GetPageInfo" , "Get page info" , Notion);
|
||||
NewTest(TestTable, "Notion_GetDatabaseInfo" , "Get database info" , Notion);
|
||||
NewTest(TestTable, "Notion_CreatePageInDatabase" , "Create page in database" , Notion);
|
||||
NewTest(TestTable, "Notion_EditPageProperties" , "Edit page properties" , Notion);
|
||||
NewTest(TestTable, "Notion_CreateDeleteBlock" , "Create/Delete block" , Notion);
|
||||
NewTest(TestTable, "Notion_GetUsers" , "Get users" , Notion);
|
||||
NewTest(TestTable, "Notion_GetUserData" , "Get user data" , Notion);
|
||||
|
||||
NewTest(TestTable, "Slack_GetBotInfo" , "Get bot information" , Slack);
|
||||
NewTest(TestTable, "Slack_GetUserList" , "Get user list" , Slack);
|
||||
NewTest(TestTable, "Slack_GetRegionList" , "Get region list" , Slack);
|
||||
NewTest(TestTable, "Slack_SendDeleteMessage" , "Send/Delete message" , Slack);
|
||||
NewTest(TestTable, "Slack_SendDeleteEphemeral" , "Send/Delete ephemeral" , Slack);
|
||||
NewTest(TestTable, "Slack_GetScheduledMessages" , "Get scheduled messages" , Slack);
|
||||
NewTest(TestTable, "Slack_CreateArchiveChannel" , "Create/Archive channel" , Slack);
|
||||
NewTest(TestTable, "Slack_GetChannelList" , "Get channel list" , Slack);
|
||||
NewTest(TestTable, "Slack_OpenCloseDialog" , "Open/Close dialog" , Slack);
|
||||
NewTest(TestTable, "Slack_GetFileList" , "Get list of files" , Slack);
|
||||
NewTest(TestTable, "Slack_UploadDeleteFile" , "Upload/Delete file" , Slack);
|
||||
NewTest(TestTable, "Slack_GetExternalFileList" , "Get external file list" , Slack);
|
||||
NewTest(TestTable, "Slack_UploadDeleteExternalFile" , "Upload/Delete external file" , Slack);
|
||||
|
||||
NewTest(TestTable, "AT_CreateDatabase" , "Create/Edit database" , AirT);
|
||||
NewTest(TestTable, "AT_CreateTable" , "Create/Edit table" , AirT);
|
||||
NewTest(TestTable, "AT_CreateField" , "Create/Edit field" , AirT);
|
||||
NewTest(TestTable, "AT_CreateDeleteRecords" , "Create/Delete records" , AirT);
|
||||
|
||||
NewTest(TestTable, "DropboxAPI_GetUpdateToken" , "Get/Update token" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_UploadFile" , "Upload file" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_UploadFileByURL" , "Upload file by URL" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_CreateFolder" , "Create folder" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_CreateDeleteTag" , "Create/Delete tag" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_GetAccount" , "Get account data" , Dropbox);
|
||||
NewTest(TestTable, "DropboxAPI_AccessManagement" , "Access management" , Dropbox);
|
||||
|
||||
Return TestTable;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ExpectsThat(Value) Export
|
||||
|
||||
Try
|
||||
|
||||
Module = GetCommonModule("UTest");
|
||||
Awaiting = TypeOf(Module) = Type("CommonModule");
|
||||
Return Module.ExpectsThat(Value);
|
||||
|
||||
Except
|
||||
Return Awaiting.What(Value);
|
||||
EndTry;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormYAXTests() Export
|
||||
|
||||
Module = GetCommonModule("UTTests");
|
||||
Sections = GetTestingSectionMapping();
|
||||
TestTable = GetTestTable();
|
||||
|
||||
For Each Section In Sections Do
|
||||
|
||||
CurrentSection = Section.TheKey;
|
||||
Filter = New Structure("Section", CurrentSection);
|
||||
SectionTests = TestTable.FindLines(Filter);
|
||||
|
||||
Set = Module.AddTestSet(CurrentSection);
|
||||
|
||||
For Each Test In SectionTests Do
|
||||
Set.AddServerTest(Test.Method, Test.Synonym);
|
||||
EndDo;
|
||||
|
||||
EndDo;
|
||||
|
||||
Return "";
|
||||
|
||||
EndFunction
|
||||
|
||||
Function FormAssertsTests() Export
|
||||
|
||||
TestTable = GetTestTable();
|
||||
ArrayOfTests = New Array;
|
||||
|
||||
For Each Test In TestTable Do
|
||||
ArrayOfTests.Add(Test.Method);
|
||||
EndDo;
|
||||
|
||||
Return ArrayOfTests;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetParameter(Parameter) Export
|
||||
|
||||
Path = DataFilePath();
|
||||
Return GetValueFromFile(Parameter, Path);
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetBinary(Parameter) Export
|
||||
|
||||
Path = DataFilePath();
|
||||
LocalParameter = Parameter + "Local";
|
||||
MainValue = GetValueFromFile(Parameter , Path);
|
||||
LocalValue = GetValueFromFile(LocalParameter, Path);
|
||||
|
||||
LocalFile = New File(LocalValue);
|
||||
|
||||
If LocalFile.Exists() Then
|
||||
Value = New BinaryData(LocalValue);
|
||||
Else
|
||||
Value = MainValue;
|
||||
EndIf;
|
||||
|
||||
If TypeOf(Value) = Type("String") Then
|
||||
Value = GetFilePath(Value, LocalParameter);
|
||||
EndIf;
|
||||
|
||||
Return Value;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetFilePath(Val Path, LocalParameter, Val SaveLocally = True) Export
|
||||
|
||||
If StrFind(Path, "http") > 0
|
||||
Or StrFind(Path, "www") > 0 Then
|
||||
|
||||
AndVF = GetTempFileName();
|
||||
CopyFile(Path, AndVF);
|
||||
Path = AndVF;
|
||||
Binary = New BinaryData(Path);
|
||||
|
||||
If SaveLocally Then
|
||||
WriteParameter(LocalParameter, AndVF);
|
||||
Else
|
||||
DeleteFiles(AndVF);
|
||||
EndIf;
|
||||
|
||||
Else
|
||||
|
||||
Binary = New BinaryData(Path);
|
||||
|
||||
EndIf;
|
||||
|
||||
Return Binary;
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure ParameterToCollection(Parameter, Collection) Export
|
||||
|
||||
Value = GetParameter(Parameter);
|
||||
Collection.Insert(Parameter, Value);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure BinaryToCollection(Parameter, Collection) Export
|
||||
|
||||
Value = GetBinary(Parameter);
|
||||
Collection.Insert(Parameter, Value);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure WriteParameter(Parameter, Value) Export
|
||||
|
||||
Path = DataFilePath();
|
||||
WriteParameterToFile(Parameter, Value, Path);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure WriteLog(Val Result, Val Method, Val Library = "") Export
|
||||
|
||||
Header = String(OPI_Tools.GetCurrentDate()) + " | " + Method;
|
||||
|
||||
Try
|
||||
Data = OPI_Tools.JSONString(Result);
|
||||
Except
|
||||
Data = "Not JSON: " + String(Result);
|
||||
EndTry;
|
||||
|
||||
Data = " " + Data;
|
||||
|
||||
Message(Header);
|
||||
Message(Chars.PS);
|
||||
Message(Data);
|
||||
Message(Chars.PS);
|
||||
Message("---------------------------------");
|
||||
Message(Chars.PS);
|
||||
|
||||
If ValueIsFilled(Library) Then
|
||||
WriteLogFile(Data, Method, Library);
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
||||
Function GetValueFromFile(Parameter, Path)
|
||||
|
||||
Values = OPI_Tools.ReadJSONFile(Path);
|
||||
Return ?(Values.Property(Parameter), Values[Parameter], "");
|
||||
|
||||
EndFunction
|
||||
|
||||
Function DataFilePath()
|
||||
|
||||
Path = "";
|
||||
PossiblePaths = New Array;
|
||||
PossiblePaths.Add("./data.json");
|
||||
PossiblePaths.Add("C:\GDrive\My Drive\data.json");
|
||||
PossiblePaths.Add("D:\GD\My Drive\data.json");
|
||||
|
||||
For Each PossiblePath In PossiblePaths Do
|
||||
|
||||
RepositoryFile = New File(PossiblePath);
|
||||
|
||||
If RepositoryFile.Exists() Then
|
||||
Path = PossiblePath;
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
Return Path;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function GetCommonModule(Val Name)
|
||||
SetSafeMode(True);
|
||||
Module = Eval(Name);
|
||||
SetSafeMode(False);
|
||||
Return Module;
|
||||
EndFunction
|
||||
|
||||
Procedure NewTest(ValueTable, Val Method, Val Synonym, Val Section)
|
||||
|
||||
NewTest = ValueTable.Add();
|
||||
NewTest.Method = Method;
|
||||
NewTest.Synonym = Synonym;
|
||||
NewTest.Section = Section;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure WriteParameterToFile(Val Parameter, Val Value, Val Path)
|
||||
|
||||
Values = OPI_Tools.ReadJSONFile(Path);
|
||||
Values.Insert(Parameter, Value);
|
||||
|
||||
Record = New JSONWriter;
|
||||
JSONWriterSettings = New JSONWriterSettings(JSONLineBreak.Auto, Chars.Tab);
|
||||
Record.OpenFile(Path, , , JSONWriterSettings);
|
||||
WriteJSON(Record, Values);
|
||||
Record.Close();
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure WriteLogFile(Val Data, Val Method, Val Library)
|
||||
|
||||
Try
|
||||
|
||||
LogPath = "./docs/results";
|
||||
LibraryLogPath = LogPath + "/" + Library;
|
||||
|
||||
LogDirectory = New File(LogPath);
|
||||
|
||||
If Not LogDirectory.Exists() Then
|
||||
CreateDirectory(LogPath);
|
||||
EndIf;
|
||||
|
||||
LibraryLogCatalog = New File(LibraryLogPath);
|
||||
|
||||
If Not LibraryLogCatalog.Exists() Then
|
||||
CreateDirectory(LibraryLogPath);
|
||||
EndIf;
|
||||
|
||||
FilePath = LibraryLogPath + "/" + Method + ".log";
|
||||
LogFile = New File(FilePath);
|
||||
|
||||
If Not LogFile.Exists() Then
|
||||
LogDocument = New TextDocument;
|
||||
LogDocument.SetText(Data);
|
||||
LogDocument.Write(FilePath);
|
||||
EndIf;
|
||||
|
||||
Except
|
||||
Message("Failed to write log file!: " + ErrorDescription());
|
||||
EndTry;
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="546edcad-c9a0-4823-a44c-fefd7200de6c">
|
||||
<name>OPI_GetTestData</name>
|
||||
<name>OPI_TestDataRetrieval</name>
|
||||
<synonym>
|
||||
<key></key>
|
||||
<value>OPI test data retrieval</value>
|
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/tools/Modules/internal/Modules/OPI_Tools.os
|
||||
//
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -33,8 +33,11 @@
|
||||
|
||||
//@skip-check module-unused-local-variable
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
#Region ServiceProgramInterface
|
||||
#Region Internal
|
||||
|
||||
#Region HTTPMethods
|
||||
|
||||
@@ -147,7 +150,7 @@ EndFunction
|
||||
|
||||
Procedure ProcessResponse(Response, Val FullResponse = False) Export
|
||||
|
||||
If FullResponse Or TypeValue(Response) <> Type("HTTPResponse") Then
|
||||
If FullResponse Or TypeOf(Response) <> Type("HTTPResponse") Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
@@ -167,9 +170,9 @@ Procedure ProcessResponse(Response, Val FullResponse = False) Export
|
||||
Response = UnpackResponse(Response);
|
||||
EndIf;
|
||||
|
||||
Response = ?(TypeValue(Response) = Type("HTTPResponse"), Response.GetBodyAsBinaryData(), Response);
|
||||
Response = ?(TypeOf(Response) = Type("HTTPResponse"), Response.GetBodyAsBinaryData(), Response);
|
||||
|
||||
If TypeValue(Response) = Type("BinaryData") Then
|
||||
If TypeOf(Response) = Type("BinaryData") Then
|
||||
|
||||
Try
|
||||
Response = JsonToStructure(Response);
|
||||
@@ -183,7 +186,7 @@ EndProcedure
|
||||
|
||||
Function CreateRequest(Val Address, Val AdditionalHeaders = "", Val DataType = "") Export
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Accept-Encoding", "gzip");
|
||||
Headers.Insert("Accept" , "*/*");
|
||||
Headers.Insert("Connection" , "keep-alive");
|
||||
@@ -193,10 +196,10 @@ Function CreateRequest(Val Address, Val AdditionalHeaders = "", Val DataType = "
|
||||
Headers.Insert("Content-Type", DataType);
|
||||
EndIf;
|
||||
|
||||
If TypeValue(AdditionalHeaders) = Type("Match") Then
|
||||
If TypeOf(AdditionalHeaders) = Type("Map") Then
|
||||
|
||||
For Each Title In AdditionalHeaders Do
|
||||
Headers.Insert(Title.Key, Title.Value);
|
||||
Headers.Insert(Title.TheKey, Title.Value);
|
||||
EndDo;
|
||||
|
||||
EndIf;
|
||||
@@ -210,7 +213,7 @@ EndFunction
|
||||
Function CreateConnection(Val Server, Val User = "", Val Password = "") Export
|
||||
|
||||
Try
|
||||
SSL = New SecureConnectionOpenSSL;
|
||||
SSL = New OpenSSLSecureConnection;
|
||||
Return New HTTPConnection(Server, 443, User, Password, , 3000, SSL);
|
||||
Except
|
||||
Return New HTTPConnection(Server, 443, User, Password, , 3000);
|
||||
@@ -237,13 +240,13 @@ Function RequestParametersToString(Val Parameters) Export
|
||||
ParameterValue = ConvertParameterToString(Parameter.Value);
|
||||
|
||||
ParameterString = ParameterString
|
||||
+ Parameter.Key
|
||||
+ Parameter.TheKey
|
||||
+ "="
|
||||
+ ParameterValue
|
||||
+ "&";
|
||||
EndDo;
|
||||
|
||||
ParameterString = Left(ParameterString, StrLength(ParameterString) - 1);
|
||||
ParameterString = Left(ParameterString, StrLen(ParameterString) - 1);
|
||||
|
||||
Return ParameterString;
|
||||
|
||||
@@ -251,15 +254,15 @@ EndFunction
|
||||
|
||||
Function SplitURL(Val URL) Export
|
||||
|
||||
URL = StringReplace(URL, "https://", "");
|
||||
URL = StringReplace(URL, "http://", "");
|
||||
URL = StringReplace(URL, ":443", "");
|
||||
URL = StrReplace(URL, "https://", "");
|
||||
URL = StrReplace(URL, "http://", "");
|
||||
URL = StrReplace(URL, ":443", "");
|
||||
|
||||
Address = Right(URL, StrLength(URL) - StrFind(URL, "/", SearchDirection.FromStart) + 1);
|
||||
Address = Right(URL, StrLen(URL) - StrFind(URL, "/", SearchDirection.FromStart) + 1);
|
||||
Server = Left(URL, StrFind(URL, "/", SearchDirection.FromStart) - 1);
|
||||
|
||||
Try
|
||||
SSL = New SecureConnectionOpenSSL;
|
||||
SSL = New OpenSSLSecureConnection;
|
||||
Except
|
||||
Server = "https://" + Server;
|
||||
EndTry;
|
||||
@@ -278,13 +281,13 @@ Function JsonToStructure(Val Text) Export
|
||||
Return "";
|
||||
EndIf;
|
||||
|
||||
Text = ?(TypeValue(Text) = Type("BinaryData"), GetStringFromBinaryData(Text), Text);
|
||||
Text = ?(TypeOf(Text) = Type("BinaryData"), GetStringFromBinaryData(Text), Text);
|
||||
|
||||
ReadingJSON = New ReadingJSON;
|
||||
ReadingJSON.SetString(Text);
|
||||
JSONReader = New JSONReader;
|
||||
JSONReader.SetString(Text);
|
||||
|
||||
Data = ReadJSON(ReadingJSON, True, Undefined, JSONDateFormat.ISO);
|
||||
ReadingJSON.Close();
|
||||
Data = ReadJSON(JSONReader, True, Undefined, JSONDateFormat.ISO);
|
||||
JSONReader.Close();
|
||||
|
||||
Return Data;
|
||||
|
||||
@@ -292,10 +295,10 @@ EndFunction
|
||||
|
||||
Function JSONString(Val Data, Val Escaping = "No") Export
|
||||
|
||||
JSONParameters = New JSONWriteParameters(JSONLineBreak.Windows
|
||||
JSONParameters = New JSONWriterSettings(JSONLineBreak.Windows
|
||||
, " "
|
||||
, True
|
||||
, EscapeJSONCharacters[Escaping]
|
||||
, JSONCharactersEscapeMode[Escaping]
|
||||
, False
|
||||
, False
|
||||
, False
|
||||
@@ -303,11 +306,11 @@ Function JSONString(Val Data, Val Escaping = "No") Export
|
||||
|
||||
Try
|
||||
|
||||
WritingJSON = New WritingJSON;
|
||||
WritingJSON.SetString(JSONParameters);
|
||||
JSONWriter = New JSONWriter;
|
||||
JSONWriter.SetString(JSONParameters);
|
||||
|
||||
WriteJSON(WritingJSON, Data);
|
||||
Return WritingJSON.Close();
|
||||
WriteJSON(JSONWriter, Data);
|
||||
Return JSONWriter.Close();
|
||||
|
||||
Except
|
||||
Return "NOT JSON: " + String(Data);
|
||||
@@ -316,16 +319,16 @@ Function JSONString(Val Data, Val Escaping = "No") Export
|
||||
EndFunction
|
||||
|
||||
Function NumberToString(Val Number) Export
|
||||
Return StringReplace(String(Number), Symbols.NPP, "");
|
||||
Return StrReplace(String(Number), Chars.NPP, "");
|
||||
EndFunction
|
||||
|
||||
Function ReadJSONFile(Val Path) Export
|
||||
|
||||
ReadingJSON = New ReadingJSON;
|
||||
ReadingJSON.OpenFile(Path);
|
||||
Values = ReadJSON(ReadingJSON);
|
||||
JSONReader = New JSONReader;
|
||||
JSONReader.OpenFile(Path);
|
||||
Values = ReadJSON(JSONReader);
|
||||
|
||||
ReadingJSON.Close();
|
||||
JSONReader.Close();
|
||||
|
||||
Return Values;
|
||||
|
||||
@@ -333,7 +336,7 @@ EndFunction
|
||||
|
||||
Function RequestParametersToMatch(Val ParameterString) Export
|
||||
|
||||
ReturnMapping = New Match;
|
||||
ReturnMapping = New Map;
|
||||
NumberOfParts = 2;
|
||||
ParameterArray = StrSplit(ParameterString, "&", False);
|
||||
|
||||
@@ -352,7 +355,7 @@ Function RequestParametersToMatch(Val ParameterString) Export
|
||||
EndFunction
|
||||
|
||||
Function GetCurrentDate() Export
|
||||
Return LocalTime(CurrentUniversalDate());
|
||||
Return ToLocalTime(CurrentUniversalDate());
|
||||
EndFunction
|
||||
|
||||
Function UNIXTime(Val Date) Export
|
||||
@@ -361,7 +364,7 @@ Function UNIXTime(Val Date) Export
|
||||
Date = OTD.ConvertValue(Date);
|
||||
|
||||
UNIX = Format(Date - Date(1970, 1, 1, 1, 0, 0), "HC=10; HDC=0; HG=0");
|
||||
UNIX = StringReplace(UNIX, ",", "");
|
||||
UNIX = StrReplace(UNIX, ",", "");
|
||||
UNIX = Left(UNIX, 10);
|
||||
|
||||
Return UNIX;
|
||||
@@ -373,7 +376,7 @@ Function ProgressInformation(Val Current, Val Total, Val Unit, Val Divider = 1)
|
||||
Whole = 100;
|
||||
Current = Round(Current / Divider, 2);
|
||||
Total = Round(Total / Divider, 2);
|
||||
Percent = Goal(Current / Total * Whole);
|
||||
Percent = Int(Current / Total * Whole);
|
||||
|
||||
StrCurrent = NumberToString(Current);
|
||||
StrTotal = NumberToString(Total);
|
||||
@@ -389,7 +392,7 @@ Function ConvertDataWithSizeRetrieval(Data, Val MinimumStreamSize = 0) Export
|
||||
|
||||
Size = 0;
|
||||
|
||||
If TypeValue(Data) = Type("String") Then
|
||||
If TypeOf(Data) = Type("String") Then
|
||||
|
||||
FileOnDisk = New File(Data);
|
||||
|
||||
@@ -429,7 +432,7 @@ EndProcedure
|
||||
|
||||
Procedure ReplaceSpecialCharacters(Text, Markup = "Markdown") Export
|
||||
|
||||
CharacterMapping = New Match;
|
||||
CharacterMapping = New Map;
|
||||
|
||||
If Markup = "HTML" Then
|
||||
|
||||
@@ -450,17 +453,17 @@ Procedure ReplaceSpecialCharacters(Text, Markup = "Markdown") Export
|
||||
EndIf;
|
||||
|
||||
For Each ArraySymbol In CharacterMapping Do
|
||||
Text = StringReplace(Text, ArraySymbol.Key, ArraySymbol.Value);
|
||||
Text = StrReplace(Text, ArraySymbol.TheKey, ArraySymbol.Value);
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure RemoveEmptyCollectionFields(Collection) Export
|
||||
|
||||
CollectionType = TypeValue(Collection);
|
||||
CollectionType = TypeOf(Collection);
|
||||
OutputCollection = New(CollectionType);
|
||||
|
||||
If CollectionType = Type("Match") Or CollectionType = Type("Structure") Then
|
||||
If CollectionType = Type("Map") Or CollectionType = Type("Structure") Then
|
||||
|
||||
RemoveEmptyKeyValues(Collection, OutputCollection);
|
||||
|
||||
@@ -532,7 +535,7 @@ EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function ExecuteRequestWithBody(Val URL
|
||||
, Val View
|
||||
@@ -657,13 +660,13 @@ Function ExecuteMultipartRequest(Val URL
|
||||
EndIf;
|
||||
|
||||
If Not ValueIsFilled(Files) Then
|
||||
Files = New Match;
|
||||
Files = New Map;
|
||||
EndIf;
|
||||
|
||||
Redirection = 300;
|
||||
Error = 400;
|
||||
Boundary = StringReplace(String(New UniqueIdentifier), "-", "");
|
||||
LineSeparator = Symbols.VK + Symbols.PS;
|
||||
Boundary = StrReplace(String(New UUID), "-", "");
|
||||
LineSeparator = Chars.VK + Chars.PS;
|
||||
DataType = "multipart/form-data; boundary=" + Boundary;
|
||||
URLStructure = SplitURL(URL);
|
||||
Server = URLStructure["Server"];
|
||||
@@ -673,7 +676,7 @@ Function ExecuteMultipartRequest(Val URL
|
||||
Connection = CreateConnection(Server);
|
||||
|
||||
RequestBody = GetTempFileName();
|
||||
TextRecord = New DataRecording(RequestBody
|
||||
TextRecord = New DataWriter(RequestBody
|
||||
, TextEncoding.UTF8
|
||||
, ByteOrder.LittleEndian
|
||||
, ""
|
||||
@@ -726,8 +729,8 @@ Function ExecuteMultipartRelatedRequest(Val URL
|
||||
|
||||
Redirection = 300;
|
||||
Error = 400;
|
||||
Boundary = StringReplace(String(New UniqueIdentifier), "-", "");
|
||||
LineSeparator = Symbols.VK + Symbols.PS;
|
||||
Boundary = StrReplace(String(New UUID), "-", "");
|
||||
LineSeparator = Chars.VK + Chars.PS;
|
||||
DataType = "multipart/related; boundary=" + Boundary;
|
||||
URLStructure = SplitURL(URL);
|
||||
Server = URLStructure["Server"];
|
||||
@@ -737,7 +740,7 @@ Function ExecuteMultipartRelatedRequest(Val URL
|
||||
Connection = CreateConnection(Server);
|
||||
|
||||
RequestBody = GetTempFileName();
|
||||
TextRecord = New DataRecording(RequestBody
|
||||
TextRecord = New DataWriter(RequestBody
|
||||
, TextEncoding.UTF8
|
||||
, ByteOrder.LittleEndian
|
||||
, ""
|
||||
@@ -797,8 +800,8 @@ EndFunction
|
||||
|
||||
Function ConvertParameterToString(Val Value)
|
||||
|
||||
If TypeValue(Value) = Type("Array") Then
|
||||
Value = StrJoin(Value, ",");
|
||||
If TypeOf(Value) = Type("Array") Then
|
||||
Value = StrConcat(Value, ",");
|
||||
Value = EncodeString(Value, StringEncodingMethod.URLencoding);
|
||||
Value = "[" + Value + "]";
|
||||
Else
|
||||
@@ -812,9 +815,9 @@ EndFunction
|
||||
|
||||
Procedure SetRequestBody(Request, Val Parameters, Val JSON)
|
||||
|
||||
Collection = TypeValue(Parameters) = Type("Structure")
|
||||
Or TypeValue(Parameters) = Type("Match")
|
||||
Or TypeValue(Parameters) = Type("Array");
|
||||
Collection = TypeOf(Parameters) = Type("Structure")
|
||||
Or TypeOf(Parameters) = Type("Map")
|
||||
Or TypeOf(Parameters) = Type("Array");
|
||||
|
||||
If JSON Then
|
||||
Data = JSONString(Parameters);
|
||||
@@ -822,10 +825,10 @@ Procedure SetRequestBody(Request, Val Parameters, Val JSON)
|
||||
Data = Parameters;
|
||||
Else
|
||||
ParameterString = RequestParametersToString(Parameters);
|
||||
Data = Right(ParameterString, StrLength(ParameterString) - 1);
|
||||
Data = Right(ParameterString, StrLen(ParameterString) - 1);
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Data) = Type("String") Then
|
||||
If TypeOf(Data) = Type("String") Then
|
||||
Request.SetBodyFromString(Data);
|
||||
Else
|
||||
//@skip-check wrong-type-expression
|
||||
@@ -836,7 +839,7 @@ EndProcedure
|
||||
|
||||
Procedure WriteMultipartParameters(TextRecord, Val Boundary, Val Parameters)
|
||||
|
||||
LineSeparator = Symbols.VK + Symbols.PS;
|
||||
LineSeparator = Chars.VK + Chars.PS;
|
||||
|
||||
For Each Parameter In Parameters Do
|
||||
|
||||
@@ -846,17 +849,17 @@ Procedure WriteMultipartParameters(TextRecord, Val Boundary, Val Parameters)
|
||||
EndIf;
|
||||
|
||||
TextRecord.WriteString("--" + boundary + LineSeparator);
|
||||
TextRecord.WriteString("Content-Disposition: form-data; name=""" + Parameter.Key + """");
|
||||
TextRecord.WriteString("Content-Disposition: form-data; name=""" + Parameter.TheKey + """");
|
||||
TextRecord.WriteString(LineSeparator);
|
||||
TextRecord.WriteString(LineSeparator);
|
||||
|
||||
If TypeValue(Parameter.Value) = Type("String")
|
||||
Or TypeValue(Parameter.Value) = Type("Number") Then
|
||||
If TypeOf(Parameter.Value) = Type("String")
|
||||
Or TypeOf(Parameter.Value) = Type("Number") Then
|
||||
|
||||
ValueAsString = NumberToString(Parameter.Value);
|
||||
TextRecord.WriteString(ValueAsString);
|
||||
|
||||
ElsIf TypeValue(Parameter.Value) = Type("Boolean") Then
|
||||
ElsIf TypeOf(Parameter.Value) = Type("Boolean") Then
|
||||
|
||||
TextRecord.WriteString(?(Parameter.Value, "true", "false"));
|
||||
|
||||
@@ -874,20 +877,20 @@ EndProcedure
|
||||
|
||||
Procedure WriteMultipartFiles(TextRecord, Val Boundary, Val ContentType, Val Files)
|
||||
|
||||
ContentType = ShortLP(ContentType);
|
||||
LineSeparator = Symbols.VK + Symbols.PS;
|
||||
ContentType = TrimAll(ContentType);
|
||||
LineSeparator = Chars.VK + Chars.PS;
|
||||
DotReplacement = "___";
|
||||
|
||||
For Each File In Files Do
|
||||
|
||||
FilePath = StringReplace(File.Key, DotReplacement, ".");
|
||||
FilePath = StrReplace(File.TheKey, DotReplacement, ".");
|
||||
|
||||
If ContentType = "image/jpeg" Then
|
||||
SendingFileName = "photo";
|
||||
Else
|
||||
SendingFileName = StringReplace(File.Key, DotReplacement, ".");
|
||||
SendingFileName = StrReplace(File.TheKey, DotReplacement, ".");
|
||||
SendingFileName = Left(SendingFileName, StrFind(SendingFileName, ".") - 1);
|
||||
SendingFileName = ?(ValueIsFilled(SendingFileName), SendingFileName, StringReplace(File.Key,
|
||||
SendingFileName = ?(ValueIsFilled(SendingFileName), SendingFileName, StrReplace(File.TheKey,
|
||||
DotReplacement, "."));
|
||||
EndIf;
|
||||
|
||||
@@ -918,16 +921,16 @@ Procedure WriteRelatedFiles(TextRecord, Val Boundary, Val Files)
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
LineSeparator = Symbols.VK + Symbols.PS;
|
||||
LineSeparator = Chars.VK + Chars.PS;
|
||||
|
||||
If TypeValue(Files) = Type("Match") Then
|
||||
If TypeOf(Files) = Type("Map") Then
|
||||
For Each File In Files Do
|
||||
|
||||
TextRecord.WriteString("--" + boundary + LineSeparator);
|
||||
TextRecord.WriteString("Content-Type: " + File.Value);
|
||||
TextRecord.WriteString(LineSeparator);
|
||||
TextRecord.WriteString(LineSeparator);
|
||||
WriteBinaryData(TextRecord, File.Key);
|
||||
WriteBinaryData(TextRecord, File.TheKey);
|
||||
TextRecord.WriteString(LineSeparator);
|
||||
TextRecord.WriteString(LineSeparator);
|
||||
|
||||
@@ -937,7 +940,7 @@ Procedure WriteRelatedFiles(TextRecord, Val Boundary, Val Files)
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure WriteBinaryData(DataRecording, Val BinaryData)
|
||||
Procedure WriteBinaryData(DataWriter, Val BinaryData)
|
||||
|
||||
ChunkSize = 268435456;
|
||||
BytesRead = 0;
|
||||
@@ -946,19 +949,19 @@ Procedure WriteBinaryData(DataRecording, Val BinaryData)
|
||||
|
||||
WHile BytesRead < TotalSize Do
|
||||
|
||||
ReadingData = New ReadingData(BinaryData);
|
||||
BytesRead = ReadingData.Skip(CurrentPosition);
|
||||
Result = ReadingData.Read(ChunkSize);
|
||||
Current data = Result.GetBinaryData();
|
||||
CurrentSize = Current data.Size();
|
||||
DataReader = New DataReader(BinaryData);
|
||||
BytesRead = DataReader.Skip(CurrentPosition);
|
||||
Result = DataReader.Read(ChunkSize);
|
||||
CurrentData = Result.GetBinaryData();
|
||||
CurrentSize = CurrentData.Size();
|
||||
|
||||
If Not ValueIsFilled(Current data) Then
|
||||
If Not ValueIsFilled(CurrentData) Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
DataRecording.Write(Current data);
|
||||
DataWriter.Write(CurrentData);
|
||||
|
||||
// !OInt ReleaseObject(Current data);
|
||||
// !OInt ReleaseObject(CurrentData);
|
||||
// !OInt PerformGarbageCollection();
|
||||
|
||||
CurrentPosition = CurrentPosition + CurrentSize;
|
||||
@@ -973,7 +976,7 @@ Procedure WriteJSONMultipart(TextRecord, Val Boundary, Val JSON)
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
LineSeparator = Symbols.VK + Symbols.PS;
|
||||
LineSeparator = Chars.VK + Chars.PS;
|
||||
|
||||
TextRecord.WriteString("--" + boundary + LineSeparator);
|
||||
TextRecord.WriteString("Content-Type: application/json; charset=UTF-8");
|
||||
@@ -1003,7 +1006,7 @@ Procedure RemoveEmptyKeyValues(Val Collection, OutputCollection)
|
||||
For Each CollectionItem In Collection Do
|
||||
|
||||
If Not CollectionItem.Value = Undefined And Not CollectionItem.Value = NULL Then
|
||||
OutputCollection.Insert(CollectionItem.Key, CollectionItem.Value);
|
||||
OutputCollection.Insert(CollectionItem.TheKey, CollectionItem.Value);
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
@@ -1024,7 +1027,7 @@ EndProcedure
|
||||
|
||||
#Region GZip
|
||||
|
||||
// Description withтруtoтур withм. зdеwithь https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
|
||||
// Description withтруtoтур withм. здеwithь https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
|
||||
// Source: https://github.com/vbondarevsky/Connector
|
||||
|
||||
// Connector: convenient HTTP client for 1C:Enterprise 8
|
||||
@@ -1070,9 +1073,9 @@ Function ReadGZip(CompressedData) Export
|
||||
SizeESD = ZipSizeEOCD();
|
||||
SizeLFH = ZipSizeLFH();
|
||||
|
||||
ReadingData = New ReadingData(CompressedData);
|
||||
ReadingData.Skip(GZipPrefixSize);
|
||||
CompressedDataSize = ReadingData.SourceStream().Size() - GZipPrefixSize - GZipPostfixSize;
|
||||
DataReader = New DataReader(CompressedData);
|
||||
DataReader.Skip(GZipPrefixSize);
|
||||
CompressedDataSize = DataReader.SourceStream().Size() - GZipPrefixSize - GZipPostfixSize;
|
||||
|
||||
ZipStream = New MemoryStream(SizeLFH
|
||||
+ CompressedDataSize
|
||||
@@ -1080,21 +1083,21 @@ Function ReadGZip(CompressedData) Export
|
||||
+ SizeCDH
|
||||
+ SizeESD);
|
||||
|
||||
DataRecording = New DataRecording(ZipStream);
|
||||
DataRecording.WriteBinaryDataBuffer(ZipLFH());
|
||||
ReadingData.CopyTo(DataRecording, CompressedDataSize);
|
||||
DataWriter = New DataWriter(ZipStream);
|
||||
DataWriter.WriteBinaryDataBuffer(ZipLFH());
|
||||
DataReader.CopyTo(DataWriter, CompressedDataSize);
|
||||
|
||||
DataRecording.Close();
|
||||
DataRecording = New DataRecording(ZipStream);
|
||||
DataWriter.Close();
|
||||
DataWriter = New DataWriter(ZipStream);
|
||||
|
||||
CRC32 = ReadingData.ReadInt32();
|
||||
UncompressedDataSize = ReadingData.ReadInt32();
|
||||
ReadingData.Close();
|
||||
CRC32 = DataReader.ReadInt32();
|
||||
UncompressedDataSize = DataReader.ReadInt32();
|
||||
DataReader.Close();
|
||||
|
||||
DataRecording.WriteBinaryDataBuffer(ZipDD(CRC32, CompressedDataSize, UncompressedDataSize));
|
||||
DataRecording.WriteBinaryDataBuffer(ZipCDH(CRC32, CompressedDataSize, UncompressedDataSize));
|
||||
DataRecording.WriteBinaryDataBuffer(ZipEOCD(CompressedDataSize));
|
||||
DataRecording.Close();
|
||||
DataWriter.WriteBinaryDataBuffer(ZipDD(CRC32, CompressedDataSize, UncompressedDataSize));
|
||||
DataWriter.WriteBinaryDataBuffer(ZipCDH(CRC32, CompressedDataSize, UncompressedDataSize));
|
||||
DataWriter.WriteBinaryDataBuffer(ZipEOCD(CompressedDataSize));
|
||||
DataWriter.Close();
|
||||
|
||||
Return ReadZip(ZipStream);
|
||||
|
||||
@@ -1103,13 +1106,13 @@ EndFunction
|
||||
Function ReadZip(CompressedData, ErrorText = Undefined)
|
||||
|
||||
Directory = GetTempFileName();
|
||||
ReadingZip = New ReadingZipFile(CompressedData);
|
||||
ReadingZip = New ZipFileReader(CompressedData);
|
||||
FileName = ReadingZip.Elements[0].Name;
|
||||
Try
|
||||
ReadingZip.Extract(ReadingZip.Elements[0], Directory, ZIPFilePathRecoveryMode.DoNotRestore);
|
||||
ReadingZip.Extract(ReadingZip.Elements[0], Directory, ZIPRestoreFilePathsMode.DontRestore);
|
||||
Except
|
||||
// Ignore archive integrity check, just read the result
|
||||
ErrorText = DetailedErrorRepresentation(ErrorInformation());
|
||||
ErrorText = DetailErrorDescription(ErrorInfo());
|
||||
EndTry;
|
||||
ReadingZip.Close();
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Twitter.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Twitter.os
|
||||
// Library: Twitter
|
||||
// CLI Command: twitter
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
// If in не зtoете with чего toчать, то withтоит toйти method GetStandardParameters()
|
||||
// If you don't know where to start, you should find the method GetStandardParameters()
|
||||
// and read comments
|
||||
|
||||
// BSLLS:Typo-off
|
||||
@@ -35,11 +35,14 @@
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region DataAndSettings
|
||||
|
||||
@@ -49,7 +52,7 @@
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - URL for browser transition
|
||||
Function GetAuthorizationLink(Parameters = "") Export
|
||||
|
||||
@@ -79,7 +82,7 @@ EndFunction
|
||||
// Code - String - Code obtained from authorization See GetAuthorizationLink - code
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function GetToken(Val Code, Val Parameters = "") Export
|
||||
|
||||
@@ -107,7 +110,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function RefreshToken(Val Parameters = "") Export
|
||||
|
||||
@@ -134,7 +137,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Request - HTTPServiceRequest - Request coming to the http service
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// HTTPResponse, Arbitrary, BinaryData - Result of reading the JSON response from the server
|
||||
Function HandleIncomingRequestAfterAuthorization(Request) Export
|
||||
|
||||
@@ -143,8 +146,8 @@ Function HandleIncomingRequestAfterAuthorization(Request) Export
|
||||
|
||||
// BSLLS:CommentedCode-off
|
||||
// Preferred token storage
|
||||
// Constants.TwitterRefresh.Уwithтаноinить(TokenResponse["refresh_token"]);
|
||||
// Constants.TwitterToken.Уwithтаноinить(TokenResponse["access_token"]);
|
||||
// Constants.TwitterRefresh.Set(ResponseToken["refresh_token"]);
|
||||
// Constants.TwitterToken.Set(ResponseToken["access_token"]);
|
||||
// BSLLS:CommentedCode-on
|
||||
|
||||
Return TokenResponse;
|
||||
@@ -160,12 +163,12 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text
|
||||
// MediaArray - Array from String, BinaryData - Array of binary data or file paths
|
||||
// PollOptionsArray - Array of Strings - Array of poll options, if necessary
|
||||
// PollDuration - String, Number - Poll duration, еwithли необхоdимо (опроwith without dлительноwithти не withозdаетwithя)
|
||||
// MediaArray - Array of String, BinaryData - Array of binary data or file paths
|
||||
// PollOptionsArray - Array of String - Array of poll options, if necessary
|
||||
// PollDuration - String, Number - Poll duration if necessary (poll without duration is not created)
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateCustomTweet(Val Text = ""
|
||||
, Val MediaArray = ""
|
||||
@@ -187,13 +190,13 @@ Function CreateCustomTweet(Val Text = ""
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
URL = "https://api.twitter.com/2/tweets";
|
||||
Array = "Array";
|
||||
Fields = New Match;
|
||||
Fields = New Map;
|
||||
|
||||
If ValueIsFilled(Text) Then
|
||||
Fields.Insert("text", Text);
|
||||
EndIf;
|
||||
|
||||
If TypeValue(PollOptionsArray) = Type(Array) And ValueIsFilled(PollDuration) Then
|
||||
If TypeOf(PollOptionsArray) = Type(Array) And ValueIsFilled(PollDuration) Then
|
||||
|
||||
PollDuration = Number(PollDuration);
|
||||
|
||||
@@ -206,7 +209,7 @@ Function CreateCustomTweet(Val Text = ""
|
||||
|
||||
EndIf;
|
||||
|
||||
If TypeValue(MediaArray) = Type(Array) Then
|
||||
If TypeOf(MediaArray) = Type(Array) Then
|
||||
If MediaArray.Quantity() > 0 Then
|
||||
Fields.Insert("media", New Structure("media_ids", MediaArray));
|
||||
EndIf;
|
||||
@@ -226,7 +229,7 @@ EndFunction
|
||||
// Text - String - Tweet text - text
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateTextTweet(Val Text, Val Parameters = "") Export
|
||||
Return CreateCustomTweet(Text, , , , Parameters);
|
||||
@@ -237,14 +240,14 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// ImageArray - Array from String, BinaryData - Image files array - pictures
|
||||
// ImageArray - Array of String, BinaryData - Image files array - pictures
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function Create image tweet(Val Text, Val ImageArray, Val Parameters = "") Export
|
||||
Function CreateImageTweet(Val Text, Val ImageArray, Val Parameters = "") Export
|
||||
|
||||
MediaArray = Upload attachments array(ImageArray, "tweet_image", Parameters);
|
||||
MediaArray = UploadAttachmentsArray(ImageArray, "tweet_image", Parameters);
|
||||
Return CreateCustomTweet(Text, MediaArray, , , Parameters);
|
||||
|
||||
EndFunction
|
||||
@@ -254,14 +257,14 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// Gif array - Array from String, BinaryData - Gif files array - gifs
|
||||
// GifsArray - Array of String, BinaryData - Gif files array - gifs
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateGifTweet(Val Text, Val Gif array, Val Parameters = "") Export
|
||||
Function CreateGifTweet(Val Text, Val GifsArray, Val Parameters = "") Export
|
||||
|
||||
MediaArray = Upload attachments array(Gif array, "tweet_gif", Parameters);
|
||||
MediaArray = UploadAttachmentsArray(GifsArray, "tweet_gif", Parameters);
|
||||
Return CreateCustomTweet(Text, MediaArray, , , Parameters);
|
||||
|
||||
EndFunction
|
||||
@@ -271,14 +274,14 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// Video array - Array from String, BinaryData - Video files array - videos
|
||||
// VideosArray - Array of String, BinaryData - Video files array - videos
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreateVideoTweet(Val Text, Val Video array, Val Parameters = "") Export
|
||||
Function CreateVideoTweet(Val Text, Val VideosArray, Val Parameters = "") Export
|
||||
|
||||
MediaArray = Upload attachments array(Video array, "tweet_video", Parameters);
|
||||
MediaArray = UploadAttachmentsArray(VideosArray, "tweet_video", Parameters);
|
||||
Return CreateCustomTweet(Text, MediaArray, , , Parameters);
|
||||
|
||||
EndFunction
|
||||
@@ -288,11 +291,11 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Tweet text - text
|
||||
// OptionArray - Array of Strings - Poll options array - options
|
||||
// OptionArray - Array of String - Poll options array - options
|
||||
// Duration - String, Number - Poll duration - duration
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Twitter
|
||||
Function CreatePollTweet(Val Text, Val OptionArray, Val Duration, Val Parameters = "") Export
|
||||
Return CreateCustomTweet(Text, , OptionArray, Duration, Parameters);
|
||||
@@ -302,13 +305,13 @@ EndFunction
|
||||
// Uploads files to the server and returns their IDs
|
||||
//
|
||||
// Parameters:
|
||||
// ArrayOfFiles - Array from String, BinaryData - Files array
|
||||
// ArrayOfFiles - Array of String, BinaryData - Files array
|
||||
// AttachmentsType - String - Attachments type
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Array Of String - Media ID array
|
||||
Function Upload attachments array(Val ArrayOfFiles, Val AttachmentsType, Val Parameters = "") Export
|
||||
Function UploadAttachmentsArray(Val ArrayOfFiles, Val AttachmentsType, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(AttachmentsType);
|
||||
OPI_TypeConversion.GetCollection(ArrayOfFiles);
|
||||
@@ -344,7 +347,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function UploadMediaFile(Val File, Val Type, Val Parameters)
|
||||
|
||||
@@ -382,7 +385,7 @@ Function UploadMediaInParts(Val File, Val Type, Val RequestType, Val URL, Parame
|
||||
Command = "command";
|
||||
Size = File.Size();
|
||||
|
||||
MIMETypeMapping = New Match;
|
||||
MIMETypeMapping = New Map;
|
||||
MIMETypeMapping.Insert("tweet_image", "image/jpeg");
|
||||
MIMETypeMapping.Insert("tweet_video", "video/mp4");
|
||||
MIMETypeMapping.Insert("tweet_gif" , "image/gif");
|
||||
@@ -430,7 +433,7 @@ Function UploadMediaInParts(Val File, Val Type, Val RequestType, Val URL, Parame
|
||||
|
||||
ProcessingStatus = GetProcessingStatus(Parameters, Fields, URL);
|
||||
|
||||
If Not TypeValue(ProcessingStatus) = Type("String") Then
|
||||
If Not TypeOf(ProcessingStatus) = Type("String") Then
|
||||
Return ProcessingStatus;
|
||||
EndIf;
|
||||
|
||||
@@ -477,21 +480,21 @@ EndFunction
|
||||
|
||||
Function GetStandardParameters(Val Parameters = "")
|
||||
|
||||
// Зdеwithь withобрано опреdеление data, необхоdимых for work.
|
||||
// For Twitter this dоinольно зtoчительный toбор, which is due to the presence of two at once API,
|
||||
// toоторые, при thisм, withозdаны не for разныз заdач, но проwithто яinляютwithя inерwithиями dруг dруга.
|
||||
// Аtoтуальной inерwithией API яinляетwithя v2 и оto требует получения inременных тоtoеноin. Notwithмотря to то,
|
||||
// Here is the definition of the data needed for work.
|
||||
// For Twitter, this is quite a significant set, which is due to the presence of 2 APIs at once,
|
||||
// which, at the same time, are not created for different tasks, but are simply versions of each other.
|
||||
// The current version of the API is v2 and it requires obtaining temporary tokens. Despite the fact,
|
||||
// that Twitter insists on using this latest version, they somehow managed not to transfer
|
||||
// file upload mechanism and some others from the old version - v1.1. Therefore, something needs to be done
|
||||
// to inерwithии 1.1, and something on 2: up to the point that they removed the ability to post tweets from v1.1,
|
||||
// on version 1.1, and something on 2: up to the point that they removed the ability to post tweets from v1.1,
|
||||
// but only through it you can add a picture to the tweet. At the same time, their authentication methods and tokens are different
|
||||
|
||||
// Мироinая гигоtoорпорация Andлоto Маwithtoа, towithтати, toпомиtoю ;)
|
||||
// The world gigacorporation of Elon Musk, by the way, a reminder ;)
|
||||
|
||||
// P.S Далее чаwithто упомиtoетwithя "withтраница towithтроеto Twitter Developer" - this
|
||||
// P.S The "Twitter Developer settings page" is often mentioned further" - this
|
||||
// https://developer.twitter.com/en/portal/dashboard и inыбор toонtoретного проеtoта from withпиwithtoа (зtoчеto c toлючем)
|
||||
|
||||
Parameters_ = New Match;
|
||||
Parameters_ = New Map;
|
||||
Permissions = "tweet.read tweet.write tweet.moderate.write users.read "
|
||||
+ "follows.read follows.write offline.access space.read mute.read "
|
||||
+ "mute.write like.read like.write list.read list.write block.read "
|
||||
@@ -503,11 +506,11 @@ Function GetStandardParameters(Val Parameters = "")
|
||||
// scope - a set of permissions for the received key. Can be any, but offline.access is mandatory
|
||||
// client_id - From OAuth 2.0 Client ID and Client Secret settings page of Twitter Developer
|
||||
// client_secret - From OAuth 2.0 Client ID and Client Secret settings page of Twitter Developer
|
||||
// access_token - GetAuthorizationLink() -> Браузер -> code приdет to redirect_uri -> GetToken(code)
|
||||
// refresh_token - Comes together with access_token and is used to refresh it (access_token lifetime - 2 ч)
|
||||
// Обноinление проиwithхоdит methodом RefreshToken with ноinыми access_token и refresh_token.
|
||||
// access_token - GetAuthorizationLink() -> Browser -> code will come to redirect_uri -> GetToken(code)
|
||||
// refresh_token - Comes together with access_token and is used to refresh it (access_token lifetime - 2 hr)
|
||||
// The update is done using the UpdateToken method with new access_token and refresh_token.
|
||||
// For the next update, you need to use a new refresh_token, so hardcode
|
||||
// не получитwithя (access_token тоже не получитwithя)
|
||||
// won't work (access_token won't work either)
|
||||
|
||||
// |--> RefreshToken() ->|access_token --> Andwithпользуетwithя in т-нии 2-х чаwithоin for запроwithоin
|
||||
// | |refresh_token --|
|
||||
@@ -535,9 +538,9 @@ Function GetStandardParameters(Val Parameters = "")
|
||||
|
||||
OPI_TypeConversion.GetCollection(Parameters);
|
||||
|
||||
If TypeValue(Parameters) = Type("Structure") Or TypeValue(Parameters) = Type("Match") Then
|
||||
If TypeOf(Parameters) = Type("Structure") Or TypeOf(Parameters) = Type("Map") Then
|
||||
For Each PassedParameter In Parameters Do
|
||||
Parameters_.Insert(PassedParameter.Key, OPI_Tools.NumberToString(PassedParameter.Value));
|
||||
Parameters_.Insert(PassedParameter.TheKey, OPI_Tools.NumberToString(PassedParameter.Value));
|
||||
EndDo;
|
||||
EndIf;
|
||||
|
||||
@@ -558,62 +561,62 @@ Function CreateAuthorizationHeaderV1(Val Parameters, Val Fields, Val RequestType
|
||||
CurrentUNIXDate = OPI_Tools.UNIXTime(CurrentDate);
|
||||
CurrentUNIXDate = OPI_Tools.NumberToString(CurrentUNIXDate);
|
||||
ParametersTable = New ValueTable;
|
||||
ParametersTable.Columns.Add("Key");
|
||||
ParametersTable.Columns.Add("TheKey");
|
||||
ParametersTable.Columns.Add("Value");
|
||||
|
||||
For Each Field In Fields Do
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = Field.Key;
|
||||
NewLine.TheKey = Field.TheKey;
|
||||
NewLine.Value = Field.Value;
|
||||
|
||||
EndDo;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = OCK;
|
||||
NewLine.TheKey = OCK;
|
||||
NewLine.Value = Parameters[OCK];
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = OTK;
|
||||
NewLine.TheKey = OTK;
|
||||
NewLine.Value = Parameters[OTK];
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = "oauth_version";
|
||||
NewLine.TheKey = "oauth_version";
|
||||
NewLine.Value = APIVersion;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = "oauth_signature_method";
|
||||
NewLine.TheKey = "oauth_signature_method";
|
||||
NewLine.Value = HashingMethod;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = "oauth_timestamp";
|
||||
NewLine.TheKey = "oauth_timestamp";
|
||||
NewLine.Value = CurrentUNIXDate;
|
||||
|
||||
NewLine = ParametersTable.Add();
|
||||
NewLine.Key = "oauth_nonce";
|
||||
NewLine.TheKey = "oauth_nonce";
|
||||
NewLine.Value = CurrentUNIXDate;
|
||||
|
||||
For Each TableRow In ParametersTable Do
|
||||
|
||||
TableRow.Key = EncodeString(TableRow.Key, StringEncodingMethod.URLencoding);
|
||||
TableRow.TheKey = EncodeString(TableRow.TheKey, StringEncodingMethod.URLencoding);
|
||||
TableRow.Value = EncodeString(TableRow.Value, StringEncodingMethod.URLencoding);
|
||||
|
||||
EndDo;
|
||||
|
||||
ParametersTable.Sort("Key");
|
||||
ParametersTable.Sort("TheKey");
|
||||
|
||||
For Each TableRow In ParametersTable Do
|
||||
|
||||
SignatureString = SignatureString
|
||||
+ TableRow.Key
|
||||
+ TableRow.TheKey
|
||||
+ "="
|
||||
+ TableRow.Value
|
||||
+ "&";
|
||||
|
||||
EndDo;
|
||||
|
||||
SignatureString = Left(SignatureString, StrLength(SignatureString) - 1);
|
||||
SignatureString = inReg(RequestType)
|
||||
SignatureString = Left(SignatureString, StrLen(SignatureString) - 1);
|
||||
SignatureString = Upper(RequestType)
|
||||
+ "&"
|
||||
+ EncodeString(URL, StringEncodingMethod.URLencoding)
|
||||
+ "&"
|
||||
@@ -641,7 +644,7 @@ Function CreateAuthorizationHeaderV1(Val Parameters, Val Fields, Val RequestType
|
||||
+ "oauth_version=""" + APIVersion + Delimiter
|
||||
+ "oauth_signature=""" + Signature;
|
||||
|
||||
HeaderMapping = New Match;
|
||||
HeaderMapping = New Map;
|
||||
HeaderMapping.Insert("authorization", AuthorizationHeader);
|
||||
|
||||
Return HeaderMapping;
|
||||
@@ -650,7 +653,7 @@ EndFunction
|
||||
|
||||
Function CreateAuthorizationHeaderV2(Val Parameters)
|
||||
|
||||
ReturnMapping = New Match;
|
||||
ReturnMapping = New Map;
|
||||
ReturnMapping.Insert("Authorization", "Bearer " + Parameters["access_token"]);
|
||||
|
||||
Return ReturnMapping;
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_Twitter</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы work with Twitter (OPI)</value>
|
||||
<value>Twitter methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/tools/Modules/OPI_TypeConversion.os
|
||||
//
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -28,9 +28,14 @@
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UnusedLocalVariable-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check undefined-function-or-procedure
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// #Use "./internal"
|
||||
|
||||
#Region ServiceProgramInterface
|
||||
#Region Internal
|
||||
|
||||
Procedure GetBinaryData(Value) Export
|
||||
|
||||
@@ -40,7 +45,7 @@ Procedure GetBinaryData(Value) Export
|
||||
|
||||
Try
|
||||
|
||||
If TypeValue(Value) = Type("BinaryData") Then
|
||||
If TypeOf(Value) = Type("BinaryData") Then
|
||||
Return;
|
||||
Else
|
||||
|
||||
@@ -73,7 +78,7 @@ Procedure GetBinaryOrStream(Value) Export
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Value) <> Type("String") Then
|
||||
If TypeOf(Value) <> Type("String") Then
|
||||
GetBinaryData(Value);
|
||||
Return;
|
||||
EndIf;
|
||||
@@ -102,36 +107,36 @@ Procedure GetCollection(Value) Export
|
||||
Return;
|
||||
Else
|
||||
|
||||
If TypeValue(Value) = Type("BinaryData") Then
|
||||
If TypeOf(Value) = Type("BinaryData") Then
|
||||
Value = GetStringFromBinaryData(Value);
|
||||
Else
|
||||
Value = OPI_Tools.NumberToString(Value);
|
||||
EndIf;
|
||||
|
||||
File = New File(Value);
|
||||
ReadingJSON = New ReadingJSON;
|
||||
JSONReader = New JSONReader;
|
||||
|
||||
If File.Exists() Then
|
||||
|
||||
ReadingJSON.OpenFile(Value);
|
||||
JSONReader.OpenFile(Value);
|
||||
|
||||
ElsIf StringStartsWith(nReg(Value), "http") Then
|
||||
ElsIf StrStartsWith(Lower(Value), "http") Then
|
||||
|
||||
AndVF = GetTempFileName();
|
||||
CopyFile(Value, AndVF);
|
||||
ReadingJSON.OpenFile(AndVF);
|
||||
ReadingJSON.Read();
|
||||
JSONReader.OpenFile(AndVF);
|
||||
JSONReader.Read();
|
||||
|
||||
DeleteFiles(AndVF);
|
||||
|
||||
Else
|
||||
|
||||
ReadingJSON.SetString(ShortLP(Value));
|
||||
JSONReader.SetString(TrimAll(Value));
|
||||
|
||||
EndIf;
|
||||
|
||||
Value = ReadJSON(ReadingJSON, True, Undefined, JSONDateFormat.ISO);
|
||||
ReadingJSON.Close();
|
||||
Value = ReadJSON(JSONReader, True, Undefined, JSONDateFormat.ISO);
|
||||
JSONReader.Close();
|
||||
|
||||
If (Not ThisIsCollection(Value)) Or Not ValueIsFilled(Value) Then
|
||||
|
||||
@@ -153,31 +158,31 @@ EndProcedure
|
||||
|
||||
Procedure GetArray(Value) Export
|
||||
|
||||
If TypeValue(Value) = Type("Array") Then
|
||||
If TypeOf(Value) = Type("Array") Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Value) = Type("String")
|
||||
And StringStartsWith(Value, "[")
|
||||
If TypeOf(Value) = Type("String")
|
||||
And StrStartsWith(Value, "[")
|
||||
And StrEndsWith(Value, "]") Then
|
||||
|
||||
CommaInQuotes = "','";
|
||||
|
||||
Value = StringReplace(Value, "['" , "");
|
||||
Value = StringReplace(Value, "']" , "");
|
||||
Value = StringReplace(Value, "', '" , CommaInQuotes);
|
||||
Value = StringReplace(Value, "' , '", CommaInQuotes);
|
||||
Value = StringReplace(Value, "' ,'" , CommaInQuotes);
|
||||
Value = StrReplace(Value, "['" , "");
|
||||
Value = StrReplace(Value, "']" , "");
|
||||
Value = StrReplace(Value, "', '" , CommaInQuotes);
|
||||
Value = StrReplace(Value, "' , '", CommaInQuotes);
|
||||
Value = StrReplace(Value, "' ,'" , CommaInQuotes);
|
||||
|
||||
Value = StrSplit(Value, CommaInQuotes, False);
|
||||
|
||||
For N = 0 For Value.WithinBoundary() Do
|
||||
Value[N] = ShortLP(Value[N]);
|
||||
For N = 0 To Value.WithinBoundary() Do
|
||||
Value[N] = TrimAll(Value[N]);
|
||||
EndDo;
|
||||
|
||||
Else
|
||||
|
||||
If TypeValue(Value) = Type("Number") Then
|
||||
If TypeOf(Value) = Type("Number") Then
|
||||
Value = OPI_Tools.NumberToString(Value);
|
||||
EndIf;
|
||||
|
||||
@@ -195,7 +200,7 @@ Procedure GetBoolean(Value) Export
|
||||
|
||||
Try
|
||||
|
||||
If TypeValue(Value) = Type("Boolean") Then
|
||||
If TypeOf(Value) = Type("Boolean") Then
|
||||
Return;
|
||||
Else
|
||||
Value = Boolean(Value);
|
||||
@@ -227,18 +232,18 @@ Procedure GetLine(Value, Val FromSource = False) Export
|
||||
|
||||
If File.Exists() Then
|
||||
|
||||
ReadingText = New ReadingText(Value);
|
||||
Value = ReadingText.Read();
|
||||
ReadingText.Close();
|
||||
TextReader = New TextReader(Value);
|
||||
Value = TextReader.Read();
|
||||
TextReader.Close();
|
||||
|
||||
ElsIf StringStartsWith(nReg(Value), "http") Then
|
||||
ElsIf StrStartsWith(Lower(Value), "http") Then
|
||||
|
||||
AndVF = GetTempFileName();
|
||||
CopyFile(Value, AndVF);
|
||||
|
||||
ReadingText = New ReadingText(AndVF);
|
||||
Value = ReadingText.Read();
|
||||
ReadingText.Close();
|
||||
TextReader = New TextReader(AndVF);
|
||||
Value = TextReader.Read();
|
||||
TextReader.Close();
|
||||
|
||||
DeleteFiles(AndVF);
|
||||
|
||||
@@ -248,7 +253,7 @@ Procedure GetLine(Value, Val FromSource = False) Export
|
||||
|
||||
EndIf;
|
||||
|
||||
ElsIf TypeValue(Value) = Type("BinaryData") Then
|
||||
ElsIf TypeOf(Value) = Type("BinaryData") Then
|
||||
|
||||
Value = GetStringFromBinaryData(Value);
|
||||
|
||||
@@ -277,7 +282,7 @@ Procedure GetDate(Value) Export
|
||||
|
||||
Try
|
||||
|
||||
If TypeValue(Value) = Type(Date) Then
|
||||
If TypeOf(Value) = Type(Date) Then
|
||||
Return;
|
||||
Else
|
||||
Value = XMLValue(Type(Date), Value);
|
||||
@@ -299,21 +304,21 @@ EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function ThisIsCollection(Val Value)
|
||||
|
||||
Return TypeValue(Value) = Type("Array")
|
||||
Or TypeValue(Value) = Type("Structure")
|
||||
Or TypeValue(Value) = Type("Match");
|
||||
Return TypeOf(Value) = Type("Array")
|
||||
Or TypeOf(Value) = Type("Structure")
|
||||
Or TypeOf(Value) = Type("Map");
|
||||
|
||||
EndFunction
|
||||
|
||||
Function ThisIsSymbolic(Val Value)
|
||||
|
||||
Return TypeValue(Value) = Type("String")
|
||||
Or TypeValue(Value) = Type("Number")
|
||||
Or TypeValue(Value) = Type("Date");
|
||||
Return TypeOf(Value) = Type("String")
|
||||
Or TypeOf(Value) = Type("Number")
|
||||
Or TypeOf(Value) = Type("Date");
|
||||
|
||||
EndFunction
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_TypeConversion</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Преобразоinание typeоin (OPI)</value>
|
||||
<value>Type conversion (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_VK.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_VK.os
|
||||
// Library: VK
|
||||
// CLI Command: vk
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
// https://github.com/Bayselonarrend/OpenIntegrations
|
||||
// If in не зtoете with чего toчать, то withтоит toйти method GetStandardParameters()
|
||||
// If you don't know where to start, you should find the method GetStandardParameters()
|
||||
// and read comments
|
||||
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
@@ -37,11 +37,14 @@
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check wrong-string-literal-content
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region TokenRetrieval
|
||||
|
||||
@@ -52,7 +55,7 @@
|
||||
// Parameters:
|
||||
// app_id - String, Number - app_id from application settings - app
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - URL to go to in the browser
|
||||
Function CreateTokenRetrievalLink(Val App_id) Export
|
||||
|
||||
@@ -74,12 +77,12 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Post text - text
|
||||
// ImageArray - Array from String, BinaryData - Array of images - pictures
|
||||
// Advertisement - Boolean - Indication ""Это реtoлама"" - ad
|
||||
// ImageArray - Array of String, BinaryData - Array of images - pictures
|
||||
// Advertisement - Boolean - Sign ""This is an ad"" - ad
|
||||
// LinkUnderPost - String - Link (URL) under the post - url
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreatePost(Val Text
|
||||
, Val ImageArray
|
||||
@@ -120,16 +123,16 @@ Function CreatePost(Val Text
|
||||
EndFunction
|
||||
|
||||
// Create composite post
|
||||
// Созdает поwithт to mainоinе маwithwithиinа иdетифиtoатороin объеtoтоin (toартиноto, inиdео и dр.)
|
||||
// Creates a post based on an array of object identifiers (images, videos, etc..)
|
||||
//
|
||||
// Parameters:
|
||||
// Text - String - Post text - text
|
||||
// Objects - Array of Strings - Array of identifiers like photo123_123 - objects
|
||||
// Advertisement - Boolean - Indication ""Это реtoлама"" - ad
|
||||
// Objects - Array of String - Array of identifiers like photo123_123 - objects
|
||||
// Advertisement - Boolean - Sign ""This is an ad"" - ad
|
||||
// LinkUnderPost - String - Link (URL) under the post - url
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateCompositePost(Val Text
|
||||
, Val Objects
|
||||
@@ -142,7 +145,7 @@ Function CreateCompositePost(Val Text
|
||||
OPI_TypeConversion.GetBoolean(Advertisement);
|
||||
|
||||
Parameters = GetStandardParameters(Parameters);
|
||||
AttachmentsString = StrJoin(Objects, ",");
|
||||
AttachmentsString = StrConcat(Objects, ",");
|
||||
AttachmentsString = AttachmentsString + LinkUnderPost;
|
||||
|
||||
Parameters.Insert("message" , Text);
|
||||
@@ -163,7 +166,7 @@ EndFunction
|
||||
// PostID - String, Number - Post ID - post
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeletePost(Val PostID, Val Parameters = "") Export
|
||||
|
||||
@@ -183,11 +186,11 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Question - String - Poll question - question
|
||||
// AnswersArray - Array of Strings - Array of answer options - options
|
||||
// AnswersArray - Array of String - Array of answer options - options
|
||||
// Image - String, BinaryData - Poll image - picture
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreatePoll(Val Question, Val AnswersArray, Val Image = "", Val Parameters = "") Export
|
||||
|
||||
@@ -220,7 +223,7 @@ Function CreatePoll(Val Question, Val AnswersArray, Val Image = "", Val Paramete
|
||||
Parameters_.Insert("is_anonymous", 1);
|
||||
Parameters_.Insert("is_multiple" , 0);
|
||||
|
||||
Answers = StrJoin(AnswersArray, """,""");
|
||||
Answers = StrConcat(AnswersArray, """,""");
|
||||
Answers = "[""" + Answers + """]";
|
||||
|
||||
Parameters_.Insert("add_answers", Answers);
|
||||
@@ -262,7 +265,7 @@ EndFunction
|
||||
// Description - String - Album description - description
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateAlbum(Val Name, Val Description = "", Val Parameters = "") Export
|
||||
|
||||
@@ -288,7 +291,7 @@ EndFunction
|
||||
// AlbumID - String, Number - Album ID - album
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeleteAlbum(Val AlbumID, Val Parameters = "") Export
|
||||
|
||||
@@ -311,7 +314,7 @@ EndFunction
|
||||
// URL - String - URL for button under the story - url
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateStory(Val Image, Val URL = "", Val Parameters = "") Export
|
||||
|
||||
@@ -336,7 +339,7 @@ EndFunction
|
||||
// Description - String - Image description - description
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function SaveImageToAlbum(Val AlbumID, Val Image, Val Description = "", Val Parameters = "") Export
|
||||
|
||||
@@ -359,7 +362,7 @@ EndFunction
|
||||
// ImageID - String, Number - Image ID - pictureid
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeleteImage(Val ImageID, Val Parameters = "") Export
|
||||
|
||||
@@ -384,7 +387,7 @@ EndFunction
|
||||
// Album - String - Album ID, if necessary - album
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function UploadVideoToServer(Val Video
|
||||
, Val Name
|
||||
@@ -413,7 +416,7 @@ Function UploadVideoToServer(Val Video
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
FileMapping = New Match;
|
||||
FileMapping = New Map;
|
||||
OPI_Tools.AddField("video_file.mp4", Video, "BinaryData", FileMapping);
|
||||
|
||||
DataSize = FileMapping["video_file.mp4"].Size();
|
||||
@@ -431,23 +434,23 @@ EndFunction
|
||||
// Parameters:
|
||||
// Image - String, BinaryData - Image file - file
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
// View - String - View upload (Post, Product, Story, Poll, Miscellaneous) - type
|
||||
// View - String - Upload type (Post, Product, Story, Poll, Other) - type
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function UploadPhotoToServer(Val Image, Val Parameters = "", Val View = "Post") Export
|
||||
|
||||
Parameters = GetStandardParameters(Parameters);
|
||||
Method = DetermineImageUploadMethod(View);
|
||||
Files = New Match;
|
||||
Files = New Map;
|
||||
|
||||
Response = "response";
|
||||
URL = "api.vk.com/method/";
|
||||
Upload = URL + Method["Upload"];
|
||||
Save = URL + Method["Save"];
|
||||
|
||||
If TypeValue(Image) = Type("String") Then
|
||||
ImageKey = StringReplace(Image, ".", "___");
|
||||
If TypeOf(Image) = Type("String") Then
|
||||
ImageKey = StrReplace(Image, ".", "___");
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
Else
|
||||
ImageKey = "image___jpeg";
|
||||
@@ -455,7 +458,7 @@ Function UploadPhotoToServer(Val Image, Val Parameters = "", Val View = "Post")
|
||||
|
||||
Files.Insert(ImageKey, Image);
|
||||
|
||||
For N = 1 For 5 Do
|
||||
For N = 1 To 5 Do
|
||||
|
||||
Response = OPI_Tools.Get(Upload, Parameters);
|
||||
Result = Response[Response];
|
||||
@@ -475,13 +478,13 @@ Function UploadPhotoToServer(Val Image, Val Parameters = "", Val View = "Post")
|
||||
Parameters.Insert("upload_url", URL);
|
||||
Response = OPI_Tools.PostMultipart(URL, Parameters, Files);
|
||||
|
||||
If TypeValue(Response) = Type("Match") Then
|
||||
If TypeOf(Response) = Type("Map") Then
|
||||
Break;
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If TypeValue(Response) <> Type("Match") Then
|
||||
If TypeOf(Response) <> Type("Map") Then
|
||||
Return GetStringFromBinaryData(Response);
|
||||
EndIf;
|
||||
|
||||
@@ -502,19 +505,19 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Name - String - Discussion name - title
|
||||
// Text of the first message - String - Text of the first message - text
|
||||
// FirstMessageText - String - Text of the first message - text
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateDiscussion(Val Name, Val Text of the first message, Val Parameters = "") Export
|
||||
Function CreateDiscussion(Val Name, Val FirstMessageText, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Name);
|
||||
OPI_TypeConversion.GetLine(Text of the first message);
|
||||
OPI_TypeConversion.GetLine(FirstMessageText);
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
Parameters_.Insert("title", Name);
|
||||
Parameters_.Insert("text" , Text of the first message);
|
||||
Parameters_.Insert("text" , FirstMessageText);
|
||||
|
||||
Response = OPI_Tools.Get("api.vk.com/method/board.addTopic", Parameters_);
|
||||
|
||||
@@ -527,20 +530,20 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// DiscussionID - String, Number - Discussion ID - topic
|
||||
// Delete completely - Boolean - Delete completely (True) or close - remove
|
||||
// DeleteCompletely - Boolean - Delete completely (True) or close - remove
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CloseDiscussion(Val DiscussionID, Val Delete completely = False, Val Parameters = "") Export
|
||||
Function CloseDiscussion(Val DiscussionID, Val DeleteCompletely = False, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(DiscussionID);
|
||||
OPI_TypeConversion.GetBoolean(Delete completely);
|
||||
OPI_TypeConversion.GetBoolean(DeleteCompletely);
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
Parameters_.Insert("topic_id", DiscussionID);
|
||||
|
||||
Method = ?(Delete completely, "deleteTopic", "closeTopic");
|
||||
Method = ?(DeleteCompletely, "deleteTopic", "closeTopic");
|
||||
Response = OPI_Tools.Get("api.vk.com/method/board." + Method, Parameters_);
|
||||
|
||||
Return Response;
|
||||
@@ -554,7 +557,7 @@ EndFunction
|
||||
// DiscussionID - String, Number - Discussion ID - topic
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function OpenDiscussion(Val DiscussionID, Val Parameters = "") Export
|
||||
|
||||
@@ -577,7 +580,7 @@ EndFunction
|
||||
// Text - String - Message text - text
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function WriteInDiscussion(Val DiscussionID, Val Text, Val Parameters = "") Export
|
||||
|
||||
@@ -606,7 +609,7 @@ EndFunction
|
||||
// WallID - String, Number - ID of the wall where the post is located - wall
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function LikePost(Val PostID, Val WallID = "", Val Parameters = "") Export
|
||||
|
||||
@@ -635,15 +638,15 @@ EndFunction
|
||||
// Parameters:
|
||||
// PostID - String, Number - Post ID - post
|
||||
// WallID - String, Number - ID of the wall where the post is located - from
|
||||
// Target wall - String, Number - ID of the target wall or group - to
|
||||
// TargetWall - String, Number - ID of the target wall or group - to
|
||||
// Advertising - Boolean - Sign of an advertising post - ad
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function MakeRepost(Val PostID
|
||||
, Val WallID = ""
|
||||
, Val Target wall = ""
|
||||
, Val TargetWall = ""
|
||||
, Val Advertising = False
|
||||
, Val Parameters = "") Export
|
||||
|
||||
@@ -653,14 +656,14 @@ Function MakeRepost(Val PostID
|
||||
OPI_TypeConversion.GetLine(GroupId);
|
||||
OPI_TypeConversion.GetLine(PostID);
|
||||
OPI_TypeConversion.GetLine(WallID);
|
||||
OPI_TypeConversion.GetLine(Target wall);
|
||||
OPI_TypeConversion.GetLine(TargetWall);
|
||||
OPI_TypeConversion.GetBoolean(Advertising);
|
||||
|
||||
Source = ?(ValueIsFilled(WallID), WallID, GroupId);
|
||||
Receiver = ?(ValueIsFilled(Target wall), Target wall, GroupId);
|
||||
Receiver = ?(ValueIsFilled(TargetWall), TargetWall, GroupId);
|
||||
|
||||
Parameters_.Insert("object" , "wall" + Source + "_" + OPI_Tools.NumberToString(PostID));
|
||||
Parameters_.Insert("group_id" , StringReplace(Receiver, "-", ""));
|
||||
Parameters_.Insert("group_id" , StrReplace(Receiver, "-", ""));
|
||||
Parameters_.Insert("mark_as_ads" , ?(Advertising, 1, 0));
|
||||
|
||||
Response = OPI_Tools.Get("api.vk.com/method/wall.repost", Parameters_);
|
||||
@@ -679,7 +682,7 @@ EndFunction
|
||||
// Keyboard - String - JSON keyboard. See FormKeyboard - keyboard
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function WriteMessage(Val Text
|
||||
, Val UserID
|
||||
@@ -720,7 +723,7 @@ EndFunction
|
||||
// Text - String - Comment text - text
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function WriteComment(Val PostID, Val WallID, Val Text, Val Parameters = "") Export
|
||||
|
||||
@@ -752,7 +755,7 @@ EndFunction
|
||||
// URL - String - URL for shortening - url
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - Shortened URL
|
||||
Function ShortenLink(Val URL, Val Parameters = "") Export
|
||||
|
||||
@@ -794,7 +797,7 @@ EndFunction
|
||||
// EndDate - Date - End date of the period - dateto
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GetStatistics(Val StartDate, Val EndDate, Val Parameters = "") Export
|
||||
|
||||
@@ -820,51 +823,51 @@ EndFunction
|
||||
// Gets statistics in terms of posts
|
||||
//
|
||||
// Parameters:
|
||||
// Array of post IDs - Array of String,Number - Array of post IDs - posts
|
||||
// PostIDsArray - Array of String,Number - Array of post IDs - posts
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Array of Arbitrary - Array of post statistics data
|
||||
Function GetPostStatistics(Val Array of post IDs, Val Parameters = "") Export
|
||||
Function GetPostStatistics(Val PostIDsArray, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetCollection(Array of post IDs);
|
||||
OPI_TypeConversion.GetCollection(PostIDsArray);
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
AnswersArray = New Array;
|
||||
Array of Sets = New Array;
|
||||
SetsArray = New Array;
|
||||
MaximumPosts = 30;
|
||||
Response = "response";
|
||||
|
||||
For Each Post In Array of post IDs Do
|
||||
For Each Post In PostIDsArray Do
|
||||
|
||||
Array of Sets.Add(OPI_Tools.NumberToString(Post));
|
||||
SetsArray.Add(OPI_Tools.NumberToString(Post));
|
||||
|
||||
If Array of Sets.Quantity() = MaximumPosts Then
|
||||
If SetsArray.Quantity() = MaximumPosts Then
|
||||
|
||||
NumbersString = StrJoin(Array of Sets, ",");
|
||||
NumbersString = StrConcat(SetsArray, ",");
|
||||
Parameters_.Insert("post_ids", NumbersString);
|
||||
|
||||
Statistics = OPI_Tools.Get("api.vk.com/method/stats.getPostReach", Parameters_);
|
||||
Array of Statistics = Statistics[Response];
|
||||
StatisticsArray = Statistics[Response];
|
||||
|
||||
For Each StatisticsItem In Array of Statistics Do
|
||||
For Each StatisticsItem In StatisticsArray Do
|
||||
AnswersArray.Add(StatisticsItem);
|
||||
EndDo;
|
||||
|
||||
Array of Sets = New Array;
|
||||
SetsArray = New Array;
|
||||
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
NumbersString = StrJoin(Array of Sets, ",");
|
||||
NumbersString = StrConcat(SetsArray, ",");
|
||||
Parameters_.Insert("post_ids", NumbersString);
|
||||
|
||||
Statistics = OPI_Tools.Get("api.vk.com/method/stats.getPostReach", Parameters_);
|
||||
Array of Statistics = Statistics[Response];
|
||||
StatisticsArray = Statistics[Response];
|
||||
|
||||
If TypeValue(Array of Statistics) = Type("Array") Then
|
||||
For Each StatisticsItem In Array of Statistics Do
|
||||
If TypeOf(StatisticsArray) = Type("Array") Then
|
||||
For Each StatisticsItem In StatisticsArray Do
|
||||
AnswersArray.Add(StatisticsItem);
|
||||
EndDo;
|
||||
EndIf;
|
||||
@@ -885,7 +888,7 @@ EndFunction
|
||||
// Name - String - Campaign name - title
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateAdvertisingCampaign(Val AccountID, Val Name, Val Parameters = "") Export
|
||||
|
||||
@@ -898,7 +901,7 @@ Function CreateAdvertisingCampaign(Val AccountID, Val Name, Val Parameters = "")
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
Parameters_.Insert("account_id", AccountID);
|
||||
|
||||
Array of Structures = New Array;
|
||||
StructuresArray = New Array;
|
||||
StartDate = OPI_Tools.UNIXTime(CurrentDate);
|
||||
EndDate = OPI_Tools.UNIXTime(EndDate);
|
||||
|
||||
@@ -911,9 +914,9 @@ Function CreateAdvertisingCampaign(Val AccountID, Val Name, Val Parameters = "")
|
||||
CampaignStructure.Insert("stop_time" , EndDate);
|
||||
CampaignStructure.Insert("status" , 1);
|
||||
|
||||
Array of Structures.Add(CampaignStructure);
|
||||
StructuresArray.Add(CampaignStructure);
|
||||
|
||||
JSONDate = OPI_Tools.JSONString(Array of Structures);
|
||||
JSONDate = OPI_Tools.JSONString(StructuresArray);
|
||||
|
||||
Parameters_.Insert("data", JSONDate);
|
||||
|
||||
@@ -934,7 +937,7 @@ EndFunction
|
||||
// AccountID - String, Number - Advertising account ID - cabinet
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateAd(Val CampaignNumber
|
||||
, Val DailyLimit
|
||||
@@ -955,7 +958,7 @@ Function CreateAd(Val CampaignNumber
|
||||
|
||||
Link = "https://vk.com/wall-" + GroupId + "_" + PostID;
|
||||
|
||||
Array of Structures = New Array;
|
||||
StructuresArray = New Array;
|
||||
CampaignStructure = New Structure;
|
||||
CampaignStructure.Insert("campaign_id" , CampaignNumber);
|
||||
CampaignStructure.Insert("ad_format" , 9);
|
||||
@@ -974,11 +977,11 @@ Function CreateAd(Val CampaignNumber
|
||||
CampaignStructure.Insert("name" , "Ad");
|
||||
CampaignStructure.Insert("link_url" , Link);
|
||||
|
||||
Array of Structures.Add(CampaignStructure);
|
||||
StructuresArray.Add(CampaignStructure);
|
||||
|
||||
OPI_TypeConversion.GetLine(Array of Structures, True);
|
||||
OPI_TypeConversion.GetLine(StructuresArray, True);
|
||||
|
||||
Parameters_.Insert("data" , Array of Structures);
|
||||
Parameters_.Insert("data" , StructuresArray);
|
||||
Parameters_.Insert("account_id" , AccountID);
|
||||
|
||||
Response = OPI_Tools.Get("api.vk.com/method/ads.createAds", Parameters_);
|
||||
@@ -995,7 +998,7 @@ EndFunction
|
||||
// AdID - String, Number - Ad ID - adv
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function PauseAdvertisingAd(Val AccountID, Val AdID, Val Parameters = "") Export
|
||||
|
||||
@@ -1006,17 +1009,17 @@ Function PauseAdvertisingAd(Val AccountID, Val AdID, Val Parameters = "") Export
|
||||
|
||||
Parameters_.Insert("account_id", AccountID);
|
||||
|
||||
Array of Structures = New Array;
|
||||
StructuresArray = New Array;
|
||||
CampaignStructure = New Structure;
|
||||
|
||||
CampaignStructure.Insert("ad_id" , AdID);
|
||||
CampaignStructure.Insert("status" , 0);
|
||||
|
||||
Array of Structures.Add(CampaignStructure);
|
||||
StructuresArray.Add(CampaignStructure);
|
||||
|
||||
OPI_TypeConversion.GetLine(Array of Structures, True);
|
||||
OPI_TypeConversion.GetLine(StructuresArray, True);
|
||||
|
||||
Parameters_.Insert("data", Array of Structures);
|
||||
Parameters_.Insert("data", StructuresArray);
|
||||
|
||||
Response = OPI_Tools.Get("api.vk.com/method/ads.updateAds", Parameters_);
|
||||
|
||||
@@ -1030,7 +1033,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GetAdvertisingCategoryList(Val Parameters = "") Export
|
||||
|
||||
@@ -1051,8 +1054,8 @@ EndFunction
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Compliance From String - Key - ID, Value - Name
|
||||
// Returns:
|
||||
// Map Of String - TheKey - ID, Value - Name
|
||||
Function GetProductCategoryList(Val Parameters = "") Export
|
||||
|
||||
Response = "response";
|
||||
@@ -1088,7 +1091,7 @@ Function GetProductCategoryList(Val Parameters = "") Export
|
||||
Return Response;
|
||||
EndIf;
|
||||
|
||||
CategoryCorrespondence = New Match;
|
||||
CategoryCorrespondence = New Map;
|
||||
|
||||
For Each Category In Categories Do
|
||||
CategoryCorrespondence.Insert(Category["id"], Category["name"]);
|
||||
@@ -1105,7 +1108,7 @@ EndFunction
|
||||
// Selection - String, Number - Selection ID, if filtering is needed - sel
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of product matches
|
||||
Function GetProductList(Val Selection = "", Val Parameters = "") Export
|
||||
|
||||
@@ -1120,10 +1123,10 @@ Function GetProductList(Val Selection = "", Val Parameters = "") Export
|
||||
Parameters_.Insert("album_id", Selection);
|
||||
EndIf;
|
||||
|
||||
Array of products = New Array;
|
||||
GetProductListRecursively(Array of products, Parameters_);
|
||||
ProductsArray = New Array;
|
||||
GetProductListRecursively(ProductsArray, Parameters_);
|
||||
|
||||
Return Array of products;
|
||||
Return ProductsArray;
|
||||
|
||||
EndFunction
|
||||
|
||||
@@ -1131,10 +1134,10 @@ EndFunction
|
||||
// Gets information about products by array of IDs
|
||||
//
|
||||
// Parameters:
|
||||
// Products - String, Array of Strings - Array of product IDs - items
|
||||
// Products - String, Array of String - Array of product IDs - items
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GetProductsByID(Val Products, Val Parameters = "") Export
|
||||
|
||||
@@ -1150,7 +1153,7 @@ Function GetProductsByID(Val Products, Val Parameters = "") Export
|
||||
ProductsString = ProductsString + CurrentProduct + ",";
|
||||
EndDo;
|
||||
|
||||
ProductsString = Left(ProductsString, StrLength(ProductsString) - 1);
|
||||
ProductsString = Left(ProductsString, StrLen(ProductsString) - 1);
|
||||
Parameters_.Insert("item_ids", ProductsString);
|
||||
Parameters_.Insert("extended", 1);
|
||||
|
||||
@@ -1168,7 +1171,7 @@ EndFunction
|
||||
// Selection - String - Selection ID for placing the product, if needed - sel
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function AddProduct(Val ProductDescription, Val Selection = "", Val Parameters = "") Export
|
||||
Return ProductManagement(ProductDescription, , Selection, Parameters);
|
||||
@@ -1183,7 +1186,7 @@ EndFunction
|
||||
// Selection - String - Identifier of the new selection, if needed - sel
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function EditProduct(Val Product, Val ProductDescription, Val Selection = "", Val Parameters = "") Export
|
||||
Return ProductManagement(ProductDescription, Product, Selection, Parameters);
|
||||
@@ -1196,7 +1199,7 @@ EndFunction
|
||||
// Product - String, Number - Product ID - item
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeleteProduct(Val Product, Val Parameters = "") Export
|
||||
|
||||
@@ -1215,25 +1218,25 @@ EndFunction
|
||||
// Groups products based on similar sets of properties
|
||||
//
|
||||
// Parameters:
|
||||
// Array of products - Array Of String - Array of product IDs - items
|
||||
// ProductsArray - Array Of String - Array of product IDs - items
|
||||
// ExistingGroup - String - ID of the existing group, if needed - sellgroup
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GroupProducts(Val Array of products, Val ExistingGroup = "", Val Parameters = "") Export
|
||||
Function GroupProducts(Val ProductsArray, Val ExistingGroup = "", Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(ExistingGroup);
|
||||
OPI_TypeConversion.GetCollection(Array of products);
|
||||
OPI_TypeConversion.GetCollection(ProductsArray);
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
Array_of_Products = New Array;
|
||||
ArrayOfProducts_ = New Array;
|
||||
|
||||
For Each Product In Array of products Do
|
||||
Array_of_Products.Add(OPI_Tools.NumberToString(Product));
|
||||
For Each Product In ProductsArray Do
|
||||
ArrayOfProducts_.Add(OPI_Tools.NumberToString(Product));
|
||||
EndDo;
|
||||
|
||||
Products = StrJoin(Array_of_Products, ",");
|
||||
Products = StrConcat(ArrayOfProducts_, ",");
|
||||
|
||||
Parameters_.Insert("item_ids", Products);
|
||||
|
||||
@@ -1249,7 +1252,7 @@ EndFunction
|
||||
|
||||
// Get product description. !NOCLI
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Empty product description:
|
||||
// *Name - String - Product name
|
||||
// *Description - String - Product description
|
||||
@@ -1261,15 +1264,15 @@ EndFunction
|
||||
// *AdditionalPhotos - Array Of String - Binary Data or Photo Paths
|
||||
// *PropertyValues - Array Of String - See AddPropertyVariant
|
||||
// *MainInGroup - Boolean - Main in the group, if exists in the group
|
||||
// *Width - Number - Width product in мм.
|
||||
// *Height - Number - Height product in мм.
|
||||
// *Depth - Number - Depth product in мм.
|
||||
// *Weight - Number - Weight in гр.
|
||||
// *Width - Number - Product width in mm.
|
||||
// *Height - Number - Product height in mm.
|
||||
// *Depth - Number - Product depth in mm.
|
||||
// *Weight - Number - Weight in g.
|
||||
// *SKU - String - SKU
|
||||
// *AvailableBalance - Number - Balance. -1 - unlimited
|
||||
Function GetProductDescription() Export
|
||||
|
||||
Product = New Match();
|
||||
Product = New Map();
|
||||
Product.Insert("Name" , "New product"); // Product name
|
||||
Product.Insert("Description" , "Product description"); // Product description
|
||||
Product.Insert("Category" , "20173"); // See GetProductCategoryList()
|
||||
@@ -1301,7 +1304,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Array of selection matches
|
||||
Function GetSelectionList(Val Parameters = "") Export
|
||||
|
||||
@@ -1319,10 +1322,10 @@ EndFunction
|
||||
// Gets the list of selections by array of IDs
|
||||
//
|
||||
// Parameters:
|
||||
// Selections - String, Array of Strings - Selection IDs - sels
|
||||
// Selections - String, Array of String - Selection IDs - sels
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GetSelectionsByID(Val Selections, Val Parameters = "") Export
|
||||
|
||||
@@ -1336,7 +1339,7 @@ Function GetSelectionsByID(Val Selections, Val Parameters = "") Export
|
||||
Selections_.Add(OPI_Tools.NumberToString(Selection));
|
||||
EndDo;
|
||||
|
||||
SelectionsString = StrJoin(Selections_, ",");
|
||||
SelectionsString = StrConcat(Selections_, ",");
|
||||
|
||||
Parameters_.Insert("album_ids", SelectionsString);
|
||||
|
||||
@@ -1356,7 +1359,7 @@ EndFunction
|
||||
// Hidden - Boolean - Hidden - hidden
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateProductCollection(Val Name
|
||||
, Val Image
|
||||
@@ -1379,7 +1382,7 @@ EndFunction
|
||||
// Hidden - Boolean - Hidden - hidden
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function EditProductCollection(Val Name
|
||||
, Val Selection
|
||||
@@ -1396,25 +1399,25 @@ EndFunction
|
||||
// Adds a product to the selection
|
||||
//
|
||||
// Parameters:
|
||||
// Array of products - Array of string, number - Array of products or product - items
|
||||
// ProductsArray - Array of string, number - Array of products or product - items
|
||||
// Selection - String - Selection ID - sel
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function AddProductToSelection(Val Array of products, Val Selection, Val Parameters = "") Export
|
||||
Function AddProductToSelection(Val ProductsArray, Val Selection, Val Parameters = "") Export
|
||||
|
||||
OPI_TypeConversion.GetCollection(Array of products);
|
||||
OPI_TypeConversion.GetCollection(ProductsArray);
|
||||
OPI_TypeConversion.GetLine(Selection);
|
||||
|
||||
Parameters_ = GetStandardParameters(Parameters);
|
||||
Array_of_Products = New Array;
|
||||
ArrayOfProducts_ = New Array;
|
||||
|
||||
For Each Product In Array of products Do
|
||||
Array_of_Products.Add(OPI_Tools.NumberToString(Product));
|
||||
For Each Product In ProductsArray Do
|
||||
ArrayOfProducts_.Add(OPI_Tools.NumberToString(Product));
|
||||
EndDo;
|
||||
|
||||
ProductList = StrJoin(Array_of_Products, ",");
|
||||
ProductList = StrConcat(ArrayOfProducts_, ",");
|
||||
|
||||
Parameters_.Insert("item_ids" , ProductList);
|
||||
Parameters_.Insert("album_ids", Selection);
|
||||
@@ -1433,7 +1436,7 @@ EndFunction
|
||||
// Selection - String - Selection ID - sel
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function RemoveProductFromSelection(Val Product, Val Selection, Val Parameters = "") Export
|
||||
|
||||
@@ -1458,7 +1461,7 @@ EndFunction
|
||||
// Selection - String - Selection ID - sel
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeleteSelection(Val Selection, Val Parameters = "") Export
|
||||
|
||||
@@ -1483,7 +1486,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GetPropertyList(Val Parameters = "") Export
|
||||
|
||||
@@ -1504,7 +1507,7 @@ EndFunction
|
||||
// Name - String - Property name - title
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function CreateProductProperty(Val Name, Val Parameters = "") Export
|
||||
|
||||
@@ -1527,7 +1530,7 @@ EndFunction
|
||||
// Property - String, Number - Property ID - prop
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function EditProductProperty(Val Name, Val Property, Val Parameters = "") Export
|
||||
|
||||
@@ -1552,7 +1555,7 @@ EndFunction
|
||||
// Property - String, Number - Property ID - prop
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeleteProductProperty(Val Property, Val Parameters = "") Export
|
||||
|
||||
@@ -1575,7 +1578,7 @@ EndFunction
|
||||
// Property - String, Number - Property ID where the variant is added - prop
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function AddProductPropertyVariant(Val Value, Val Property, Val Parameters = "") Export
|
||||
|
||||
@@ -1601,7 +1604,7 @@ EndFunction
|
||||
// Option - String, Number - Variant ID - option
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function EditProductPropertyVariant(Val Value, Val Property, Val Option, Val Parameters = "") Export
|
||||
|
||||
@@ -1627,7 +1630,7 @@ EndFunction
|
||||
// Option - String, Number - Variant ID - option
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function DeleteProductPropertyVariant(Val Option, Val Parameters = "") Export
|
||||
|
||||
@@ -1652,7 +1655,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - Serialized JSON response from VK
|
||||
Function GetOrderList(Val Parameters = "") Export
|
||||
|
||||
@@ -1674,9 +1677,9 @@ EndFunction
|
||||
// Forms a keyboard from an array of buttons
|
||||
//
|
||||
// Parameters:
|
||||
// ButtonArray - Array of Strings - Array of button titles - buttons
|
||||
// ButtonArray - Array of String - Array of button titles - buttons
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// String - Keyboard JSON
|
||||
Function FormKeyboard(Val ButtonArray) Export
|
||||
|
||||
@@ -1712,7 +1715,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function GetStandardParameters(Val Parameters = "")
|
||||
|
||||
@@ -1722,12 +1725,12 @@ Function GetStandardParameters(Val Parameters = "")
|
||||
|
||||
Parameters_ = New Structure;
|
||||
|
||||
// access_token - можно получить in браузере по URL from фунtoции CreateTokenRetrievalLink()
|
||||
// access_token - can be obtained in the browser via the URL from the CreateTokenRetrievalLink function()
|
||||
// from_group - actions will be performed on behalf of the group
|
||||
// owner_id - group ID with "-" at the beginning. Can be found in the settings of the VK group or in its URL if not set
|
||||
// set your
|
||||
// app_id - application ID that needs to be created in the profile on the developer page
|
||||
// group_id - owner_id, но without "-"
|
||||
// group_id - owner_id, but without "-"
|
||||
|
||||
Parameters_.Insert("access_token" , "");
|
||||
Parameters_.Insert("from_group" , "1");
|
||||
@@ -1738,9 +1741,9 @@ Function GetStandardParameters(Val Parameters = "")
|
||||
|
||||
OPI_TypeConversion.GetCollection(Parameters);
|
||||
|
||||
If TypeValue(Parameters) = Type("Structure") Or TypeValue(Parameters) = Type("Match") Then
|
||||
If TypeOf(Parameters) = Type("Structure") Or TypeOf(Parameters) = Type("Map") Then
|
||||
For Each PassedParameter In Parameters Do
|
||||
Parameters_.Insert(PassedParameter.Key, OPI_Tools.NumberToString(PassedParameter.Value));
|
||||
Parameters_.Insert(PassedParameter.TheKey, OPI_Tools.NumberToString(PassedParameter.Value));
|
||||
EndDo;
|
||||
EndIf;
|
||||
|
||||
@@ -1775,7 +1778,7 @@ Function GetImageCorrespondence(Val Image, Val Parameters, Val View)
|
||||
Response = UploadPhotoToServer(Image, Parameters, View);
|
||||
ResponseArray = Response.Get("response");
|
||||
|
||||
If Not ValueIsFilled(ResponseArray) Or Not TypeValue(ResponseArray) = Type("Array") Then
|
||||
If Not ValueIsFilled(ResponseArray) Or Not TypeOf(ResponseArray) = Type("Array") Then
|
||||
Return Response;
|
||||
Else
|
||||
If ResponseArray.Quantity() = 0 Then
|
||||
@@ -1813,7 +1816,7 @@ EndFunction
|
||||
|
||||
Function DetermineImageUploadMethod(Val View)
|
||||
|
||||
MethodCorrespondence = New Match;
|
||||
MethodCorrespondence = New Map;
|
||||
Upload = "Upload";
|
||||
Save = "Save";
|
||||
Method = "Method";
|
||||
@@ -1860,7 +1863,7 @@ EndFunction
|
||||
|
||||
Function GetProductParameterMapping()
|
||||
|
||||
Fields = New Match();
|
||||
Fields = New Map();
|
||||
Fields.Insert("Name" , "name");
|
||||
Fields.Insert("Description" , "description");
|
||||
Fields.Insert("Category" , "category_id");
|
||||
@@ -1966,7 +1969,7 @@ Function AddImageParameter(Val Image, Val SelectionID, Parameters)
|
||||
|
||||
PhotoID = GetImageID(Image, Parameters, "Product");
|
||||
|
||||
If Not TypeValue(PhotoID) = Type("String") Then
|
||||
If Not TypeOf(PhotoID) = Type("String") Then
|
||||
Return PhotoID;
|
||||
EndIf;
|
||||
|
||||
@@ -1978,7 +1981,7 @@ Function AddImageParameter(Val Image, Val SelectionID, Parameters)
|
||||
|
||||
Selections = GetSelectionArray(SelectionID, Parameters);
|
||||
|
||||
If Not TypeValue(Selections) = Type("Array") Then
|
||||
If Not TypeOf(Selections) = Type("Array") Then
|
||||
Return Selections;
|
||||
EndIf;
|
||||
|
||||
@@ -2068,7 +2071,7 @@ Procedure FillProductRequestFields(Val ProductDescription, Parameters)
|
||||
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Properties) = Type("Array") Then
|
||||
If TypeOf(Properties) = Type("Array") Then
|
||||
|
||||
Properties_ = New Array;
|
||||
|
||||
@@ -2076,7 +2079,7 @@ Procedure FillProductRequestFields(Val ProductDescription, Parameters)
|
||||
Properties_.Add(OPI_Tools.NumberToString(Property));
|
||||
EndDo;
|
||||
|
||||
Properties = StrJoin(Properties_, ",");
|
||||
Properties = StrConcat(Properties_, ",");
|
||||
|
||||
EndIf;
|
||||
|
||||
@@ -2088,10 +2091,10 @@ Procedure FillProductRequestFields(Val ProductDescription, Parameters)
|
||||
|
||||
For Each Field In GetProductParameterMapping() Do
|
||||
|
||||
Value = ProductDescription[Field.Key];
|
||||
Value = ProductDescription[Field.TheKey];
|
||||
|
||||
If Value <> Undefined Then
|
||||
Parameters.Insert(Field.Value, ProductDescription[Field.Key]);
|
||||
Parameters.Insert(Field.Value, ProductDescription[Field.TheKey]);
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
@@ -2100,7 +2103,7 @@ EndProcedure
|
||||
|
||||
Procedure AddAdditionalProductPhotos(Val PhotoArray, Parameters)
|
||||
|
||||
If TypeValue(PhotoArray) = Type("Array") Then
|
||||
If TypeOf(PhotoArray) = Type("Array") Then
|
||||
If PhotoArray.Quantity() > 0 Then
|
||||
|
||||
PhotoString = "";
|
||||
@@ -2109,7 +2112,7 @@ Procedure AddAdditionalProductPhotos(Val PhotoArray, Parameters)
|
||||
|
||||
PhotoID = GetImageID(Photo, Parameters, "Product");
|
||||
|
||||
If Not TypeValue(PhotoID) = Type("String") Then
|
||||
If Not TypeOf(PhotoID) = Type("String") Then
|
||||
Return;
|
||||
EndIf;
|
||||
|
||||
@@ -2117,14 +2120,14 @@ Procedure AddAdditionalProductPhotos(Val PhotoArray, Parameters)
|
||||
|
||||
EndDo;
|
||||
|
||||
PhotoString = Left(PhotoString, StrLength(PhotoString) - 1);
|
||||
PhotoString = Left(PhotoString, StrLen(PhotoString) - 1);
|
||||
Parameters.Insert("photo_ids", PhotoString);
|
||||
EndIf;
|
||||
EndIf;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure GetProductListRecursively(Array of products, Parameters, Shift = 0)
|
||||
Procedure GetProductListRecursively(ProductsArray, Parameters, Shift = 0)
|
||||
|
||||
Response = "response";
|
||||
MaxInRequest = 200;
|
||||
@@ -2136,12 +2139,12 @@ Procedure GetProductListRecursively(Array of products, Parameters, Shift = 0)
|
||||
EndIf;
|
||||
|
||||
For Each Product In Products Do
|
||||
Array of products.Add(Product);
|
||||
ProductsArray.Add(Product);
|
||||
EndDo;
|
||||
|
||||
Shift = Shift + MaxInRequest;
|
||||
Parameters.Insert("offset", Shift);
|
||||
GetProductListRecursively(Array of products, Parameters, Shift);
|
||||
GetProductListRecursively(ProductsArray, Parameters, Shift);
|
||||
|
||||
EndProcedure
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_VK</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы интеграции with VK (OPI)</value>
|
||||
<value>VK integration methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_Viber.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Viber.os
|
||||
// Library: Viber
|
||||
// CLI Command: viber
|
||||
|
||||
@@ -29,15 +29,19 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region SettingsAndInformation
|
||||
|
||||
// Set Webhook
|
||||
// InАЖNО: Уwithтаноintoа Webhook обязательto по праinилам Viber. For thisго todо иметь withinобоdный URL,
|
||||
// IMPORTANT: Setting up Webhook is mandatory according to Viber rules. You need to have a free URL for this.,
|
||||
// which will return 200 and a genuine SSL certificate. If there is a certificate and the database is published
|
||||
// on the server - you can use an HTTP service. Information about new messages will also be sent there
|
||||
// Viber periodically knocks on the Webhook address, so if it is inactive, everything will stop working
|
||||
@@ -46,7 +50,7 @@
|
||||
// Token - String - Viber Token - token
|
||||
// URL - String - URL for setting up Webhook - url
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SetWebhook(Val Token, Val URL) Export
|
||||
|
||||
@@ -65,7 +69,7 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function GetChannelInformation(Val Token) Export
|
||||
|
||||
@@ -81,7 +85,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// UserID - String, Number - Viber User ID - user
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function GetUserData(Val Token, Val UserID) Export
|
||||
|
||||
@@ -103,7 +107,7 @@ EndFunction
|
||||
// Token - String - Viber Token - token
|
||||
// UserIDs - String,Number,Array of String,Number - Viber User(s) ID - users
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function GetOnlineUsers(Val Token, Val UserIDs) Export
|
||||
|
||||
@@ -132,7 +136,7 @@ EndFunction
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
// Keyboard - Structure Of String - See CreateKeyboardFromArrayButton - keyboard
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendTextMessage(Val Token
|
||||
, Val Text
|
||||
@@ -154,7 +158,7 @@ EndFunction
|
||||
// SendingToChannel - boolean - Sending to channel or bot chat - ischannel
|
||||
// Description - String - Image annotation - description
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendImage(Val Token, Val URL, Val UserID, Val SendingToChannel, Val Description = "") Export
|
||||
|
||||
@@ -173,7 +177,7 @@ EndFunction
|
||||
// Extension - String - File extension - ext
|
||||
// Size - Number - File size. If not filled in > determined automatically by downloading the file - size
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendFile(Val Token
|
||||
, Val URL
|
||||
@@ -190,7 +194,7 @@ Function SendFile(Val Token
|
||||
EndIf;
|
||||
|
||||
String_ = "String";
|
||||
Extension = StringReplace(Extension, ".", "");
|
||||
Extension = StrReplace(Extension, ".", "");
|
||||
|
||||
Parameters = New Structure;
|
||||
OPI_Tools.AddField("URL" , URL , String_, Parameters);
|
||||
@@ -211,7 +215,7 @@ EndFunction
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendContact(Val Token
|
||||
, Val ContactName
|
||||
@@ -237,7 +241,7 @@ EndFunction
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendLocation(Val Token, Val Latitude, Val Longitude, Val UserID, Val SendingToChannel) Export
|
||||
|
||||
@@ -258,7 +262,7 @@ EndFunction
|
||||
// UserID - String, Number - User ID. For channel > administrator, for bot > recipient - user
|
||||
// SendingToChannel - Boolean - Sending to channel or bot chat - ischannel
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Viber
|
||||
Function SendLink(Val Token, Val URL, Val UserID, Val SendingToChannel) Export
|
||||
|
||||
@@ -270,10 +274,10 @@ EndFunction
|
||||
// Returns a keyboard structure for messages
|
||||
//
|
||||
// Parameters:
|
||||
// ButtonArray - Array of Strings - Array of buttons - buttons
|
||||
// ButtonArray - Array of String - Array of buttons - buttons
|
||||
// ButtonColor - String - HEX color of buttons with # at the beginning - color
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Structure - Create a keyboard from an array of buttons:
|
||||
// * Buttons - Array of Structure - Array of formed buttons
|
||||
// * Type - String - KeyboardType
|
||||
@@ -309,7 +313,7 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
// Send message.
|
||||
//
|
||||
@@ -325,8 +329,8 @@ EndFunction
|
||||
// Text - String - Message text
|
||||
// Keyboard - Structure Of String - Keyboard, if needed, see CreateKeyboardFromArrayButton
|
||||
//
|
||||
// Return value:
|
||||
// Arbitrary, HTTP Response - Send message
|
||||
// Returns:
|
||||
// Arbitrary, HTTPResponse - Send message
|
||||
Function SendMessage(Val Token
|
||||
, Val Type
|
||||
, Val UserID
|
||||
@@ -349,7 +353,7 @@ Function SendMessage(Val Token
|
||||
ParametersStructure.Insert("text", Text);
|
||||
EndIf;
|
||||
|
||||
If TypeValue(Keyboard) = Type("Structure") Then
|
||||
If TypeOf(Keyboard) = Type("Structure") Then
|
||||
ParametersStructure.Insert("keyboard", Keyboard);
|
||||
EndIf;
|
||||
|
||||
@@ -405,7 +409,7 @@ Function TokenInHeaders(Val Token)
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
|
||||
HeadersStructure = New Match;
|
||||
HeadersStructure = New Map;
|
||||
HeadersStructure.Insert("X-Viber-Auth-Token", Token);
|
||||
Return HeadersStructure;
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_Viber</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы интеграции with Viber (OPI)</value>
|
||||
<value>Viber integration methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// OS Location: ./OInt/core/Modules/OPI_YandexDisk.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_YandexDisk.os
|
||||
// Library: Yandex Disk
|
||||
// CLI command: yadisk
|
||||
|
||||
@@ -32,11 +32,14 @@
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
#Region FileAndFolderManagement
|
||||
|
||||
@@ -46,7 +49,7 @@
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetDiskInformation(Val Token) Export
|
||||
|
||||
@@ -66,7 +69,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the created folder - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function CreateFolder(Val Token, Val Path) Export
|
||||
|
||||
@@ -102,7 +105,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to folder or file - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetObject(Val Token, Val Path) Export
|
||||
|
||||
@@ -127,7 +130,7 @@ EndFunction
|
||||
// Path - String - Path to the folder or file to be deleted - path
|
||||
// ToCart - Boolean - To cart - can
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function DeleteObject(Val Token, Val Path, Val ToCart = True) Export
|
||||
|
||||
@@ -156,7 +159,7 @@ EndFunction
|
||||
// Path - String - Destination path for the copy - to
|
||||
// Overwrite - Boolean - Overwrite if a file with the same name already exists - rewrite
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function CreateObjectCopy(Val Token, Val Original, Val Path, Val Overwrite = False) Export
|
||||
|
||||
@@ -196,7 +199,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the file for downloading - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetDownloadLink(Val Token, Val Path) Export
|
||||
|
||||
@@ -222,7 +225,7 @@ EndFunction
|
||||
// Path - String - Path to the file for downloading - path
|
||||
// SavePath - String - File save path - out
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// BinaryData,String - Binary data or file path when SavePath parameter is specified
|
||||
Function DownloadFile(Val Token, Val Path, Val SavePath = "") Export
|
||||
|
||||
@@ -242,7 +245,7 @@ EndFunction
|
||||
|
||||
// Get list of files
|
||||
// Gets a list of files with or without filtering by type
|
||||
// List available typeоin: audio, backup, book, compressed, data, development,
|
||||
// List of available types: audio, backup, book, compressed, data, development,
|
||||
// diskimage, document, encoded, executable, flash, font,
|
||||
// mage, settings, spreadsheet, text, unknown, video, web
|
||||
//
|
||||
@@ -253,7 +256,7 @@ EndFunction
|
||||
// FilterByType - String - Filter by file type - type
|
||||
// SortByDate - Boolean - True > sort by date, False > alphabetically - datesort
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetFilesList(Val Token
|
||||
, Val Quantity = 0
|
||||
@@ -304,7 +307,7 @@ EndFunction
|
||||
// Path - String - Destination path for moving - to
|
||||
// Overwrite - Boolean - Overwrite if a file with the same name already exists - rewrite
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function MoveObject(Val Token, Val Original, Val Path, Val Overwrite = False) Export
|
||||
|
||||
@@ -345,7 +348,7 @@ EndFunction
|
||||
// File - String, BinaryData - File for upload - file
|
||||
// Overwrite - Boolean - Overwrite if a file with the same name already exists - rewrite
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function UploadFile(Val Token, Val Path, Val File, Val Overwrite = False) Export
|
||||
|
||||
@@ -383,7 +386,7 @@ EndFunction
|
||||
// Path - String - Path to place the downloaded file - path
|
||||
// Address - String - File URL - url
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function UploadFileByURL(Val Token, Val Path, Val Address) Export
|
||||
|
||||
@@ -416,7 +419,7 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the object to be published - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function PublishObject(Val Token, Val Path) Export
|
||||
Return TogglePublicAccess(Token, Path, True);
|
||||
@@ -429,13 +432,13 @@ EndFunction
|
||||
// Token - String - Token - token
|
||||
// Path - String - Path to the previously published object - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function CancelObjectPublication(Val Token, Val Path) Export
|
||||
Return TogglePublicAccess(Token, Path, False);
|
||||
EndFunction
|
||||
|
||||
// Get published list объеtoтоin.
|
||||
// Get list of published objects.
|
||||
// Gets a list of published objects
|
||||
//
|
||||
// Parameters:
|
||||
@@ -443,7 +446,7 @@ EndFunction
|
||||
// Quantity - Number - Number of returned objects - amount
|
||||
// OffsetFromStart - Number - Offset for getting objects not from the beginning of the list - offset
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetPublishedObjectsList(Val Token, Val Quantity = 0, Val OffsetFromStart = 0) Export
|
||||
|
||||
@@ -475,10 +478,10 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - Object address - url
|
||||
// Quantity - Number - Quantity inозinращаемых inложенных объеtoтоin (for directory) - amount
|
||||
// Quantity - Number - Number of returned nested objects (for catalog) - amount
|
||||
// OffsetFromStart - Number - Offset for getting nested objects not from the beginning of the list - offset
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetPublicObject(Val Token, Val URL, Val Quantity = 0, Val OffsetFromStart = 0) Export
|
||||
|
||||
@@ -515,7 +518,7 @@ EndFunction
|
||||
// URL - String - Object address - url
|
||||
// Path - String - Path inside the object - path
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetDownloadLinkForPublicObject(Val Token, Val URL, Val Path = "") Export
|
||||
|
||||
@@ -545,17 +548,17 @@ EndFunction
|
||||
// Parameters:
|
||||
// Token - String - Token - token
|
||||
// URL - String - Object address - url
|
||||
// From - String - Path inнутри публичного directory (тольtoо for папоto) - from
|
||||
// To - String - File save path - to
|
||||
// From - String - Path within public catalog (folders only) - from
|
||||
// Target - String - File save path - to
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function SavePublicObjectToDisk(Val Token, Val URL, From = "", To = "") Export
|
||||
Function SavePublicObjectToDisk(Val Token, Val URL, From = "", Target = "") Export
|
||||
|
||||
OPI_TypeConversion.GetLine(Token);
|
||||
OPI_TypeConversion.GetLine(URL);
|
||||
OPI_TypeConversion.GetLine(From);
|
||||
OPI_TypeConversion.GetLine(To);
|
||||
OPI_TypeConversion.GetLine(Target);
|
||||
|
||||
Headers = AuthorizationHeader(Token);
|
||||
Address = "https://cloud-api.yandex.net/v1/disk/public/resources/save-to-disk";
|
||||
@@ -568,8 +571,8 @@ Function SavePublicObjectToDisk(Val Token, Val URL, From = "", To = "") Export
|
||||
Parameters.Insert("path", From);
|
||||
EndIf;
|
||||
|
||||
If ValueIsFilled(To) Then
|
||||
Parameters.Insert("save_path", To);
|
||||
If ValueIsFilled(Target) Then
|
||||
Parameters.Insert("save_path", Target);
|
||||
EndIf;
|
||||
|
||||
Parameters = OPI_Tools.RequestParametersToString(Parameters);
|
||||
@@ -591,11 +594,11 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region ServiceProceduresAndFunctions
|
||||
#Region Private
|
||||
|
||||
Function AuthorizationHeader(Val Token)
|
||||
|
||||
Headers = New Match;
|
||||
Headers = New Map;
|
||||
Headers.Insert("Authorization", "OAuth " + Token);
|
||||
|
||||
Return Headers;
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_YandexDisk</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы work with Yandex Disk (OPI)</value>
|
||||
<value>Yandex Disk methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Location OS: ./OInt/core/Modules/OPI_YandexID.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_YandexID.os
|
||||
// Library: Yandex ID
|
||||
// CLI Command: yandex
|
||||
|
||||
@@ -29,10 +29,14 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Uncomment if OneScript is executed
|
||||
// #Use "../../tools"
|
||||
|
||||
#Region ProgrammingInterface
|
||||
#Region Public
|
||||
|
||||
// Get confirmation code
|
||||
// Gets the confirmation code and the address of the page where it needs to be entered
|
||||
@@ -40,7 +44,7 @@
|
||||
// Parameters:
|
||||
// ClientId - String - Client id - id
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function GetConfirmationCode(Val ClientId) Export
|
||||
|
||||
@@ -61,7 +65,7 @@ EndFunction
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// DeviceCode - String - device_code from GetConfirmationCode() - device
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function ConvertCodeToToken(Val ClientId, Val ClientSecret, Val DeviceCode) Export
|
||||
|
||||
@@ -89,7 +93,7 @@ EndFunction
|
||||
// ClientSecret - String - Client secret - secret
|
||||
// RefreshToken - String - Refresh token - refresh
|
||||
//
|
||||
// Return value:
|
||||
// Returns:
|
||||
// Key-Value Pair - serialized JSON response from Yandex
|
||||
Function RefreshToken(Val ClientId, Val ClientSecret, Val RefreshToken) Export
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<name>OPI_YandexID</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Methodы work with Yandex ID (OPI)</value>
|
||||
<value>Yandex ID methods (OPI)</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
|
@@ -29,7 +29,7 @@
|
||||
<version>1.9.0</version>
|
||||
<detailedInformation>
|
||||
<key>ru</key>
|
||||
<value>Open integrations package - toбор библиотеto for интеграции with неtoоторыми популярными API for 1C:Enterprise. He consists of general modules, each responsible for its own API, as well as several tool modules common for all.</value>
|
||||
<value>The Open Integration Package is a set of libraries for integrating with some popular APIs for 1C:Enterprise. It consists of common modules, each responsible for its own API, as well as several shared tool modules..</value>
|
||||
</detailedInformation>
|
||||
<vendorInformationAddress>
|
||||
<key>ru</key>
|
||||
@@ -39,14 +39,6 @@
|
||||
<key>ru</key>
|
||||
<value>https://github.com/Bayselonarrend/OpenIntegrations</value>
|
||||
</configurationInformationAddress>
|
||||
<languages uuid="0e858b44-34f3-4d20-986d-13290bb5ba5a">
|
||||
<name>Russian</name>
|
||||
<objectBelonging>Adopted</objectBelonging>
|
||||
<extension xsi:type="mdclassExtension:LanguageExtension">
|
||||
<languageCode>Checked</languageCode>
|
||||
</extension>
|
||||
<languageCode>ru</languageCode>
|
||||
</languages>
|
||||
<subsystems>Subsystem.OPI_Integrations</subsystems>
|
||||
<commonModules>CommonModule.OPI_Tools</commonModules>
|
||||
<commonModules>CommonModule.OPI_Cryptography</commonModules>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Airtable.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Airtable.os
|
||||
// Библиотека: Airtable
|
||||
// Команда CLI: airtable
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Dropbox.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Dropbox.os
|
||||
// Библиотека: Dropbox
|
||||
// Команда CLI: dropbox
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_GoogleCalendar.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleCalendar.os
|
||||
// Библиотека: Google Calendar
|
||||
// Команда CLI: gcalendar
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_GoogleDrive.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleDrive.os
|
||||
// Библиотека: Google Drive
|
||||
// Команда CLI: gdrive
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_GoogleSheets.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleSheets.os
|
||||
// Библиотека: Google Sheets
|
||||
// Команда CLI: gsheets
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_GoogleWorkspace.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_GoogleWorkspace.os
|
||||
// Библиотека: Google Workspace
|
||||
// Команда CLI: google
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Notion.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Notion.os
|
||||
// Библиотека: Notion
|
||||
// Команда CLI: notion
|
||||
|
||||
@@ -31,7 +31,10 @@
|
||||
// BSLLS:NumberOfOptionalParams-off
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
// @skip-check method-too-many-params
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Slack.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Slack.os
|
||||
// Библиотека: Slack
|
||||
// Команда CLI: slack
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:Typo-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Telegram.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Telegram.os
|
||||
// Библиотека: Telegram
|
||||
// Команда CLI: telegram
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
// BSLLS:UnreachableCode-off
|
||||
// BSLLS:CommentedCode-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Twitter.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Twitter.os
|
||||
// Библиотека: Twitter
|
||||
// Команда CLI: twitter
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_VK.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_VK.os
|
||||
// Библиотека: VK
|
||||
// Команда CLI: vk
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check wrong-string-literal-content
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_Viber.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_Viber.os
|
||||
// Библиотека: Viber
|
||||
// Команда CLI: viber
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_YandexDisk.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_YandexDisk.os
|
||||
// Библиотека: Yandex Disk
|
||||
// Команда CLI: yadisk
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
// BSLLS:UsingServiceTag-off
|
||||
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/core/Modules/OPI_YandexID.os
|
||||
// OneScript: ./OInt/core/Modules/OPI_YandexID.os
|
||||
// Библиотека: Yandex ID
|
||||
// Команда CLI: yandex
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
// BSLLS:LatinAndCyrillicSymbolInWord-off
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "../../tools"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/tools/Modules/internal/Modules/OPI_Инструменты.os
|
||||
// OneScript: ./OInt/tools/Modules/internal/Modules/OPI_Инструменты.os
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
|
||||
//@skip-check module-unused-local-variable
|
||||
//@skip-check method-too-many-params
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
#Область СлужебныйПрограммныйИнтерфейс
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/tools/Modules/internal/Modules/OPI_Криптография.os
|
||||
// OneScript: ./OInt/tools/Modules/internal/Modules/OPI_Криптография.os
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UnusedLocalVariable-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
#Область СлужебныйПрограммныйИнтерфейс
|
||||
|
||||
#Область БСП
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/tools/Modules/OPI_ПолучениеДанныхТестов.os
|
||||
// OneScript: ./OInt/tools/Modules/OPI_ПолучениеДанныхТестов.os
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
// BSLLS:DuplicateStringLiteral-off
|
||||
|
||||
//@skip-check use-non-recommended-method
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check undefined-function-or-procedure
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать "./internal"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/tools/Modules/OPI_ПреобразованиеТипов.os
|
||||
// OneScript: ./OInt/tools/Modules/OPI_ПреобразованиеТипов.os
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -28,6 +28,11 @@
|
||||
// BSLLS:IncorrectLineBreak-off
|
||||
// BSLLS:UnusedLocalVariable-off
|
||||
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check undefined-function-or-procedure
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// #Использовать "./internal"
|
||||
|
||||
#Область СлужебныйПрограммныйИнтерфейс
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Расположение OS: ./OInt/tests/Modules/internal/OPI_Тесты.os
|
||||
// OneScript: ./OInt/tests/Modules/internal/OPI_Тесты.os
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -33,8 +33,12 @@
|
||||
// BSLLS:UnusedParameters-off
|
||||
// BSLLS:DuplicateStringLiteral-off
|
||||
|
||||
// @skip-check undefined-variable
|
||||
// @skip-check wrong-string-literal-content
|
||||
//@skip-check undefined-variable
|
||||
//@skip-check wrong-string-literal-content
|
||||
//@skip-check module-structure-top-region
|
||||
//@skip-check module-structure-method-in-regions
|
||||
//@skip-check undefined-function-or-procedure
|
||||
//@skip-check wrong-string-literal-content
|
||||
|
||||
// Раскомментировать, если выполняется OneScript
|
||||
// #Использовать oint
|
||||
|
@@ -39,14 +39,6 @@
|
||||
<key>ru</key>
|
||||
<value>https://github.com/Bayselonarrend/OpenIntegrations</value>
|
||||
</configurationInformationAddress>
|
||||
<languages uuid="0e858b44-34f3-4d20-986d-13290bb5ba5a">
|
||||
<name>Русский</name>
|
||||
<objectBelonging>Adopted</objectBelonging>
|
||||
<extension xsi:type="mdclassExtension:LanguageExtension">
|
||||
<languageCode>Checked</languageCode>
|
||||
</extension>
|
||||
<languageCode>ru</languageCode>
|
||||
</languages>
|
||||
<subsystems>Subsystem.OPI_Интеграция</subsystems>
|
||||
<commonModules>CommonModule.OPI_Инструменты</commonModules>
|
||||
<commonModules>CommonModule.OPI_Криптография</commonModules>
|
||||
|
@@ -14,6 +14,8 @@
|
||||
ЛишниеСимволы = 2;
|
||||
СписокКоманд = Лев(СписокКоманд, СтрДлина(СписокКоманд) - ЛишниеСимволы);
|
||||
|
||||
|
||||
|
||||
Консоль.ЦветТекста = ЦветКонсоли.Зеленый;
|
||||
Консоль.ВывестиСтроку("-----------------------------------------------------");
|
||||
Консоль.ВывестиСтроку("");
|
||||
|
Reference in New Issue
Block a user