convert_api 1.0.2 → 1.2.1

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
- SHA1:
3
- metadata.gz: 579e24496742c1b5f949eff206edc7807aed4de0
4
- data.tar.gz: 0e112e384ada532f85e05f21b06165fb65dc9ef5
2
+ SHA256:
3
+ metadata.gz: ea28c6a952160cc868c1cb6096caaf70b5abc1a6fb0c3f70dbac395e51c1007a
4
+ data.tar.gz: ac977fc1f46e0a73a1f0f8ae4f3ca8e8b86fccd1e9233eee9c86848d56639385
5
5
  SHA512:
6
- metadata.gz: 358043b516746c62338ae6033a4a9720dadb5016bbf1d769a340ab251ba190984dadb0e8131ba47e57135341d54061d748adc6d5a8ad01680debf834aaca3e06
7
- data.tar.gz: f9e9b78218d3342e713132d4f31adf42740162204b2a5222f3f6abcca558f55cb697a068fcdcd1a31a572ffc02d6e0aaf60e8d8acff3a833dd4d0e69c13019a9
6
+ metadata.gz: d21d85dea222a35c40f42fcc8a215b55de8c02df961820e77b2b010f25f1f4899ee68e105ec3684fa0aa499f74db551c1f33056c4e5f96c9c3543ac70ba02ec6
7
+ data.tar.gz: '0893b1517f36116d60631e1707f6af23cdc838167754c9864e6997bcd0d7c418487916191eedd144a9d53a2e5ae98348eb43acfcffb84f45c15a3fc2eb5b08e4'
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.6.3
@@ -6,8 +6,8 @@ rvm:
6
6
  - 2.3.0
7
7
  - 2.4.1
8
8
  - 2.5.1
9
- - ruby-head
10
- - ruby-head-clang
9
+ - 2.6.5
10
+ - 2.7.0
11
11
  - jruby-head
12
12
  bundler_args: --jobs=3 --retry=3 --binstubs
13
13
  env:
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 api secret'
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
@@ -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', '~> 1.16'
25
- spec.add_development_dependency 'rake', '~> 10.0'
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
@@ -21,7 +21,7 @@ module ConvertApi
21
21
  Zlib::GzipFile::Error,
22
22
  ]
23
23
 
24
- USER_AGENT = "convertapi-ruby-#{VERSION}"
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 = URI.encode(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(read_timeout: nil)
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 || config.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
- extension = File.extname(path).downcase
9
- format = extension[1..-1]
8
+ return @resource.file_ext.downcase if @resource.is_a?(UploadIO)
10
9
 
11
- raise(FormatError, 'Unable to detect format') if format.nil?
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
@@ -21,7 +21,7 @@ module ConvertApi
21
21
  end
22
22
 
23
23
  def io
24
- @io ||= open(url, download_options)
24
+ @io ||= URI.parse(url).open(download_options)
25
25
  end
26
26
 
27
27
  def save(path)
@@ -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
- "#{from_format}/to/#{@to_format}",
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
- @file_id ||= upload_file['FileId']
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
@@ -1,3 +1,3 @@
1
1
  module ConvertApi
2
- VERSION = '1.0.2'
2
+ VERSION = '1.2.1'
3
3
  end
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.0.2
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: 2018-07-15 00:00:00.000000000 Z
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: '1.16'
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: '1.16'
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: '10.0'
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: '10.0'
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
- rubyforge_project:
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
@@ -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