rev-api 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +21 -21
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +8 -8
- data/Gemfile +3 -3
- data/LICENSE +191 -191
- data/README.md +132 -132
- data/Rakefile +13 -13
- data/examples/cli.rb +270 -270
- data/lib/rev-api.rb +25 -25
- data/lib/rev-api/api.rb +326 -326
- data/lib/rev-api/api_serializable.rb +30 -30
- data/lib/rev-api/exceptions.rb +100 -100
- data/lib/rev-api/http_client.rb +97 -97
- data/lib/rev-api/models/order.rb +138 -138
- data/lib/rev-api/models/order_request.rb +222 -228
- data/lib/rev-api/version.rb +3 -3
- data/rev-api.gemspec +34 -34
- data/spec/fixtures/api_cassettes/cancel_order.yml +38 -38
- data/spec/fixtures/api_cassettes/cancel_order_not_allowed.yml +40 -40
- data/spec/fixtures/api_cassettes/get_attachment_content.yml +399 -399
- data/spec/fixtures/api_cassettes/get_attachment_content_as_pdf.yml +399 -399
- data/spec/fixtures/api_cassettes/get_attachment_content_as_text.yml +65 -65
- data/spec/fixtures/api_cassettes/get_attachment_content_as_youtube_transcript.yml +66 -66
- data/spec/fixtures/api_cassettes/get_attachment_content_unacceptable_representation.yml +42 -42
- data/spec/fixtures/api_cassettes/get_attachment_content_with_invalid_id.yml +42 -42
- data/spec/fixtures/api_cassettes/get_attachment_metadata.yml +42 -42
- data/spec/fixtures/api_cassettes/get_attachment_with_invalid_id.yml +40 -40
- data/spec/fixtures/api_cassettes/get_orders.yml +122 -122
- data/spec/fixtures/api_cassettes/get_orders_with_clientRef.yml +41 -41
- data/spec/fixtures/api_cassettes/get_tc_order.yml +44 -44
- data/spec/fixtures/api_cassettes/get_third_page_of_orders.yml +58 -58
- data/spec/fixtures/api_cassettes/get_tr_order.yml +44 -44
- data/spec/fixtures/api_cassettes/link_input.yml +44 -44
- data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -44
- data/spec/fixtures/api_cassettes/link_input_with_spaces_in_filename.yml +45 -45
- data/spec/fixtures/api_cassettes/not_found_order.yml +42 -42
- data/spec/fixtures/api_cassettes/submit_cp_order.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_su_order.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tc_order_without_specifying_payment.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tr_order.yml +44 -44
- data/spec/fixtures/api_cassettes/unauthorized.yml +42 -42
- data/spec/fixtures/api_cassettes/upload_input.yml +90 -90
- data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +91 -91
- data/spec/lib/rev/api_spec.rb +24 -24
- data/spec/lib/rev/cancel_order_spec.rb +24 -24
- data/spec/lib/rev/exceptions_spec.rb +8 -8
- data/spec/lib/rev/get_attachment_content_spec.rb +79 -79
- data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -33
- data/spec/lib/rev/get_order_spec.rb +67 -67
- data/spec/lib/rev/get_orders_spec.rb +61 -61
- data/spec/lib/rev/http_client_spec.rb +32 -32
- data/spec/lib/rev/models/order_request_spec.rb +6 -14
- data/spec/lib/rev/models/order_spec.rb +58 -58
- data/spec/lib/rev/post_inputs_spec.rb +94 -94
- data/spec/lib/rev/post_order_spec.rb +195 -195
- data/spec/spec_helper.rb +49 -49
- metadata +39 -82
@@ -1,62 +1,62 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
describe 'GET /orders' do
|
4
|
-
let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
|
5
|
-
|
6
|
-
describe 'GET /orders without page number' do
|
7
|
-
it 'must get first page of existing orders' do
|
8
|
-
VCR.insert_cassette 'get_orders'
|
9
|
-
|
10
|
-
page = client.get_orders_page
|
11
|
-
|
12
|
-
assert_requested :get, /.*\/api\/v1\/orders\?page=0/, :times => 1
|
13
|
-
|
14
|
-
page.orders.must_be_instance_of Array
|
15
|
-
page.results_per_page.must_equal 8
|
16
|
-
page.orders.size.must_equal 8
|
17
|
-
page.page.must_equal 0
|
18
|
-
page.total_count.must_equal 77
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'GET /orders?page={pagenum}' do
|
23
|
-
it 'must load any page' do
|
24
|
-
VCR.insert_cassette 'get_third_page_of_orders'
|
25
|
-
|
26
|
-
page = client.get_orders_page(2)
|
27
|
-
|
28
|
-
assert_requested :get, /.*\/api\/v1\/orders\?page=2/, :times => 1
|
29
|
-
|
30
|
-
page.orders.size.must_equal 8
|
31
|
-
page.page.must_equal 2
|
32
|
-
page.orders.first.order_number.must_equal 'TC0229215557'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'GET /orders without client reference raises' do
|
37
|
-
it 'must raise NotAcceptableError' do
|
38
|
-
assert_raises(ArgumentError) { client.get_orders_by_client_ref }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'GET /orders?page=0&clientRef={client_ref}' do
|
43
|
-
it 'must load order with given reference id' do
|
44
|
-
VCR.insert_cassette 'get_orders_with_clientRef'
|
45
|
-
|
46
|
-
page = client.get_orders_by_client_ref('my ref')
|
47
|
-
|
48
|
-
assert_requested :get, /.*\/api\/v1\/orders\?clientRef=my%20ref&page=0/, :times => 1
|
49
|
-
|
50
|
-
page.orders.must_be_instance_of Array
|
51
|
-
page.results_per_page.must_equal 25
|
52
|
-
page.orders.size.must_equal 1
|
53
|
-
page.page.must_equal 0
|
54
|
-
page.total_count.must_equal 1
|
55
|
-
page.orders[0].order_number.must_equal 'CP0180436196'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
after do
|
60
|
-
VCR.eject_cassette
|
61
|
-
end
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe 'GET /orders' do
|
4
|
+
let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
|
5
|
+
|
6
|
+
describe 'GET /orders without page number' do
|
7
|
+
it 'must get first page of existing orders' do
|
8
|
+
VCR.insert_cassette 'get_orders'
|
9
|
+
|
10
|
+
page = client.get_orders_page
|
11
|
+
|
12
|
+
assert_requested :get, /.*\/api\/v1\/orders\?page=0/, :times => 1
|
13
|
+
|
14
|
+
page.orders.must_be_instance_of Array
|
15
|
+
page.results_per_page.must_equal 8
|
16
|
+
page.orders.size.must_equal 8
|
17
|
+
page.page.must_equal 0
|
18
|
+
page.total_count.must_equal 77
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'GET /orders?page={pagenum}' do
|
23
|
+
it 'must load any page' do
|
24
|
+
VCR.insert_cassette 'get_third_page_of_orders'
|
25
|
+
|
26
|
+
page = client.get_orders_page(2)
|
27
|
+
|
28
|
+
assert_requested :get, /.*\/api\/v1\/orders\?page=2/, :times => 1
|
29
|
+
|
30
|
+
page.orders.size.must_equal 8
|
31
|
+
page.page.must_equal 2
|
32
|
+
page.orders.first.order_number.must_equal 'TC0229215557'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'GET /orders without client reference raises' do
|
37
|
+
it 'must raise NotAcceptableError' do
|
38
|
+
assert_raises(ArgumentError) { client.get_orders_by_client_ref }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'GET /orders?page=0&clientRef={client_ref}' do
|
43
|
+
it 'must load order with given reference id' do
|
44
|
+
VCR.insert_cassette 'get_orders_with_clientRef'
|
45
|
+
|
46
|
+
page = client.get_orders_by_client_ref('my ref')
|
47
|
+
|
48
|
+
assert_requested :get, /.*\/api\/v1\/orders\?clientRef=my%20ref&page=0/, :times => 1
|
49
|
+
|
50
|
+
page.orders.must_be_instance_of Array
|
51
|
+
page.results_per_page.must_equal 25
|
52
|
+
page.orders.size.must_equal 1
|
53
|
+
page.page.must_equal 0
|
54
|
+
page.total_count.must_equal 1
|
55
|
+
page.orders[0].order_number.must_equal 'CP0180436196'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
after do
|
60
|
+
VCR.eject_cassette
|
61
|
+
end
|
62
62
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
describe Rev::HttpClient do
|
4
|
-
it 'must support predefined production host' do
|
5
|
-
client = Rev::HttpClient.new('foo', 'bar', Rev::Api::PRODUCTION_HOST)
|
6
|
-
Rev::HttpClient.base_uri.must_equal 'https://www.rev.com/api/v1'
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'must support predefined sandbox host' do
|
10
|
-
client = Rev::HttpClient.new('foo', 'bar', Rev::Api::SANDBOX_HOST)
|
11
|
-
Rev::HttpClient.base_uri.must_equal 'https://api-sandbox.rev.com/api/v1'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'must support custom host for development purposes' do
|
15
|
-
client = Rev::HttpClient.new('foo', 'bar', 'localhost')
|
16
|
-
Rev::HttpClient.base_uri.must_equal 'https://localhost/api/v1'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must include authorization and User-Agent headers for any request' do
|
20
|
-
host = 'www.example.com'
|
21
|
-
stub_request(:any, /www\.example\.com\/.*/)
|
22
|
-
|
23
|
-
client = Rev::HttpClient.new('foo', 'bar', host)
|
24
|
-
response = client.get('/orders')
|
25
|
-
|
26
|
-
assert_requested :get, "https://#{host}/api/v1/orders", :headers => {
|
27
|
-
'Authorization' => "Rev foo:bar",
|
28
|
-
'User-Agent' => Rev::HttpClient::USER_AGENT
|
29
|
-
}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Rev::HttpClient do
|
4
|
+
it 'must support predefined production host' do
|
5
|
+
client = Rev::HttpClient.new('foo', 'bar', Rev::Api::PRODUCTION_HOST)
|
6
|
+
Rev::HttpClient.base_uri.must_equal 'https://www.rev.com/api/v1'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'must support predefined sandbox host' do
|
10
|
+
client = Rev::HttpClient.new('foo', 'bar', Rev::Api::SANDBOX_HOST)
|
11
|
+
Rev::HttpClient.base_uri.must_equal 'https://api-sandbox.rev.com/api/v1'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'must support custom host for development purposes' do
|
15
|
+
client = Rev::HttpClient.new('foo', 'bar', 'localhost')
|
16
|
+
Rev::HttpClient.base_uri.must_equal 'https://localhost/api/v1'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'must include authorization and User-Agent headers for any request' do
|
20
|
+
host = 'www.example.com'
|
21
|
+
stub_request(:any, /www\.example\.com\/.*/)
|
22
|
+
|
23
|
+
client = Rev::HttpClient.new('foo', 'bar', host)
|
24
|
+
response = client.get('/orders')
|
25
|
+
|
26
|
+
assert_requested :get, "https://#{host}/api/v1/orders", :headers => {
|
27
|
+
'Authorization' => "Rev foo:bar",
|
28
|
+
'User-Agent' => Rev::HttpClient::USER_AGENT
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -2,23 +2,15 @@ require_relative '../../../spec_helper'
|
|
2
2
|
|
3
3
|
describe 'OrderRequest' do
|
4
4
|
|
5
|
-
it '
|
6
|
-
Rev::OrderRequest::PRIORITY[:normal].must_equal 'Normal'
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'has time insensitivie priority' do
|
10
|
-
Rev::OrderRequest::PRIORITY[:time_insensitivie].must_equal 'TimeInsensitivie'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'defaults to normal priority' do
|
5
|
+
it 'defaults to standard TAT guarantee' do
|
14
6
|
order = Rev::OrderRequest.new({})
|
15
|
-
order.
|
7
|
+
order.non_standard_tat_guarantee.must_equal false
|
16
8
|
end
|
17
9
|
|
18
|
-
it 'accepts
|
19
|
-
|
20
|
-
order = Rev::OrderRequest.new({ '
|
21
|
-
order.
|
10
|
+
it 'accepts non standard TAT guarantee flag during init' do
|
11
|
+
non_standard_tat_guarantee = true
|
12
|
+
order = Rev::OrderRequest.new({ 'non_standard_tat_guarantee' => non_standard_tat_guarantee })
|
13
|
+
order.non_standard_tat_guarantee.must_equal non_standard_tat_guarantee
|
22
14
|
end
|
23
15
|
|
24
16
|
it 'has caption options' do
|
@@ -1,58 +1,58 @@
|
|
1
|
-
require_relative '../../../spec_helper'
|
2
|
-
|
3
|
-
describe 'Order' do
|
4
|
-
let(:cp_order) {
|
5
|
-
Rev::Order.new (
|
6
|
-
{ 'attachments' => { },
|
7
|
-
'comments' => {},
|
8
|
-
'caption' => { 'total_length_seconds' => 300 }
|
9
|
-
}
|
10
|
-
)
|
11
|
-
}
|
12
|
-
|
13
|
-
it 'has caption info' do
|
14
|
-
assert_respond_to cp_order, 'caption'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'parses caption info' do
|
18
|
-
assert_kind_of Rev::CaptionInfo, cp_order.caption
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'has captions attachments' do
|
22
|
-
assert_respond_to cp_order, 'captions'
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'Attachments' do
|
26
|
-
describe 'REPRESENTATIONS' do
|
27
|
-
it 'has srt' do
|
28
|
-
Rev::Attachment::REPRESENTATIONS[:srt].must_equal 'application/x-subrip'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'has scc' do
|
32
|
-
Rev::Attachment::REPRESENTATIONS[:scc].must_equal 'text/x-scc'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'has ttml' do
|
36
|
-
Rev::Attachment::REPRESENTATIONS[:ttml].must_equal 'application/ttml+xml'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'has qt' do
|
40
|
-
Rev::Attachment::REPRESENTATIONS[:qt].must_equal 'application/x-quicktime-timedtext'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'KINDS' do
|
45
|
-
it 'has caption' do
|
46
|
-
Rev::Attachment::KINDS[:caption].must_equal 'caption'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end # Attachments
|
50
|
-
|
51
|
-
describe 'CaptionInfo' do
|
52
|
-
it 'has total_length_seconds' do
|
53
|
-
info = Rev::CaptionInfo.new({})
|
54
|
-
assert_respond_to info, 'total_length_seconds'
|
55
|
-
end
|
56
|
-
end # CaptionInfo
|
57
|
-
end
|
58
|
-
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
|
3
|
+
describe 'Order' do
|
4
|
+
let(:cp_order) {
|
5
|
+
Rev::Order.new (
|
6
|
+
{ 'attachments' => { },
|
7
|
+
'comments' => {},
|
8
|
+
'caption' => { 'total_length_seconds' => 300 }
|
9
|
+
}
|
10
|
+
)
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'has caption info' do
|
14
|
+
assert_respond_to cp_order, 'caption'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'parses caption info' do
|
18
|
+
assert_kind_of Rev::CaptionInfo, cp_order.caption
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has captions attachments' do
|
22
|
+
assert_respond_to cp_order, 'captions'
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Attachments' do
|
26
|
+
describe 'REPRESENTATIONS' do
|
27
|
+
it 'has srt' do
|
28
|
+
Rev::Attachment::REPRESENTATIONS[:srt].must_equal 'application/x-subrip'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has scc' do
|
32
|
+
Rev::Attachment::REPRESENTATIONS[:scc].must_equal 'text/x-scc'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'has ttml' do
|
36
|
+
Rev::Attachment::REPRESENTATIONS[:ttml].must_equal 'application/ttml+xml'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'has qt' do
|
40
|
+
Rev::Attachment::REPRESENTATIONS[:qt].must_equal 'application/x-quicktime-timedtext'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'KINDS' do
|
45
|
+
it 'has caption' do
|
46
|
+
Rev::Attachment::KINDS[:caption].must_equal 'caption'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end # Attachments
|
50
|
+
|
51
|
+
describe 'CaptionInfo' do
|
52
|
+
it 'has total_length_seconds' do
|
53
|
+
info = Rev::CaptionInfo.new({})
|
54
|
+
assert_respond_to info, 'total_length_seconds'
|
55
|
+
end
|
56
|
+
end # CaptionInfo
|
57
|
+
end
|
58
|
+
|
@@ -1,94 +1,94 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
describe 'POST /inputs' do
|
4
|
-
let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
|
5
|
-
|
6
|
-
it 'must link external file with explicit content-type and file' do
|
7
|
-
VCR.insert_cassette 'link_input_with_all_attributes'
|
8
|
-
|
9
|
-
link = 'https://www.rev.com/content/img/rev/rev_logo_colored_top.png'
|
10
|
-
filename = 'sourcedocument.png'
|
11
|
-
content_type = 'image/png'
|
12
|
-
new_input_location = client.create_input_from_link(link, filename, content_type)
|
13
|
-
|
14
|
-
new_input_location.must_match 'urn:rev:inputmedia:'
|
15
|
-
expected_body = {
|
16
|
-
'url' => link,
|
17
|
-
'filename' => filename,
|
18
|
-
'content_type' => content_type
|
19
|
-
}
|
20
|
-
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
21
|
-
req.headers['Content-Type'].must_equal 'application/json'
|
22
|
-
actual_body = JSON.load req.body
|
23
|
-
actual_body.must_equal expected_body
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'must quote the filename' do
|
28
|
-
VCR.insert_cassette 'link_input_with_spaces_in_filename'
|
29
|
-
|
30
|
-
link = 'https://s3-us-west-2.amazonaws.com/public-rev/translation/Rev Certified Template (2014-06-11).docx'
|
31
|
-
filename = 'Rev Certified Template (2014-06-11).docx'
|
32
|
-
content_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
33
|
-
new_input_location = client.create_input_from_link(link, filename, content_type)
|
34
|
-
|
35
|
-
new_input_location.must_match 'urn:rev:inputmedia:'
|
36
|
-
expected_body = {
|
37
|
-
'url' => link,
|
38
|
-
'filename' => filename,
|
39
|
-
'content_type' => content_type
|
40
|
-
}
|
41
|
-
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
42
|
-
actual_body = JSON.load req.body
|
43
|
-
actual_body.must_equal expected_body
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'must link external file without content-type and filename' do
|
48
|
-
VCR.insert_cassette 'link_input'
|
49
|
-
|
50
|
-
link = 'https://www.rev.com/content/img/rev/rev_logo_colored_top.png'
|
51
|
-
new_input_location = client.create_input_from_link(link)
|
52
|
-
|
53
|
-
new_input_location.must_match 'urn:rev:inputmedia:'
|
54
|
-
expected_body = { 'url' => link }
|
55
|
-
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
56
|
-
req.headers['Content-Type'].must_equal 'application/json'
|
57
|
-
actual_body = JSON.load req.body
|
58
|
-
actual_body.must_equal expected_body
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'must upload source file directly' do
|
63
|
-
VCR.insert_cassette 'upload_input'
|
64
|
-
|
65
|
-
filename = './spec/fixtures/sourcedocument.png'
|
66
|
-
content_type = 'image/png'
|
67
|
-
|
68
|
-
new_input_location = client.upload_input(filename, content_type)
|
69
|
-
|
70
|
-
new_input_location.must_match 'urn:rev:inputmedia:'
|
71
|
-
expected_body = File.read(filename)
|
72
|
-
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
73
|
-
req.headers['Content-Type'].must_equal content_type
|
74
|
-
req.headers['Content-Disposition'].must_equal 'attachment; filename="sourcedocument.png"'
|
75
|
-
req.body.must_equal expected_body
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'must raise BadRequestError on failure' do
|
80
|
-
VCR.insert_cassette 'upload_input_with_invalid_content_type'
|
81
|
-
|
82
|
-
filename = './spec/fixtures/sourcedocument.png'
|
83
|
-
content_type = 'trololo'
|
84
|
-
|
85
|
-
action = lambda { client.upload_input(filename, content_type) }
|
86
|
-
exception = action.must_raise Rev::BadRequestError
|
87
|
-
exception.message.must_match '10001: The content-type explicitly specified in the request is not supported for input media'
|
88
|
-
exception.code.must_equal Rev::InputRequestErrorCodes::UNSUPPORTED_CONTENT_TYPE
|
89
|
-
end
|
90
|
-
|
91
|
-
after do
|
92
|
-
VCR.eject_cassette
|
93
|
-
end
|
94
|
-
end
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe 'POST /inputs' do
|
4
|
+
let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
|
5
|
+
|
6
|
+
it 'must link external file with explicit content-type and file' do
|
7
|
+
VCR.insert_cassette 'link_input_with_all_attributes'
|
8
|
+
|
9
|
+
link = 'https://www.rev.com/content/img/rev/rev_logo_colored_top.png'
|
10
|
+
filename = 'sourcedocument.png'
|
11
|
+
content_type = 'image/png'
|
12
|
+
new_input_location = client.create_input_from_link(link, filename, content_type)
|
13
|
+
|
14
|
+
new_input_location.must_match 'urn:rev:inputmedia:'
|
15
|
+
expected_body = {
|
16
|
+
'url' => link,
|
17
|
+
'filename' => filename,
|
18
|
+
'content_type' => content_type
|
19
|
+
}
|
20
|
+
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
21
|
+
req.headers['Content-Type'].must_equal 'application/json'
|
22
|
+
actual_body = JSON.load req.body
|
23
|
+
actual_body.must_equal expected_body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'must quote the filename' do
|
28
|
+
VCR.insert_cassette 'link_input_with_spaces_in_filename'
|
29
|
+
|
30
|
+
link = 'https://s3-us-west-2.amazonaws.com/public-rev/translation/Rev Certified Template (2014-06-11).docx'
|
31
|
+
filename = 'Rev Certified Template (2014-06-11).docx'
|
32
|
+
content_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
33
|
+
new_input_location = client.create_input_from_link(link, filename, content_type)
|
34
|
+
|
35
|
+
new_input_location.must_match 'urn:rev:inputmedia:'
|
36
|
+
expected_body = {
|
37
|
+
'url' => link,
|
38
|
+
'filename' => filename,
|
39
|
+
'content_type' => content_type
|
40
|
+
}
|
41
|
+
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
42
|
+
actual_body = JSON.load req.body
|
43
|
+
actual_body.must_equal expected_body
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'must link external file without content-type and filename' do
|
48
|
+
VCR.insert_cassette 'link_input'
|
49
|
+
|
50
|
+
link = 'https://www.rev.com/content/img/rev/rev_logo_colored_top.png'
|
51
|
+
new_input_location = client.create_input_from_link(link)
|
52
|
+
|
53
|
+
new_input_location.must_match 'urn:rev:inputmedia:'
|
54
|
+
expected_body = { 'url' => link }
|
55
|
+
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
56
|
+
req.headers['Content-Type'].must_equal 'application/json'
|
57
|
+
actual_body = JSON.load req.body
|
58
|
+
actual_body.must_equal expected_body
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'must upload source file directly' do
|
63
|
+
VCR.insert_cassette 'upload_input'
|
64
|
+
|
65
|
+
filename = './spec/fixtures/sourcedocument.png'
|
66
|
+
content_type = 'image/png'
|
67
|
+
|
68
|
+
new_input_location = client.upload_input(filename, content_type)
|
69
|
+
|
70
|
+
new_input_location.must_match 'urn:rev:inputmedia:'
|
71
|
+
expected_body = File.read(filename)
|
72
|
+
assert_requested(:post, /.*\/inputs/, :times => 1) do |req|
|
73
|
+
req.headers['Content-Type'].must_equal content_type
|
74
|
+
req.headers['Content-Disposition'].must_equal 'attachment; filename="sourcedocument.png"'
|
75
|
+
req.body.must_equal expected_body
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'must raise BadRequestError on failure' do
|
80
|
+
VCR.insert_cassette 'upload_input_with_invalid_content_type'
|
81
|
+
|
82
|
+
filename = './spec/fixtures/sourcedocument.png'
|
83
|
+
content_type = 'trololo'
|
84
|
+
|
85
|
+
action = lambda { client.upload_input(filename, content_type) }
|
86
|
+
exception = action.must_raise Rev::BadRequestError
|
87
|
+
exception.message.must_match '10001: The content-type explicitly specified in the request is not supported for input media'
|
88
|
+
exception.code.must_equal Rev::InputRequestErrorCodes::UNSUPPORTED_CONTENT_TYPE
|
89
|
+
end
|
90
|
+
|
91
|
+
after do
|
92
|
+
VCR.eject_cassette
|
93
|
+
end
|
94
|
+
end
|