rev-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +42 -0
  7. data/LICENSE +191 -0
  8. data/README.md +124 -0
  9. data/Rakefile +14 -0
  10. data/examples/cli.rb +200 -0
  11. data/lib/rev-api.rb +26 -0
  12. data/lib/rev-api/api.rb +311 -0
  13. data/lib/rev-api/api_serializable.rb +30 -0
  14. data/lib/rev-api/exceptions.rb +108 -0
  15. data/lib/rev-api/http_client.rb +97 -0
  16. data/lib/rev-api/models/order.rb +113 -0
  17. data/lib/rev-api/models/order_request.rb +183 -0
  18. data/lib/rev-api/version.rb +3 -0
  19. data/rev-api.gemspec +33 -0
  20. data/spec/fixtures/api_cassettes/cancel_order.yml +38 -0
  21. data/spec/fixtures/api_cassettes/cancel_order_not_allowed.yml +40 -0
  22. data/spec/fixtures/api_cassettes/get_attachment_content.yml +399 -0
  23. data/spec/fixtures/api_cassettes/get_attachment_content_as_pdf.yml +399 -0
  24. data/spec/fixtures/api_cassettes/get_attachment_content_as_text.yml +65 -0
  25. data/spec/fixtures/api_cassettes/get_attachment_content_as_youtube_transcript.yml +66 -0
  26. data/spec/fixtures/api_cassettes/get_attachment_content_unacceptable_representation.yml +42 -0
  27. data/spec/fixtures/api_cassettes/get_attachment_content_with_invalid_id.yml +42 -0
  28. data/spec/fixtures/api_cassettes/get_attachment_metadata.yml +42 -0
  29. data/spec/fixtures/api_cassettes/get_attachment_with_invalid_id.yml +40 -0
  30. data/spec/fixtures/api_cassettes/get_orders.yml +122 -0
  31. data/spec/fixtures/api_cassettes/get_tc_order.yml +44 -0
  32. data/spec/fixtures/api_cassettes/get_third_page_of_orders.yml +58 -0
  33. data/spec/fixtures/api_cassettes/get_tr_order.yml +44 -0
  34. data/spec/fixtures/api_cassettes/link_input.yml +44 -0
  35. data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -0
  36. data/spec/fixtures/api_cassettes/not_found_order.yml +42 -0
  37. data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +45 -0
  38. data/spec/fixtures/api_cassettes/submit_tc_order_with_cc_and_all_attributes.yml +46 -0
  39. data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -0
  40. data/spec/fixtures/api_cassettes/submit_tc_order_with_saved_cc.yml +45 -0
  41. data/spec/fixtures/api_cassettes/submit_tr_order.yml +44 -0
  42. data/spec/fixtures/api_cassettes/unauthorized.yml +42 -0
  43. data/spec/fixtures/api_cassettes/upload_input.yml +130 -0
  44. data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +131 -0
  45. data/spec/fixtures/sourcedocument.png +0 -0
  46. data/spec/lib/rev/api_spec.rb +24 -0
  47. data/spec/lib/rev/cancel_order_spec.rb +25 -0
  48. data/spec/lib/rev/get_attachment_content_spec.rb +79 -0
  49. data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -0
  50. data/spec/lib/rev/get_order_spec.rb +68 -0
  51. data/spec/lib/rev/get_orders_spec.rb +39 -0
  52. data/spec/lib/rev/http_client_spec.rb +32 -0
  53. data/spec/lib/rev/post_inputs_spec.rb +75 -0
  54. data/spec/lib/rev/post_order_spec.rb +207 -0
  55. data/spec/spec_helper.rb +31 -0
  56. metadata +248 -0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api-sandbox.rev.com/api/v1/orders?page=0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Rev welcome:trololo
