rev-api 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -1
  3. data/.gitignore +21 -21
  4. data/.ruby-gemset +1 -1
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +8 -8
  7. data/Gemfile +3 -3
  8. data/LICENSE +191 -191
  9. data/README.md +132 -132
  10. data/Rakefile +13 -13
  11. data/examples/cli.rb +270 -270
  12. data/lib/rev-api.rb +25 -25
  13. data/lib/rev-api/api.rb +326 -326
  14. data/lib/rev-api/api_serializable.rb +30 -30
  15. data/lib/rev-api/exceptions.rb +97 -100
  16. data/lib/rev-api/http_client.rb +97 -97
  17. data/lib/rev-api/models/order.rb +130 -138
  18. data/lib/rev-api/models/order_request.rb +194 -222
  19. data/lib/rev-api/version.rb +3 -3
  20. data/rev-api.gemspec +34 -34
  21. data/spec/fixtures/api_cassettes/cancel_order.yml +38 -38
  22. data/spec/fixtures/api_cassettes/cancel_order_not_allowed.yml +40 -40
  23. data/spec/fixtures/api_cassettes/get_attachment_content.yml +399 -399
  24. data/spec/fixtures/api_cassettes/get_attachment_content_as_pdf.yml +399 -399
  25. data/spec/fixtures/api_cassettes/get_attachment_content_as_text.yml +65 -65
  26. data/spec/fixtures/api_cassettes/get_attachment_content_as_youtube_transcript.yml +66 -66
  27. data/spec/fixtures/api_cassettes/get_attachment_content_unacceptable_representation.yml +42 -42
  28. data/spec/fixtures/api_cassettes/get_attachment_content_with_invalid_id.yml +42 -42
  29. data/spec/fixtures/api_cassettes/get_attachment_metadata.yml +42 -42
  30. data/spec/fixtures/api_cassettes/get_attachment_with_invalid_id.yml +40 -40
  31. data/spec/fixtures/api_cassettes/get_orders.yml +122 -122
  32. data/spec/fixtures/api_cassettes/get_orders_with_clientRef.yml +41 -41
  33. data/spec/fixtures/api_cassettes/get_tc_order.yml +44 -44
  34. data/spec/fixtures/api_cassettes/get_third_page_of_orders.yml +52 -58
  35. data/spec/fixtures/api_cassettes/link_input.yml +44 -44
  36. data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -44
  37. data/spec/fixtures/api_cassettes/link_input_with_spaces_in_filename.yml +45 -45
  38. data/spec/fixtures/api_cassettes/not_found_order.yml +42 -42
  39. data/spec/fixtures/api_cassettes/submit_cp_order.yml +45 -45
  40. data/spec/fixtures/api_cassettes/submit_su_order.yml +45 -45
  41. data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +45 -45
  42. data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -45
  43. data/spec/fixtures/api_cassettes/submit_tc_order_without_specifying_payment.yml +45 -45
  44. data/spec/fixtures/api_cassettes/unauthorized.yml +42 -42
  45. data/spec/fixtures/api_cassettes/upload_input.yml +90 -90
  46. data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +91 -91
  47. data/spec/lib/rev/api_spec.rb +24 -24
  48. data/spec/lib/rev/cancel_order_spec.rb +24 -24
  49. data/spec/lib/rev/exceptions_spec.rb +8 -8
  50. data/spec/lib/rev/get_attachment_content_spec.rb +79 -79
  51. data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -33
  52. data/spec/lib/rev/get_order_spec.rb +52 -68
  53. data/spec/lib/rev/get_orders_spec.rb +62 -62
  54. data/spec/lib/rev/http_client_spec.rb +32 -32
  55. data/spec/lib/rev/models/order_request_spec.rb +0 -7
  56. data/spec/lib/rev/models/order_spec.rb +58 -58
  57. data/spec/lib/rev/post_inputs_spec.rb +94 -94
  58. data/spec/lib/rev/post_order_spec.rb +163 -195
  59. data/spec/spec_helper.rb +49 -49
  60. metadata +38 -41
  61. data/spec/fixtures/api_cassettes/get_tr_order.yml +0 -44
  62. data/spec/fixtures/api_cassettes/submit_tr_order.yml +0 -44
@@ -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
+
@@ -46,13 +46,6 @@ describe 'OrderRequest' do
46
46
  end
47
47
  end
48
48
 
49
- describe 'TranslationOptions' do
50
- it 'is InputOptions' do
51
- options = Rev::TranslationOptions.new([{}], {})
52
- options.must_be_kind_of Rev::InputOptions
53
- end
54
- end
55
-
56
49
  describe 'CaptionOptions' do
57
50
  it 'is InputOptions' do
58
51
  options = Rev::CaptionOptions.new([{}], {})
