convert_api 1.0.2 → 1.2.1
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 +5 -5
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/README.md +14 -3
- data/convert_api.gemspec +2 -2
- data/lib/convert_api/client.rb +4 -4
- data/lib/convert_api/format_detector.rb +8 -7
- data/lib/convert_api/result_file.rb +1 -1
- data/lib/convert_api/task.rb +3 -2
- data/lib/convert_api/upload_io.rb +16 -6
- data/lib/convert_api/version.rb +1 -1
- metadata +11 -13
- data/Gemfile.lock +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea28c6a952160cc868c1cb6096caaf70b5abc1a6fb0c3f70dbac395e51c1007a
|
4
|
+
data.tar.gz: ac977fc1f46e0a73a1f0f8ae4f3ca8e8b86fccd1e9233eee9c86848d56639385
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d21d85dea222a35c40f42fcc8a215b55de8c02df961820e77b2b010f25f1f4899ee68e105ec3684fa0aa499f74db551c1f33056c4e5f96c9c3543ac70ba02ec6
|
7
|
+
data.tar.gz: '0893b1517f36116d60631e1707f6af23cdc838167754c9864e6997bcd0d7c418487916191eedd144a9d53a2e5ae98348eb43acfcffb84f45c15a3fc2eb5b08e4'
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3
|
1
|
+
2.6.3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -25,14 +25,14 @@ You can get your secret at https://www.convertapi.com/a
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
ConvertApi.configure do |config|
|
28
|
-
config.api_secret = 'your
|
28
|
+
config.api_secret = 'your-api-secret'
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
32
|
### File conversion
|
33
33
|
|
34
34
|
Example to convert file to PDF. All supported formats and options can be found
|
35
|
-
[here](https://www.convertapi.com).
|
35
|
+
[here](https://www.convertapi.com/doc/supported-formats).
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
result = ConvertApi.convert('pdf', File: '/path/to/my_file.docx')
|
@@ -84,6 +84,17 @@ result = ConvertApi.convert(
|
|
84
84
|
)
|
85
85
|
```
|
86
86
|
|
87
|
+
#### Accessing result file properties
|
88
|
+
|
89
|
+
You can access result file collection like this:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
result = ConvertApi.convert('pdf', File: 'https://website/my_file.docx')
|
93
|
+
|
94
|
+
puts result.files[0].url
|
95
|
+
puts result.files[0].size
|
96
|
+
```
|
97
|
+
|
87
98
|
### User information
|
88
99
|
|
89
100
|
You can always check remaining seconds amount by fetching [user information](https://www.convertapi.com/doc/user).
|
@@ -96,7 +107,7 @@ puts user_info['SecondsLeft']
|
|
96
107
|
|
97
108
|
### More examples
|
98
109
|
|
99
|
-
You can find more advanced examples in the [examples/](examples) folder.
|
110
|
+
You can find more advanced examples in the [examples/](https://github.com/ConvertAPI/convertapi-ruby/tree/master/examples) folder.
|
100
111
|
|
101
112
|
|
102
113
|
## Development
|
data/convert_api.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency 'rake', '
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
27
|
end
|
data/lib/convert_api/client.rb
CHANGED
@@ -21,7 +21,7 @@ module ConvertApi
|
|
21
21
|
Zlib::GzipFile::Error,
|
22
22
|
]
|
23
23
|
|
24
|
-
USER_AGENT = "
|
24
|
+
USER_AGENT = "ConvertAPI-Ruby/#{VERSION}"
|
25
25
|
|
26
26
|
DEFAULT_HEADERS = {
|
27
27
|
'User-Agent' => USER_AGENT,
|
@@ -48,7 +48,7 @@ module ConvertApi
|
|
48
48
|
def upload(io, filename)
|
49
49
|
handle_response do
|
50
50
|
request_uri = base_uri.path + 'upload'
|
51
|
-
encoded_filename =
|
51
|
+
encoded_filename = CGI.escape(filename)
|
52
52
|
|
53
53
|
headers = DEFAULT_HEADERS.merge(
|
54
54
|
'Content-Type' => 'application/octet-stream',
|
@@ -91,10 +91,10 @@ module ConvertApi
|
|
91
91
|
raise(TimeoutError, e)
|
92
92
|
end
|
93
93
|
|
94
|
-
def http(
|
94
|
+
def http(options = {})
|
95
95
|
http = Net::HTTP.new(base_uri.host, base_uri.port)
|
96
96
|
http.open_timeout = config.connect_timeout
|
97
|
-
http.read_timeout = read_timeout
|
97
|
+
http.read_timeout = options.fetch(:read_timeout, config.read_timeout)
|
98
98
|
http.use_ssl = base_uri.scheme == 'https'
|
99
99
|
# http.set_debug_output $stderr
|
100
100
|
http
|
@@ -5,24 +5,25 @@ module ConvertApi
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def run
|
8
|
-
|
9
|
-
format = extension[1..-1]
|
8
|
+
return @resource.file_ext.downcase if @resource.is_a?(UploadIO)
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
format
|
10
|
+
format_from_path
|
14
11
|
end
|
15
12
|
|
16
13
|
private
|
17
14
|
|
15
|
+
def format_from_path
|
16
|
+
extension = File.extname(path).downcase
|
17
|
+
format = extension[1..-1]
|
18
|
+
format || raise(FormatError, 'Unable to detect format')
|
19
|
+
end
|
20
|
+
|
18
21
|
def path
|
19
22
|
case @resource
|
20
23
|
when String
|
21
24
|
URI(@resource).path
|
22
25
|
when File
|
23
26
|
@resource.path
|
24
|
-
when UploadIO
|
25
|
-
@resource.filename
|
26
27
|
else
|
27
28
|
''
|
28
29
|
end
|
data/lib/convert_api/task.rb
CHANGED
@@ -15,9 +15,10 @@ module ConvertApi
|
|
15
15
|
|
16
16
|
from_format = @from_format || detect_format(params)
|
17
17
|
read_timeout = @conversion_timeout + config.conversion_timeout_delta
|
18
|
+
converter = params[:converter] ? "/converter/#{params[:converter]}" : ''
|
18
19
|
|
19
20
|
response = ConvertApi.client.post(
|
20
|
-
"
|
21
|
+
"convert/#{from_format}/to/#{@to_format}#{converter}",
|
21
22
|
params,
|
22
23
|
read_timeout: read_timeout
|
23
24
|
)
|
@@ -72,4 +73,4 @@ module ConvertApi
|
|
72
73
|
ConvertApi.config
|
73
74
|
end
|
74
75
|
end
|
75
|
-
end
|
76
|
+
end
|
@@ -2,8 +2,6 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module ConvertApi
|
4
4
|
class UploadIO
|
5
|
-
attr_reader :io, :filename
|
6
|
-
|
7
5
|
def initialize(io, filename = nil)
|
8
6
|
@io = io
|
9
7
|
@filename = filename || io_filename || raise(FileNameError, 'IO filename must be provided')
|
@@ -14,18 +12,30 @@ module ConvertApi
|
|
14
12
|
end
|
15
13
|
|
16
14
|
def file_id
|
17
|
-
|
15
|
+
result['FileId']
|
16
|
+
end
|
17
|
+
|
18
|
+
def file_name
|
19
|
+
result['FileName']
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_ext
|
23
|
+
result['FileExt']
|
18
24
|
end
|
19
25
|
|
20
26
|
private
|
21
27
|
|
28
|
+
def result
|
29
|
+
@result ||= upload_file
|
30
|
+
end
|
31
|
+
|
22
32
|
def upload_file
|
23
|
-
ConvertApi.client.upload(io, filename)
|
33
|
+
ConvertApi.client.upload(@io, @filename)
|
24
34
|
end
|
25
35
|
|
26
36
|
def io_filename
|
27
|
-
return unless io.respond_to?(:path)
|
28
|
-
File.basename(io.path)
|
37
|
+
return unless @io.respond_to?(:path)
|
38
|
+
File.basename(@io.path)
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
data/lib/convert_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convert_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Rutkauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- ".ruby-version"
|
68
68
|
- ".travis.yml"
|
69
69
|
- Gemfile
|
70
|
-
- Gemfile.lock
|
71
70
|
- LICENSE.txt
|
72
71
|
- README.md
|
73
72
|
- Rakefile
|
@@ -102,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
101
|
- !ruby/object:Gem::Version
|
103
102
|
version: '0'
|
104
103
|
requirements: []
|
105
|
-
|
106
|
-
rubygems_version: 2.5.1
|
104
|
+
rubygems_version: 3.0.3
|
107
105
|
signing_key:
|
108
106
|
specification_version: 4
|
109
107
|
summary: ConvertAPI client library
|
data/Gemfile.lock
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
convert_api (1.0.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.3)
|
10
|
-
rake (10.5.0)
|
11
|
-
rspec (3.7.0)
|
12
|
-
rspec-core (~> 3.7.0)
|
13
|
-
rspec-expectations (~> 3.7.0)
|
14
|
-
rspec-mocks (~> 3.7.0)
|
15
|
-
rspec-core (3.7.1)
|
16
|
-
rspec-support (~> 3.7.0)
|
17
|
-
rspec-expectations (3.7.0)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.7.0)
|
20
|
-
rspec-mocks (3.7.0)
|
21
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.7.0)
|
23
|
-
rspec-support (3.7.1)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
ruby
|
27
|
-
|
28
|
-
DEPENDENCIES
|
29
|
-
bundler (~> 1.16)
|
30
|
-
convert_api!
|
31
|
-
rake (~> 10.0)
|
32
|
-
rspec (~> 3.0)
|
33
|
-
|
34
|
-
BUNDLED WITH
|
35
|
-
1.16.1
|