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.
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 +100 -100
  16. data/lib/rev-api/http_client.rb +97 -97
  17. data/lib/rev-api/models/order.rb +138 -138
  18. data/lib/rev-api/models/order_request.rb +222 -228
  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 +58 -58
  35. data/spec/fixtures/api_cassettes/get_tr_order.yml +44 -44
  36. data/spec/fixtures/api_cassettes/link_input.yml +44 -44
  37. data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -44
  38. data/spec/fixtures/api_cassettes/link_input_with_spaces_in_filename.yml +45 -45
  39. data/spec/fixtures/api_cassettes/not_found_order.yml +42 -42
  40. data/spec/fixtures/api_cassettes/submit_cp_order.yml +45 -45
  41. data/spec/fixtures/api_cassettes/submit_su_order.yml +45 -45
  42. data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +45 -45
  43. data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -45
  44. data/spec/fixtures/api_cassettes/submit_tc_order_without_specifying_payment.yml +45 -45
  45. data/spec/fixtures/api_cassettes/submit_tr_order.yml +44 -44
  46. data/spec/fixtures/api_cassettes/unauthorized.yml +42 -42
  47. data/spec/fixtures/api_cassettes/upload_input.yml +90 -90
  48. data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +91 -91
  49. data/spec/lib/rev/api_spec.rb +24 -24
  50. data/spec/lib/rev/cancel_order_spec.rb +24 -24
  51. data/spec/lib/rev/exceptions_spec.rb +8 -8
  52. data/spec/lib/rev/get_attachment_content_spec.rb +79 -79
  53. data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -33
  54. data/spec/lib/rev/get_order_spec.rb +67 -67
  55. data/spec/lib/rev/get_orders_spec.rb +61 -61
  56. data/spec/lib/rev/http_client_spec.rb +32 -32
  57. data/spec/lib/rev/models/order_request_spec.rb +6 -14
  58. data/spec/lib/rev/models/order_spec.rb +58 -58
  59. data/spec/lib/rev/post_inputs_spec.rb +94 -94
  60. data/spec/lib/rev/post_order_spec.rb +195 -195
  61. data/spec/spec_helper.rb +49 -49
  62. metadata +39 -82
@@ -1,24 +1,24 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'API Client' do
4
- let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
-
6
- it 'must raise NotAuthorizedError on unauthorized HTTP response' do
7
- VCR.insert_cassette 'unauthorized'
8
-
9
- unauthorized_client = Rev.new('welcome', 'trololo', Rev::Api::SANDBOX_HOST)
10
- action = lambda { unauthorized_client.get_orders_page }
11
- action.must_raise Rev::NotAuthorizedError
12
- end
13
-
14
- it 'must raise NotFoundError on NotFound HTTP response' do
15
- VCR.insert_cassette 'not_found_order'
16
-
17
- action = lambda { client.get_order('trololo') }
18
- action.must_raise Rev::NotFoundError
19
- end
20
-
21
- after do
22
- VCR.eject_cassette
23
- end
24
- end
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'API Client' do
4
+ let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
+
6
+ it 'must raise NotAuthorizedError on unauthorized HTTP response' do
7
+ VCR.insert_cassette 'unauthorized'
8
+
9
+ unauthorized_client = Rev.new('welcome', 'trololo', Rev::Api::SANDBOX_HOST)
10
+ action = lambda { unauthorized_client.get_orders_page }
11
+ action.must_raise Rev::NotAuthorizedError
12
+ end
13
+
14
+ it 'must raise NotFoundError on NotFound HTTP response' do
15
+ VCR.insert_cassette 'not_found_order'
16
+
17
+ action = lambda { client.get_order('trololo') }
18
+ action.must_raise Rev::NotFoundError
19
+ end
20
+
21
+ after do
22
+ VCR.eject_cassette
23
+ end
24
+ end
@@ -1,25 +1,25 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'POST /orders/{order_num}/cancel' do
4
- let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
-
6
- it 'must cancel order' do
7
- VCR.insert_cassette 'cancel_order'
8
-
9
- client.cancel_order('TC0166192942').must_equal true
10
-
11
- assert_requested :post, /.*\/api\/v1\/orders\/TC0166192942\/cancel/, :times => 1,
12
- :body => { :order_num => 'TC0166192942' }
13
- end
14
-
15
- it 'must raise ForbiddenError when cancellation is not allowed' do
16
- VCR.insert_cassette 'cancel_order_not_allowed'
17
-
18
- action = lambda { client.cancel_order('TC0367111289') }
19
- action.must_raise Rev::ForbiddenError
20
- end
21
-
22
- after do
23
- VCR.eject_cassette
24
- end
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'POST /orders/{order_num}/cancel' do
4
+ let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
+
6
+ it 'must cancel order' do
7
+ VCR.insert_cassette 'cancel_order'
8
+
9
+ client.cancel_order('TC0166192942').must_equal true
10
+
11
+ assert_requested :post, /.*\/api\/v1\/orders\/TC0166192942\/cancel/, :times => 1,
12
+ :body => { :order_num => 'TC0166192942' }
13
+ end
14
+
15
+ it 'must raise ForbiddenError when cancellation is not allowed' do
16
+ VCR.insert_cassette 'cancel_order_not_allowed'
17
+
18
+ action = lambda { client.cancel_order('TC0367111289') }
19
+ action.must_raise Rev::ForbiddenError
20
+ end
21
+
22
+ after do
23
+ VCR.eject_cassette
24
+ end
25
25
  end
