convert_api 2.0.0 → 3.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: e87ee021afbce241b24e28e70245ec318a6c6ae799c1ff769cd6437a4065536f
4
- data.tar.gz: b385c3030e308d7dde8d711f3b2f30d48303f5af6bc5208437b09ae329b50519
3
+ metadata.gz: a03a5db74661e761e600143a2156eb8b123cbd24a7b2a1f965f04cc78df567c5
4
+ data.tar.gz: da3d99dcba730103b6545ac4700a1e4d0d859be7c3c47fc92032e49274bcf94f
5
5
  SHA512:
6
- metadata.gz: 0447ac667edc5df34913612ff81003dfbcdea39a345b1fc111ecfd28dd123651d0fa2218b4942258e4aecd32266438ae2768e593ceb5c0ff7573fbb4f389d26e
7
- data.tar.gz: 57a409748204a607373d4b1d2a6db8b8d7ad68a02f4da5a6aab1bf023358e6d727972f29113c606d940686c854b3a261f2e690921a3345785c394f321364a32c
6
+ metadata.gz: 1196c45816646b1f2b58acb79598c69cf9706a333f92c0d47e0bdd94f1b336a813963b8c7e84db2c3d7e0cfb39f8016626ed35eac8c144d8ab88397e0b7fadad
7
+ data.tar.gz: 434915e2525a5b3cf5fadd8ed2af3177844ca9aca29160efefb17d5ae2dd45485ee45075fc0f1b7a052e09513dd168a8ef94aacec7612f40068b54d7f3c25418
@@ -24,5 +24,4 @@ jobs:
24
24
  - run: bundle install
25
25
  - env:
26
26
  CONVERT_API_SECRET: ${{ secrets.CONVERTAPI_SECRET }}
27
- CONVERT_API_TOKEN: ${{ secrets.CONVERTAPI_TOKEN }}
28
27
  run: bundle exec rake spec
data/README.md CHANGED
@@ -23,20 +23,11 @@ gem 'convert_api'
23
23
 
24
24
  ### Configuration
25
25
 
26
- You can get your secret at https://www.convertapi.com/a/auth
26
+ You can get your credentials at https://www.convertapi.com/a/auth
27
27
 
28
28
  ```ruby
29
29
  ConvertApi.configure do |config|
30
- config.api_secret = 'your-api-secret'
31
- end
32
- ```
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'
30
+ config.api_credentials = 'your-api-secret-or-token'
40
31
  end
41
32
  ```
42
33
 
@@ -108,7 +99,7 @@ puts result.files[0].size
108
99
 
109
100
  ### User information
110
101
 
111
- You can always check your remaining seconds programmatically by fetching [user information](https://www.convertapi.com/doc/user).
102
+ You can always check your usage by fetching [user information](https://www.convertapi.com/doc/user).
112
103
 
113
104
  ```ruby
114
105
  user_info = ConvertApi.user
@@ -136,10 +127,6 @@ Find more advanced examples in the [examples/](https://github.com/ConvertAPI/con
136
127
 
137
128
  Run `CONVERT_API_SECRET=your_secret rake spec` to run the tests.
138
129
 
139
- Or
140
-
141
- Run `CONVERT_API_TOKEN=your_token rake spec` to run the tests.
142
-
143
130
  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).
144
131
 
145
132
  ## Contributing
@@ -30,7 +30,7 @@ module ConvertApi
30
30
 
31
31
  def get(path, params = {}, options = {})
32
32
  handle_response do
33
- request = Net::HTTP::Get.new(request_uri(path, params), DEFAULT_HEADERS)
33
+ request = Net::HTTP::Get.new(request_uri(path, params), headers_with_auth)
34
34
 
35
35
  http(options).request(request)
36
36
  end
@@ -38,7 +38,7 @@ module ConvertApi
38
38
 
39
39
  def post(path, params, options = {})
40
40
  handle_response do
41
- request = Net::HTTP::Post.new(request_uri(path), DEFAULT_HEADERS)
41
+ request = Net::HTTP::Post.new(request_uri(path), headers_with_auth)
42
42
  request.form_data = build_form_data(params)
43
43
 
44
44
  http(options).request(request)
@@ -101,12 +101,7 @@ module ConvertApi
101
101
  end
102
102
 
103
103
  def request_uri(path, params = {})
104
- raise(AuthenticationError, 'API secret or Token not configured') if authentication.nil?
105
-
106
- params_with_authentication = params.merge(authentication)
107
- query = URI.encode_www_form(params_with_authentication)
108
-
109
- base_uri.path + path + '?' + query
104
+ base_uri.path + path + '?' + URI.encode_www_form(params)
110
105
  end
111
106
 
112
107
  def build_form_data(params)
@@ -123,11 +118,16 @@ module ConvertApi
123
118
  data
124
119
  end
125
120
 
126
- def authentication
127
- return { Secret: config.api_secret } unless config.api_secret.nil?
128
- return { Token: config.token } unless config.token.nil?
121
+ def headers_with_auth
122
+ DEFAULT_HEADERS.merge(auth_headers)
123
+ end
124
+
125
+ def auth_headers
126
+ { 'Authorization' => "Bearer #{api_credentials}" }
127
+ end
129
128
 
130
- nil
129
+ def api_credentials
130
+ config.api_credentials || raise(AuthenticationError, 'API credentials not configured')
131
131
  end
132
132
 
133
133
  def base_uri
@@ -1,7 +1,6 @@
1
1
  module ConvertApi
2
2
  class Configuration
3
- attr_accessor :api_secret
4
- attr_accessor :token
3
+ attr_accessor :api_credentials
5
4
  attr_accessor :base_uri
6
5
  attr_accessor :connect_timeout
7
6
  attr_accessor :read_timeout
@@ -15,11 +15,9 @@ 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 = detect_converter(params)
19
- converter_path = converter ? "/converter/#{converter}" : ''
20
18
 
21
19
  response = ConvertApi.client.post(
22
- "convert/#{from_format}/to/#{@to_format}#{converter_path}",
20
+ "convert/#{from_format}/to/#{@to_format}",
23
21
  params,
24
22
  read_timeout: read_timeout,
25
23
  )
@@ -70,14 +68,6 @@ module ConvertApi
70
68
  FormatDetector.new(resource, @to_format).run
71
69
  end
72
70
 
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
-
81
71
  def config
82
72
  ConvertApi.config
83
73
  end
@@ -1,3 +1,3 @@
1
1
  module ConvertApi
2
- VERSION = '2.0.0'
2
+ VERSION = '3.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: 2.0.0
4
+ version: 3.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: 2024-08-04 00:00:00.000000000 Z
11
+ date: 2024-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,7 +87,7 @@ homepage: https://github.com/ConvertAPI/convertapi-ruby
87
87
  licenses:
88
88
  - MIT
89
89
  metadata: {}
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubygems_version: 3.5.11
106
- signing_key:
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: ConvertAPI client library
109
109
  test_files: []