onlyoffice_documentserver_conversion_helper 0.4.0 → 0.5.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/exceptions.rb +6 -0
- data/lib/onlyoffice_documentserver_conversion_helper/version.rb +1 -1
- data/lib/onlyoffice_documentserver_conversion_helper/xml_responce_parser.rb +22 -12
- data/lib/onlyoffice_documentserver_conversion_helper.rb +23 -14
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e61195de2597796b8ec3e2e69262e4fc8f6f0661c349c1e1ec54ea19e11c5999
|
4
|
+
data.tar.gz: 7ddd137983f8365ace8d38cfb071fdb270dafa9e00da98ba27a1ac4c009cfb2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594b183a8df277b5fbf9fec7530bc5852b272bda90facf702d5f796c121cdf58c6e49fd575d63cab508a6f0539f31883e358ee5d1ec98b8f24ef6e790d7b1948
|
7
|
+
data.tar.gz: 14987d0620cc3fd31aec3e6e647bb7d4b5318e7a149804c0816e35b08cd590b88109405fdfb5ea42b50a559e0fe4cd0b1f920cbdad0acd0df85cc11543f18979
|
@@ -1,17 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module OnlyofficeDocumentserverConversionHelper
|
4
|
+
# Class for parse Xml responce
|
5
|
+
class XmlResponceParser
|
6
|
+
def initialize(string_with_xml, file_format, result_in_zip: false)
|
7
|
+
@string_with_xml = string_with_xml
|
8
|
+
@file_format = file_format
|
9
|
+
@result_in_zip = result_in_zip
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] output file format
|
13
|
+
def file_format
|
14
|
+
return 'zip' if @result_in_zip
|
15
|
+
|
16
|
+
@file_format
|
17
|
+
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
# Method parses server response
|
20
|
+
# returning url with unescape HTML
|
21
|
+
# @return [String] URL
|
22
|
+
def result_url
|
23
|
+
res_result = /(http|https).*\.(#{file_format})/.match(@string_with_xml)
|
24
|
+
CGI.unescapeHTML(res_result.to_s)
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
@@ -4,6 +4,7 @@ require 'jwt'
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'securerandom'
|
6
6
|
require 'timeout'
|
7
|
+
require_relative 'onlyoffice_documentserver_conversion_helper/exceptions'
|
7
8
|
require_relative 'onlyoffice_documentserver_conversion_helper/xml_responce_parser'
|
8
9
|
require_relative 'onlyoffice_documentserver_conversion_helper/version'
|
9
10
|
|
@@ -46,11 +47,14 @@ module OnlyofficeDocumentserverConversionHelper
|
|
46
47
|
end
|
47
48
|
|
48
49
|
# Auto detect output file format
|
50
|
+
# @raise [UnknownConvertFormatError] if file format is not known
|
49
51
|
# @return [String] result format
|
50
52
|
def output_file_type_auto
|
51
53
|
return 'docx' if DOCUMENT_EXTENSIONS.include?(@input_filetype.upcase)
|
52
54
|
return 'xlsx' if SPREADSHEET_EXTENSIONS.include?(@input_filetype.upcase)
|
53
55
|
return 'pptx' if PRESENTATION_EXTENSIONS.include?(@input_filetype.upcase)
|
56
|
+
|
57
|
+
raise UnknownConvertFormatError, "Unknown convert auto format: #{@input_filetype}"
|
54
58
|
end
|
55
59
|
|
56
60
|
# @return [String] random generated key
|
@@ -79,16 +83,6 @@ module OnlyofficeDocumentserverConversionHelper
|
|
79
83
|
params
|
80
84
|
end
|
81
85
|
|
82
|
-
# @return [String] with url to result file
|
83
|
-
# @param [String] data is a response body
|
84
|
-
# @param [String] file_format is a format of result file
|
85
|
-
# Method will get link from response body.
|
86
|
-
# Link start from 'https', and end from result file format
|
87
|
-
def get_url_from_responce(data, file_format)
|
88
|
-
res_result = /(http|https).*(#{file_format})/.match(data)
|
89
|
-
CGI.unescapeHTML(res_result.to_s)
|
90
|
-
end
|
91
|
-
|
92
86
|
# Add jwt data to request
|
93
87
|
# @param [Net::HTTP::Post] request to add data
|
94
88
|
# @return [Net::HTTP::Post] request with JWT
|
@@ -109,7 +103,7 @@ module OnlyofficeDocumentserverConversionHelper
|
|
109
103
|
add_jwt_data(req)
|
110
104
|
http = Net::HTTP.new(uri.host, uri.port)
|
111
105
|
http.read_timeout = @timeout
|
112
|
-
http.use_ssl =
|
106
|
+
http.use_ssl = (uri.scheme == 'https')
|
113
107
|
send_request(http, req)
|
114
108
|
end
|
115
109
|
|
@@ -129,8 +123,8 @@ module OnlyofficeDocumentserverConversionHelper
|
|
129
123
|
|
130
124
|
# @return [Hash] with usl for download file
|
131
125
|
# after conversion and response data
|
132
|
-
# @param [Hash] args collect all parameters of request
|
133
|
-
# OR
|
126
|
+
# @param [Hash, Srting] args collect all parameters of request
|
127
|
+
# OR string if you not need to use advenced params
|
134
128
|
# and want to set all etc params automaticly.
|
135
129
|
# All args, except of :url and if it is [Hash],
|
136
130
|
# will be attache in end of request
|
@@ -148,8 +142,23 @@ module OnlyofficeDocumentserverConversionHelper
|
|
148
142
|
@input_filetype = File.extname(@file_url).delete('.')
|
149
143
|
advanced_params = autocomplete_missing_params(args)
|
150
144
|
data = request(convert_url, advanced_params)
|
151
|
-
url = XmlResponceParser.new(data,
|
145
|
+
url = XmlResponceParser.new(data,
|
146
|
+
advanced_params[:outputtype],
|
147
|
+
result_in_zip: result_in_zip?(advanced_params)).result_url
|
152
148
|
{ url: url, data: data }
|
153
149
|
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
# Will be result of convert in zip?
|
154
|
+
# @param [Hash] params with options
|
155
|
+
# @return [Boolean]
|
156
|
+
def result_in_zip?(params)
|
157
|
+
return false unless params.key?(:thumbnail)
|
158
|
+
return false unless params[:thumbnail].key?(:first)
|
159
|
+
return true unless params[:thumbnail][:first]
|
160
|
+
|
161
|
+
false
|
162
|
+
end
|
154
163
|
end
|
155
164
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ONLYOFFICE
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-03-
|
13
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jwt
|
@@ -125,19 +125,19 @@ dependencies:
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '2'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
|
-
name: simplecov
|
128
|
+
name: simplecov
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
131
|
- - "~>"
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '
|
133
|
+
version: '0'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
138
|
- - "~>"
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: '
|
140
|
+
version: '0'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: yard
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +166,7 @@ extensions: []
|
|
166
166
|
extra_rdoc_files: []
|
167
167
|
files:
|
168
168
|
- lib/onlyoffice_documentserver_conversion_helper.rb
|
169
|
+
- lib/onlyoffice_documentserver_conversion_helper/exceptions.rb
|
169
170
|
- lib/onlyoffice_documentserver_conversion_helper/name.rb
|
170
171
|
- lib/onlyoffice_documentserver_conversion_helper/version.rb
|
171
172
|
- lib/onlyoffice_documentserver_conversion_helper/xml_responce_parser.rb
|
@@ -194,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
195
|
- !ruby/object:Gem::Version
|
195
196
|
version: '0'
|
196
197
|
requirements: []
|
197
|
-
rubygems_version: 3.3.
|
198
|
+
rubygems_version: 3.3.10
|
198
199
|
signing_key:
|
199
200
|
specification_version: 4
|
200
201
|
summary: onlyoffice_documentserver_conversion_helper Gem
|