@@ -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/transcript/Rev Transcript File.docx'
31
+ filename = 'Rev Transcript File.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,195 +1,163 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'POST /orders' do
4
- let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
-
6
- # some defaults we use often
7
- let(:billing_address) { Rev::BillingAddress.new(
8
- :street => '123 Pine Lane',
9
- :street2 => 'Apt D',
10
- :city => 'MyTown',
11
- :state => 'MN',
12
- :zip => '12345',
13
- :country_alpha2 => 'US'
14
- )}
15
-
16
- let(:balance_payment) { Rev::Payment.new(Rev::Payment::TYPES[:account_balance]) }
17
- let(:transcription_inputs) {
18
- inputs = []
19
- inputs << Rev::Input.new(:external_link => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc')
20
- inputs << Rev::Input.new(:audio_length_seconds => 900, :external_link => 'https://vimeo.com/7976699')
21
- }
22
- let(:translation_inputs) {
23
- inputs = []
24
- inputs << Rev::Input.new(:word_length => 1000, :uri => 'urn:rev:inputmedia:SnVwbG9hZHMvMjAxMy0wOS0xNy9lMzk4MWIzNS0wNzM1LTRlMDAtODY1NC1jNWY4ZjE4MzdlMTIvc291cmNlZG9jdW1lbnQucG5n')
25
- }
26
- let(:caption_inputs) {
27
- inputs = []
28
- inputs << Rev::Input.new(:video_length_seconds => 900, :external_link => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc')
29
- }
30
- let(:transcription_options) { Rev::TranscriptionOptions.new(transcription_inputs,
31
- :verbatim => true, :timestamps => true) }
32
- let(:translation_options) { Rev::TranslationOptions.new(translation_inputs,
33
- :source_language_code => 'es', :destination_language_code => 'en') }
34
- let(:caption_options) {
35
- Rev::CaptionOptions.new(caption_inputs, :output_file_formats => ['SubRip'])
36
- }
37
- let(:subtitle_options) {
38
- Rev::CaptionOptions.new(caption_inputs, :subtitle_languages => ['es','it'],
39
- :output_file_formats => ['SubRip'])
40
- }
41
-
42
- it 'must place order using account balance' do
43
- VCR.insert_cassette 'submit_tc_order_with_account_balance'
44
-
45
- request = Rev::OrderRequest.new(
46
- :transcription_options => transcription_options
47
- )
48
-
49
- new_order_num = client.submit_order(request)
50
-
51
- new_order_num.must_equal 'TC0406615008'
52
- expected_body = {
53
- 'payment' => {
54
- 'type' => 'AccountBalance'
55
- },
56
- 'non_standard_tat_guarantee' => false,
57
- 'transcription_options' => {
58
- 'inputs' => [
59
- { 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' },
60
- { 'external_link' => 'https://vimeo.com/7976699', 'audio_length_seconds' => 900 }
61
- ],
62
- 'verbatim' => true,
63
- 'timestamps' => true
64
- }
65
- }
66
- assert_order_placement_success(expected_body)
67
- end
68
-
69
- it 'must default to account balance if payment property not set' do
70
- VCR.insert_cassette 'submit_tc_order_without_specifying_payment'
71
-
72
- request = Rev::OrderRequest.new(
73
- :transcription_options => transcription_options
74
- )
75
-
76
- new_order_num = client.submit_order(request)
77
-
78
- new_order_num.must_equal 'TC0406615008'
79
- expected_body = {
80
- 'payment' => {
81
- 'type' => 'AccountBalance'
82
- },
83
- 'non_standard_tat_guarantee' => false,
84
- 'transcription_options' => {
85
- 'inputs' => [
86
- { 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' },
87
- { 'external_link' => 'https://vimeo.com/7976699', 'audio_length_seconds' => 900 }
88
- ],
89
- 'verbatim' => true,
90
- 'timestamps' => true
91
- }
92
- }
93
- assert_order_placement_success(expected_body)
94
- end
95
-
96
- it 'must raise BadRequest error in case of request validation failure' do
97
- VCR.insert_cassette 'submit_tc_order_with_invalid_request'
98
-
99
- # example - missing transcription options
100
- request = Rev::OrderRequest.new
101
-
102
- action = lambda { client.submit_order(request) }
103
- exception = action.must_raise Rev::BadRequestError
104
- exception.message.must_match '10004: You must specify either translation or transcription options in an order'
105
- exception.code.must_equal Rev::OrderRequestErrorCodes::TC_OR_TR_OPTIONS_NOT_SPECIFIED
106
- end
107
-
108
- it 'must submit translation order with options' do
109
- VCR.insert_cassette 'submit_tr_order'
110
-
111
- request = Rev::OrderRequest.new(
112
- :translation_options => translation_options
113
- )
114
-
115
- new_order_num = client.submit_order(request)
116
-
117
- new_order_num.must_equal 'TR0235803277'
118
- expected_body = {
119
- 'payment' => {
120
- 'type' => 'AccountBalance'
121
- },
122
- 'non_standard_tat_guarantee' => false,
123
- 'translation_options' => {
124
- 'inputs'=> [
125
- { 'word_length' => 1000, 'uri' => 'urn:rev:inputmedia:SnVwbG9hZHMvMjAxMy0wOS0xNy9lMzk4MWIzNS0wNzM1LTRlMDAtODY1NC1jNWY4ZjE4MzdlMTIvc291cmNlZG9jdW1lbnQucG5n' },
126
- ],
127
- 'source_language_code' => 'es',
128
- 'destination_language_code' => 'en'
129
- }
130
- }
131
- assert_order_placement_success(expected_body)
132
- end
133
-
134
- it 'must submit caption order with options' do
135
- VCR.insert_cassette 'submit_cp_order'
136
-
137
- request = Rev::OrderRequest.new(:caption_options => caption_options)
138
-
139
- new_order_num = client.submit_order(request)
140
-
141
- new_order_num.must_equal 'CP12345'
142
- expected_body = {
143
- 'payment' => {
144
- 'type' => 'AccountBalance'
145
- },
146
- 'non_standard_tat_guarantee' => false,
147
- 'caption_options' => {
148
- 'inputs'=> [
149
- { 'video_length_seconds' => 900, 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' }
150
- ],
151
- 'output_file_formats' => [Rev::CaptionOptions::OUTPUT_FILE_FORMATS[:subrip]]
152
- }
153
- }
154
- assert_order_placement_success(expected_body)
155
- end
156
-
157
- it 'must submit subtitle order with options' do
158
- VCR.insert_cassette 'submit_su_order'
159
-
160
- request = Rev::OrderRequest.new(:caption_options => subtitle_options)
161
-
162
- new_order_num = client.submit_order(request)
163
-
164
- new_order_num.must_equal 'CP56789'
165
- expected_body = {
166
- 'payment' => {
167
- 'type' => 'AccountBalance'
168
- },
169
- 'non_standard_tat_guarantee' => false,
170
- 'caption_options' => {
171
- 'inputs'=> [
172
- { 'video_length_seconds' => 900, 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' }
173
- ],
174
- 'subtitle_languages' => ['es','it'],
175
- 'output_file_formats' => [Rev::CaptionOptions::OUTPUT_FILE_FORMATS[:subrip]]
176
- }
177
- }
178
- assert_order_placement_success(expected_body)
179
- end
180
-
181
- after do
182
- VCR.eject_cassette
183
- end
184
-
185
- private
186
-
187
- def assert_order_placement_success(expected_body)
188
- assert_requested(:post, /.*\/orders/, :times => 1) do |req|
189
- req.headers['Content-Type'].must_equal 'application/json'
190
- actual_body = JSON.load req.body
191
- actual_body.must_equal expected_body
192
- end
193
- end
194
-
195
- end
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'POST /orders' do
4
+ let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
+
6
+ # some defaults we use often
7
+ let(:billing_address) { Rev::BillingAddress.new(
8
+ :street => '123 Pine Lane',
9
+ :street2 => 'Apt D',
10
+ :city => 'MyTown',
11
+ :state => 'MN',
12
+ :zip => '12345',
13
+ :country_alpha2 => 'US'
14
+ )}
15
+
16
+ let(:balance_payment) { Rev::Payment.new(Rev::Payment::TYPES[:account_balance]) }
17
+ let(:transcription_inputs) {
18
+ inputs = []
19
+ inputs << Rev::Input.new(:external_link => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc')
20
+ inputs << Rev::Input.new(:audio_length_seconds => 900, :external_link => 'https://vimeo.com/7976699')
21
+ }
22
+ let(:caption_inputs) {
23
+ inputs = []
24
+ inputs << Rev::Input.new(:video_length_seconds => 900, :external_link => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc')
25
+ }
26
+ let(:transcription_options) { Rev::TranscriptionOptions.new(transcription_inputs,
27
+ :verbatim => true, :timestamps => true) }
28
+ let(:caption_options) {
29
+ Rev::CaptionOptions.new(caption_inputs, :output_file_formats => ['SubRip'])
30
+ }
31
+ let(:subtitle_options) {
32
+ Rev::CaptionOptions.new(caption_inputs, :subtitle_languages => ['es','it'],
33
+ :output_file_formats => ['SubRip'])
34
+ }
35
+
36
+ it 'must place order using account balance' do
37
+ VCR.insert_cassette 'submit_tc_order_with_account_balance'
38
+
39
+ request = Rev::OrderRequest.new(
40
+ :transcription_options => transcription_options
41
+ )
42
+
43
+ new_order_num = client.submit_order(request)
44
+
45
+ new_order_num.must_equal 'TC0406615008'
46
+ expected_body = {
47
+ 'payment' => {
48
+ 'type' => 'AccountBalance'
49
+ },
50
+ 'non_standard_tat_guarantee' => false,
51
+ 'transcription_options' => {
52
+ 'inputs' => [
53
+ { 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' },
54
+ { 'external_link' => 'https://vimeo.com/7976699', 'audio_length_seconds' => 900 }
55
+ ],
56
+ 'verbatim' => true,
57
+ 'timestamps' => true
58
+ }
59
+ }
60
+ assert_order_placement_success(expected_body)
61
+ end
62
+
63
+ it 'must default to account balance if payment property not set' do
64
+ VCR.insert_cassette 'submit_tc_order_without_specifying_payment'
65
+
66
+ request = Rev::OrderRequest.new(
67
+ :transcription_options => transcription_options
68
+ )
69
+
70
+ new_order_num = client.submit_order(request)
71
+
72
+ new_order_num.must_equal 'TC0406615008'
73
+ expected_body = {
74
+ 'payment' => {
75
+ 'type' => 'AccountBalance'
76
+ },
77
+ 'non_standard_tat_guarantee' => false,
78
+ 'transcription_options' => {
79
+ 'inputs' => [
80
+ { 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' },
81
+ { 'external_link' => 'https://vimeo.com/7976699', 'audio_length_seconds' => 900 }
82
+ ],
83
+ 'verbatim' => true,
84
+ 'timestamps' => true
85
+ }
86
+ }
87
+ assert_order_placement_success(expected_body)
88
+ end
89
+
90
+ it 'must raise BadRequest error in case of request validation failure' do
91
+ VCR.insert_cassette 'submit_tc_order_with_invalid_request'
92
+
93
+ # example - missing transcription options
94
+ request = Rev::OrderRequest.new
95
+
96
+ action = lambda { client.submit_order(request) }
97
+ exception = action.must_raise Rev::BadRequestError
98
+ exception.message.must_match '10004: You must specify either transcription or caption options in an order'
99
+ exception.code.must_equal Rev::OrderRequestErrorCodes::OPTIONS_NOT_SPECIFIED
100
+ end
101
+
102
+ it 'must submit caption order with options' do
103
+ VCR.insert_cassette 'submit_cp_order'
104
+
105
+ request = Rev::OrderRequest.new(:caption_options => caption_options)
106
+
107
+ new_order_num = client.submit_order(request)
108
+
109
+ new_order_num.must_equal 'CP12345'
110
+ expected_body = {
111
+ 'payment' => {
112
+ 'type' => 'AccountBalance'
113
+ },
114
+ 'non_standard_tat_guarantee' => false,
115
+ 'caption_options' => {
116
+ 'inputs'=> [
117
+ { 'video_length_seconds' => 900, 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' }
118
+ ],
119
+ 'output_file_formats' => [Rev::CaptionOptions::OUTPUT_FILE_FORMATS[:subrip]]
120
+ }
121
+ }
122
+ assert_order_placement_success(expected_body)
123
+ end
124
+
125
+ it 'must submit subtitle order with options' do
126
+ VCR.insert_cassette 'submit_su_order'
127
+
128
+ request = Rev::OrderRequest.new(:caption_options => subtitle_options)
129
+
130
+ new_order_num = client.submit_order(request)
131
+
132
+ new_order_num.must_equal 'CP56789'
133
+ expected_body = {
134
+ 'payment' => {
135
+ 'type' => 'AccountBalance'
136
+ },
137
+ 'non_standard_tat_guarantee' => false,
138
+ 'caption_options' => {
139
+ 'inputs'=> [
140
+ { 'video_length_seconds' => 900, 'external_link' => 'http://www.youtube.com/watch?v=UF8uR6Z6KLc' }
141
+ ],
142
+ 'subtitle_languages' => ['es','it'],
143
+ 'output_file_formats' => [Rev::CaptionOptions::OUTPUT_FILE_FORMATS[:subrip]]
144
+ }
145
+ }
146
+ assert_order_placement_success(expected_body)
147
+ end
148
+
149
+ after do
150
+ VCR.eject_cassette
151
+ end
152
+
153
+ private
154
+
155
+ def assert_order_placement_success(expected_body)
156
+ assert_requested(:post, /.*\/orders/, :times => 1) do |req|
157
+ req.headers['Content-Type'].must_equal 'application/json'
158
+ actual_body = JSON.load req.body
159
+ actual_body.must_equal expected_body
160
+ end
161
+ end
162
+
163
+ end