onlyoffice_documentserver_conversion_helper 0.1.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onlyoffice_documentserver_conversion_helper/name.rb +9 -0
- data/lib/onlyoffice_documentserver_conversion_helper/version.rb +4 -1
- data/lib/onlyoffice_documentserver_conversion_helper/xml_responce_parser.rb +17 -0
- data/lib/onlyoffice_documentserver_conversion_helper.rb +48 -13
- metadata +147 -9
- data/README.md +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2052d02f45954ff45a8a5d222d3387e2492b6f81b7790d27a0a270d1ebde0700
|
4
|
+
data.tar.gz: 112a1889a8471d5fcc1d90dd726a5fce1d4b68c976b2e72c3d97638b9a2aade9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f06371b23c50fc660a9aa4ee76b82cfa7e6513d62d61491320115fa566ba20950f7bdd388fa956fdf52de1c8c6b4917b060569d03ea91079c3779177341722f
|
7
|
+
data.tar.gz: 0eeee137a054d173b5fa083990e5a06aa1db09e33684353f4e050557db5d50722a7c1047c523ac82e3baeaa29475c5d8448df07b3809b25f3838a0b7085020d4
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeDocumentserverConversionHelper
|
4
|
+
# This module holds the OnlyofficeDocumentserverConversionHelper gem name
|
5
|
+
module Name
|
6
|
+
# @return [String] name of gem
|
7
|
+
STRING = 'onlyoffice_documentserver_conversion_helper'
|
8
|
+
end
|
9
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module OnlyofficeDocumentserverConversionHelper
|
2
4
|
# This module holds the OnlyofficeDocumentserverConversionHelper gem version
|
3
5
|
module Version
|
4
|
-
|
6
|
+
# @return [String] version of gem
|
7
|
+
STRING = '0.4.0'
|
5
8
|
end
|
6
9
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Class for parse Xml responce
|
4
|
+
class XmlResponceParser
|
5
|
+
def initialize(string_with_xml, file_format)
|
6
|
+
@string_with_xml = string_with_xml
|
7
|
+
@file_format = file_format
|
8
|
+
end
|
9
|
+
|
10
|
+
# Method parses server response
|
11
|
+
# returning url with unescape HTML
|
12
|
+
# @return [String] URL
|
13
|
+
def result_url
|
14
|
+
res_result = /(http|https).*\.(#{@file_format})/.match(@string_with_xml)
|
15
|
+
CGI.unescapeHTML(res_result.to_s)
|
16
|
+
end
|
17
|
+
end
|
@@ -1,24 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'jwt'
|
2
4
|
require 'net/http'
|
3
5
|
require 'securerandom'
|
4
6
|
require 'timeout'
|
7
|
+
require_relative 'onlyoffice_documentserver_conversion_helper/xml_responce_parser'
|
5
8
|
require_relative 'onlyoffice_documentserver_conversion_helper/version'
|
6
9
|
|
7
10
|
# Stuff for working with conversion service
|
8
11
|
# See: https://api.onlyoffice.com/editors/conversionapi
|
9
12
|
module OnlyofficeDocumentserverConversionHelper
|
10
13
|
# ==== Examples
|
11
|
-
# ConvertFileData.new('https://
|
12
|
-
#
|
13
|
-
#
|
14
|
+
# converter = ConvertFileData.new('https://server')
|
15
|
+
# converter.perform_convert('http://files/googerd.docx')
|
16
|
+
# converter.perform_convert({:url=>'http://files/googerd.docx'})
|
17
|
+
# converter.perform_convert({:url=>'http://files/googerd.docx',
|
18
|
+
# :outputtype => 'pdf'})
|
14
19
|
class ConvertFileData
|
20
|
+
# @return [String] file_url to convert
|
15
21
|
attr_accessor :file_url
|
22
|
+
# @return [String] key for convert operation
|
16
23
|
attr_accessor :key
|
24
|
+
# @return [String] input_filetype format
|
17
25
|
attr_writer :input_filetype
|
26
|
+
# @return [String] output_file_type format
|
18
27
|
attr_accessor :output_file_type
|
19
28
|
|
29
|
+
# @return [Array<String>] list of text formats
|
20
30
|
DOCUMENT_EXTENSIONS = %w[TXT HTML HTM ODT DOCT DOCX RTF DOC PDF].freeze
|
31
|
+
# @return [Array<String>] list of spreadsheet formats
|
21
32
|
SPREADSHEET_EXTENSIONS = %w[XLS XLSX ODS XLST].freeze
|
33
|
+
# @return [Array<String>] list of presentation formats
|
22
34
|
PRESENTATION_EXTENSIONS = %w[PPT PPTX PPTT ODP].freeze
|
23
35
|
|
24
36
|
def initialize(server_path,
|
@@ -33,24 +45,33 @@ module OnlyofficeDocumentserverConversionHelper
|
|
33
45
|
@timeout = timeout
|
34
46
|
end
|
35
47
|
|
48
|
+
# Auto detect output file format
|
49
|
+
# @return [String] result format
|
36
50
|
def output_file_type_auto
|
37
51
|
return 'docx' if DOCUMENT_EXTENSIONS.include?(@input_filetype.upcase)
|
38
52
|
return 'xlsx' if SPREADSHEET_EXTENSIONS.include?(@input_filetype.upcase)
|
39
53
|
return 'pptx' if PRESENTATION_EXTENSIONS.include?(@input_filetype.upcase)
|
40
54
|
end
|
41
55
|
|
56
|
+
# @return [String] random generated key
|
42
57
|
def key_auto
|
43
58
|
SecureRandom.uuid
|
44
59
|
end
|
45
60
|
|
61
|
+
# Get input file name from url
|
62
|
+
# @return [String] result file name
|
46
63
|
def input_filetype
|
47
64
|
File.extname(@file_url).delete('.')
|
48
65
|
end
|
49
66
|
|
67
|
+
# @return [String] convert service url
|
50
68
|
def convert_url
|
51
69
|
"#{@server_path}/ConvertService.ashx"
|
52
70
|
end
|
53
71
|
|
72
|
+
# Complete missing params
|
73
|
+
# @param [Hash] params manually defined
|
74
|
+
# @return [Hash] filled params hash
|
54
75
|
def autocomplete_missing_params(params)
|
55
76
|
params[:key] = key_auto unless params.key?(:key)
|
56
77
|
params[:outputtype] = output_file_type_auto unless params.key?(:outputtype)
|
@@ -61,18 +82,26 @@ module OnlyofficeDocumentserverConversionHelper
|
|
61
82
|
# @return [String] with url to result file
|
62
83
|
# @param [String] data is a response body
|
63
84
|
# @param [String] file_format is a format of result file
|
64
|
-
# Method will get link from response body.
|
85
|
+
# Method will get link from response body.
|
86
|
+
# Link start from 'https', and end from result file format
|
65
87
|
def get_url_from_responce(data, file_format)
|
66
88
|
res_result = /(http|https).*(#{file_format})/.match(data)
|
67
89
|
CGI.unescapeHTML(res_result.to_s)
|
68
90
|
end
|
69
91
|
|
92
|
+
# Add jwt data to request
|
93
|
+
# @param [Net::HTTP::Post] request to add data
|
94
|
+
# @return [Net::HTTP::Post] request with JWT
|
70
95
|
def add_jwt_data(request)
|
71
|
-
payload_to_encode = { 'payload' =>
|
96
|
+
payload_to_encode = { 'payload' => JSON.parse(request.body) }
|
72
97
|
jwt_encoded = JWT.encode payload_to_encode, @jwt_key
|
73
98
|
request[@jwt_header] = "#{@jwt_prefix} #{jwt_encoded}"
|
74
99
|
end
|
75
100
|
|
101
|
+
# Make request
|
102
|
+
# @param [String] convert_url to call
|
103
|
+
# @param [Hash] params with options
|
104
|
+
# @return [String] body of responce
|
76
105
|
def request(convert_url, params)
|
77
106
|
uri = URI(convert_url)
|
78
107
|
req = Net::HTTP::Post.new(uri)
|
@@ -92,28 +121,34 @@ module OnlyofficeDocumentserverConversionHelper
|
|
92
121
|
(@timeout / 5).times do
|
93
122
|
responce = http.request(req)
|
94
123
|
return responce.body unless responce.code == '504'
|
124
|
+
|
95
125
|
sleep 5
|
96
126
|
end
|
97
127
|
end
|
98
128
|
end
|
99
129
|
|
100
|
-
# @return [Hash] with usl for download file
|
101
|
-
#
|
102
|
-
#
|
130
|
+
# @return [Hash] with usl for download file
|
131
|
+
# after conversion and response data
|
132
|
+
# @param [Hash] args collect all parameters of request
|
133
|
+
# OR [String] if you not need to use advenced params
|
134
|
+
# and want to set all etc params automaticly.
|
135
|
+
# All args, except of :url and if it is [Hash],
|
136
|
+
# will be attache in end of request
|
103
137
|
# ==== Examples
|
104
|
-
# perform_convert('https://
|
105
|
-
# perform_convert({:url => 'https://
|
138
|
+
# perform_convert('https://example.com/filename.docx')
|
139
|
+
# perform_convert({:url => 'https://example.com/filename.docx'})
|
106
140
|
# perform_convert({:url => 'https://google.com/filename.docx',
|
107
|
-
#
|
108
|
-
#
|
141
|
+
# :key=>'askjdhaskdasdasdi',
|
142
|
+
# :outputtype => 'pdf'})
|
109
143
|
def perform_convert(args = {})
|
110
144
|
args = { url: args } if args.is_a?(String)
|
111
145
|
raise 'Parameter :url with link on file is necessary!!' if args[:url].nil? || args.nil?
|
146
|
+
|
112
147
|
@file_url = args[:url]
|
113
148
|
@input_filetype = File.extname(@file_url).delete('.')
|
114
149
|
advanced_params = autocomplete_missing_params(args)
|
115
150
|
data = request(convert_url, advanced_params)
|
116
|
-
url =
|
151
|
+
url = XmlResponceParser.new(data, advanced_params[:outputtype]).result_url
|
117
152
|
{ url: url, data: data }
|
118
153
|
end
|
119
154
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onlyoffice_documentserver_conversion_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- ONLYOFFICE
|
7
8
|
- Pavel Lobashov
|
8
9
|
- Dmitry Rotaty
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2022-03-09 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: jwt
|
@@ -25,21 +26,159 @@ dependencies:
|
|
25
26
|
- - "~>"
|
26
27
|
- !ruby/object:Gem::Version
|
27
28
|
version: '2'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: overcommit
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '13'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '13'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '3'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rubocop
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rubocop-performance
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '1'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rubocop-rake
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rubocop-rspec
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '2'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - "~>"
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '2'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: simplecov-cobertura
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '2'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: yard
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.9.20
|
151
|
+
type: :development
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 0.9.20
|
28
161
|
description: Helper method for using ONLYOFFICE DocumentServer conversion api
|
29
162
|
email:
|
30
163
|
- shockwavenn@gmail.com
|
31
|
-
- flaminestone@gmail.com
|
32
164
|
executables: []
|
33
165
|
extensions: []
|
34
166
|
extra_rdoc_files: []
|
35
167
|
files:
|
36
|
-
- README.md
|
37
168
|
- lib/onlyoffice_documentserver_conversion_helper.rb
|
169
|
+
- lib/onlyoffice_documentserver_conversion_helper/name.rb
|
38
170
|
- lib/onlyoffice_documentserver_conversion_helper/version.rb
|
39
|
-
|
171
|
+
- lib/onlyoffice_documentserver_conversion_helper/xml_responce_parser.rb
|
172
|
+
homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper
|
40
173
|
licenses:
|
41
174
|
- AGPL-3.0
|
42
|
-
metadata:
|
175
|
+
metadata:
|
176
|
+
bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper/issues
|
177
|
+
changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper/blob/master/CHANGELOG.md
|
178
|
+
documentation_uri: https://www.rubydoc.info/gems/onlyoffice_documentserver_conversion_helper
|
179
|
+
homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper
|
180
|
+
source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_documentserver_conversion_helper
|
181
|
+
rubygems_mfa_required: 'true'
|
43
182
|
post_install_message:
|
44
183
|
rdoc_options: []
|
45
184
|
require_paths:
|
@@ -48,15 +187,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
187
|
requirements:
|
49
188
|
- - ">="
|
50
189
|
- !ruby/object:Gem::Version
|
51
|
-
version: '2.
|
190
|
+
version: '2.5'
|
52
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
192
|
requirements:
|
54
193
|
- - ">="
|
55
194
|
- !ruby/object:Gem::Version
|
56
195
|
version: '0'
|
57
196
|
requirements: []
|
58
|
-
|
59
|
-
rubygems_version: 2.7.6
|
197
|
+
rubygems_version: 3.3.7
|
60
198
|
signing_key:
|
61
199
|
specification_version: 4
|
62
200
|
summary: onlyoffice_documentserver_conversion_helper Gem
|
data/README.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# onlyoffice_documentserver_conversion_helper
|