@@ -1,8 +1,8 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'Exceptions' do
4
- it 'has INVALID_MEDIA_LENGTH' do
5
- Rev::OrderRequestErrorCodes::INVALID_MEDIA_LENGTH.must_equal Rev::OrderRequestErrorCodes::INVALID_AUDIO_LENGTH
6
- end
7
- end
8
-
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'Exceptions' do
4
+ it 'has INVALID_MEDIA_LENGTH' do
5
+ Rev::OrderRequestErrorCodes::INVALID_MEDIA_LENGTH.must_equal Rev::OrderRequestErrorCodes::INVALID_AUDIO_LENGTH
6
+ end
7
+ end
8
+
@@ -1,79 +1,79 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'GET /attachments/{id}/content' do
4
- let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
-
6
- filename = './spec/tmp_get_attachment_content'
7
-
8
- before do
9
- File.delete filename if File.file? filename # clean before
10
- end
11
-
12
- after do
13
- File.delete filename if File.file? filename # clean after
14
- end
15
-
16
- describe 'success' do
17
-
18
- describe 'must save binary content to file' do
19
- it 'when no representation given' do
20
- VCR.insert_cassette 'get_attachment_content'
21
- # we just save mocked binary response body to file and check for existence
22
- client.save_attachment_content('4QWoFrwBAAABAAAA', filename) # from order TC0380110305
23
- File.file?(filename).must_equal true
24
-
25
- assert_requested :get, /.*\/api\/v1\/attachments\/4QWoFrwBAAABAAAA\/content/, :times => 1
26
- end
27
-
28
- it 'using given correct representation' do
29
- VCR.insert_cassette 'get_attachment_content_as_pdf'
30
-
31
- client.save_attachment_content('4QWoFrwBAAABAAAA', filename, Rev::Attachment::REPRESENTATIONS[:pdf])
32
- File.file?(filename).must_equal true
33
- # we don't actually check whether it's PDF - we assume it is. We just supply headers as requested
34
- end
35
- end
36
-
37
- it 'must specify Accept-Charset header for plain text' do
38
- VCR.insert_cassette 'get_attachment_content_as_text'
39
-
40
- client.save_attachment_content('4QWoFrwBAAABAAAA', filename, Rev::Attachment::REPRESENTATIONS[:txt])
41
-
42
- assert_requested :get, /.*\/api\/v1\/attachments\/4QWoFrwBAAABAAAA\/content/, :times => 1 do |req|
43
- req.headers['Accept-Charset'].must_equal 'utf-8'
44
- end
45
- end
46
-
47
- it 'must specify Accept-Charset header for youtube transcript' do
48
- VCR.insert_cassette 'get_attachment_content_as_youtube_transcript'
49
-
50
- client.save_attachment_content('4QWoFrwBAAABAAAA', filename, Rev::Attachment::REPRESENTATIONS[:youtube])
51
-
52
- assert_requested :get, /.*\/api\/v1\/attachments\/4QWoFrwBAAABAAAA\/content/, :times => 1 do |req|
53
- req.headers['Accept-Charset'].must_equal 'utf-8'
54
- end
55
- end
56
- end
57
-
58
- it 'must raise NotFoundError when attachment id is invalid' do
59
- VCR.insert_cassette 'get_attachment_content_with_invalid_id'
60
-
61
- action = lambda { client.save_attachment_content('trololo', filename) }
62
- action.must_raise Rev::NotFoundError
63
- end
64
-
65
- # requesting conversion from pdf to :docx from order TC0263917003
66
- it 'must raise NotAcceptableError when requested representation is not supported by API' do
67
- VCR.insert_cassette 'get_attachment_content_unacceptable_representation'
68
-
69
- action = lambda { client.save_attachment_content('yw27D3gCAAABAAAA', filename,
70
- Rev::Attachment::REPRESENTATIONS[:docx]) }
71
- action.must_raise Rev::NotAcceptableError
72
- end
73
-
74
- after do
75
- VCR.eject_cassette
76
- end
77
- end
78
-
79
-
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'GET /attachments/{id}/content' do
4
+ let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
+
6
+ filename = './spec/tmp_get_attachment_content'
7
+
8
+ before do
9
+ File.delete filename if File.file? filename # clean before
10
+ end
11
+
12
+ after do
13
+ File.delete filename if File.file? filename # clean after
14
+ end
15
+
16
+ describe 'success' do
17
+
18
+ describe 'must save binary content to file' do
19
+ it 'when no representation given' do
20
+ VCR.insert_cassette 'get_attachment_content'
21
+ # we just save mocked binary response body to file and check for existence
22
+ client.save_attachment_content('4QWoFrwBAAABAAAA', filename) # from order TC0380110305
23
+ File.file?(filename).must_equal true
24
+
25
+ assert_requested :get, /.*\/api\/v1\/attachments\/4QWoFrwBAAABAAAA\/content/, :times => 1
26
+ end
27
+
28
+ it 'using given correct representation' do
29
+ VCR.insert_cassette 'get_attachment_content_as_pdf'
30
+
31
+ client.save_attachment_content('4QWoFrwBAAABAAAA', filename, Rev::Attachment::REPRESENTATIONS[:pdf])
32
+ File.file?(filename).must_equal true
33
+ # we don't actually check whether it's PDF - we assume it is. We just supply headers as requested
34
+ end
35
+ end
36
+
37
+ it 'must specify Accept-Charset header for plain text' do
38
+ VCR.insert_cassette 'get_attachment_content_as_text'
39
+
40
+ client.save_attachment_content('4QWoFrwBAAABAAAA', filename, Rev::Attachment::REPRESENTATIONS[:txt])
41
+
42
+ assert_requested :get, /.*\/api\/v1\/attachments\/4QWoFrwBAAABAAAA\/content/, :times => 1 do |req|
43
+ req.headers['Accept-Charset'].must_equal 'utf-8'
44
+ end
45
+ end
46
+
47
+ it 'must specify Accept-Charset header for youtube transcript' do
48
+ VCR.insert_cassette 'get_attachment_content_as_youtube_transcript'
49
+
50
+ client.save_attachment_content('4QWoFrwBAAABAAAA', filename, Rev::Attachment::REPRESENTATIONS[:youtube])
51
+
52
+ assert_requested :get, /.*\/api\/v1\/attachments\/4QWoFrwBAAABAAAA\/content/, :times => 1 do |req|
53
+ req.headers['Accept-Charset'].must_equal 'utf-8'
54
+ end
55
+ end
56
+ end
57
+
58
+ it 'must raise NotFoundError when attachment id is invalid' do
59
+ VCR.insert_cassette 'get_attachment_content_with_invalid_id'
60
+
61
+ action = lambda { client.save_attachment_content('trololo', filename) }
62
+ action.must_raise Rev::NotFoundError
63
+ end
64
+
65
+ # requesting conversion from pdf to :docx from order TC0263917003
66
+ it 'must raise NotAcceptableError when requested representation is not supported by API' do
67
+ VCR.insert_cassette 'get_attachment_content_unacceptable_representation'
68
+
69
+ action = lambda { client.save_attachment_content('yw27D3gCAAABAAAA', filename,
70
+ Rev::Attachment::REPRESENTATIONS[:docx]) }
71
+ action.must_raise Rev::NotAcceptableError
72
+ end
73
+
74
+ after do
75
+ VCR.eject_cassette
76
+ end
77
+ end
78
+
79
+
@@ -1,33 +1,33 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'GET /attachments/{id}' do
4
- let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
-
6
- it 'must retrieve metadata' do
7
- VCR.insert_cassette 'get_attachment_metadata'
8
-
9
- attachment = client.get_attachment_metadata('LufnCVQCAAAAAAAA')
10
-
11
- assert_requested :get, /.*\/api\/v1\/attachments\/LufnCVQCAAAAAAAA/, :times => 1
12
-
13
- attachment.id.must_equal 'LufnCVQCAAAAAAAA'
14
- attachment.name.must_equal 'How can I find success in life.mp4'
15
- attachment.kind.must_equal 'media'
16
- attachment.audio_length_seconds.must_equal 300
17
- attachment.links.must_be_instance_of Array
18
- attachment.links.size.must_equal 1
19
- attachment.links.first.rel.must_equal 'content'
20
- attachment.links.first.href.must_equal 'https://www.revtrunk.com/api/v1/attachments/LufnCVQCAAAAAAAA/content'
21
- end
22
-
23
- it 'must raise NotFoundError when attachment id is invalid' do
24
- VCR.insert_cassette 'get_attachment_with_invalid_id'
25
-
26
- action = lambda { client.get_attachment_metadata('trololo') }
27
- action.must_raise Rev::NotFoundError
28
- end
29
-
30
- after do
31
- VCR.eject_cassette
32
- end
33
- end
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'GET /attachments/{id}' do
4
+ let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
+
6
+ it 'must retrieve metadata' do
7
+ VCR.insert_cassette 'get_attachment_metadata'
8
+
9
+ attachment = client.get_attachment_metadata('LufnCVQCAAAAAAAA')
10
+
11
+ assert_requested :get, /.*\/api\/v1\/attachments\/LufnCVQCAAAAAAAA/, :times => 1
12
+
13
+ attachment.id.must_equal 'LufnCVQCAAAAAAAA'
14
+ attachment.name.must_equal 'How can I find success in life.mp4'
15
+ attachment.kind.must_equal 'media'
16
+ attachment.audio_length_seconds.must_equal 300
17
+ attachment.links.must_be_instance_of Array
18
+ attachment.links.size.must_equal 1
19
+ attachment.links.first.rel.must_equal 'content'
20
+ attachment.links.first.href.must_equal 'https://www.revtrunk.com/api/v1/attachments/LufnCVQCAAAAAAAA/content'
21
+ end
22
+
23
+ it 'must raise NotFoundError when attachment id is invalid' do
24
+ VCR.insert_cassette 'get_attachment_with_invalid_id'
25
+
26
+ action = lambda { client.get_attachment_metadata('trololo') }
27
+ action.must_raise Rev::NotFoundError
28
+ end
29
+
30
+ after do
31
+ VCR.eject_cassette
32
+ end
33
+ end
@@ -1,68 +1,68 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe 'GET /orders/{order_num}' do
4
- let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
-
6
- describe 'Transcription' do
7
- before do
8
- VCR.insert_cassette 'get_tc_order'
9
- end
10
-
11
- it 'must get an order by given order number' do
12
- client.get_order('TC0233908691').wont_be_nil
13
-
14
- assert_requested :get, /.*\/api\/v1\/orders\/TC0233908691/, :times => 1
15
- end
16
-
17
- describe 'loaded order' do
18
- let(:order) { client.get_order('TC0233908691') }
19
-
20
- it 'must have basic attributes' do
21
- order.order_number.must_equal 'TC0233908691'
22
- order.price.must_equal 10.0
23
- order.status.must_equal 'Finding Transcriptionist'
24
- order.client_ref.must_equal 'XC123'
25
- end
26
-
27
- it 'must have comments' do
28
- order.comments.size.must_equal 1
29
- order.comments.first.by.must_equal 'Admin Admin'
30
- order.comments.first.text.must_be_empty
31
- order.comments.first.timestamp.day.must_equal 6
32
- order.comments.first.timestamp.month.must_equal 9
33
- order.comments.first.timestamp.year.must_equal 2013
34
- end
35
-
36
- it 'must have attachments' do
37
- order.attachments.size.must_equal 1
38
- order.attachments.first.kind.must_equal 'media'
39
- end
40
-
41
- it 'must have transcription info' do
42
- order.transcription.total_length_seconds.must_equal 600
43
- order.transcription.verbatim.must_equal false
44
- order.transcription.timestamps.must_equal false
45
- end
46
- end
47
- end
48
-
49
- describe 'Translation' do
50
- before do
51
- VCR.insert_cassette 'get_tr_order'
52
- end
53
-
54
- describe 'loaded order' do
55
- let(:order) { client.get_order('TR0116711100') }
56
-
57
- it 'must have translation info' do
58
- order.translation.total_word_count.must_equal 2
59
- order.translation.source_language_code.must_equal 'cs'
60
- order.translation.destination_language_code.must_equal 'en'
61
- end
62
- end
63
- end
64
-
65
- after do
66
- VCR.eject_cassette
67
- end
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'GET /orders/{order_num}' do
4
+ let(:client) { Rev.new('welcome', 'AAAAAu/YjZ3phXU5FsF35yIcgiA=', 'www.revtrunk.com') }
5
+
6
+ describe 'Transcription' do
7
+ before do
8
+ VCR.insert_cassette 'get_tc_order'
9
+ end
10
+
11
+ it 'must get an order by given order number' do
12
+ client.get_order('TC0233908691').wont_be_nil
13
+
14
+ assert_requested :get, /.*\/api\/v1\/orders\/TC0233908691/, :times => 1
15
+ end
16
+
17
+ describe 'loaded order' do
18
+ let(:order) { client.get_order('TC0233908691') }
19
+
20
+ it 'must have basic attributes' do
21
+ order.order_number.must_equal 'TC0233908691'
22
+ order.price.must_equal 10.0
23
+ order.status.must_equal 'Finding Transcriptionist'
24
+ order.client_ref.must_equal 'XC123'
25
+ end
26
+
27
+ it 'must have comments' do
28
+ order.comments.size.must_equal 1
29
+ order.comments.first.by.must_equal 'Admin Admin'
30
+ order.comments.first.text.must_be_empty
31
+ order.comments.first.timestamp.day.must_equal 6
32
+ order.comments.first.timestamp.month.must_equal 9
33
+ order.comments.first.timestamp.year.must_equal 2013
34
+ end
35
+
36
+ it 'must have attachments' do
37
+ order.attachments.size.must_equal 1
38
+ order.attachments.first.kind.must_equal 'media'
39
+ end
40
+
41
+ it 'must have transcription info' do
42
+ order.transcription.total_length_seconds.must_equal 600
43
+ order.transcription.verbatim.must_equal false
44
+ order.transcription.timestamps.must_equal false
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'Translation' do
50
+ before do
51
+ VCR.insert_cassette 'get_tr_order'
52
+ end
53
+
54
+ describe 'loaded order' do
55
+ let(:order) { client.get_order('TR0116711100') }
56
+
57
+ it 'must have translation info' do
58
+ order.translation.total_word_count.must_equal 2
59
+ order.translation.source_language_code.must_equal 'cs'
60
+ order.translation.destination_language_code.must_equal 'en'
61
+ end
62
+ end
63
+ end
64
+
65
+ after do
66
+ VCR.eject_cassette
67
+ end
68
68
  end