onlyoffice-docs_integration_sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/onlyoffice/docs_integration_sdk/document_editor/config.rb +1479 -0
- data/lib/onlyoffice/docs_integration_sdk/document_editor/config_test.rb +1713 -0
- data/lib/onlyoffice/docs_integration_sdk/document_editor.rb +29 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/command.rb +417 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/command_test.rb +672 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/conversion.rb +477 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/conversion_test.rb +682 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/healthcheck.rb +101 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/healthcheck_test.rb +209 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/jwt.rb +116 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/jwt_test.rb +70 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/response.rb +73 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/response_test.rb +49 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/service.rb +44 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/ua.rb +31 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/ua_test.rb +35 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client.rb +321 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client_test.rb +1259 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server.rb +29 -0
- data/lib/onlyoffice/docs_integration_sdk/document_storage/callback.rb +276 -0
- data/lib/onlyoffice/docs_integration_sdk/document_storage/callback_test.rb +291 -0
- data/lib/onlyoffice/docs_integration_sdk/document_storage.rb +29 -0
- data/lib/onlyoffice/docs_integration_sdk/jwt.rb +448 -0
- data/lib/onlyoffice/docs_integration_sdk/jwt_test.rb +598 -0
- data/lib/onlyoffice/docs_integration_sdk/test_test.rb +113 -0
- data/lib/onlyoffice/docs_integration_sdk/version.rb +26 -0
- data/lib/onlyoffice/docs_integration_sdk/version_test.rb +33 -0
- data/lib/onlyoffice/docs_integration_sdk.rb +31 -0
- data/lib/onlyoffice.rb +21 -0
- metadata +283 -0
@@ -0,0 +1,477 @@
|
|
1
|
+
#
|
2
|
+
# (c) Copyright Ascensio System SIA 2025
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
# typed: strict
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
require "sorbet-runtime"
|
21
|
+
require_relative "response"
|
22
|
+
require_relative "service"
|
23
|
+
|
24
|
+
module Onlyoffice
|
25
|
+
module DocsIntegrationSdk
|
26
|
+
module DocumentServer
|
27
|
+
class Client
|
28
|
+
# ConversionServing is an interface that describes the methods that must
|
29
|
+
# be implemented to be considered a conversion service.
|
30
|
+
#
|
31
|
+
# @since 0.1.0
|
32
|
+
module ConversionServing
|
33
|
+
extend T::Sig
|
34
|
+
extend T::Helpers
|
35
|
+
interface!
|
36
|
+
|
37
|
+
# @param r The request options.
|
38
|
+
# @return A tuple containing the result and the response.
|
39
|
+
sig {abstract.params(r: ConversionService::Request).returns([ConversionService::Result, Response])}
|
40
|
+
def do(r); end
|
41
|
+
end
|
42
|
+
|
43
|
+
# ConversionService is an implementation of the {ConversionServing}
|
44
|
+
# interface.
|
45
|
+
#
|
46
|
+
# @since 0.1.0
|
47
|
+
class ConversionService < Service
|
48
|
+
include ConversionServing
|
49
|
+
|
50
|
+
# Error is an enum that represents the possible errors that can occur
|
51
|
+
# when using the conversion service.
|
52
|
+
#
|
53
|
+
# @since 0.1.0
|
54
|
+
class Error < T::Enum
|
55
|
+
extend T::Sig
|
56
|
+
|
57
|
+
enums do
|
58
|
+
# @since 0.1.0
|
59
|
+
UnknownError = new(-1)
|
60
|
+
|
61
|
+
# @since 0.1.0
|
62
|
+
ConversionTimeout = new(-2)
|
63
|
+
|
64
|
+
# @since 0.1.0
|
65
|
+
ConversionError = new(-3)
|
66
|
+
|
67
|
+
# @since 0.1.0
|
68
|
+
DownloadError = new(-4)
|
69
|
+
|
70
|
+
# @since 0.1.0
|
71
|
+
IncorrectPassword = new(-5)
|
72
|
+
|
73
|
+
# @since 0.1.0
|
74
|
+
DatabaseError = new(-6)
|
75
|
+
|
76
|
+
# @since 0.1.0
|
77
|
+
InputError = new(-7)
|
78
|
+
|
79
|
+
# @since 0.1.0
|
80
|
+
InvalidToken = new(-8)
|
81
|
+
|
82
|
+
# @since 0.1.0
|
83
|
+
UnknownFormat = new(-9)
|
84
|
+
|
85
|
+
# @since 0.1.0
|
86
|
+
SizeLimitExceeded = new(-10)
|
87
|
+
end
|
88
|
+
|
89
|
+
# description returns the human-readable description of the error.
|
90
|
+
#
|
91
|
+
# @since 0.1.0
|
92
|
+
sig {returns(String)}
|
93
|
+
def description
|
94
|
+
case self
|
95
|
+
when UnknownError
|
96
|
+
"Unknown error"
|
97
|
+
when ConversionTimeout
|
98
|
+
"Conversion timeout error"
|
99
|
+
when ConversionError
|
100
|
+
"Conversion error"
|
101
|
+
when DownloadError
|
102
|
+
"Error while downloading the document file to be converted"
|
103
|
+
when IncorrectPassword
|
104
|
+
"Incorrect password"
|
105
|
+
when DatabaseError
|
106
|
+
"Error while accessing the conversion result database"
|
107
|
+
when InputError
|
108
|
+
"Input error"
|
109
|
+
when InvalidToken
|
110
|
+
"Invalid token"
|
111
|
+
when UnknownFormat
|
112
|
+
"The converter cannot automatically determine the output file format"
|
113
|
+
when SizeLimitExceeded
|
114
|
+
"Size limit exceeded"
|
115
|
+
else
|
116
|
+
# :nocov:
|
117
|
+
# unreachable
|
118
|
+
# :nocov:
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Request is a class that represents the request options for the
|
124
|
+
# conversion service.
|
125
|
+
#
|
126
|
+
# @since 0.1.0
|
127
|
+
class Request < T::Struct
|
128
|
+
extend T::Sig
|
129
|
+
|
130
|
+
# @since 0.1.0
|
131
|
+
class Delimiter < T::Enum
|
132
|
+
enums do
|
133
|
+
# @since 0.1.0
|
134
|
+
None = new(0)
|
135
|
+
|
136
|
+
# @since 0.1.0
|
137
|
+
Tab = new(1)
|
138
|
+
|
139
|
+
# @since 0.1.0
|
140
|
+
Semicolon = new(2)
|
141
|
+
|
142
|
+
# @since 0.1.0
|
143
|
+
Colon = new(3)
|
144
|
+
|
145
|
+
# @since 0.1.0
|
146
|
+
Comma = new(4)
|
147
|
+
|
148
|
+
# @since 0.1.0
|
149
|
+
Space = new(5)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# @since 0.1.0
|
154
|
+
class DocumentLayout < T::Struct
|
155
|
+
extend T::Sig
|
156
|
+
|
157
|
+
# @since 0.1.0
|
158
|
+
prop :draw_place_holders, T.nilable(T::Boolean), name: "drawPlaceHolders"
|
159
|
+
|
160
|
+
# @since 0.1.0
|
161
|
+
prop :draw_form_highlight, T.nilable(T::Boolean), name: "drawFormHighlight"
|
162
|
+
|
163
|
+
# @since 0.1.0
|
164
|
+
prop :is_print, T.nilable(T::Boolean), name: "isPrint"
|
165
|
+
|
166
|
+
# @since 0.1.0
|
167
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(DocumentLayout)}
|
168
|
+
def self.from_hash(hash, strict = nil)
|
169
|
+
super(hash, strict)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# @since 0.1.0
|
174
|
+
class DocumentRenderer < T::Struct
|
175
|
+
extend T::Sig
|
176
|
+
|
177
|
+
# @since 0.1.0
|
178
|
+
class TextAssociation < T::Enum
|
179
|
+
enums do
|
180
|
+
# @since 0.1.0
|
181
|
+
BlockChar = new("blockChar")
|
182
|
+
|
183
|
+
# @since 0.1.0
|
184
|
+
BlockLine = new("blockLine")
|
185
|
+
|
186
|
+
# @since 0.1.0
|
187
|
+
PlainLine = new("plainLine")
|
188
|
+
|
189
|
+
# @since 0.1.0
|
190
|
+
PlainParagraph = new("plainParagraph")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# @since 0.1.0
|
195
|
+
prop :text_association, T.nilable(TextAssociation), name: "textAssociation"
|
196
|
+
|
197
|
+
# @since 0.1.0
|
198
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(DocumentRenderer)}
|
199
|
+
def self.from_hash(hash, strict = nil)
|
200
|
+
super(hash, strict)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# @since 0.1.0
|
205
|
+
class Pdf < T::Struct
|
206
|
+
extend T::Sig
|
207
|
+
|
208
|
+
# @since 0.1.0
|
209
|
+
prop :form, T.nilable(T::Boolean), name: "form"
|
210
|
+
|
211
|
+
# @since 0.1.0
|
212
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(Pdf)}
|
213
|
+
def self.from_hash(hash, strict = nil)
|
214
|
+
super(hash, strict)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# @since 0.1.0
|
219
|
+
class SpreadsheetLayout < T::Struct
|
220
|
+
extend T::Sig
|
221
|
+
|
222
|
+
# @since 0.1.0
|
223
|
+
class Margins < T::Struct
|
224
|
+
extend T::Sig
|
225
|
+
|
226
|
+
# @since 0.1.0
|
227
|
+
prop :bottom, T.nilable(String), name: "bottom"
|
228
|
+
|
229
|
+
# @since 0.1.0
|
230
|
+
prop :left, T.nilable(String), name: "left"
|
231
|
+
|
232
|
+
# @since 0.1.0
|
233
|
+
prop :right, T.nilable(String), name: "right"
|
234
|
+
|
235
|
+
# @since 0.1.0
|
236
|
+
prop :top, T.nilable(String), name: "top"
|
237
|
+
|
238
|
+
# @since 0.1.0
|
239
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(Margins)}
|
240
|
+
def self.from_hash(hash, strict = nil)
|
241
|
+
super(hash, strict)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# @since 0.1.0
|
246
|
+
class Orientation < T::Enum
|
247
|
+
enums do
|
248
|
+
# @since 0.1.0
|
249
|
+
Landscape = new("landscape")
|
250
|
+
|
251
|
+
# @since 0.1.0
|
252
|
+
Portrait = new("portrait")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# @since 0.1.0
|
257
|
+
class PageSize < T::Struct
|
258
|
+
extend T::Sig
|
259
|
+
|
260
|
+
# @since 0.1.0
|
261
|
+
prop :height, T.nilable(String), name: "height"
|
262
|
+
|
263
|
+
# @since 0.1.0
|
264
|
+
prop :width, T.nilable(String), name: "width"
|
265
|
+
|
266
|
+
# @since 0.1.0
|
267
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(PageSize)}
|
268
|
+
def self.from_hash(hash, strict = nil)
|
269
|
+
super(hash, strict)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
# @since 0.1.0
|
274
|
+
prop :fit_to_height, T.nilable(Integer), name: "fitToHeight"
|
275
|
+
|
276
|
+
# @since 0.1.0
|
277
|
+
prop :fit_to_width, T.nilable(Integer), name: "fitToWidth"
|
278
|
+
|
279
|
+
# @since 0.1.0
|
280
|
+
prop :grid_lines, T.nilable(T::Boolean), name: "gridLines"
|
281
|
+
|
282
|
+
# @since 0.1.0
|
283
|
+
prop :headings, T.nilable(T::Boolean), name: "headings"
|
284
|
+
|
285
|
+
# @since 0.1.0
|
286
|
+
prop :ignore_print_area, T.nilable(T::Boolean), name: "ignorePrintArea"
|
287
|
+
|
288
|
+
# @since 0.1.0
|
289
|
+
prop :margins, T.nilable(Margins), name: "margins"
|
290
|
+
|
291
|
+
# @since 0.1.0
|
292
|
+
prop :orientation, T.nilable(Orientation), name: "orientation"
|
293
|
+
|
294
|
+
# @since 0.1.0
|
295
|
+
prop :page_size, T.nilable(PageSize), name: "pageSize"
|
296
|
+
|
297
|
+
# @since 0.1.0
|
298
|
+
prop :scale, T.nilable(Integer), name: "scale"
|
299
|
+
|
300
|
+
# @since 0.1.0
|
301
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(SpreadsheetLayout)}
|
302
|
+
def self.from_hash(hash, strict = nil)
|
303
|
+
super(hash, strict)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# @since 0.1.0
|
308
|
+
class Thumbnail < T::Struct
|
309
|
+
extend T::Sig
|
310
|
+
|
311
|
+
# @since 0.1.0
|
312
|
+
class Aspect < T::Enum
|
313
|
+
enums do
|
314
|
+
# @since 0.1.0
|
315
|
+
Stretch = new(0)
|
316
|
+
|
317
|
+
# @since 0.1.0
|
318
|
+
Keep = new(1)
|
319
|
+
|
320
|
+
# @since 0.1.0
|
321
|
+
Page = new(2)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
# @since 0.1.0
|
326
|
+
prop :aspect, T.nilable(Aspect), name: "aspect"
|
327
|
+
|
328
|
+
# @since 0.1.0
|
329
|
+
prop :first, T.nilable(T::Boolean), name: "first"
|
330
|
+
|
331
|
+
# @since 0.1.0
|
332
|
+
prop :height, T.nilable(Integer), name: "height"
|
333
|
+
|
334
|
+
# @since 0.1.0
|
335
|
+
prop :width, T.nilable(Integer), name: "width"
|
336
|
+
|
337
|
+
# @since 0.1.0
|
338
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(Thumbnail)}
|
339
|
+
def self.from_hash(hash, strict = nil)
|
340
|
+
super(hash, strict)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
# @since 0.1.0
|
345
|
+
class Watermark < T::Struct
|
346
|
+
extend T::Sig
|
347
|
+
|
348
|
+
# todo
|
349
|
+
|
350
|
+
# @since 0.1.0
|
351
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(Watermark)}
|
352
|
+
def self.from_hash(hash, strict = nil)
|
353
|
+
super(hash, strict)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
# @since 0.1.0
|
358
|
+
prop :async, T.nilable(T::Boolean), name: "async"
|
359
|
+
|
360
|
+
# @since 0.1.0
|
361
|
+
prop :code_page, T.nilable(Integer), name: "codePage"
|
362
|
+
|
363
|
+
# @since 0.1.0
|
364
|
+
prop :delimiter, T.nilable(Delimiter), name: "delimiter"
|
365
|
+
|
366
|
+
# @since 0.1.0
|
367
|
+
prop :document_layout, T.nilable(DocumentLayout), name: "documentLayout"
|
368
|
+
|
369
|
+
# @since 0.1.0
|
370
|
+
prop :document_renderer, T.nilable(DocumentRenderer), name: "documentRenderer"
|
371
|
+
|
372
|
+
# @since 0.1.0
|
373
|
+
prop :filetype, T.nilable(String), name: "filetype"
|
374
|
+
|
375
|
+
# @since 0.1.0
|
376
|
+
prop :key, T.nilable(String), name: "key"
|
377
|
+
|
378
|
+
# @since 0.1.0
|
379
|
+
prop :outputtype, T.nilable(String), name: "outputtype"
|
380
|
+
|
381
|
+
# @since 0.1.0
|
382
|
+
prop :password, T.nilable(String), name: "password"
|
383
|
+
|
384
|
+
# @since 0.1.0
|
385
|
+
prop :pdf, T.nilable(Pdf), name: "pdf"
|
386
|
+
|
387
|
+
# @since 0.1.0
|
388
|
+
prop :region, T.nilable(String), name: "region"
|
389
|
+
|
390
|
+
# @since 0.1.0
|
391
|
+
prop :spreadsheet_layout, T.nilable(SpreadsheetLayout), name: "spreadsheetLayout"
|
392
|
+
|
393
|
+
# @since 0.1.0
|
394
|
+
prop :thumbnail, T.nilable(Thumbnail), name: "thumbnail"
|
395
|
+
|
396
|
+
# @since 0.1.0
|
397
|
+
prop :title, T.nilable(String), name: "title"
|
398
|
+
|
399
|
+
# @since 0.1.0
|
400
|
+
prop :url, T.nilable(String), name: "url"
|
401
|
+
|
402
|
+
# @since 0.1.0
|
403
|
+
prop :watermark, T.nilable(Watermark), name: "watermark"
|
404
|
+
|
405
|
+
# @since 0.1.0
|
406
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(Request)}
|
407
|
+
def self.from_hash(hash, strict = nil)
|
408
|
+
super(hash, strict)
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
# @since 0.1.0
|
413
|
+
class Result < T::Struct
|
414
|
+
extend T::Sig
|
415
|
+
|
416
|
+
# @since 0.1.0
|
417
|
+
prop :end_convert, T.nilable(T::Boolean), name: "endConvert"
|
418
|
+
|
419
|
+
# @since 0.1.0
|
420
|
+
prop :file_type, T.nilable(String), name: "fileType"
|
421
|
+
|
422
|
+
# @since 0.1.0
|
423
|
+
prop :file_url, T.nilable(String), name: "fileUrl"
|
424
|
+
|
425
|
+
# @since 0.1.0
|
426
|
+
prop :percent, T.nilable(Integer), name: "percent"
|
427
|
+
|
428
|
+
# @since 0.1.0
|
429
|
+
sig {params(hash: T.untyped, strict: T.untyped).returns(Result)}
|
430
|
+
def self.from_hash(hash, strict = nil)
|
431
|
+
super(hash, strict)
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
# do makes a request to the conversion service. It returns an empty
|
436
|
+
# result if an error occurs.
|
437
|
+
#
|
438
|
+
# @param r The request options.
|
439
|
+
# @return A tuple containing the result and the response.
|
440
|
+
# @since 0.1.0
|
441
|
+
sig {override.params(r: Request).returns([Result, Response])}
|
442
|
+
def do(r)
|
443
|
+
con, res = @client.post("ConvertService.ashx", r.serialize)
|
444
|
+
if res.error
|
445
|
+
return [Result.new, res]
|
446
|
+
end
|
447
|
+
|
448
|
+
err = T.let(nil, T.untyped)
|
449
|
+
|
450
|
+
begin
|
451
|
+
if con && con.is_a?(Hash) && con.key?("error")
|
452
|
+
err = Error.from_serialized(con["error"])
|
453
|
+
elsif con
|
454
|
+
ret = Result.from_hash(con)
|
455
|
+
else
|
456
|
+
ret = Result.new
|
457
|
+
end
|
458
|
+
rescue StandardError => e
|
459
|
+
err = e
|
460
|
+
end
|
461
|
+
|
462
|
+
if err
|
463
|
+
ret = Result.new
|
464
|
+
res = Response.new(
|
465
|
+
request: res.request,
|
466
|
+
response: res.response,
|
467
|
+
error: err,
|
468
|
+
)
|
469
|
+
end
|
470
|
+
|
471
|
+
[ret, res]
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|