convert_api 1.3.2 → 2.0.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: b0c19d784a48c22fedfcb2f00b4d150cc638b99b4688bae2d6f5bb13e28af08d
4
- data.tar.gz: 775a9a90934f9447acde26c05a004f9106541603b6a2fb3fcb458dbb426cca98
3
+ metadata.gz: e87ee021afbce241b24e28e70245ec318a6c6ae799c1ff769cd6437a4065536f
4
+ data.tar.gz: b385c3030e308d7dde8d711f3b2f30d48303f5af6bc5208437b09ae329b50519
5
5
  SHA512:
6
- metadata.gz: c15b8d712d8ce29cb11ad915d11676b1ff13f064c3df3655611f085f958c8ca9502352300b940bffea2ce2ccfc5f64bfc177f6b7a70262e5c43236b3f02a3b10
7
- data.tar.gz: 24ad1374796432ed6a3e332676b3421e183a9224b70bea09fe2bd1c2dfa0eea86fc6c9f1ca496a0ec2a134fcb5b6fed9ead4a2edf10b1b5aee2e1342c19110ee
6
+ metadata.gz: 0447ac667edc5df34913612ff81003dfbcdea39a345b1fc111ecfd28dd123651d0fa2218b4942258e4aecd32266438ae2768e593ceb5c0ff7573fbb4f389d26e
7
+ data.tar.gz: 57a409748204a607373d4b1d2a6db8b8d7ad68a02f4da5a6aab1bf023358e6d727972f29113c606d940686c854b3a261f2e690921a3345785c394f321364a32c
@@ -9,8 +9,9 @@ jobs:
9
9
  - 2.0
10
10
  - 2.6
11
11
  - 2.7
12
- - 3.0
13
- - ruby-head
12
+ - 3.1
13
+ - 3.2
14
+ - 3.3
14
15
  - jruby-9.1
15
16
  - jruby-head
16
17
  name: Ruby ${{ matrix.ruby-version }} sample
@@ -23,4 +24,5 @@ jobs:
23
24
  - run: bundle install
24
25
  - env:
25
26
  CONVERT_API_SECRET: ${{ secrets.CONVERTAPI_SECRET }}
27
+ CONVERT_API_TOKEN: ${{ secrets.CONVERTAPI_TOKEN }}
26
28
  run: bundle exec rake spec
@@ -0,0 +1,21 @@
1
+ name: Publish gem to rubygems
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - uses: ruby/setup-ruby@v1
11
+
12
+ # setup .gem/credentials
13
+ - run: mkdir -p ~/.gem
14
+ - env:
15
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
16
+ run: >-
17
+ echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
18
+ - run: chmod 0600 ~/.gem/credentials
19
+
20
+ - run: gem build convert_api.gemspec --output=release.gem
21
+ - run: gem push release.gem
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ 3.3.4
data/README.md CHANGED
@@ -23,7 +23,7 @@ gem 'convert_api'
23
23
 
24
24
  ### Configuration
25
25
 
26
- You can get your secret at https://www.convertapi.com/a
26
+ You can get your secret at https://www.convertapi.com/a/auth
27
27
 
28
28
  ```ruby
29
29
  ConvertApi.configure do |config|
@@ -31,13 +31,22 @@ ConvertApi.configure do |config|
31
31
  end
32
32
  ```
33
33
 
34
+ Or
35
+
36
+ You can get your token at https://www.convertapi.com/a/access-tokens
37
+ ```ruby
38
+ ConvertApi.configure do |config|
39
+ config.token = 'your-token'
40
+ end
41
+ ```
42
+
34
43
  ### File conversion
35
44
 