12
+ User-Agent:
13
+ - RevOfficialRubySDK/1.0.0
14
+ response:
15
+ status:
16
+ code: 401
17
+ message: Unauthorized
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Expires:
24
+ - '-1'
25
+ Server:
26
+ - Microsoft-IIS/8.0
27
+ Www-Authenticate:
28
+ - Rev
29
+ X-Miniprofiler-Ids:
30
+ - ! '["5b5d655c-3f79-4e76-8e24-c6e36b7170fb"]'
31
+ X-Powered-By:
32
+ - ASP.NET
33
+ Date:
34
+ - Thu, 12 Sep 2013 18:38:00 GMT
35
+ Content-Length:
36
+ - '0'
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ''
40
+ http_version:
41
+ recorded_at: Thu, 12 Sep 2013 18:38:05 GMT
42
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,130 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.revtrunk.com/api/v1/inputs
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! 'iVBORw0KGgoAAAANSUhEUgAAAHMAAAAyCAYAAABvR+QvAAAGtklEQVR42u2c
9
+
10
+ z2scZRjH9w9QMxFBPEhHm7Smoe2ANGnamAxWqEqR9SIKoiOoeJIRc/Ako0gR
11
+
12
+ L4N48eTQowcdCAgWU6dumzSpttOiF0+DB3+kye5E/Bk1Xd/ZPKNvJzu77/O+
13
+
14
+ z0w2dA9fFtLu7Mz7eZ+f7ztvpdlsVjqpcWiocF1YnD8Gev7C4kLtRs2vMTUl
15
+
16
+ tZa53iz721ugGe53B8t4Thl148OrIgBTZ6oyORKymUyqB5u/GmpMJshicphc
17
+
18
+ poApZGoqKoJreXDt5DfMHQ8TIIRMTRKN7zm1OnXgoaIfngOewg4AkiroGK6V
19
+
20
+ QjZ2BEx2EYsM4la52zXLvzz9ycOLC+dmwPIoLLkJgF0ArHe7BzahB9nEfg7G
21
+
22
+ IUhVnxh5tSiYUYEwE3m9EpPAihNr88H6KFx1MlmszG8locrvMi4mKUx2AaNg
23
+
24
+ kKmsXkw4EvfJuWcVqK+3LPGB/Xewz88Ex4QcZrUkmFGvZpCpLp6du33p3NkX
25
+
26
+ F766eApptR8n3//xsem72OfXiDHRqWE6JcFsgheo7BQxSFVwoZ1Ahovnv7iF
27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1QWWYR2kfftC7rVBOSfTL8xTSK2opC6WU8y/lmKDQPVJTdZ
59
+
60
+ YXdTiIJMLPJXptcQW1BcqlpTpiwJFLLCoEdgUiRd7UD+wjSL3E9EVZroKj1Z
61
+
62
+ 2YHRFWJmlNm8xTcPUpcbgDXFHXYYUIHcyIC8xHQbAiRV08BrNQ1Wpw7cq+gq
63
+
64
+ XcXJUPYapkkEM60j15l+hok2itzhR/UOjL4Jc3L0mGKJUVWsOf0dBpN3r+sQ
65
+
66
+ I1eZnkC6V6pGe/W/Rnv96L4ZxcHRJAbEUEiithMm717XIWut18f3vokE6VA2
67
+
68
+ 2P+HOTHynuK+H5lWoKP4fZXOEwXMdShBkvH4AAmSKk5u2bVXYbOqRrAPBhs3
69
+
70
+ 7Tb1ZhGx01NccmsHM60lk4QnWJk+OIAA6VE11dvuAWqMDa8RNMyxy1h6zl4a
71
+
72
+ 6j6tTtzcT2H+zlQTzVwh2QmIXhc0cnfnMZhXERA6dVhiQcvutO1fAxesaqVx
73
+
74
+ l43PmoRrT5OexCrfZhpAdHgoFqG9bjvcN9/k3XR7Pv8mLycf/r3bW8F69m1g
75
+
76
+ 7vsO8o0vDazdRVhR2uazEM0FC+4vEoi9yfsjyablXYIQdaKMVWgDtOgBFb0m
77
+
78
+ vZdfBQSX6hBBtKhPG+kLBzEmgGinb4L1YZYLUYd4pgoxbHMOQh9mSRAtggw1
79
+
80
+ holglHWoU183Hl5BYYV+OyvswyzvHIOIwAIt/q3oPsxyYqBNcC5QCAmR0jkL
81
+
82
+ fZh412kTWF96FJuJtb4+THlwVYJDm/gj1gqteW96mAAtPUbNkwQXZ064NEXO
83
+
84
+ xuvDxMc0k4OVnnsXIGJcehRpamEOuFqzrNMqb0qYXExzEKpywE3qONarMP8F
85
+
86
+ PE/RzQd+eHkAAAAASUVORK5CYII=
87
+
88
+ '
89
+ headers:
90
+ Accept:
91
+ - ! '*/*'
92
+ Content-Disposition:
93
+ - attachment; filename=sourcedocument.png
94
+ Content-Type:
95
+ - image/png
96
+ Content-Length:
97
+ - '1775'
98
+ Authorization:
99
+ - Rev welcome:AAAAAu/YjZ3phXU5FsF35yIcgiA=
100
+ User-Agent:
101
+ - RevOfficialRubySDK/1.0.0
102
+ response:
103
+ status:
104
+ code: 201
105
+ message: Created
106
+ headers:
107
+ Cache-Control:
108
+ - no-cache
109
+ Pragma:
110
+ - no-cache
111
+ Expires:
112
+ - '-1'
113
+ Location:
114
+ - urn:foxtranslate:inputmedia:SnVwbG9hZHMvMjAxMy0wOS0xNy9lMzk4MWIzNS0wNzM1LTRlMDAtODY1NC1jNWY4ZjE4MzdlMTIvc291cmNlZG9jdW1lbnQucG5n
115
+ Server:
116
+ - Microsoft-IIS/7.5
117
+ X-Miniprofiler-Ids:
118
+ - ! '["bda0d010-c658-4ff5-a201-4b1395adf2e6","5ef43220-60f5-458c-9ebb-864d8349345c"]'
119
+ X-Powered-By:
120
+ - ASP.NET
121
+ Date:
122
+ - Tue, 17 Sep 2013 21:42:29 GMT
123
+ Content-Length:
124
+ - '0'
125
+ body:
126
+ encoding: US-ASCII
127
+ string: ''
128
+ http_version:
129
+ recorded_at: Tue, 17 Sep 2013 21:42:29 GMT
130
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,131 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.revtrunk.com/api/v1/inputs
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! 'iVBORw0KGgoAAAANSUhEUgAAAHMAAAAyCAYAAABvR+QvAAAGtklEQVR42u2c
9
+
10
+ z2scZRjH9w9QMxFBPEhHm7Smoe2ANGnamAxWqEqR9SIKoiOoeJIRc/Ako0gR
11
+
12
+ L4N48eTQowcdCAgWU6dumzSpttOiF0+DB3+kye5E/Bk1Xd/ZPKNvJzu77/O+
13
+
14
+ z0w2dA9fFtLu7Mz7eZ+f7ztvpdlsVjqpcWiocF1YnD8Gev7C4kLtRs2vMTUl
15
+
16
+ tZa53iz721ugGe53B8t4Th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6hBBtKhPG+kLBzEmgGinb4L1YZYLUYd4pgoxbHMOQh9mSRAtggw1
79
+
80
+ holglHWoU183Hl5BYYV+OyvswyzvHIOIwAIt/q3oPsxyYqBNcC5QCAmR0jkL
81
+
82
+ fZh412kTWF96FJuJtb4+THlwVYJDm/gj1gqteW96mAAtPUbNkwQXZ064NEXO
83
+
84
+ xuvDxMc0k4OVnnsXIGJcehRpamEOuFqzrNMqb0qYXExzEKpywE3qONarMP8F
85
+
86
+ PE/RzQd+eHkAAAAASUVORK5CYII=
87
+
88
+ '
89
+ headers:
90
+ Accept:
91
+ - ! '*/*'
92
+ Content-Disposition:
93
+ - attachment; filename=sourcedocument.png
94
+ Content-Type:
95
+ - trololo
96
+ Content-Length:
97
+ - '1775'
98
+ Authorization:
99
+ - Rev welcome:AAAAAu/YjZ3phXU5FsF35yIcgiA=
100
+ User-Agent:
101
+ - RevOfficialRubySDK/1.0.0
102
+ response:
103
+ status:
104
+ code: 400
105
+ message: Bad Request
106
+ headers:
107
+ Cache-Control:
108
+ - no-cache
109
+ Pragma:
110
+ - no-cache
111
+ Content-Type:
112
+ - application/json; charset=utf-8
113
+ Expires:
114
+ - '-1'
115
+ Server:
116
+ - Microsoft-IIS/7.5
117
+ X-Miniprofiler-Ids:
118
+ - ! '["898ff908-ed7d-4ba9-a7d4-1ef77477b595","9fe829e6-5487-4079-bc96-5c95abf1cf80","e7f8c536-dacd-4a4e-a594-e1660295c0f5","dabe1796-e497-463b-946e-bbedf84dddcb"]'
119
+ X-Powered-By:
120
+ - ASP.NET
121
+ Date:
122
+ - Tue, 17 Sep 2013 21:25:06 GMT
123
+ Content-Length:
124
+ - '112'
125
+ body:
126
+ encoding: US-ASCII
127
+ string: ! '{"code":10001,"message":"The content-type explicitly specified in
128
+ the request is not supported for input media"}'
129
+ http_version:
130
+ recorded_at: Tue, 17 Sep 2013 21:25:06 GMT
131
+ recorded_with: VCR 2.5.0
@@ -0,0 +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
@@ -0,0 +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
25
+ end
@@ -0,0 +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
+
@@ -0,0 +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.must_equal 5
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