1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-02-03 13:22:19 +02:00

Попытка локализации en

This commit is contained in:
Anton 2024-06-01 00:44:55 +03:00
parent 0f9f3115b0
commit cd23b8744e
94 changed files with 17273 additions and 35789 deletions

View File

@ -24,10 +24,15 @@
Процедура СоздатьСловарь(Знач Язык)
ФайлыМодулей = НайтиФайлы("./src/ru/", "*.os", Истина);
ФайлыМодулей = НайтиФайлы("./src/ru/", "*", Истина);
СписокСлов = Новый СписокЗначений();
Для Каждого Модуль Из ФайлыМодулей Цикл
Если Модуль.ЭтоКаталог() Тогда
Продолжить;
КонецЕсли;
Если СтрНайти(Модуль.ПолноеИмя, "cli\data") <> 0 Тогда
Продолжить;
КонецЕсли;
@ -107,6 +112,10 @@
ТекстовыйДок.ДобавитьСтроку("""" + Ключ + """: """ + Значение + """,");
КонецЦикла;
ПоследняяСтрока = ТекстовыйДок.ПолучитьСтроку(ТекстовыйДок.КоличествоСтрок());
ПоследняяСтрока = Лев(ПоследняяСтрока, СтрДлина(ПоследняяСтрока) - 1);
ТекстовыйДок.ЗаменитьСтроку(ТекстовыйДок.КоличествоСтрок(), ПоследняяСтрока);
ТекстовыйДок.ДобавитьСтроку("}");
ТекстовыйДок.Записать(ПутьСловаря);
@ -133,11 +142,17 @@
Продолжить;
КонецЕсли;
Если СтрНайти(ТекущаяСтрока, """") <> 0 Или СтрНайти(ТекущаяСтрока, "|") <> 0 Тогда
Если СтрНайти(ТекущаяСтрока, """") <> 0
Или СтрНайти(ТекущаяСтрока, "|") <> 0
Или СтрНайти(ТекущаяСтрока, "<") <> 0
Или СтрНайти(ТекущаяСтрока, ">") <> 0 Тогда
ТекущаяСтрока = " " + ТекущаяСтрока;
ТекущаяСтрока = СтрЗаменить(ТекущаяСтрока, """", "$");
ТекущаяСтрока = СтрЗаменить(ТекущаяСтрока, "|", "$");
ТекущаяСтрока = СтрЗаменить(ТекущаяСтрока, "<", "$");
ТекущаяСтрока = СтрЗаменить(ТекущаяСтрока, ">", "$");
ТекущаяСтрока = СтрЗаменить(ТекущаяСтрока, "$$", """""");
МассивСтроки = СтрРазделить(ТекущаяСтрока, "$", Истина);

View File

@ -29,15 +29,15 @@
ПолучитьТаблицуСловаря(ПутьКСловарю);
КаталогИсточник = Новый Файл(".\ru\OPI");
КаталогПриемник = Новый Файл(".\service\interim\" + Язык + "\OPI");
КаталогИсточник = Новый Файл(".\src\ru\OPI");
КаталогПриемник = Новый Файл(".\src\" + Язык + "\OPI");
Если КаталогПриемник.Существует() Тогда
УдалитьФайлы(КаталогПриемник.ПолноеИмя);
КонецЕсли;
СкопироватьФайлы(КаталогИсточник.ПолноеИмя, КаталогПриемник.ПолноеИмя);
ФайлыМодулей = НайтиФайлы(".\service\interim\" + Язык + "\", "*", Истина);
ФайлыМодулей = НайтиФайлы(".\src\" + Язык + "\", "*", Истина);
Для Каждого ФайлМодуля Из ФайлыМодулей Цикл
@ -48,7 +48,7 @@
ПеревестиМодуль(ФайлМодуля.ПолноеИмя);
КонецЦикла;
ВсеФайлыЛокализации = НайтиФайлы("./" + Язык, "*", Истина);
ВсеФайлыЛокализации = НайтиФайлы(".\src\" + Язык, "*", Истина);
ОтборИменМодулей = Новый Структура("ИмяМодуля", Истина);
СтрокиИмен = ТаблицаСловаря.НайтиСтроки(ОтборИменМодулей);
УдаляемыеКаталоги = Новый Массив;
@ -107,6 +107,18 @@
ДокументМодуля = Новый ТекстовыйДокумент();
ДокументМодуля.Прочитать(ПутьКМодулю, "UTF-8");
Для Н = 1 По ДокументМодуля.КоличествоСтрок() Цикл
ТекущаяСтрока = СокрЛП(ДокументМодуля.ПолучитьСтроку(Н));
Пока СтрНайти(ТекущаяСтрока, " ") <> 0 Цикл
ТекущаяСтрока = СтрЗаменить(ТекущаяСтрока, " ", " ");
КонецЦикла;
ДокументМодуля.ЗаменитьСтроку(Н, ТекущаяСтрока);
КонецЦикла;
ТекстМодуля = ДокументМодуля.ПолучитьТекст();
Для Каждого Элемент Из ТаблицаСловаря Цикл

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>OPI</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>com._1c.g5.v8.dt.core.V8ExtensionNature</nature>
</natures>
</projectDescription>

View File

@ -1,2 +0,0 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Runtime-Version: 8.3.15
Base-Project: OpenIntegrations

View File

@ -1,681 +0,0 @@
// 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 ProgrammingInterface
#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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
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.Key, 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 Structures - Array of field descriptions - fieldsdata
// Description - String - Table description - description
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 TypeValue(FieldStructure) = Type("Structure")
And Not TypeValue(FieldStructure) = Type("Match") 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
//
// Return value:
// 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 поле (withтроtoоinое)
// Gets the description of a string field
//
// Parameters:
// Name - String - New field name - title
//
// Return value:
// Structure - Field description
Function GetStringField(Val Name) Export
Return PrimitiveFieldDescription(Name, "richText");
EndFunction
// Get поле (чиwithлоinое)
// Gets the description of a numeric field
//
// Parameters:
// Name - String - New field name - title
// Precision - Number, String - Number of decimal places - precision
//
// Return value:
// 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 поле (file)
// Gets the description of a file field
//
// Parameters:
// Name - String - Field name - title
//
// Return value:
// Structure - Field description
Function GetAttachmentField(Val Name) Export
Return PrimitiveFieldDescription(Name, "multipleAttachments");
EndFunction
// Get поле (флажоto)
// Gets the description of a boolean field
//
// Parameters:
// Name - String - Field name - title
//
// Return value:
// Structure - Field description
Function GetCheckboxField(Val Name) Export
OptionsStructure = New Structure("icon,color", "check", "yellowBright");
Return PrimitiveFieldDescription(Name, "checkbox", OptionsStructure);
EndFunction
// Get поле (dата)
// Gets the description of a date field
//
// Parameters:
// Name - String - Field name - title
//
// Return value:
// 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 поле (email)
// Gets the description of an email field
//
// Parameters:
// Name - String - Field name - title
//
// Return value:
// Structure - Field description
Function GetEmailField(Val Name) Export
Return PrimitiveFieldDescription(Name, "email");
EndFunction
// Get поле (телефон)
// Gets the description of a phone number field
//
// Parameters:
// Name - String - Field name - title
//
// Return value:
// Structure - Field description
Function GetPhoneField(Val Name) Export
Return PrimitiveFieldDescription(Name, "phoneNumber");
EndFunction
// Get поле (url)
// Gets the description of a URL field
//
// Parameters:
// Name - String - Field name - title
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 Structures - Set or array of sets of Key : Value pairs > Field : Indicator - data
//
// Return value:
// 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 Strings - Identifier or array of record identifiers - records
//
// Return value:
// 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
+ ?(ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ServiceProceduresAndFunctions
Function GetAuthorizationHeader(Val Token)
OPI_TypeConversion.GetLine(Token);
Headers = New Match;
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 TypeValue(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

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="457991ad-c2ad-49b8-a26a-9fc83c8a7d11">
<name>OPI_Airtable</name>
<synonym>
<key></key>
<value>OPI airtable</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,961 +0,0 @@
// 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 ProgrammingInterface
#Region AccountAndAuthorization
// Get authorization link
// Generates an authorization link for browser transition
//
// Parameters:
// AppKey - String - Application key - appkey
//
// Return value:
// 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
//
// Return value:
// 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, StrLength(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
//
// Return value:
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Dropbox
Function GetAccountInformation(Val Token, Val Account = "") Export
If ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// HTTPResponse - Get list of folder files
Function GetListOfFolderFiles(Val Token, Val Path = "", Val Detailed = False, Val Cursor = "") Export
If Not ValueFilled(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
// Forлучает PDF or HTML преinью объеtoта (тольtoо for тоtoументоin)
//
// Parameters:
// Token - String - Token - token
// Path - String - Path to the object - path
//
// Return value:
// 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
//
// Return value:
// 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();
Boundary = 100000000;
If Size > Boundary 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Dropbox
Function DeleteObject(Val Token, Val Path, Val Irretrievably = False) Export
OPI_TypeConversion.GetBoolean(Irretrievably);
If Irretrievably 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
// To - String - Target path for the new object - to
//
// Return value:
// Key-Value Pair - serialized JSON response from Dropbox
Function CopyObject(Val Token, Val From, Val To) 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);
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
// To - String - Target path for the new object - to
//
// Return value:
// Key-Value Pair - serialized JSON response from Dropbox
Function MoveObject(Val Token, Val From, Val To) 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);
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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
// Inоwithwithтаtoinлиinает withоwithтояние объеtoта to необхоdимой inерwithии (реinfromии)
//
// Parameters:
// Token - String - Token - token
// Path - String - Path to the object - path
// Version - String - ID of the version (revision) for restoration - rev
//
// Return value:
// 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 Strings - Path or set of paths to the files - paths
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 публичного directory (shared folder ID) - folder
//
// Return value:
// 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 Strings - List of email addresses of users being added - emails
// ViewOnly - Boolean - Prohibits file editing for the external user - readonly
//
// Return value:
// 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 StringStartsWith(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 Match;
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 публичного directory (shared folder ID) - folder
// EmailAddresses - String, Array of Strings - List of email addresses of users being added - emails
// ViewOnly - Boolean - Prohibits file editing for the external user - readonly
//
// Return value:
// 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 Match;
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
//
// Return value:
// 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
//
// Return value:
// 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
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 ServiceProceduresAndFunctions
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 Match;
Headers.Insert("Authorization" , "Bearer " + Token);
If ValueFilled(Parameters) Then
JSON = OPI_Tools.JSONString(Parameters, "No");
JSON = StringReplace(JSON, Symbols.VK + Symbols.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);
ReadingData = New ReadingData(File);
BytesRead = ReadingData.Skip(CurrentPosition);
Result = ReadingData.Read(ChunkSize);
Current data = Result.GetBinaryData();
CurrentSize = Current data.Size();
NextPosition = CurrentPosition + CurrentSize;
If Not ValueFilled(Current data) Then
Break;
EndIf;
Response = OPI_Tools.PostBinary(URL, Current data, Headers);
CurrentPosition = NextPosition;
// !OInt KBytes = 1024;
// !OInt MByte = KBytes * KBytes;
// !OInt Notify(OPI_Tools.ProgressInformation(CurrentPosition, TotalSize, "MB", MByte));
// !OInt PerformGarbageCollection();
// !OInt ReleaseObject(Current data);
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

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="66ce7792-41e5-47e4-bfad-2dcff1c96287">
<name>OPI_Dropbox</name>
<synonym>
<key></key>
<value>OPI dropbox</value>
</synonym>
<synonym>
<key>ru</key>
<value>Drop box</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,631 +0,0 @@
// 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 ProgrammingInterface
#Region CalendarMetadataManagement
// Create calendar
// Creates an empty calendar
//
// Parameters:
// Token - String - Token - token
// Name - String - Name of the created calendar - title
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ValueFilled(Name) Then
Parameters.Insert("summary", Name);
EndIf;
If ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 mainоinного цinета (#ffffff) - primary
// SecondaryColor - String - HEX addолнительного цinета (#ffffff) - secondary
// Hidden - Boolean - Hidden calendar - hidden
//
// Return value:
// 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 Match;
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
//
// Return value:
// Key-Value Pair - Empty event template
Function GetEventDescription() Export
CurrentDate = OPI_Tools.GetCurrentDate();
Hour = 3600;
Event = New Match;
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("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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ServiceProceduresAndFunctions
Function ConvertDate(Val Date)
OPI_TypeConversion.GetDate(Date);
DateStructure = New Structure;
If Not TypeValue(Date) = Type("Date") Then
Return Undefined;
EndIf;
If Date = StartOfDay(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 TypeValue(Attachments) = Type("Match") Or TypeValue(Attachments) = Type("Structure") Then
For Each Attachment In Attachments Do
CurrentAttachment = New Structure;
CurrentAttachment.Insert("title" , Attachment.Key);
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 = ValueFilled(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" , ?(ValueFilled(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 ValueFilled(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 ValueFilled(Page) Then
GetCalendarsListRecursively(Headers, ArrayOfCalendars, Page);
EndIf;
EndProcedure
Procedure GetEventsListRecursively(Val Headers, Val Calendar, ArrayOfEvents, Page = "")
Items = "items";
NPT = "nextPageToken";
Parameters = New Structure;
If ValueFilled(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 ValueFilled(Page) Then
GetEventsListRecursively(Headers, ArrayOfEvents, Page);
EndIf;
EndProcedure
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="d27d4ffb-31c2-4362-bd6d-d785ce171b49">
<name>OPI_GoogleCalendar</name>
<synonym>
<key></key>
<value>OPI google calendar</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,719 +0,0 @@
// 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 ProgrammingInterface
#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
//
// Return value:
// 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
//
// Return value:
// 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 ValueFilled(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
//
// Return value:
// 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 ValueFilled(NameContains) Then
Filter.Add("name contains '" + NameContains + "'");
EndIf;
If ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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 Match;
Description.Insert("MIME" , "application/vnd.google-apps.folder");
Description.Insert("Name" , Name);
Description.Insert("Description", "");
Description.Insert("Parent", ?(ValueFilled(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
//
// Return value:
// 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 Match;
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
//
// Return value:
// 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 ValueFilled(NewName) Then
Parameters.Insert("name", NewName);
EndIf;
If ValueFilled(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 - Nоinое имя file (еwithли необхоdимо) - title
//
// Return value:
// 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 ValueFilled(NewName) Then
Description = New Match;
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
//
// Return value:
// 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
//
// Return value:
// Key-Value Pair - File description
Function GetFileDescription() Export
Description = New Match;
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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ServiceProceduresAndFunctions
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 ValueFilled(Page) Then
Parameters.Insert("pageToken", Page);
EndIf;
If ValueFilled(Filter) And TypeValue(Filter) = Type("Array") Then
FilterString = StrJoin(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 ValueFilled(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 Match;
OPI_Tools.RemoveEmptyCollectionFields(Description);
FieldMapping = New Match;
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.Key = "Parent" Then
CurrentValue = New Array;
CurrentValue.Add(Element.Value);
Else
CurrentValue = Element.Value;
EndIf;
FieldName = FieldMapping.Get(Element.Key);
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 ValueFilled(Description) Then
OPI_TypeConversion.GetCollection(Description);
EndIf;
MimeType = "mimeType";
If ValueFilled(Identifier) Then
MIME = GetObjectInformation(Token, Identifier)[MimeType];
Else
MIME = Description["MIME"];
EndIf;
If Not ValueFilled(Description) Then
Description = New Match;
EndIf;
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
FormFileUploadParameters(Description);
JSONDescription = OPI_Tools.JSONString(Description);
FileMapping = New Match;
If ValueFilled(File) Then
ChunkSize = 268435457;
Size = OPI_Tools.ConvertDataWithSizeRetrieval(File, ChunkSize);
FileMapping.Insert(File, MIME);
If Size < ChunkSize And TypeValue(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 ValueFilled(Identifier) Then
URL = StringReplace(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.Key;
Break;
EndDo;
URL = "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable";
If ValueFilled(Identifier) Then
URL = StringReplace(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 ValueFilled(UploadURL) Then
OPI_Tools.ProcessResponse(Response);
Return Response;
EndIf;
UploadResponse = UploadFileInParts(Binary, UploadURL);
Response = ?(ValueFilled(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);
ReadingData = New ReadingData(Binary);
SourceStream = ReadingData.SourceStream();
WHile BytesRead < TotalSize Do
BytesRead = SourceStream.CurrentPosition();
Result = ReadingData.Read(ChunkSize);
Current data = Result.GetBinaryData();
CurrentSize = Current data.Size();
NextPosition = CurrentPosition + CurrentSize - 1;
If Not ValueFilled(Current data) Then
Break;
EndIf;
StreamHeader = "bytes "
+ OPI_Tools.NumberToString(CurrentPosition)
+ "-"
+ OPI_Tools.NumberToString(NextPosition)
+ "/"
+ StrTotalSize;
AdditionalHeaders = New Match;
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);
CheckResult = CheckPartUpload(Response, StrTotalSize, AdditionalHeaders, UploadURL, CurrentPosition);
If ValueFilled(CheckResult) Then
Return CheckResult;
EndIf;
// !OInt KBytes = 1024;
// !OInt MByte = KBytes * KBytes;
// !OInt Notify(OPI_Tools.ProgressInformation(CurrentPosition, TotalSize, "MB", MByte));
// !OInt PerformGarbageCollection();
// !OInt ReleaseObject(Current data);
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 ValueFilled(UploadedData) Then
OPI_Tools.ProcessResponse(Response);
Return Response;
EndIf;
UploadedData = StringReplace(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

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="3bf39c90-a263-4300-b800-7fd85f7c6d40">
<name>OPI_GoogleDrive</name>
<synonym>
<key></key>
<value>OPI google drive</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,409 +0,0 @@
// 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 ProgrammingInterface
#Region BookWork
// CreateBook
// Creates a new book
//
// Parameters:
// Token - String - Token - token
// Name - String - Name - title
// ArrayOfSheetNames - Array of Strings - Array of names to add new sheets to the book - sheets
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
// To - String - DestinationBookID - to
// Sheet - String - CopiedSheetID - sheet
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
Function CopySheet(Val Token, Val From, Val To, Val Sheet) Export
OPI_TypeConversion.GetLine(From);
OPI_TypeConversion.GetLine(To);
OPI_TypeConversion.GetLine(Sheet);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/"
+ From
+ "/sheets/"
+ Sheet
+ ":copyTo";
Parameters = New Structure("destinationSpreadsheetId", To);
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 - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
// MajorDimension - String - Main dimension when filling the array range - dim
//
// Return value:
// 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 TypeValue(ValueMapping) = Type("Structure")
And Not TypeValue(ValueMapping) = Type("Match") 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);
Parameters = New Structure("data,valueInputOption", Data array, "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
// Cell array - Array of Strings - Array of cells like A1 to be cleared - cells
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
Function ClearCells(Val Token, Val Book, Val Cell array, Val Sheet = "") Export
OPI_TypeConversion.GetLine(Book);
OPI_TypeConversion.GetCollection(Cell array);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchClear";
FormCellNameArray(Cell array, Sheet);
Parameters = New Structure("ranges", Cell array);
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
// Cell array - Array of Strings - Array ячееto inиdа А1 for получения (inеwithь лиwithт, еwithли не заполнено) - cells
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
Function GetCellValues(Val Token, Val Book, Val Cell array = "", Val Sheet = "") Export
OPI_TypeConversion.GetLine(Book);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchGet";
If ValueFilled(Cell array) Then
OPI_TypeConversion.GetCollection(Cell array);
FormCellNameArray(Cell array, Sheet);
First = True;
For Each Cell In Cell array 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 ServiceProceduresAndFunctions
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 ValueFilled(Sheet) Then
Cell = "'" + Sheet + "'!" + Cell;
EndIf;
EndProcedure
Function CreateSheet(Val Name)
OPI_TypeConversion.GetLine(Name);
Sheet properties = New Structure("title" , Name);
Sheet = New Structure("properties", Sheet properties);
Return Sheet;
EndFunction
Function FormCellDataArray(Val ValueStructure, Val MajorDimension, Val Sheet)
OPI_TypeConversion.GetLine(Sheet);
Data array = New Array;
For Each CellData In ValueStructure Do
CurrentValue = CellData.Value;
Current key = CellData.Key;
AddSheetName(Current key, Sheet);
OPI_TypeConversion.GetArray(CurrentValue);
Current data = New Match;
Current array = New Array;
Current array.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);
Data array.Add(Current data);
EndDo;
Return Data array;
EndFunction
Procedure FormCellNameArray(Val ArrayOfNames, Val Sheet)
OPI_TypeConversion.GetLine(Sheet);
For N = 0 For ArrayOfNames.WithinBoundary() Do
AddSheetName(ArrayOfNames[N], Sheet);
EndDo;
EndProcedure
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="3890523a-552f-495c-ae7d-2991df8bb175">
<name>OPI_GoogleSheets</name>
<synonym>
<key></key>
<value>OPI google sheets</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,173 +0,0 @@
// 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 ProgrammingInterface
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ServiceProgramInterface
Function GetAuthorizationHeader(Val Token) Export
OPI_TypeConversion.GetLine(Token);
Headers = New Match;
Headers.Insert("Authorization", "Bearer " + Token);
Return Headers;
EndFunction
#EndRegion
#Region ServiceProceduresAndFunctions
Function GetPermissionsList(Calendar, Drive, Sheets)
Permissions array = New Array;
If Calendar Then
Permissions array.Add("https://www.googleapis.com/auth/calendar");
EndIf;
If Drive Then
Permissions array.Add("https://www.googleapis.com/auth/drive");
EndIf;
If Sheets Then
Permissions array.Add("https://www.googleapis.com/auth/spreadsheets");
EndIf;
Return StrJoin(Permissions array, " ");
EndFunction
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="e5bf1867-4c83-4724-91f2-931150325ea0">
<name>OPI_GoogleWorkspace</name>
<synonym>
<key></key>
<value>OPI google workspace</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,889 +0,0 @@
// 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 ProgrammingInterface
#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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 нет (boolean) - archive
//
// Return value:
// 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 ValueFilled(Data)
And (TypeValue(Data) = Type("Match") Or TypeValue(Data) = Type("Structure")) Then
Properties = FillDataBySchema(Page, Data, Token, False);
Else
Properties = New Match;
EndIf;
If ValueFilled(Icon) Then
Icon match = New Match;
Icon match.Insert("Icon", Icon);
Icon object = ConvertValueByType(Files, Icon match);
Icon object = Icon object[Files][0];
Icon object.Delete("name");
Parameters.Insert("icon", Icon object);
EndIf;
If ValueFilled(Cover) Then
Cover match = New Match;
Cover match.Insert("Cover", Cover);
Cover object = ConvertValueByType(Files, Cover match);
Cover object = Cover object[Files][0];
Cover object.Delete("name");
Parameters.Insert("cover", Cover object);
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
//
// Return value:
// 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
// In progress : checkbox
// Quantity : number
// Date : date
// Status : Map
// Active : green
// Inactive : red
// Archive : yellow
// All pages created as children must have parent base properties
If Not TypeValue(Properties) = Type("Structure") And Not TypeValue(Properties) = Type("Match") 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
//
// Return value:
// 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 from KeyAndValue - New or modified database properties - props
// Title - String - New database title - title
// Description - String - New database description - description
//
// Return value:
// 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 ValueFilled(Title) Then
AddDatabaseHeader(Title, Parameters);
EndIf;
If ValueFilled(Description) Then
AddDatabaseDescription(Description, Parameters);
EndIf;
If TypeValue(Properties) = Type("Structure") Or TypeValue(Properties) = Type("Match") 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 From KeyAndValue - Block ID or block sample itself - block
// InsertAfter - String - Block ID after which to insert the new one - prev
//
// Return value:
// 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 TypeValue(Block) = Type("Array") Then
Block = Block[0];
EndIf;
Headers = CreateRequestHeaders(Token);
ConvertID(Parent);
If TypeValue(Block) = Type("String") Then
ConvertID(Block);
Block = ReturnBlock(Token, Block);
EndIf;
BlockArray = New Array;
BlockArray.Add(Block);
Parameters = New Match;
Parameters.Insert("children", BlockArray);
If ValueFilled(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
// Inернуть блоto.
//
// 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:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ServiceProceduresAndFunctions
Function CreateRequestHeaders(Val Token)
OPI_TypeConversion.GetLine(Token);
Headers = New Match;
Headers.Insert("Authorization" , "Bearer " + Token);
Headers.Insert("Notion-Version", "2022-06-28");
Return Headers;
EndFunction
Procedure ConvertID(Identifier)
OPI_TypeConversion.GetLine(Identifier);
Identifier = StringReplace(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;
Data array = New Array;
Title = "title";
TextStructure.Insert("content", Title);
TextStructure.Insert("link" , Undefined);
DataStructure.Insert("text", TextStructure);
DataStructure.Insert("type", "text");
Data array.Add(DataStructure);
SubordinateStructure.Insert("id" , Title);
SubordinateStructure.Insert("type" , Title);
SubordinateStructure.Insert(Title , Data array);
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 Match;
For Each Property In Properties Do
If TypeValue(Property.Value) = Type("String") Then
ParameterMap.Insert(Property.Key, New Structure(Property.Value, New Structure));
ElsIf TypeValue(Property.Value) = Type("Structure")
Or TypeValue(Property.Value) = Type("Match") Then
ValueSelection = FormSelectionValues(Property.Value);
ParameterMap.Insert(Property.Key, New Structure("select", ValueSelection));
Else
ParameterMap.Insert(Property.Key, Property.Value);
EndIf;
EndDo;
MainStructure.Insert("properties", ParameterMap);
EndProcedure
Function FormSelectionValues(Val VariantStructure)
OptionArray = New Array;
For Each Option In VariantStructure Do
OptionMap = New Match;
OptionMap.Insert("name" , Option.Key);
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 Match;
If ValueFilled(BaseFields) Then
For Each Field In BaseFields Do
FieldData = Field.Value;
FieldType = FieldData["type"];
FillableData = Data.Get(Field.Key);
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 ConvertLink(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;
Data array = New Array;
TextStructure.Insert("content", Title);
TextStructure.Insert("link" , Undefined);
DataStructure.Insert("type", "text");
DataStructure.Insert("text", TextStructure);
Data array.Add(DataStructure);
Return New Structure("title", Data array);
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 = StartOfDay(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 TypeValue(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.Key);
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 ConvertLink(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

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="1bef723b-a2a4-4547-b29f-63cf9c78d813">
<name>OPI_Notion</name>
<synonym>
<key>ru</key>
<value>Methodы work with Notion (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="21b89e7a-e792-4a4c-9d01-c630225fe48a">
<name>OPI_Slack</name>
<synonym>
<key>ru</key>
<value>Slack</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="fe603e76-e34a-40fd-977d-ee3c2dbc6620">
<name>OPI_Telegram</name>
<synonym>
<key>ru</key>
<value>Methodы интеграции with Telegram (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,682 +0,0 @@
// 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 in не зtoете with чего toчать, то withтоит toйти метоd 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 ProgrammingInterface
#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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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.Уwithтаноinить(TokenResponse["refresh_token"]);
// Constants.TwitterToken.Уwithтаноinить(TokenResponse["access_token"]);
// BSLLS:CommentedCode-on
Return TokenResponse;
EndFunction
#EndRegion
#Region Tweets
// !NOCLI
// Create custom tweet
//
// 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я)
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
//
// Return value:
// 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 ValueFilled(MediaArray) Then
OPI_TypeConversion.GetCollection(MediaArray);
EndIf;
If ValueFilled(PollOptionsArray) Then
OPI_TypeConversion.GetCollection(PollOptionsArray);
EndIf;
Parameters_ = GetStandardParameters(Parameters);
URL = "https://api.twitter.com/2/tweets";
Array = "Array";
Fields = New Match;
If ValueFilled(Text) Then
Fields.Insert("text", Text);
EndIf;
If TypeValue(PollOptionsArray) = Type(Array) And ValueFilled(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 TypeValue(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
//
// Return value:
// 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 from String, BinaryData - Image files array - pictures
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
//
// Return value:
// Key-Value Pair - serialized JSON response from Twitter
Function Create image tweet(Val Text, Val ImageArray, Val Parameters = "") Export
MediaArray = Upload attachments array(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
// Gif array - Array from String, BinaryData - Gif files array - gifs
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
//
// Return value:
// Key-Value Pair - serialized JSON response from Twitter
Function CreateGifTweet(Val Text, Val Gif array, Val Parameters = "") Export
MediaArray = Upload attachments array(Gif array, "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
// Video array - Array from String, BinaryData - Video files array - videos
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
//
// Return value:
// Key-Value Pair - serialized JSON response from Twitter
Function CreateVideoTweet(Val Text, Val Video array, Val Parameters = "") Export
MediaArray = Upload attachments array(Video array, "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 Strings - 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:
// 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 from String, BinaryData - Files array
// AttachmentsType - String - Attachments type
// Parameters - Structure Of String - See GetStandardParameters - auth - Authorization JSON or path to .json
//
// Return value:
// Array Of String - Media ID array
Function Upload attachments array(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 ValueFilled(ArrayOfFiles) Then
For Each SendingFile In ArrayOfFiles Do
OPI_TypeConversion.GetBinaryData(SendingFile);
Response = UploadMediaFile(SendingFile, AttachmentsType, Parameters_);
MediaID = Response[MIS];
If Not ValueFilled(MediaID) Then
Return Response;
EndIf;
MediaArray.Add(MediaID);
EndDo;
EndIf;
Return MediaArray;
EndFunction
#EndRegion
#EndRegion
#Region ServiceProceduresAndFunctions
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 Match;
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 ValueFilled(InitializationKey) Or Not ValueFilled(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 TypeValue(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 ValueFilled(Information) Then
Return Response;
EndIf;
ProcessingStatus = Information["state"];
If Not ValueFilled(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 = "")
// З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 то,
// 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,
// 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ю ;)
// P.S Далее чаwithто упомиtoетwithя "withтраница towithтроеto Twitter Developer" - this
// https://developer.twitter.com/en/portal/dashboard и inыбор toонtoретного проеtoта from withпиwithtoа (зtoчеto c toлючем)
Parameters_ = New Match;
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() -> Браузер -> 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ит метоdом RefreshToken with ноinыми access_token и refresh_token.
// For the next update, you need to use a new refresh_token, so hardcode
// не получитwithя (access_token тоже не получитwithя)
// |--> RefreshToken() ->| access_token --> Used in the interval of 2 hours for requests
// | |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 TypeValue(Parameters) = Type("Structure") Or TypeValue(Parameters) = Type("Match") Then
For Each PassedParameter In Parameters Do
Parameters_.Insert(PassedParameter.Key, 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("Key");
ParametersTable.Columns.Add("Value");
For Each Field In Fields Do
NewLine = ParametersTable.Add();
NewLine.Key = Field.Key;
NewLine.Value = Field.Value;
EndDo;
NewLine = ParametersTable.Add();
NewLine.Key = OCK;
NewLine.Value = Parameters[OCK];
NewLine = ParametersTable.Add();
NewLine.Key = OTK;
NewLine.Value = Parameters[OTK];
NewLine = ParametersTable.Add();
NewLine.Key = "oauth_version";
NewLine.Value = APIVersion;
NewLine = ParametersTable.Add();
NewLine.Key = "oauth_signature_method";
NewLine.Value = HashingMethod;
NewLine = ParametersTable.Add();
NewLine.Key = "oauth_timestamp";
NewLine.Value = CurrentUNIXDate;
NewLine = ParametersTable.Add();
NewLine.Key = "oauth_nonce";
NewLine.Value = CurrentUNIXDate;
For Each TableRow In ParametersTable Do
TableRow.Key = EncodeString(TableRow.Key, StringEncodingMethod.URLencoding);
TableRow.Value = EncodeString(TableRow.Value, StringEncodingMethod.URLencoding);
EndDo;
ParametersTable.Sort("Key");
For Each TableRow In ParametersTable Do
SignatureString = SignatureString
+ TableRow.Key
+ "="
+ TableRow.Value
+ "&";
EndDo;
SignatureString = Left(SignatureString, StrLength(SignatureString) - 1);
SignatureString = inReg(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 Match;
HeaderMapping.Insert("authorization", AuthorizationHeader);
Return HeaderMapping;
EndFunction
Function CreateAuthorizationHeaderV2(Val Parameters)
ReturnMapping = New Match;
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 ValueFilled(Information) Then
Return Response;
EndIf;
ProcessingStatus = Information["state"];
If Not ValueFilled(ProcessingStatus) Then
Return Response;
Else
Return ProcessingStatus;
EndIf;
EndFunction
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="748f90c6-8251-482b-a249-b0372df0c72e">
<name>OPI_Twitter</name>
<synonym>
<key>ru</key>
<value>Methodы work with Twitter (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="1ab0a76a-246d-4037-97c3-212d680aa589">
<name>OPI_VK</name>
<synonym>
<key>ru</key>
<value>Methodы интеграции with VK (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,414 +0,0 @@
// 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 ProgrammingInterface
#Region SettingsAndInformation
// Set Webhook
// InАЖNО: Уwithтаноintoа Webhook обязательto по праinилам Viber. For thisго todо иметь withinобоdный URL,
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ValueFilled(Size) Then
Response = OPI_Tools.Get(URL);
Size = Response.Size();
EndIf;
String_ = "String";
Extension = StringReplace(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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 Strings - Array of buttons - buttons
// ButtonColor - String - HEX color of buttons with # at the beginning - color
//
// Return value:
// 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 ServiceProceduresAndFunctions
// 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 - When sending 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
//
// Return value:
// Arbitrary, HTTP Response - 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 ValueFilled(Text) Then
ParametersStructure.Insert("text", Text);
EndIf;
If TypeValue(Keyboard) = Type("Structure") Then
ParametersStructure.Insert("keyboard", Keyboard);
EndIf;
If ValueFilled(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 Match;
HeadersStructure.Insert("X-Viber-Auth-Token", Token);
Return HeadersStructure;
EndFunction
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="ece78a60-71c0-4443-a6e4-63dd8a7b10d0">
<name>OPI_Viber</name>
<synonym>
<key>ru</key>
<value>Methodы интеграции with Viber (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,635 +0,0 @@
// 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 ProgrammingInterface
#Region FileAndFolderManagement
// Get disk information
// Gets information about the current disk
//
// Parameters:
// Token - String - Token - token
//
// Return value:
// 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
//
// Return value:
// 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 ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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 ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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 ValueFilled(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 available typeоin: 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
//
// Return value:
// 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 ValueFilled(Quantity) Then
Parameters.Insert("limit", OPI_Tools.NumberToString(Quantity));
EndIf;
If ValueFilled(OffsetFromStart) Then
Parameters.Insert("offset", OPI_Tools.NumberToString(OffsetFromStart));
EndIf;
If ValueFilled(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
//
// Return value:
// 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 ValueFilled(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
//
// Return value:
// 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 ValueFilled(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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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.
// 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
//
// Return value:
// 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 ValueFilled(Quantity) Then
Parameters.Insert("limit", Quantity);
EndIf;
If ValueFilled(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 - Quantity inозinращаемых inложенных объеtoтоin (for directory) - amount
// OffsetFromStart - Number - Offset for getting nested objects not from the beginning of the list - offset
//
// Return value:
// 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 ValueFilled(Quantity) Then
Parameters.Insert("limit", OPI_Tools.NumberToString(Quantity));
EndIf;
If ValueFilled(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
//
// Return value:
// 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 ValueFilled(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 inнутри публичного directory (тольtoо for папоto) - from
// To - String - File save path - to
//
// Return value:
// Key-Value Pair - serialized JSON response from Yandex
Function SavePublicObjectToDisk(Val Token, Val URL, From = "", To = "") Export
OPI_TypeConversion.GetLine(Token);
OPI_TypeConversion.GetLine(URL);
OPI_TypeConversion.GetLine(From);
OPI_TypeConversion.GetLine(To);
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 ValueFilled(From) Then
Parameters.Insert("path", From);
EndIf;
If ValueFilled(To) Then
Parameters.Insert("save_path", To);
EndIf;
Parameters = OPI_Tools.RequestParametersToString(Parameters);
Response = OPI_Tools.Post(Address + Parameters, , Headers, False);
ResponseURL = Response[Href];
If Not ValueFilled(ResponseURL) Then
Return Response;
EndIf;
Response = OPI_Tools.Get(ResponseURL, , Headers);
Return Response;
EndFunction
#EndRegion
#EndRegion
#Region ServiceProceduresAndFunctions
Function AuthorizationHeader(Val Token)
Headers = New Match;
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 ValueFilled(ResponseURL) Then
Return Response;
EndIf;
Response = OPI_Tools.Get(ResponseURL, , Headers);
Return Response;
EndFunction
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="af0b34e8-10fa-414f-a643-915210c6289a">
<name>OPI_YandexDisk</name>
<synonym>
<key>ru</key>
<value>Methodы work with Yandex Disk (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,112 +0,0 @@
// 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 ProgrammingInterface
// 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
//
// Return value:
// 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
//
// Return value:
// 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
//
// Return value:
// 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

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="32379ca2-0f58-4143-9b34-cb552c54b962">
<name>OPI_YandexID</name>
<synonym>
<key>ru</key>
<value>Methodы work with Yandex ID (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="e810f1d2-6714-4c85-94b1-c3ce20788e78">
<name>OPI_Tools</name>
<synonym>
<key>ru</key>
<value>OPI инwithтрументы</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,110 +0,0 @@
// 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 ServiceProgramInterface
#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)
// License text available at:
// https://creativecommons.org/licenses/by/4.0/legalcode
///////////////////////////////////////////////////////////////////////////////////////////////////////
Function HMACSHA256(Val Key, Val Data) Export
Return HMAC(Key, Data, HashFunction.SHA256, 64);
EndFunction
Function Hash(BinaryData, Type) Export
Hashing = New DataHashing(Type);
Hashing.Add(BinaryData);
Return Hashing.HashSum;
EndFunction
Function HMAC(Val Key, Val Data, Type, BlockSize) Export
Twice = 2;
If Key.Size() > BlockSize Then
Key = Hash(Key, Type);
EndIf;
If Key.Size() <= BlockSize Then
Key = GetHexStringFromBinaryData(Key);
Key = Left(Key + RepeatString("00", BlockSize), BlockSize * Twice);
EndIf;
Key = GetBinaryDataBufferFromBinaryData(GetBinaryDataFromHexString(Key));
Ipad = GetBinaryDataBufferFromHexString(RepeatString("36", BlockSize));
Opad = GetBinaryDataBufferFromHexString(RepeatString("5c", BlockSize));
Ipad.WriteBitwiseExclusiveOr(0, Key);
Ikeypad = GetBinaryDataFromBinaryDataBuffer(ipad);
Opad.WriteBitwiseExclusiveOr(0, Key);
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 JoinBinaryData(BinaryDataArray);
EndFunction
Function RepeatString(String, Quantity) Export
Parts = New Array(Quantity);
For To = 1 For Quantity Do
Parts.Add(String);
EndDo;
Return StrJoin(Parts, "");
EndFunction
#EndRegion
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="55bb3987-d7ac-4ed7-a6fd-aa4cfeb61c27">
<name>OPI_Cryptography</name>
<synonym>
<key>ru</key>
<value>Toриптография (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,470 +0,0 @@
// Location OS: ./OInt/tools/Modules/OPI_TestDataRetrieval.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:UsingHardcodePath-off
// BSLLS:Typo-off
// BSLLS:DeprecatedMessage-off
// BSLLS:UsingServiceTag-off
// BSLLS:ExecuteExternalCodeInCommonModule-off
// BSLLS:DuplicateStringLiteral-off
//@skip-check use-non-recommended-method
// Uncomment if OneScript is executed
// #Use "./internal"
// #Use asserts
#Region ServiceProgramInterface
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";
VK = "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, "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, "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, "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, "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);
Return TestTable;
EndFunction
Function ExpectsThat(Value) Export
Try
Module = GetCommonModule("UTest");
Awaiting = TypeValue(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.Key;
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 TypeValue(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;
Notify(Header);
Notify(Symbols.PS);
Notify(Data);
Notify(Symbols.PS);
Notify("---------------------------------");
Notify(Symbols.PS);
If ValueFilled(Library) Then
WriteLogFile(Data, Method, Library);
EndIf;
EndProcedure
#EndRegion
#Region ServiceProceduresAndFunctions
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)
УwithтаноinитьБезопаwithныйMode(True);
Module = Calculate(Name);
УwithтаноinитьБезопаwithныйMode(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 WritingJSON;
JSONWriteParameters = New JSONWriteParameters(JSONLineBreak.Auto, Symbols.Tab);
Record.OpenFile(Path, , , JSONWriteParameters);
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
Notify("Failed to write log file!: " + ErrorDescription());
EndTry;
EndProcedure
#EndRegion

View File

@ -1,11 +0,0 @@
<?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>
<synonym>
<key></key>
<value>OPI получение data tests</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,320 +0,0 @@
// 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 ServiceProgramInterface
Procedure GetBinaryData(Value) Export
If Value = Undefined Then
Return;
EndIf;
Try
If TypeValue(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 TypeValue(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 TypeValue(Value) = Type("BinaryData") Then
Value = GetStringFromBinaryData(Value);
Else
Value = OPI_Tools.NumberToString(Value);
EndIf;
File = New File(Value);
ReadingJSON = New ReadingJSON;
If File.Exists() Then
ReadingJSON.OpenFile(Value);
ElsIf StringStartsWith(nReg(Value), "http") Then
AndVF = GetTempFileName();
CopyFile(Value, AndVF);
ReadingJSON.OpenFile(AndVF);
ReadingJSON.Read();
DeleteFiles(AndVF);
Else
ReadingJSON.SetString(ShortLP(Value));
EndIf;
Value = ReadJSON(ReadingJSON, True, Undefined, JSONDateFormat.ISO);
ReadingJSON.Close();
If (Not ThisIsCollection(Value)) Or Not ValueFilled(Value) Then
Value = InitialValue;
GetArray(Value);
EndIf;
EndIf;
Except
Value = InitialValue;
GetArray(Value);
EndTry;
EndProcedure
Procedure GetArray(Value) Export
If TypeValue(Value) = Type("Array") Then
Return;
EndIf;
If TypeValue(Value) = Type("String")
And StringStartsWith(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 = StrSplit(Value, CommaInQuotes, False);
For N = 0 For Value.WithinBoundary() Do
Value[N] = ShortLP(Value[N]);
EndDo;
Else
If TypeValue(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 TypeValue(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
ReadingText = New ReadingText(Value);
Value = ReadingText.Read();
ReadingText.Close();
ElsIf StringStartsWith(nReg(Value), "http") Then
AndVF = GetTempFileName();
CopyFile(Value, AndVF);
ReadingText = New ReadingText(AndVF);
Value = ReadingText.Read();
ReadingText.Close();
DeleteFiles(AndVF);
Else
Return;
EndIf;
ElsIf TypeValue(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 TypeValue(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 ServiceProceduresAndFunctions
Function ThisIsCollection(Val Value)
Return TypeValue(Value) = Type("Array")
Or TypeValue(Value) = Type("Structure")
Or TypeValue(Value) = Type("Match");
EndFunction
Function ThisIsSymbolic(Val Value)
Return TypeValue(Value) = Type("String")
Or TypeValue(Value) = Type("Number")
Or TypeValue(Value) = Type("Date");
EndFunction
#EndRegion

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="e15aee63-1565-4f37-ba54-4d4e79723fc5">
<name>OPI_TypeConversion</name>
<synonym>
<key>ru</key>
<value>Преобразоinание typeоin (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="ca6868b2-8987-4ae3-9d97-50a8becc72df">
<name>OPI_Tests</name>
<synonym>
<key></key>
<value>OPI теwithты</value>
</synonym>
<synonym>
<key>ru</key>
<value>Tests for YaxUnit (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,70 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" xmlns:mdclassExtension="http://g5.1c.ru/v8/dt/metadata/mdclass/extension" uuid="aa51f610-7ed3-4091-8908-8ecccf0aaf0f">
<name>OpenIntegrations</name>
<synonym>
<key>ru</key>
<value>Отtoрытый паtoет интеграций</value>
</synonym>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:ConfigurationExtension">
<defaultRunMode>Checked</defaultRunMode>
<usePurposes>Checked</usePurposes>
<interfaceCompatibilityMode>Checked</interfaceCompatibilityMode>
</extension>
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="12689443-2950-4e3b-b313-9a692b6acac7"/>
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="f6f98fbd-010a-4aba-8f11-01203bbc59c7"/>
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="33990ba2-16f0-473d-851f-a9132c777ed6"/>
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="917bb154-d76e-42a4-b161-336b7c57a1ac"/>
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="793db0b3-8d01-4f55-982c-73cb3d4547da"/>
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="c67ca98f-c017-4f18-8175-02819e09b383"/>
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="c9ed170a-ffaa-4859-9d92-fd1cbc7051b3"/>
<keepMappingToExtendedConfigurationObjectsByIDs>true</keepMappingToExtendedConfigurationObjectsByIDs>
<namePrefix>OPI_</namePrefix>
<configurationExtensionCompatibilityMode>8.3.9</configurationExtensionCompatibilityMode>
<configurationExtensionPurpose>Customization</configurationExtensionPurpose>
<defaultRunMode>ManagedApplication</defaultRunMode>
<usePurposes>PersonalComputer</usePurposes>
<scriptVariant>Russian</scriptVariant>
<vendor>Bayselonarrend</vendor>
<version>1.9.0</version>
<detailedInformation>
<key>ru</key>
<value>Отtoрытый паtoет интеграций - toбор библиотеto for интеграции with неtoоторыми популярными API for 1C:Enterprise. Он withоwithтоит from общих моdулей, toажdый from toоторых отinечает за withinой API, а таtoже неwithtoольtoих моdулей-инwithтрументоin, общих for all.</value>
</detailedInformation>
<vendorInformationAddress>
<key>ru</key>
<value>https://github.com/Bayselonarrend</value>
</vendorInformationAddress>
<configurationInformationAddress>
<key>ru</key>
<value>https://github.com/Bayselonarrend/OpenIntegrations</value>
</configurationInformationAddress>
<languages uuid="0e858b44-34f3-4d20-986d-13290bb5ba5a">
<name>Руwithwithtoий</name>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:LanguageExtension">
<languageCode>Checked</languageCode>
</extension>
<languageCode>ru</languageCode>
</languages>
<subsystems>Subsystem.OPI_Andнтеграция</subsystems>
<commonModules>CommonModule.OPI_Tools</commonModules>
<commonModules>CommonModule.OPI_Cryptography</commonModules>
<commonModules>CommonModule.OPI_TypeConversion</commonModules>
<commonModules>CommonModule.OPI_Telegram</commonModules>
<commonModules>CommonModule.OPI_VK</commonModules>
<commonModules>CommonModule.OPI_Viber</commonModules>
<commonModules>CommonModule.OPI_Twitter</commonModules>
<commonModules>CommonModule.OPI_Notion</commonModules>
<commonModules>CommonModule.OPI_YandexID</commonModules>
<commonModules>CommonModule.OPI_YandexDisk</commonModules>
<commonModules>CommonModule.OPI_GoogleWorkspace</commonModules>
<commonModules>CommonModule.OPI_GoogleCalendar</commonModules>
<commonModules>CommonModule.OPI_GoogleDrive</commonModules>
<commonModules>CommonModule.OPI_GoogleSheets</commonModules>
<commonModules>CommonModule.OPI_Slack</commonModules>
<commonModules>CommonModule.OPI_Airtable</commonModules>
<commonModules>CommonModule.OPI_Dropbox</commonModules>
<commonModules>CommonModule.OPI_Tests</commonModules>
<commonModules>CommonModule.OPI_GetTestData</commonModules>
</mdclass:Configuration>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Subsystem xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="86c261d7-2729-405f-9d39-5d9104a56bd1">
<name>OPI_Andнтеграция</name>
<synonym>
<key>ru</key>
<value>Andнтеграция</value>
</synonym>
<includeHelpInContents>true</includeHelpInContents>
<includeInCommandInterface>true</includeInCommandInterface>
<content>CommonModule.OPI_Tools</content>
<content>CommonModule.OPI_Cryptography</content>
<content>CommonModule.OPI_TypeConversion</content>
<content>CommonModule.OPI_VK</content>
<content>CommonModule.OPI_Telegram</content>
<content>CommonModule.OPI_Viber</content>
<content>CommonModule.OPI_Twitter</content>
<content>CommonModule.OPI_Notion</content>
<content>CommonModule.OPI_YandexID</content>
<content>CommonModule.OPI_YandexDisk</content>
<content>CommonModule.OPI_GoogleWorkspace</content>
<content>CommonModule.OPI_GoogleCalendar</content>
<content>CommonModule.OPI_GoogleDrive</content>
<content>CommonModule.OPI_GoogleSheets</content>
<content>CommonModule.OPI_Slack</content>
<content>CommonModule.OPI_Airtable</content>
<content>CommonModule.OPI_Tests</content>
<content>CommonModule.OPI_GetTestData</content>
</mdclass:Subsystem>

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>OPI</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>com._1c.g5.v8.dt.core.V8ExtensionNature</nature>
</natures>
<name>OPI</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>com._1c.g5.v8.dt.core.V8ExtensionNature</nature>
</natures>
</projectDescription>

View File

@ -1,2 +1,2 @@
eclipse.preferences.version=1
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -1,3 +1,3 @@
Manifest-Version: 1.0
Manifest-Version: 1.0
Runtime-Version: 8.3.15
Base-Project: OpenIntegrations

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="457991ad-c2ad-49b8-a26a-9fc83c8a7d11">
<name>OPI_Airtable</name>
<synonym>
<key></key>
<value>OPI airtable</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Airtable</name>
<synonym>
<key></key>
<value>OPI airtable</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -34,75 +34,75 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2019, LLC 1C-Soft
// All rights reserved. This program and accompanying materials are provided
// 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)
// License text available at:
// https://creativecommons.org/licenses/by/4.0/legalcode
///////////////////////////////////////////////////////////////////////////////////////////////////////
Function HMACSHA256(Val Key, Val Data) Export
Return HMAC(Key, Data, HashFunction.SHA256, 64);
Return HMAC(Key, Data, HashFunction.SHA256, 64);
EndFunction
Function Hash(BinaryData, Type) Export
Hashing = New DataHashing(Type);
Hashing.Add(BinaryData);
Return Hashing.HashSum;
Hashing = New DataHashing(Type);
Hashing.Add(BinaryData);
Return Hashing.HashSum;
EndFunction
Function HMAC(Val Key, Val Data, Type, BlockSize) Export
Twice = 2;
If Key.Size() > BlockSize Then
Key = Hash(Key, Type);
EndIf;
If Key.Size() <= BlockSize Then
Key = GetHexStringFromBinaryData(Key);
Key = Left(Key + RepeatString("00", BlockSize), BlockSize * Twice);
EndIf;
Key = GetBinaryDataBufferFromBinaryData(GetBinaryDataFromHexString(Key));
Ipad = GetBinaryDataBufferFromHexString(RepeatString("36", BlockSize));
Opad = GetBinaryDataBufferFromHexString(RepeatString("5c", BlockSize));
Ipad.WriteBitwiseExclusiveOr(0, Key);
Ikeypad = GetBinaryDataFromBinaryDataBuffer(ipad);
Opad.WriteBitwiseExclusiveOr(0, Key);
Okeypad = GetBinaryDataFromBinaryDataBuffer(opad);
Return Hash(ConcatenateBinaryData(okeypad, Hash(ConcatenateBinaryData(ikeypad, Data), Type)), Type);
Twice = 2;
If Key.Size() > BlockSize Then
Key = Hash(Key, Type);
EndIf;
If Key.Size() <= BlockSize Then
Key = GetHexStringFromBinaryData(Key);
Key = Left(Key + RepeatString("00", BlockSize), BlockSize * Twice);
EndIf;
Key = GetBinaryDataBufferFromBinaryData(GetBinaryDataFromHexString(Key));
Ipad = GetBinaryDataBufferFromHexString(RepeatString("36", BlockSize));
Opad = GetBinaryDataBufferFromHexString(RepeatString("5c", BlockSize));
Ipad.WriteBitwiseExclusiveOr(0, Key);
Ikeypad = GetBinaryDataFromBinaryDataBuffer(ipad);
Opad.WriteBitwiseExclusiveOr(0, Key);
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 JoinBinaryData(BinaryDataArray);
BinaryDataArray = New Array;
BinaryDataArray.Add(BinaryData1);
BinaryDataArray.Add(BinaryData2);
Return JoinBinaryData(BinaryDataArray);
EndFunction
Function RepeatString(String, Quantity) Export
Parts = New Array(Quantity);
For To = 1 by Quantity Loop
Parts.Add(String);
EndOfLoop;
Return StrJoin(Parts, "");
Parts = New Array(Quantity);
For To = 1 For Quantity Do
Parts.Add(String);
EndDo;
Return StrJoin(Parts, "");
EndFunction
#EndRegion

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="55bb3987-d7ac-4ed7-a6fd-aa4cfeb61c27">
<name>OPI_Криптография</name>
<synonym>
<key>ru</key>
<value>Криптография (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Cryptography</name>
<synonym>
<key>ru</key>
<value>Toриптография (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="66ce7792-41e5-47e4-bfad-2dcff1c96287">
<name>OPI_Dropbox</name>
<synonym>
<key></key>
<value>OPI dropbox</value>
</synonym>
<synonym>
<key>ru</key>
<value>Drop box</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Dropbox</name>
<synonym>
<key></key>
<value>OPI dropbox</value>
</synonym>
<synonym>
<key>ru</key>
<value>Drop box</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -42,429 +42,429 @@
#Region ServiceProgramInterface
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;
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";
VK = "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, "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, "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, "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, "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);
Return TestTable;
EndFunction
Telegram = "Telegram";
VK = "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, "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, "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, "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, "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);
Return TestTable;
EndFunction
Function ExpectsThat(Value) Export
Attempt
Module = GetCommonModule("UTest");
Awaiting = TypeValue(Module) = Type("CommonModule");
Return Module.ExpectsThat(Value);
Exception
Return Awaiting.What(Value);
EndOfAttempt;
Try
Module = GetCommonModule("UTest");
Awaiting = TypeValue(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 Of Sections Loop
CurrentSection = Section.Key;
Filter = New Structure("Section", CurrentSection);
SectionTests = TestTable.FindLines(Filter);
Set = Module.AddTestSet(CurrentSection);
For Each Test Of SectionTests Loop
Set.AddServerTest(Test.Method, Test.Synonym);
EndOfLoop;
EndOfLoop;
Return "";
Module = GetCommonModule("UTTests");
Sections = GetTestingSectionMapping();
TestTable = GetTestTable();
For Each Section In Sections Do
CurrentSection = Section.Key;
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 Of TestTable Loop
ArrayOfTests.Add(Test.Method);
EndOfLoop;
Return ArrayOfTests;
TestTable = GetTestTable();
ArrayOfTests = New Array;
For Each Test In TestTable Do
ArrayOfTests.Add(Test.Method);
EndDo;
Return ArrayOfTests;
EndFunction
Function GetParameter(Parameter) Export
Function GetParameter(Parameter) Export
Path = DataFilePath();
Return GetValueFromFile(Parameter, Path);
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);
Otherwise
Value = MainValue;
EndIf;
If TypeValue(Value) = Type("String") Then
Value = GetFilePath(Value, LocalParameter);
EndIf;
Return Value;
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 TypeValue(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);
Otherwise
DeleteFiles(AndVF);
EndIf;
Otherwise
Binary = New BinaryData(Path);
EndIf;
Return Binary;
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);
Value = GetParameter(Parameter);
Collection.Insert(Parameter, Value);
EndProcedure
Procedure BinaryToCollection(Parameter, Collection) Export
Value = GetBinary(Parameter);
Collection.Insert(Parameter, Value);
Value = GetBinary(Parameter);
Collection.Insert(Parameter, Value);
EndProcedure
Procedure WriteParameter(Parameter, Value) Export
Path = DataFilePath();
WriteParameterToFile(Parameter, Value, Path);
Path = DataFilePath();
WriteParameterToFile(Parameter, Value, Path);
EndProcedure
Procedure WriteLog(Val Result, Val Method, Val Library = "") Export
Header = String(OPI_Tools.GetCurrentDate()) + " | " + Method;
Attempt
Data = OPI_Tools.JSONString(Result);
Exception
Data = "Not JSON: " + String(Result);
EndOfAttempt;
Data = " " + Data;
Notify(Header);
Notify(Symbols.PS);
Notify(Data);
Notify(Symbols.PS);
Notify("---------------------------------");
Notify(Symbols.PS);
If ValueFilled(Library) Then
WriteLogFile(Data, Method, Library);
EndIf;
Header = String(OPI_Tools.GetCurrentDate()) + " | " + Method;
Try
Data = OPI_Tools.JSONString(Result);
Except
Data = "Not JSON: " + String(Result);
EndTry;
Data = " " + Data;
Notify(Header);
Notify(Symbols.PS);
Notify(Data);
Notify(Symbols.PS);
Notify("---------------------------------");
Notify(Symbols.PS);
If ValueIsFilled(Library) Then
WriteLogFile(Data, Method, Library);
EndIf;
EndProcedure
#EndRegion
#Region ServiceProceduresAndFunctions
Function GetValueFromFile(Parameter, Path)
Values = OPI_Tools.ReadJSONFile(Path);
Return ?(Values.Property(Parameter), Values[Parameter], "");
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 Of PossiblePaths Loop
RepositoryFile = New File(PossiblePath);
If RepositoryFile.Exists() Then
Path = PossiblePath;
EndIf;
EndOfLoop;
Return Path;
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)
УwithтаноinитьБезопаwithныйMode(True);
Module = Calculate(Name);
УwithтаноinитьБезопаwithныйMode(False);
Return Module;
SetSafeMode(True);
Module = Calculate(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;
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 WritingJSON;
JSONWriteParameters = New JSONWriteParameters(JSONLineBreak.Auto, Symbols.Tab);
Record.OpenFile(Path, , , JSONWriteParameters);
WriteJSON(Record, Values);
Record.Close();
Values = OPI_Tools.ReadJSONFile(Path);
Values.Insert(Parameter, Value);
Record = New WritingJSON;
JSONWriteParameters = New JSONWriteParameters(JSONLineBreak.Auto, Symbols.Tab);
Record.OpenFile(Path, , , JSONWriteParameters);
WriteJSON(Record, Values);
Record.Close();
EndProcedure
Procedure WriteLogFile(Val Data, Val Method, Val Library)
Attempt
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;
Exception
Notify("Failed to write log file!: " + ErrorDescription());
EndOfAttempt;
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
Notify("Failed to write log file!: " + ErrorDescription());
EndTry;
EndProcedure
#EndRegion

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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_ПолучениеДанныхТестов</name>
<synonym>
<key></key>
<value>OPI получение данных тестов</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_GetTestData</name>
<synonym>
<key></key>
<value>OPI test data retrieval</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="d27d4ffb-31c2-4362-bd6d-d785ce171b49">
<name>OPI_GoogleCalendar</name>
<synonym>
<key></key>
<value>OPI google calendar</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_GoogleCalendar</name>
<synonym>
<key></key>
<value>OPI google calendar</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="3bf39c90-a263-4300-b800-7fd85f7c6d40">
<name>OPI_GoogleDrive</name>
<synonym>
<key></key>
<value>OPI google drive</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_GoogleDrive</name>
<synonym>
<key></key>
<value>OPI google drive</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -38,90 +38,90 @@
// CreateBook
// Creates a new book
//
//
// Parameters:
// Token - String - Token - token
// Name - String - Name - title
// ArrayOfSheetNames - Array of Strings - Array of names to add new sheets to the book - sheets
//
// Token - String - Token - token
// Name - String - Name - title
// ArrayOfSheetNames - Array of Strings - Array of names to add new sheets to the book - sheets
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
//
// Token - String - Token - token
// Identifier - String - BookIdentifier - spreadsheet
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
//
// Token - String - Token - token
// Book - String - BookID - spreadsheet
// Name - String - New name - title
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
@ -130,95 +130,95 @@ EndFunction
// AddSheet
// Adds a new sheet to the book
//
//
//
//
// Parameters:
// Token - String - Token - token
// Book - String - BookIdentifier - spreadsheet
// Name - String - NewSheetName - title
//
// Token - String - Token - token
// Book - String - BookIdentifier - spreadsheet
// Name - String - NewSheetName - title
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
//
// Token - String - Token - token
// Book - String - BookIdentifier - spreadsheet
// Sheet - String - IdentifierOfSheetToDelete - sheet
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
// To - String - DestinationBookID - to
// Sheet - String - CopiedSheetID - sheet
//
// Token - String - Token - token
// From - String - SourceBookID - from
// To - String - DestinationBookID - to
// Sheet - String - CopiedSheetID - sheet
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// Key-Value Pair - serialized JSON response from Google
Function CopySheet(Val Token, Val From, Val To, Val Sheet) Export
OPI_TypeConversion.GetLine(From);
OPI_TypeConversion.GetLine(To);
OPI_TypeConversion.GetLine(Sheet);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/"
+ From
+ "/sheets/"
+ Sheet
+ ":copyTo";
Parameters = New Structure("destinationSpreadsheetId", To);
Response = OPI_Tools.Post(URL, Parameters, Headers);
Return Response;
OPI_TypeConversion.GetLine(From);
OPI_TypeConversion.GetLine(To);
OPI_TypeConversion.GetLine(Sheet);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/"
+ From
+ "/sheets/"
+ Sheet
+ ":copyTo";
Parameters = New Structure("destinationSpreadsheetId", To);
Response = OPI_Tools.Post(URL, Parameters, Headers);
Return Response;
EndFunction
#EndRegion
@ -227,105 +227,105 @@ EndFunction
// 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 - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
// MajorDimension - String - Main dimension when filling the array range - dim
//
// 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
// MajorDimension - String - Main dimension when filling the array range - dim
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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 TypeValue(ValueMapping) = Type("Structure")
And Not TypeValue(ValueMapping) = Type("Match") 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);
, Val Book
, Val ValueMapping
, Val Sheet = ""
, Val MajorDimension = "COLUMNS") Export
OPI_TypeConversion.GetLine(Book);
OPI_TypeConversion.GetCollection(ValueMapping);
If Not TypeValue(ValueMapping) = Type("Structure")
And Not TypeValue(ValueMapping) = Type("Match") 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);
Parameters = New Structure("data,valueInputOption", Data array, "USER_ENTERED");
Response = OPI_Tools.Post(URL, Parameters, Headers);
Return Response;
Parameters = New Structure("data,valueInputOption", Data array, "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
// Cell array - Array of Strings - Array of cells like A1 to be cleared - cells
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// Key-Value Pair - serialized JSON response from Google
Function ClearCells(Val Token, Val Book, Val Cell array, Val Sheet = "") Export
OPI_TypeConversion.GetLine(Book);
OPI_TypeConversion.GetCollection(Cell array);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchClear";
FormCellNameArray(Cell array, Sheet);
Parameters = New Structure("ranges", Cell array);
Response = OPI_Tools.Post(URL, Parameters, Headers);
Return Response;
OPI_TypeConversion.GetLine(Book);
OPI_TypeConversion.GetCollection(Cell array);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchClear";
FormCellNameArray(Cell array, Sheet);
Parameters = New Structure("ranges", Cell array);
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
// Cell array - Array of Strings - Array ячееto inиdа А1 for получения (inеwithь лиwithт, еwithли не заполнено) - cells
// Sheet - String - Name лиwithта (перinый лиwithт по умолчанию) - sheetname
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// Key-Value Pair - serialized JSON response from Google
Function GetCellValues(Val Token, Val Book, Val Cell array = "", Val Sheet = "") Export
OPI_TypeConversion.GetLine(Book);
Headers = OPI_GoogleWorkspace.GetAuthorizationHeader(Token);
URL = "https://sheets.googleapis.com/v4/spreadsheets/" + Book + "/values:batchGet";
If ValueFilled(Cell array) Then
OPI_TypeConversion.GetCollection(Cell array);
FormCellNameArray(Cell array, Sheet);
First = True;
For Each Cell Of Cell array Loop
Delimiter = ?(First, "?", "&");
URL = URL + Delimiter + "ranges=" + Cell;
First = False;
EndOfLoop;
Otherwise
URL = URL + "?ranges='" + Sheet + "'";
EndIf;
Response = OPI_Tools.Get(URL, , Headers);
Return Response;
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);
First = True;
For Each Cell In Cell array 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
@ -335,75 +335,75 @@ EndFunction
#Region ServiceProceduresAndFunctions
Procedure FillSheetArray(Val ArrayOfNames, SheetArray)
For Each SheetName Of ArrayOfNames Loop
Sheet = CreateSheet(SheetName);
SheetArray.Add(Sheet);
EndOfLoop;
For Each SheetName In ArrayOfNames Do
Sheet = CreateSheet(SheetName);
SheetArray.Add(Sheet);
EndDo;
EndProcedure
Procedure AddSheetName(Cell, Val Sheet)
If ValueFilled(Sheet) Then
Cell = "'" + Sheet + "'!" + Cell;
EndIf;
If ValueIsFilled(Sheet) Then
Cell = "'" + Sheet + "'!" + Cell;
EndIf;
EndProcedure
Function CreateSheet(Val Name)
OPI_TypeConversion.GetLine(Name);
Sheet properties = New Structure("title" , Name);
Sheet = New Structure("properties", Sheet properties);
Return Sheet;
OPI_TypeConversion.GetLine(Name);
Sheet properties = New Structure("title" , Name);
Sheet = New Structure("properties", Sheet properties);
Return Sheet;
EndFunction
Function FormCellDataArray(Val ValueStructure, Val MajorDimension, Val Sheet)
OPI_TypeConversion.GetLine(Sheet);
Data array = New Array;
For Each CellData Of ValueStructure Loop
CurrentValue = CellData.Value;
Current key = CellData.Key;
AddSheetName(Current key, Sheet);
OPI_TypeConversion.GetArray(CurrentValue);
Current data = New Match;
Current array = New Array;
Current array.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);
Data array.Add(Current data);
EndOfLoop;
Return Data array;
OPI_TypeConversion.GetLine(Sheet);
Data array = New Array;
For Each CellData In ValueStructure Do
CurrentValue = CellData.Value;
Current key = CellData.Key;
AddSheetName(Current key, Sheet);
OPI_TypeConversion.GetArray(CurrentValue);
Current data = New Match;
Current array = New Array;
Current array.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);
Data array.Add(Current data);
EndDo;
Return Data array;
EndFunction
Procedure FormCellNameArray(Val ArrayOfNames, Val Sheet)
OPI_TypeConversion.GetLine(Sheet);
For N = 0 by ArrayOfNames.WithinBoundary() Loop
AddSheetName(ArrayOfNames[N], Sheet);
EndOfLoop;
OPI_TypeConversion.GetLine(Sheet);
For N = 0 For ArrayOfNames.WithinBoundary() Do
AddSheetName(ArrayOfNames[N], Sheet);
EndDo;
EndProcedure
#EndRegion

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="3890523a-552f-495c-ae7d-2991df8bb175">
<name>OPI_GoogleSheets</name>
<synonym>
<key></key>
<value>OPI google sheets</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_GoogleSheets</name>
<synonym>
<key></key>
<value>OPI google sheets</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -36,98 +36,98 @@
// 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
//
// ClientID - String - Client ID - id
// Calendar - Boolean - Calendar methods permission - calendar
// Drive - Boolean - Drive methods permission - drive
// Sheets - Boolean - Sheets methods permission - sheets
//
// Return value:
// String - Code retrieval link
// 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;
, 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
//
// ClientID - String - Client ID - id
// ClientSecret - String - Client secret - secret
// Code - String - Code from browser - code
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
//
// ClientID - String - Client ID - id
// ClientSecret - String - Client secret - secret
// RefreshToken - String - Refresh token - refresh
//
// Return value:
// Key-Value Pair - serialized JSON response from Google
// 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;
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
@ -136,14 +136,14 @@ EndFunction
#Region ServiceProgramInterface
Function GetAuthorizationHeader(Val Token) Export
OPI_TypeConversion.GetLine(Token);
Headers = New Match;
Headers.Insert("Authorization", "Bearer " + Token);
Return Headers;
OPI_TypeConversion.GetLine(Token);
Headers = New Match;
Headers.Insert("Authorization", "Bearer " + Token);
Return Headers;
EndFunction
#EndRegion
@ -151,23 +151,23 @@ EndFunction
#Region ServiceProceduresAndFunctions
Function GetPermissionsList(Calendar, Drive, Sheets)
Permissions array = New Array;
If Calendar Then
Permissions array.Add("https://www.googleapis.com/auth/calendar");
EndIf;
If Drive Then
Permissions array.Add("https://www.googleapis.com/auth/drive");
EndIf;
If Sheets Then
Permissions array.Add("https://www.googleapis.com/auth/spreadsheets");
EndIf;
Return StrJoin(Permissions array, " ");
Permissions array = New Array;
If Calendar Then
Permissions array.Add("https://www.googleapis.com/auth/calendar");
EndIf;
If Drive Then
Permissions array.Add("https://www.googleapis.com/auth/drive");
EndIf;
If Sheets Then
Permissions array.Add("https://www.googleapis.com/auth/spreadsheets");
EndIf;
Return StrJoin(Permissions array, " ");
EndFunction
#EndRegion

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="e5bf1867-4c83-4724-91f2-931150325ea0">
<name>OPI_GoogleWorkspace</name>
<synonym>
<key></key>
<value>OPI google workspace</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_GoogleWorkspace</name>
<synonym>
<key></key>
<value>OPI google workspace</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="1bef723b-a2a4-4547-b29f-63cf9c78d813">
<name>OPI_Notion</name>
<synonym>
<key>ru</key>
<value>Методы работы с Notion (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Notion</name>
<synonym>
<key>ru</key>
<value>Methodы work with Notion (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="21b89e7a-e792-4a4c-9d01-c630225fe48a">
<name>OPI_Slack</name>
<synonym>
<key>ru</key>
<value>Slack</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Slack</name>
<synonym>
<key>ru</key>
<value>Slack</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="fe603e76-e34a-40fd-977d-ee3c2dbc6620">
<name>OPI_Telegram</name>
<synonym>
<key>ru</key>
<value>Методы интеграции с Telegram (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Telegram</name>
<synonym>
<key>ru</key>
<value>Methodы интеграции with Telegram (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="ca6868b2-8987-4ae3-9d97-50a8becc72df">
<name>OPI_Tests</name>
<synonym>
<key></key>
<value>OPI tests</value>
</synonym>
<synonym>
<key>ru</key>
<value>Tests for YaxUnit (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="e810f1d2-6714-4c85-94b1-c3ce20788e78">
<name>OPI_Инструменты</name>
<synonym>
<key>ru</key>
<value>OPI инструменты</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Tools</name>
<synonym>
<key>ru</key>
<value>OPI tools</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="748f90c6-8251-482b-a249-b0372df0c72e">
<name>OPI_Twitter</name>
<synonym>
<key>ru</key>
<value>Методы работы с Twitter (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Twitter</name>
<synonym>
<key>ru</key>
<value>Methodы work with Twitter (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -33,268 +33,268 @@
#Region ServiceProgramInterface
Procedure GetBinaryData(Value) Export
If Value = Undefined Then
Return;
EndIf;
Attempt
If TypeValue(Value) = Type("BinaryData") Then
Return;
Otherwise
File = New File(Value);
If File.Exists() Then
Value = New BinaryData(Value);
ElseIf StrFind(Value, "//") Then
Value = OPI_Tools.Get(Value);
Otherwise
Value = Base64Value(Value);
EndIf;
EndIf;
Exception
RaiseException "Error getting binary data from parameter: " + ErrorDescription();
EndOfAttempt;
If Value = Undefined Then
Return;
EndIf;
Try
If TypeValue(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 TypeValue(Value) <> Type("String") Then
GetBinaryData(Value);
Return;
EndIf;
File = New File(Value);
If File.Exists() Then
Value = New FileStream(Value, FileOpenMode.Open);
Otherwise
GetBinaryData(Value);
EndIf;
If Value = Undefined Then
Return;
EndIf;
If TypeValue(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;
Attempt
InitialValue = Value;
If ThisIsCollection(Value) Then
Return;
Otherwise
If TypeValue(Value) = Type("BinaryData") Then
Value = GetStringFromBinaryData(Value);
Otherwise
Value = OPI_Tools.NumberToString(Value);
EndIf;
File = New File(Value);
ReadingJSON = New ReadingJSON;
If File.Exists() Then
ReadingJSON.OpenFile(Value);
ElseIf StringStartsWith(nReg(Value), "http") Then
AndVF = GetTempFileName();
CopyFile(Value, AndVF);
ReadingJSON.OpenFile(AndVF);
ReadingJSON.Read();
DeleteFiles(AndVF);
Otherwise
ReadingJSON.SetString(ShortLP(Value));
EndIf;
Value = ReadJSON(ReadingJSON, True, Undefined, JSONDateFormat.ISO);
ReadingJSON.Close();
If (Not ThisIsCollection(Value)) Or Not ValueFilled(Value) Then
Value = InitialValue;
GetArray(Value);
EndIf;
EndIf;
Exception
Value = InitialValue;
GetArray(Value);
EndOfAttempt;
If Value = Undefined Then
Return;
EndIf;
Try
InitialValue = Value;
If ThisIsCollection(Value) Then
Return;
Else
If TypeValue(Value) = Type("BinaryData") Then
Value = GetStringFromBinaryData(Value);
Else
Value = OPI_Tools.NumberToString(Value);
EndIf;
File = New File(Value);
ReadingJSON = New ReadingJSON;
If File.Exists() Then
ReadingJSON.OpenFile(Value);
ElsIf StringStartsWith(nReg(Value), "http") Then
AndVF = GetTempFileName();
CopyFile(Value, AndVF);
ReadingJSON.OpenFile(AndVF);
ReadingJSON.Read();
DeleteFiles(AndVF);
Else
ReadingJSON.SetString(ShortLP(Value));
EndIf;
Value = ReadJSON(ReadingJSON, True, Undefined, JSONDateFormat.ISO);
ReadingJSON.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 TypeValue(Value) = Type("Array") Then
Return;
EndIf;
If TypeValue(Value) = Type("String")
And StringStartsWith(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 = StrSplit(Value, CommaInQuotes, False);
For N = 0 by Value.WithinBoundary() Loop
Value[N] = ShortLP(Value[N]);
EndOfLoop;
Otherwise
If TypeValue(Value) = Type("Number") Then
Value = OPI_Tools.NumberToString(Value);
EndIf;
OPI_Tools.ValueToArray(Value);
EndIf;
If TypeValue(Value) = Type("Array") Then
Return;
EndIf;
If TypeValue(Value) = Type("String")
And StringStartsWith(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 = StrSplit(Value, CommaInQuotes, False);
For N = 0 For Value.WithinBoundary() Do
Value[N] = ShortLP(Value[N]);
EndDo;
Else
If TypeValue(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;
Attempt
If TypeValue(Value) = Type("Boolean") Then
Return;
Otherwise
Value = Boolean(Value);
EndIf;
Exception
RaiseException "Error getting boolean data from parameter";
EndOfAttempt;
If Value = Undefined Then
Return;
EndIf;
Try
If TypeValue(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;
Attempt
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
ReadingText = New ReadingText(Value);
Value = ReadingText.Read();
ReadingText.Close();
ElseIf StringStartsWith(nReg(Value), "http") Then
AndVF = GetTempFileName();
CopyFile(Value, AndVF);
ReadingText = New ReadingText(AndVF);
Value = ReadingText.Read();
ReadingText.Close();
DeleteFiles(AndVF);
Otherwise
Return;
EndIf;
ElseIf TypeValue(Value) = Type("BinaryData") Then
Value = GetStringFromBinaryData(Value);
ElseIf ThisIsCollection(Value) Then
Value = OPI_Tools.JSONString(Value);
Otherwise
Return;
EndIf;
Exception
Value = String(Value);
Return;
EndOfAttempt;
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
ReadingText = New ReadingText(Value);
Value = ReadingText.Read();
ReadingText.Close();
ElsIf StringStartsWith(nReg(Value), "http") Then
AndVF = GetTempFileName();
CopyFile(Value, AndVF);
ReadingText = New ReadingText(AndVF);
Value = ReadingText.Read();
ReadingText.Close();
DeleteFiles(AndVF);
Else
Return;
EndIf;
ElsIf TypeValue(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";
Attempt
If TypeValue(Value) = Type(Date) Then
Return;
Otherwise
Value = XMLValue(Type(Date), Value);
EndIf;
Exception
OOD = New TypeDescription(Date);
Value = OOD.ConvertValue(Value);
EndOfAttempt;
If Value = Undefined Then
Return;
EndIf;
Date = "Date";
Try
If TypeValue(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);
TypeDescription = New TypeDescription("Number");
Value = TypeDescription.ConvertValue(Value);
EndProcedure
#EndRegion
@ -302,19 +302,19 @@ EndProcedure
#Region ServiceProceduresAndFunctions
Function ThisIsCollection(Val Value)
Return TypeValue(Value) = Type("Array")
Or TypeValue(Value) = Type("Structure")
Or TypeValue(Value) = Type("Match");
EndFunction
Return TypeValue(Value) = Type("Array")
Or TypeValue(Value) = Type("Structure")
Or TypeValue(Value) = Type("Match");
EndFunction
Function ThisIsSymbolic(Val Value)
Return TypeValue(Value) = Type("String")
Or TypeValue(Value) = Type("Number")
Or TypeValue(Value) = Type("Date");
EndFunction
Return TypeValue(Value) = Type("String")
Or TypeValue(Value) = Type("Number")
Or TypeValue(Value) = Type("Date");
EndFunction
#EndRegion

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="e15aee63-1565-4f37-ba54-4d4e79723fc5">
<name>OPI_ПреобразованиеТипов</name>
<synonym>
<key>ru</key>
<value>Преобразование типов (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_TypeConversion</name>
<synonym>
<key>ru</key>
<value>Преобразоinание typeоin (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="1ab0a76a-246d-4037-97c3-212d680aa589">
<name>OPI_VK</name>
<synonym>
<key>ru</key>
<value>Методы интеграции с VK (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_VK</name>
<synonym>
<key>ru</key>
<value>Methodы интеграции with VK (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -23,7 +23,7 @@
// 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
@ -41,80 +41,80 @@
// 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
//
// Token - String - Viber Token - token
// URL - String - URL for setting up Webhook - url
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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);
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
//
// Token - String - Token - token
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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));
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
//
// Token - String - Token - token
// UserID - String, Number - Viber User ID - user
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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;
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
//
// Token - String - Viber Token - token
// UserIDs - String,Number,Array of String,Number - Viber User(s) ID - users
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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;
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
@ -124,185 +124,185 @@ EndFunction
// 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
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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);
, 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
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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);
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
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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 ValueFilled(Size) Then
Response = OPI_Tools.Get(URL);
Size = Response.Size();
EndIf;
String_ = "String";
Extension = StringReplace(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);
, 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 = StringReplace(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
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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);
, 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
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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);
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
//
// 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
//
// Return value:
// Key-Value Pair - serialized JSON response from Viber
// 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);
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 Strings - Array of buttons - buttons
// ButtonColor - String - HEX color of buttons with # at the beginning - color
//
// ButtonArray - Array of Strings - Array of buttons - buttons
// ButtonColor - String - HEX color of buttons with # at the beginning - color
//
// Return value:
// Structure - Create a keyboard from an array of buttons:
// * Buttons - Array of Structure - Array of formed buttons
// * Type - String - KeyboardType
// 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 Of ButtonArray Loop
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);
EndOfLoop;
KeyboardStructure.Insert("Buttons", ArrayOfButtonStructures);
KeyboardStructure.Insert("Type" , "keyboard");
Return KeyboardStructure;
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
@ -312,103 +312,103 @@ EndFunction
#Region ServiceProceduresAndFunctions
// 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 - When sending URL
// 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
//
// Text - String - Message text
// Keyboard - Structure Of String - Keyboard, if needed, see CreateKeyboardFromArrayButton
//
// Return value:
// Arbitrary, HTTP Response - Send message
// Arbitrary, HTTP Response - 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 ValueFilled(Text) Then
ParametersStructure.Insert("text", Text);
EndIf;
If TypeValue(Keyboard) = Type("Structure") Then
ParametersStructure.Insert("keyboard", Keyboard);
EndIf;
If ValueFilled(Value) Then
If Type = "file" Then
ParametersStructure.Insert("media" , Value["URL"]);
ParametersStructure.Insert("size" , Value["Size"]);
ParametersStructure.Insert("file_name", "File." + Value["Extension"]);
ElseIf Type = "contact" Then
ParametersStructure.Insert("contact" , Value);
ElseIf Type = "location" Then
ParametersStructure.Insert("location" , Value);
Otherwise
ParametersStructure.Insert("media" , Value);
EndIf;
EndIf;
If IsChannel Then
ParametersStructure.Insert("from", UserID);
URL = "https://chatapi.viber.com/pa/post";
Otherwise
ParametersStructure.Insert("receiver", UserID);
URL = "https://chatapi.viber.com/pa/send_message";
EndIf;
Response = OPI_Tools.Post(URL, ParametersStructure, TokenInHeaders(Token));
Attempt
Return OPI_Tools.JsonToStructure(Response.GetBodyAsBinaryData());
Exception
Return Response;
EndOfAttempt;
, 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 TypeValue(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;
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 Match;
HeadersStructure.Insert("X-Viber-Auth-Token", Token);
Return HeadersStructure;
OPI_TypeConversion.GetLine(Token);
HeadersStructure = New Match;
HeadersStructure.Insert("X-Viber-Auth-Token", Token);
Return HeadersStructure;
EndFunction
#EndRegion

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="ece78a60-71c0-4443-a6e4-63dd8a7b10d0">
<name>OPI_Viber</name>
<synonym>
<key>ru</key>
<value>Методы интеграции с Viber (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_Viber</name>
<synonym>
<key>ru</key>
<value>Methodы интеграции with Viber (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="af0b34e8-10fa-414f-a643-915210c6289a">
<name>OPI_YandexDisk</name>
<synonym>
<key>ru</key>
<value>Методы работы с Yandex Disk (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_YandexDisk</name>
<synonym>
<key>ru</key>
<value>Methodы work with Yandex Disk (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -36,77 +36,77 @@
// 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
//
// ClientId - String - Client id - id
//
// Return value:
// Key-Value Pair - serialized JSON response from Yandex
// 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;
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
//
// ClientId - String - Client id - id
// ClientSecret - String - Client secret - secret
// DeviceCode - String - device_code from GetConfirmationCode() - device
//
// Return value:
// Key-Value Pair - serialized JSON response from Yandex
// 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;
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
//
// ClientId - String - Client id - id
// ClientSecret - String - Client secret - secret
// RefreshToken - String - Refresh token - refresh
//
// Return value:
// Key-Value Pair - serialized JSON response from Yandex
// 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;
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

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="32379ca2-0f58-4143-9b34-cb552c54b962">
<name>OPI_YandexID</name>
<synonym>
<key>ru</key>
<value>Методы работы с Yandex ID (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
<name>OPI_YandexID</name>
<synonym>
<key>ru</key>
<value>Methodы work with Yandex ID (OPI)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="ca6868b2-8987-4ae3-9d97-50a8becc72df">
<name>OPI_Тесты</name>
<synonym>
<key></key>
<value>OPI тесты</value>
</synonym>
<synonym>
<key>ru</key>
<value>Тесты для YaxUnit (ОПИ)</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -1,70 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" xmlns:mdclassExtension="http://g5.1c.ru/v8/dt/metadata/mdclass/extension" uuid="aa51f610-7ed3-4091-8908-8ecccf0aaf0f">
<name>OpenIntegrations</name>
<synonym>
<key>ru</key>
<value>Открытый пакет интеграций</value>
</synonym>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:ConfigurationExtension">
<defaultRunMode>Checked</defaultRunMode>
<usePurposes>Checked</usePurposes>
<interfaceCompatibilityMode>Checked</interfaceCompatibilityMode>
</extension>
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="12689443-2950-4e3b-b313-9a692b6acac7"/>
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="f6f98fbd-010a-4aba-8f11-01203bbc59c7"/>
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="33990ba2-16f0-473d-851f-a9132c777ed6"/>
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="917bb154-d76e-42a4-b161-336b7c57a1ac"/>
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="793db0b3-8d01-4f55-982c-73cb3d4547da"/>
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="c67ca98f-c017-4f18-8175-02819e09b383"/>
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="c9ed170a-ffaa-4859-9d92-fd1cbc7051b3"/>
<keepMappingToExtendedConfigurationObjectsByIDs>true</keepMappingToExtendedConfigurationObjectsByIDs>
<namePrefix>OPI_</namePrefix>
<configurationExtensionCompatibilityMode>8.3.9</configurationExtensionCompatibilityMode>
<configurationExtensionPurpose>Customization</configurationExtensionPurpose>
<defaultRunMode>ManagedApplication</defaultRunMode>
<usePurposes>PersonalComputer</usePurposes>
<scriptVariant>Russian</scriptVariant>
<vendor>Bayselonarrend</vendor>
<version>1.9.0</version>
<detailedInformation>
<key>ru</key>
<value>Открытый пакет интеграций - набор библиотек для интеграции с некоторыми популярными API для 1C:Enterprise. Он состоит из общих модулей, каждый из которых отвечает за свой API, а также нескольких модулей-инструментов, общих для всех.</value>
</detailedInformation>
<vendorInformationAddress>
<key>ru</key>
<value>https://github.com/Bayselonarrend</value>
</vendorInformationAddress>
<configurationInformationAddress>
<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>
<commonModules>CommonModule.OPI_ПреобразованиеТипов</commonModules>
<commonModules>CommonModule.OPI_Telegram</commonModules>
<commonModules>CommonModule.OPI_VK</commonModules>
<commonModules>CommonModule.OPI_Viber</commonModules>
<commonModules>CommonModule.OPI_Twitter</commonModules>
<commonModules>CommonModule.OPI_Notion</commonModules>
<commonModules>CommonModule.OPI_YandexID</commonModules>
<commonModules>CommonModule.OPI_YandexDisk</commonModules>
<commonModules>CommonModule.OPI_GoogleWorkspace</commonModules>
<commonModules>CommonModule.OPI_GoogleCalendar</commonModules>
<commonModules>CommonModule.OPI_GoogleDrive</commonModules>
<commonModules>CommonModule.OPI_GoogleSheets</commonModules>
<commonModules>CommonModule.OPI_Slack</commonModules>
<commonModules>CommonModule.OPI_Airtable</commonModules>
<commonModules>CommonModule.OPI_Dropbox</commonModules>
<commonModules>CommonModule.OPI_Тесты</commonModules>
<commonModules>CommonModule.OPI_ПолучениеДанныхТестов</commonModules>
<name>OpenIntegrations</name>
<synonym>
<key>ru</key>
<value>Open integrations package</value>
</synonym>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:ConfigurationExtension">
<defaultRunMode>Checked</defaultRunMode>
<usePurposes>Checked</usePurposes>
<interfaceCompatibilityMode>Checked</interfaceCompatibilityMode>
</extension>
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="12689443-2950-4e3b-b313-9a692b6acac7"/>
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="f6f98fbd-010a-4aba-8f11-01203bbc59c7"/>
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="33990ba2-16f0-473d-851f-a9132c777ed6"/>
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="917bb154-d76e-42a4-b161-336b7c57a1ac"/>
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="793db0b3-8d01-4f55-982c-73cb3d4547da"/>
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="c67ca98f-c017-4f18-8175-02819e09b383"/>
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="c9ed170a-ffaa-4859-9d92-fd1cbc7051b3"/>
<keepMappingToExtendedConfigurationObjectsByIDs>true</keepMappingToExtendedConfigurationObjectsByIDs>
<namePrefix>OPI_</namePrefix>
<configurationExtensionCompatibilityMode>8.3.9</configurationExtensionCompatibilityMode>
<configurationExtensionPurpose>Customization</configurationExtensionPurpose>
<defaultRunMode>ManagedApplication</defaultRunMode>
<usePurposes>PersonalComputer</usePurposes>
<scriptVariant>Russian</scriptVariant>
<vendor>Bayselonarrend</vendor>
<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>
</detailedInformation>
<vendorInformationAddress>
<key>ru</key>
<value>https://github.com/Bayselonarrend</value>
</vendorInformationAddress>
<configurationInformationAddress>
<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>
<commonModules>CommonModule.OPI_TypeConversion</commonModules>
<commonModules>CommonModule.OPI_Telegram</commonModules>
<commonModules>CommonModule.OPI_VK</commonModules>
<commonModules>CommonModule.OPI_Viber</commonModules>
<commonModules>CommonModule.OPI_Twitter</commonModules>
<commonModules>CommonModule.OPI_Notion</commonModules>
<commonModules>CommonModule.OPI_YandexID</commonModules>
<commonModules>CommonModule.OPI_YandexDisk</commonModules>
<commonModules>CommonModule.OPI_GoogleWorkspace</commonModules>
<commonModules>CommonModule.OPI_GoogleCalendar</commonModules>
<commonModules>CommonModule.OPI_GoogleDrive</commonModules>
<commonModules>CommonModule.OPI_GoogleSheets</commonModules>
<commonModules>CommonModule.OPI_Slack</commonModules>
<commonModules>CommonModule.OPI_Airtable</commonModules>
<commonModules>CommonModule.OPI_Dropbox</commonModules>
<commonModules>CommonModule.OPI_Tests</commonModules>
<commonModules>CommonModule.OPI_TestDataRetrieval</commonModules>
</mdclass:Configuration>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Subsystem xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="86c261d7-2729-405f-9d39-5d9104a56bd1">
<name>OPI_Integrations</name>
<synonym>
<key>ru</key>
<value>Integrations</value>
</synonym>
<includeHelpInContents>true</includeHelpInContents>
<includeInCommandInterface>true</includeInCommandInterface>
<content>CommonModule.OPI_Tools</content>
<content>CommonModule.OPI_Cryptography</content>
<content>CommonModule.OPI_TypeConversion</content>
<content>CommonModule.OPI_VK</content>
<content>CommonModule.OPI_Telegram</content>
<content>CommonModule.OPI_Viber</content>
<content>CommonModule.OPI_Twitter</content>
<content>CommonModule.OPI_Notion</content>
<content>CommonModule.OPI_YandexID</content>
<content>CommonModule.OPI_YandexDisk</content>
<content>CommonModule.OPI_GoogleWorkspace</content>
<content>CommonModule.OPI_GoogleCalendar</content>
<content>CommonModule.OPI_GoogleDrive</content>
<content>CommonModule.OPI_GoogleSheets</content>
<content>CommonModule.OPI_Slack</content>
<content>CommonModule.OPI_Airtable</content>
<content>CommonModule.OPI_Tests</content>
<content>CommonModule.OPI_TestDataRetrieval</content>
</mdclass:Subsystem>

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Subsystem xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="86c261d7-2729-405f-9d39-5d9104a56bd1">
<name>OPI_Интеграция</name>
<synonym>
<key>ru</key>
<value>Интеграция</value>
</synonym>
<includeHelpInContents>true</includeHelpInContents>
<includeInCommandInterface>true</includeInCommandInterface>
<content>CommonModule.OPI_Инструменты</content>
<content>CommonModule.OPI_Криптография</content>
<content>CommonModule.OPI_ПреобразованиеТипов</content>
<content>CommonModule.OPI_VK</content>
<content>CommonModule.OPI_Telegram</content>
<content>CommonModule.OPI_Viber</content>
<content>CommonModule.OPI_Twitter</content>
<content>CommonModule.OPI_Notion</content>
<content>CommonModule.OPI_YandexID</content>
<content>CommonModule.OPI_YandexDisk</content>
<content>CommonModule.OPI_GoogleWorkspace</content>
<content>CommonModule.OPI_GoogleCalendar</content>
<content>CommonModule.OPI_GoogleDrive</content>
<content>CommonModule.OPI_GoogleSheets</content>
<content>CommonModule.OPI_Slack</content>
<content>CommonModule.OPI_Airtable</content>
<content>CommonModule.OPI_Тесты</content>
<content>CommonModule.OPI_ПолучениеДанныхТестов</content>
</mdclass:Subsystem>