convert_api 1.4.0 → 3.0.0
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 +4 -4
- data/.github/workflows/main.yml +1 -0
- data/.github/workflows/publish.yml +21 -0
- data/.ruby-version +1 -1
- data/README.md +5 -5
- data/lib/convert_api/client.rb +15 -8
- data/lib/convert_api/configuration.rb +1 -1
- data/lib/convert_api/errors.rb +1 -1
- data/lib/convert_api/task.rb +1 -11
- data/lib/convert_api/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a03a5db74661e761e600143a2156eb8b123cbd24a7b2a1f965f04cc78df567c5
|
4
|
+
data.tar.gz: da3d99dcba730103b6545ac4700a1e4d0d859be7c3c47fc92032e49274bcf94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1196c45816646b1f2b58acb79598c69cf9706a333f92c0d47e0bdd94f1b336a813963b8c7e84db2c3d7e0cfb39f8016626ed35eac8c144d8ab88397e0b7fadad
|
7
|
+
data.tar.gz: 434915e2525a5b3cf5fadd8ed2af3177844ca9aca29160efefb17d5ae2dd45485ee45075fc0f1b7a052e09513dd168a8ef94aacec7612f40068b54d7f3c25418
|
data/.github/workflows/main.yml
CHANGED
@@ -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
|
-
|
1
|
+
3.3.4
|
data/README.md
CHANGED
@@ -23,17 +23,17 @@ gem 'convert_api'
|
|
23
23
|
|
24
24
|
### Configuration
|
25
25
|
|
26
|
-
You can get your
|
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.
|
30
|
+
config.api_credentials = 'your-api-secret-or-token'
|
31
31
|
end
|
32
32
|
```
|
33
33
|
|
34
34
|
### File conversion
|
35
35
|
|
36
|
-
Example to convert file to PDF. All supported formats and options can be found
|
36
|
+
Example to convert file to PDF. All supported formats and options can be found
|
37
37
|
[here](https://www.convertapi.com/doc/supported-formats).
|
38
38
|
|
39
39
|
```ruby
|
@@ -99,12 +99,12 @@ puts result.files[0].size
|
|
99
99
|
|
100
100
|
### User information
|
101
101
|
|
102
|
-
You can always check your
|
102
|
+
You can always check your usage by fetching [user information](https://www.convertapi.com/doc/user).
|
103
103
|
|
104
104
|
```ruby
|
105
105
|
user_info = ConvertApi.user
|
106
106
|
|
107
|
-
puts user_info['
|
107
|
+
puts user_info['ConversionsConsumed']
|
108
108
|
```
|
109
109
|
|
110
110
|
### Alternative domain
|
data/lib/convert_api/client.rb
CHANGED
@@ -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),
|
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),
|
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
|
-
|
105
|
-
|
106
|
-
params_with_secret = params.merge(Secret: config.api_secret)
|
107
|
-
query = URI.encode_www_form(params_with_secret)
|
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,6 +118,18 @@ module ConvertApi
|
|
123
118
|
data
|
124
119
|
end
|
125
120
|
|
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
|
128
|
+
|
129
|
+
def api_credentials
|
130
|
+
config.api_credentials || raise(AuthenticationError, 'API credentials not configured')
|
131
|
+
end
|
132
|
+
|
126
133
|
def base_uri
|
127
134
|
config.base_uri
|
128
135
|
end
|
data/lib/convert_api/errors.rb
CHANGED
data/lib/convert_api/task.rb
CHANGED
@@ -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}
|
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
|
data/lib/convert_api/version.rb
CHANGED
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:
|
4
|
+
version: 3.0.0
|
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: 2024-09-14 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"
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.5.11
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: ConvertAPI client library
|