Skip to content

Commit 5bb10b1

Browse files
committed
Request path method extraction with async prefix support
1 parent 5c03482 commit 5bb10b1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/convert_api/task.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ def run
1313
StoreFile: true,
1414
)
1515

16-
from_format = @from_format || detect_format(params)
1716
read_timeout = @conversion_timeout + config.conversion_timeout_delta if @conversion_timeout
18-
converter = params[:converter] ? "/converter/#{params[:converter]}" : ''
1917

2018
response = ConvertApi.client.post(
21-
"convert/#{from_format}/to/#{@to_format}#{converter}",
19+
request_path(params),
2220
params,
2321
read_timeout: read_timeout,
2422
)
@@ -28,6 +26,14 @@ def run
2826

2927
private
3028

29+
def request_path(params)
30+
from_format = @from_format || detect_format(params)
31+
converter = params[:converter] ? "/converter/#{params[:converter]}" : ''
32+
async = params[:Async] ? 'async/' : ''
33+
34+
"#{async}convert/#{from_format}/to/#{@to_format}#{converter}"
35+
end
36+
3137
def normalize_params(params)
3238
result = {}
3339

spec/convert_api/task_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,17 @@
1616

1717
expect(subject).to be_instance_of(ConvertApi::Result)
1818
end
19+
20+
describe 'async' do
21+
let(:params) { { Async: true, File: 'https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt' } }
22+
23+
it 'submits an async task and returns result' do
24+
expect(ConvertApi.client).to(
25+
receive(:post).with('async/convert/txt/to/pdf', instance_of(Hash), instance_of(Hash)).and_return(result)
26+
)
27+
28+
expect(subject).to be_instance_of(ConvertApi::Result)
29+
end
30+
end
1931
end
2032
end

0 commit comments

Comments
 (0)