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