36
- Example to convert file to PDF. All supported formats and options can be found
45
+ Example to convert file to PDF. All supported formats and options can be found
37
46
  [here](https://www.convertapi.com/doc/supported-formats).
38
47
 
39
48
  ```ruby
40
- result = ConvertApi.convert('pdf', File: '/path/to/my_file.docx')
49
+ result = ConvertApi.convert('pdf', { File: '/path/to/my_file.docx' })
41
50
 
42
51
  # save to file
43
52
  result.file.save('/path/to/save/file.pdf')
@@ -59,7 +68,7 @@ conversion_cost = result.conversion_cost
59
68
  #### Convert file url
60
69
 
61
70
  ```ruby
62
- result = ConvertApi.convert('pdf', File: 'https://website/my_file.docx')
71
+ result = ConvertApi.convert('pdf', { File: 'https://website/my_file.docx' })
63
72
  ```
64
73
 
65
74
  #### Specifying from format
@@ -67,7 +76,7 @@ result = ConvertApi.convert('pdf', File: 'https://website/my_file.docx')
67
76
  ```ruby
68
77
  result = ConvertApi.convert(
69
78
  'pdf',
70
- { File: /path/to/my_file' },
79
+ {File: /path/to/my_file'},
71
80
  from_format: 'docx'
72
81
  )
73
82
  ```
@@ -75,14 +84,14 @@ result = ConvertApi.convert(
75
84
  #### Additional conversion parameters
76
85
 
77
86
  ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion
78
- parameters and explanations can be found [here](https://www.convertapi.com).
87
+ parameters and explanations can be found [here](https://www.convertapi.com/doc/supported-formats).
79
88
 
80
89
  ```ruby
81
90
  result = ConvertApi.convert(
82
91
  'pdf',
83
- File: /path/to/my_file.docx',
92
+ {File: /path/to/my_file.docx',
84
93
  PageRange: '1-10',
85
- PdfResolution: '150',
94
+ PdfResolution: '150'}
86
95
  )
87
96
  ```
88
97
 
@@ -91,7 +100,7 @@ result = ConvertApi.convert(
91
100
  You can access result file collection like this:
92
101
 
93
102
  ```ruby
94
- result = ConvertApi.convert('pdf', File: 'https://website/my_file.docx')
103
+ result = ConvertApi.convert('pdf', { File: 'https://website/my_file.docx' })
95
104
 
96
105
  puts result.files[0].url
97
106
  puts result.files[0].size
@@ -104,9 +113,20 @@ You can always check your remaining seconds programmatically by fetching [user i
104
113
  ```ruby
105
114
  user_info = ConvertApi.user
106
115
 
107
- puts user_info['SecondsLeft']
116
+ puts user_info['ConversionsConsumed']
117
+ ```
118
+
119
+ ### Alternative domain
120
+
121
+ Set config `base_uri` attribute to use other service domains. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location).
122
+
123
+ ```ruby
124
+ ConvertApi.configure do |config|
125
+ config.base_uri = URI('https://eu-v2.convertapi.com/')
126
+ end
108
127
  ```
109
128
 
129
+
110
130
  ### More examples
111
131
 
112
132
  Find more advanced examples in the [examples/](https://github.com/ConvertAPI/convertapi-ruby/tree/master/examples) folder.
@@ -116,6 +136,10 @@ Find more advanced examples in the [examples/](https://github.com/ConvertAPI/con
116
136
 
117
137
  Run `CONVERT_API_SECRET=your_secret rake spec` to run the tests.
118
138
 
139
+ Or
140
+
141
+ Run `CONVERT_API_TOKEN=your_token rake spec` to run the tests.
142
+
119
143
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
120
144
 
121
145
  ## Contributing
@@ -101,10 +101,10 @@ module ConvertApi
101
101
  end
102
102
 
103
103
  def request_uri(path, params = {})
104
- raise(SecretError, 'API secret not configured') if config.api_secret.nil?
104
+ raise(AuthenticationError, 'API secret or Token not configured') if authentication.nil?
105
105
 
106
- params_with_secret = params.merge(Secret: config.api_secret)
107
- query = URI.encode_www_form(params_with_secret)
106
+ params_with_authentication = params.merge(authentication)
107
+ query = URI.encode_www_form(params_with_authentication)
108
108
 
109
109
  base_uri.path + path + '?' + query
110
110
  end
@@ -123,6 +123,13 @@ module ConvertApi
123
123
  data
124
124
  end
125
125
 
126
+ def authentication
127
+ return { Secret: config.api_secret } unless config.api_secret.nil?
128
+ return { Token: config.token } unless config.token.nil?
129
+
130
+ nil
131
+ end
132
+
126
133
  def base_uri
127
134
  config.base_uri
128
135
  end
@@ -1,6 +1,7 @@
1
1
  module ConvertApi
2
2
  class Configuration
3
3
  attr_accessor :api_secret
4
+ attr_accessor :token
4
5
  attr_accessor :base_uri
5
6
  attr_accessor :connect_timeout
6
7
  attr_accessor :read_timeout
@@ -1,6 +1,6 @@
1
1
  module ConvertApi
2
2
  class Error < StandardError; end
3
- class SecretError < Error; end
3
+ class AuthenticationError < Error; end
4
4
  class FileNameError < Error; end
5
5
  class TimeoutError < Error; end
6
6
  class ConnectionFailed < Error; end
@@ -15,10 +15,11 @@ module ConvertApi
15
15
 
16
16
  from_format = @from_format || detect_format(params)
17
17
  read_timeout = @conversion_timeout + config.conversion_timeout_delta if @conversion_timeout
18
- converter = params[:converter] ? "/converter/#{params[:converter]}" : ''
18
+ converter = detect_converter(params)
19
+ converter_path = converter ? "/converter/#{converter}" : ''
19
20
 
20
21
  response = ConvertApi.client.post(
21
- "convert/#{from_format}/to/#{@to_format}#{converter}",
22
+ "convert/#{from_format}/to/#{@to_format}#{converter_path}",
22
23
  params,
23
24
  read_timeout: read_timeout,
24
25
  )
@@ -32,10 +33,10 @@ module ConvertApi
32
33
  result = {}
33
34
 
34
35
  symbolize_keys(params).each do |key, value|
35
- case key
36
- when :File
37
- result[:File] = FileParam.build(value)
38
- when :Files
36
+ case
37
+ when key != :StoreFile && key.to_s.end_with?('File')
38
+ result[key] = FileParam.build(value)
39
+ when key == :Files
39
40
  result[:Files] = files_batch(value)
40
41
  else
41
42
  result[key] = value
@@ -69,6 +70,14 @@ module ConvertApi
69
70
  FormatDetector.new(resource, @to_format).run
70
71
  end
71
72
 
73
+ def detect_converter(params)
74
+ params.each do |key, value|
75
+ return value if key.to_s.downcase == 'converter'
76
+ end
77
+
78
+ nil
79
+ end
80
+
72
81
  def config
73
82
  ConvertApi.config
74
83
  end
@@ -1,3 +1,3 @@
1
1
  module ConvertApi
2
- VERSION = '1.3.2'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convert_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Rutkauskas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-18 00:00:00.000000000 Z
11
+ date: 2024-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,6 +63,7 @@ extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
65
  - ".github/workflows/main.yml"
66
+ - ".github/workflows/publish.yml"
66
67
  - ".gitignore"
67
68
  - ".rspec"
68
69
  - ".ruby-version"
@@ -86,7 +87,7 @@ homepage: https://github.com/ConvertAPI/convertapi-ruby
86
87
  licenses:
87
88
  - MIT
88
89
  metadata: {}
89
- post_install_message:
90
+ post_install_message:
90
91
  rdoc_options: []
91
92
  require_paths:
92
93
  - lib
@@ -101,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
104
  requirements: []
104
- rubygems_version: 3.0.3
105
- signing_key:
105
+ rubygems_version: 3.5.11
106
+ signing_key:
106
107
  specification_version: 4
107
108
  summary: ConvertAPI client library
108
109
  test_files: []