rev-api 2.2.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +22 -21
  3. data/.ruby-gemset +1 -1
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +8 -8
  6. data/Gemfile +3 -3
  7. data/LICENSE +191 -191
  8. data/README.md +131 -132
  9. data/Rakefile +13 -13
  10. data/examples/cli.rb +270 -270
  11. data/lib/rev-api.rb +26 -26
  12. data/lib/rev-api/api.rb +326 -326
  13. data/lib/rev-api/api_serializable.rb +30 -30
  14. data/lib/rev-api/exceptions.rb +97 -97
  15. data/lib/rev-api/http_client.rb +97 -97
  16. data/lib/rev-api/models/order.rb +129 -130
  17. data/lib/rev-api/models/order_request.rb +292 -194
  18. data/lib/rev-api/version.rb +3 -3
  19. data/rev-api.gemspec +33 -34
  20. data/spec/fixtures/api_cassettes/cancel_order.yml +38 -38
  21. data/spec/fixtures/api_cassettes/cancel_order_not_allowed.yml +40 -40
  22. data/spec/fixtures/api_cassettes/get_attachment_content.yml +399 -399
  23. data/spec/fixtures/api_cassettes/get_attachment_content_as_pdf.yml +399 -399
  24. data/spec/fixtures/api_cassettes/get_attachment_content_as_text.yml +65 -65
  25. data/spec/fixtures/api_cassettes/get_attachment_content_as_youtube_transcript.yml +66 -66
  26. data/spec/fixtures/api_cassettes/get_attachment_content_unacceptable_representation.yml +42 -42
  27. data/spec/fixtures/api_cassettes/get_attachment_content_with_invalid_id.yml +42 -42
  28. data/spec/fixtures/api_cassettes/get_attachment_metadata.yml +42 -42
  29. data/spec/fixtures/api_cassettes/get_attachment_with_invalid_id.yml +40 -40
  30. data/spec/fixtures/api_cassettes/get_orders.yml +122 -122
  31. data/spec/fixtures/api_cassettes/get_orders_with_clientRef.yml +41 -41
  32. data/spec/fixtures/api_cassettes/get_tc_order.yml +44 -44
  33. data/spec/fixtures/api_cassettes/get_third_page_of_orders.yml +52 -52
  34. data/spec/fixtures/api_cassettes/link_input.yml +44 -44
  35. data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -44
  36. data/spec/fixtures/api_cassettes/link_input_with_spaces_in_filename.yml +45 -45
  37. data/spec/fixtures/api_cassettes/not_found_order.yml +42 -42
  38. data/spec/fixtures/api_cassettes/submit_cp_order.yml +44 -45
  39. data/spec/fixtures/api_cassettes/submit_su_order.yml +44 -45
  40. data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +44 -45
  41. data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -45
  42. data/spec/fixtures/api_cassettes/submit_tc_order_without_specifying_payment.yml +44 -45
  43. data/spec/fixtures/api_cassettes/unauthorized.yml +42 -42
  44. data/spec/fixtures/api_cassettes/upload_input.yml +90 -90
  45. data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +91 -91
  46. data/spec/lib/rev/api_spec.rb +30 -24
  47. data/spec/lib/rev/cancel_order_spec.rb +24 -24
  48. data/spec/lib/rev/exceptions_spec.rb +8 -8
  49. data/spec/lib/rev/get_attachment_content_spec.rb +79 -79
  50. data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -33
  51. data/spec/lib/rev/get_order_spec.rb +52 -52
  52. data/spec/lib/rev/get_orders_spec.rb +62 -62
  53. data/spec/lib/rev/http_client_spec.rb +32 -32
  54. data/spec/lib/rev/models/order_request_spec.rb +122 -11
  55. data/spec/lib/rev/models/order_spec.rb +58 -58
  56. data/spec/lib/rev/post_inputs_spec.rb +94 -94
  57. data/spec/lib/rev/post_order_spec.rb +163 -163
  58. data/spec/spec_helper.rb +47 -49
  59. data/spec/test_helpers.rb +5 -0
  60. metadata +54 -69
  61. data/.coveralls.yml +0 -2
@@ -1,194 +1,292 @@
1
- require 'rev-api/api_serializable'
2
-
3
- module Rev
4
- # OrderRequest is used for constructing order 'spec' in consumer code and passing it into.
5
- # It consists of three main elements: :payment, :transcription_options and :notification.
6
- # You can also supply reference number, customer comment, and whether standard turnaround time is not required
7
- #
8
- # @note https://www.rev.com/api/ordersposttranscription, https://www.rev.com/api/orderspostcaption
9
- class OrderRequest < ApiSerializable
10
- # see {Rev::Payment}
11
- attr_reader :payment
12
-
13
- # see {Rev::TranscriptionOptions}
14
- attr_reader :transcription_options
15
-
16
- # see {Rev::CaptionOptions}
17
- attr_reader :caption_options
18
-
19
- # see {Rev::Notification}
20
- attr_reader :notification
21
-
22
- # a reference number for the order meaningful for the client (optional)
23
- attr_reader :client_ref
24
-
25
- # a comment with any special messages about the order (optional)
26
- attr_reader :comment
27
-
28
- # a boolean flag specifying whether normal turnaround time is not required, defaults to false (optional)
29
- attr_reader :non_standard_tat_guarantee
30
-
31
- # @param payment [Payment] payment info
32
- # @param fields [Hash] of fields to initialize instance. See instance attributes for available fields.
33
- # @deprecated payment always defaults to :account_balance
34
- def self.new_with_payment(payment, fields = {})
35
- fields = { :non_standard_tat_guarantee => false }.merge(fields)
36
- super fields
37
- @payment = payment
38
- end
39
-
40
- # @param fields [Hash] of fields to initialize instance. See instance attributes for available fields.
41
- def initialize(fields = {})
42
- fields = { :non_standard_tat_guarantee => false }.merge(fields)
43
- @payment = Rev::Payment.with_account_balance
44
- super fields
45
- end
46
- end
47
-
48
- # Payment Info. Payment can only be done by debiting the user's account balance.
49
- # @deprecated setting the payment is no longer necessary. All orders now default to :account_balance
50
- class Payment < ApiSerializable
51
- attr_accessor :type
52
-
53
- # use to correctly set payment type
54
- TYPES = {
55
- :account_balance => 'AccountBalance'
56
- }
57
-
58
- CC_ON_FILE_ID = 1
59
-
60
- # @param type [String] payment method
61
- def initialize(type)
62
- @type = type
63
- end
64
-
65
- class << self
66
- def with_account_balance()
67
- Payment::new(TYPES[:account_balance])
68
- end
69
- end
70
- end
71
-
72
- # Billing address
73
- class BillingAddress < ApiSerializable
74
- attr_reader :street, :street2, :city, :state, :zip, :country_alpha2
75
- end
76
-
77
- # Superclass for the business-line options that handles capture and common validation of inputs.
78
- class InputOptions < ApiSerializable
79
- # Mandatory, contains list of inputs. Must have at least one element.
80
- attr_reader :inputs
81
-
82
- # @param inputs [Array] list of inputs
83
- # @param info [Hash] of fields to initialize instance.
84
- def initialize(inputs, info = {})
85
- super info
86
- raise(ArgumentError, "inputs must have at least one element") unless validate_inputs(inputs)
87
- @inputs = inputs
88
- end
89
-
90
- private
91
-
92
- def validate_inputs(inputs)
93
- !inputs.nil? && inputs.length > 0
94
- end
95
- end
96
-
97
- # Transcription options. This section contains the input media that must be transferred to our servers
98
- # using a POST to /inputs, and are referenced using the URIs returned by that call. We also support external links.
99
- # @see https://www.rev.com/api/ordersposttranscription
100
- class TranscriptionOptions < InputOptions
101
- # Optional, should we transcribe the provided files verbatim? If true,
102
- # all filler words (i.e. umm, huh) will be included.
103
- attr_reader :verbatim
104
-
105
- # Optional, should we include timestamps?
106
- attr_reader :timestamps
107
-
108
- # @param inputs [Array] list of inputs
109
- # @param info [Hash] of fields to initialize instance. May contain:
110
- # - :verbatim => true/false
111
- # - :timestamps => true/false
112
- def initialize(inputs, info = {})
113
- super inputs, info
114
- end
115
- end
116
-
117
- # Caption options. This section contains the input media that must be transferred to our servers
118
- # using a POST to /inputs, and are referenced using the URIs returned by that call. We also support external links.
119
- # @see https://www.rev.com/api/orderspostcaption
120
- class CaptionOptions < InputOptions
121
- # Array of file formats the captions should be delivered as. (Optional, default is SubRip)
122
- attr_reader :output_file_formats
123
-
124
- # Optional, Array of language codes to request foreign language subtitles
125
- attr_reader :subtitle_languages
126
-
127
- # All supported output file formats
128
- OUTPUT_FILE_FORMATS = {
129
- :subrip => 'SubRip',
130
- :scc => 'Scc',
131
- :mcc => 'Mcc',
132
- :ttml => 'Ttml',
133
- :qttext => 'QTtext',
134
- :transcript => 'Transcript',
135
- :webvtt => 'WebVtt',
136
- :dfxp => 'Dfxp',
137
- :cheetahcap => 'CheetahCap'
138
- }
139
-
140
- # @param inputs [Array] list of inputs
141
- # @param info [Hash] of fields to initialize instance. May contain:
142
- # - :subtitle_languages
143
- # @see For language codes refer to http://www.loc.gov/standards/iso639-2/php/code_list.php
144
- def initialize(inputs, info = {})
145
- super(inputs, info)
146
- raise(ArgumentError, "invalid format(s)") unless validate_output_formats(info[:output_file_formats])
147
- end
148
-
149
- private
150
-
151
- def validate_output_formats(formats)
152
- formats.nil? || formats.select{|f| !OUTPUT_FILE_FORMATS.has_value?(f) }.empty?
153
- end
154
- end
155
-
156
- # Input for order (aka source file)
157
- class Input < ApiSerializable
158
- # Length of audio in seconds (mandatory in case of inability to determine it automatically).
159
- # Used within {Rev::OrderRequest::TranscriptionInfo}
160
- attr_reader :audio_length_seconds
161
-
162
- # Length of video in seconds (mandatory in case of inability to determine it automatically).
163
- # Used within {Rev::OrderRequest::CaptionInfo}
164
- attr_reader :video_length_seconds
165
-
166
- # Mandatory, URI of the media, as returned from the call to POST /inputs.
167
- # :external_link might substitute :uri for Transcription or Caption.
168
- attr_reader :uri
169
-
170
- # External URL, if sources wasn't POSTed as input (YouTube, Vimeo, Dropbox, etc)
171
- attr_reader :external_link
172
- end
173
-
174
- # Notification Info. Optionally you may request that an HTTP post be made to a url of your choice when the order enters
175
- # a new status (eg being transcribed or reviewed) and when it is complete.
176
- class Notification < ApiSerializable
177
- attr_reader :url, :level
178
-
179
- # Notification levels
180
- LEVELS = {
181
- :detailed => 'Detailed',
182
- :final_only => 'FinalOnly'
183
- }
184
-
185
- # @param url [String] The url for notifications. Mandatory if the notifications element is used. Updates will be posted to this URL
186
- # @param level [String] Optional, specifies which notifications are sent:
187
- # - :detailed - a notification is sent whenever the order is in a new status or has a new comment
188
- # - :final_only - (the default), notification is sent only when the order is complete
189
- def initialize(url, level = nil)
190
- @url = url
191
- @level = level ? level : LEVELS[:final_only]
192
- end
193
- end
194
- end
1
+ require 'rev-api/api_serializable'
2
+
3
+ module Rev
4
+ # OrderRequest is used for constructing order 'spec' in consumer code and passing it into.
5
+ # It consists of three main elements: :payment, :transcription_options and :notification.
6
+ # You can also supply reference number and whether standard turnaround time is not required
7
+ #
8
+ # @note https://www.rev.com/api/ordersposttranscription, https://www.rev.com/api/orderspostcaption
9
+
10
+ GLOSSARY_ENTRIES_LIMIT = 1000
11
+ GLOSSARY_ENTRY_LENGTH_LIMIT = 255
12
+ SPEAKER_ENTRIES_LIMIT = 100
13
+ SPEAKER_ENTRY_LENGTH_LIMIT = 15
14
+
15
+ class OrderRequest < ApiSerializable
16
+ # see {Rev::Payment}
17
+ attr_reader :payment
18
+
19
+ # see {Rev::TranscriptionOptions}
20
+ attr_reader :transcription_options
21
+
22
+ # see {Rev::CaptionOptions}
23
+ attr_reader :caption_options
24
+
25
+ # see {Rev::Notification}
26
+ attr_reader :notification
27
+
28
+ # a reference number for the order meaningful for the client (optional)
29
+ attr_reader :client_ref
30
+
31
+ # a boolean flag specifying whether normal turnaround time is not required, defaults to false (optional)
32
+ attr_reader :non_standard_tat_guarantee
33
+
34
+ # @param payment [Payment] payment info
35
+ # @param fields [Hash] of fields to initialize instance. See instance attributes for available fields.
36
+ # @deprecated payment always defaults to :account_balance
37
+ def self.new_with_payment(payment, fields = {})
38
+ fields = { :non_standard_tat_guarantee => false }.merge(fields)
39
+ super fields
40
+ @payment = payment
41
+ end
42
+
43
+ # @param fields [Hash] of fields to initialize instance. See instance attributes for available fields.
44
+ def initialize(fields = {})
45
+ fields = { :non_standard_tat_guarantee => false }.merge(fields)
46
+ @payment = Rev::Payment.with_account_balance
47
+ super fields
48
+ end
49
+ end
50
+
51
+ # Payment Info. Payment can only be done by debiting the user's account balance.
52
+ # @deprecated setting the payment is no longer necessary. All orders now default to :account_balance
53
+ class Payment < ApiSerializable
54
+ attr_accessor :type
55
+
56
+ # use to correctly set payment type
57
+ TYPES = {
58
+ :account_balance => 'AccountBalance'
59
+ }
60
+
61
+ CC_ON_FILE_ID = 1
62
+
63
+ # @param type [String] payment method
64
+ def initialize(type)
65
+ @type = type
66
+ end
67
+
68
+ class << self
69
+ def with_account_balance()
70
+ Payment::new(TYPES[:account_balance])
71
+ end
72
+ end
73
+ end
74
+
75
+ # Billing address
76
+ class BillingAddress < ApiSerializable
77
+ attr_reader :street, :street2, :city, :state, :zip, :country_alpha2
78
+ end
79
+
80
+ # Superclass for the business-line options that handles capture and common validation of inputs.
81
+ class InputOptions < ApiSerializable
82
+ # Mandatory, contains list of inputs. Must have at least one element.
83
+ attr_reader :inputs
84
+
85
+ # @param inputs [Array] list of inputs
86
+ # @param info [Hash] of fields to initialize instance.
87
+ def initialize(inputs, info = {})
88
+ super info
89
+ raise(ArgumentError, "inputs must have at least one element") unless validate_inputs(inputs)
90
+ @inputs = inputs
91
+ end
92
+
93
+ private
94
+
95
+ def validate_inputs(inputs)
96
+ !inputs.nil? && inputs.length > 0
97
+ end
98
+ end
99
+
100
+ # Transcription options. This section contains the input media that must be transferred to our servers
101
+ # using a POST to /inputs, and are referenced using the URIs returned by that call. We also support external links.
102
+ # @see https://www.rev.com/api/ordersposttranscription
103
+ class TranscriptionOptions < InputOptions
104
+ # Optional, array of file formats the captions should be delivered as.
105
+ # default is MS Word
106
+ attr_reader :output_file_formats
107
+
108
+ # Optional, should we transcribe the provided files verbatim? If true,
109
+ # all filler words (i.e. umm, huh) will be included.
110
+ attr_reader :verbatim
111
+
112
+ # Optional, should we include timestamps?
113
+ attr_reader :timestamps
114
+
115
+ # All supported output file formats
116
+ OUTPUT_FILE_FORMATS = {
117
+ :ms_word => 'MS Word',
118
+ :json => 'JSON',
119
+ :text => 'Text',
120
+ :pdf => 'Pdf'
121
+ }
122
+
123
+ # @param inputs [Array] list of inputs
124
+ # @param info [Hash] of fields to initialize instance. May contain:
125
+ # - :output_file_formats => String[]
126
+ # - :verbatim => true/false
127
+ # - :timestamps => true/false
128
+ def initialize(inputs, info = {})
129
+ super inputs, info
130
+ raise(ArgumentError, "invalid format(s)") unless validate_output_formats(info[:output_file_formats])
131
+ options_validation(inputs)
132
+ end
133
+
134
+ private
135
+
136
+ def validate_output_formats(formats)
137
+ formats.nil? || formats.select{|f| !OUTPUT_FILE_FORMATS.has_value?(f) }.empty?
138
+ end
139
+
140
+ def options_validation(inputs)
141
+ inputs.each { |input|
142
+ input.validate_glossary
143
+ input.validate_speakers
144
+ input.validate_accents
145
+ }
146
+ end
147
+ end
148
+
149
+ # Caption options. This section contains the input media that must be transferred to our servers
150
+ # using a POST to /inputs, and are referenced using the URIs returned by that call. We also support external links.
151
+ # @see https://www.rev.com/api/orderspostcaption
152
+ class CaptionOptions < InputOptions
153
+ # Array of file formats the captions should be delivered as. (Optional, default is SubRip)
154
+ attr_reader :output_file_formats
155
+
156
+ # Optional, Array of language codes to request foreign language subtitles
157
+ attr_reader :subtitle_languages
158
+
159
+ # All supported output file formats
160
+ OUTPUT_FILE_FORMATS = {
161
+ :subrip => 'SubRip',
162
+ :scc => 'Scc',
163
+ :mcc => 'Mcc',
164
+ :ttml => 'Ttml',
165
+ :qttext => 'QTtext',
166
+ :transcript => 'Transcript',
167
+ :webvtt => 'WebVtt',
168
+ :dfxp => 'Dfxp',
169
+ :cheetahcap => 'CheetahCap'
170
+ }
171
+
172
+ # @param inputs [Array] list of inputs
173
+ # @param info [Hash] of fields to initialize instance. May contain:
174
+ # - :output_file_formats => String[]
175
+ # - :subtitle_languages => String[]
176
+ # @see For language codes refer to http://www.loc.gov/standards/iso639-2/php/code_list.php
177
+ def initialize(inputs, info = {})
178
+ super(inputs, info)
179
+ raise(ArgumentError, "invalid format(s)") unless validate_output_formats(info[:output_file_formats])
180
+ options_validation(inputs)
181
+ end
182
+
183
+ private
184
+
185
+ def validate_output_formats(formats)
186
+ formats.nil? || formats.select{|f| !OUTPUT_FILE_FORMATS.has_value?(f) }.empty?
187
+ end
188
+
189
+ def options_validation(inputs)
190
+ inputs.each { |input|
191
+ input.validate_glossary
192
+ input.validate_speakers
193
+ }
194
+ end
195
+ end
196
+
197
+ # Input for order (aka source file)
198
+ class Input < ApiSerializable
199
+ # Length of audio in seconds (mandatory in case of inability to determine it automatically).
200
+ # Used within {Rev::OrderRequest::TranscriptionInfo}
201
+ attr_reader :audio_length_seconds
202
+
203
+ # Length of video in seconds (mandatory in case of inability to determine it automatically).
204
+ # Used within {Rev::OrderRequest::CaptionInfo}
205
+ attr_reader :video_length_seconds
206
+
207
+ # Mandatory, URI of the media, as returned from the call to POST /inputs.
208
+ # :external_link might substitute :uri for Transcription or Caption.
209
+ attr_reader :uri
210
+
211
+ # External URL, if sources wasn't POSTed as input (YouTube, Vimeo, Dropbox, etc)
212
+ attr_reader :external_link
213
+
214
+ # Optional, list of glossary entries.
215
+ attr_reader :glossary
216
+
217
+ # Optional, list of speaker names.
218
+ attr_reader :speakers
219
+
220
+ # Optional, list of accents.
221
+ attr_reader :accents
222
+
223
+ SUPPORTED_ACCENTS = {
224
+ :american_neutral => 'AmericanNeutral',
225
+ :american_southern => 'AmericanSouthern',
226
+ :asian => 'Asian',
227
+ :australian => 'Australian',
228
+ :british => 'British',
229
+ :indian => 'Indian',
230
+ :other => 'Other',
231
+ :unknown => 'Unknown'
232
+ }
233
+
234
+ def validate_glossary
235
+ if glossary
236
+ if glossary.length > GLOSSARY_ENTRIES_LIMIT
237
+ raise(ArgumentError, "Glossary must not exceed #{GLOSSARY_ENTRIES_LIMIT} entries")
238
+ end
239
+ glossary.each { |term|
240
+ if term.length > GLOSSARY_ENTRY_LENGTH_LIMIT
241
+ raise(ArgumentError, "Glossary entries cannot exceed #{GLOSSARY_ENTRY_LENGTH_LIMIT} characters")
242
+ end
243
+ }
244
+ end
245
+ end
246
+
247
+ def validate_speakers
248
+ if speakers
249
+ if speakers.length > SPEAKER_ENTRIES_LIMIT
250
+ raise(ArgumentError, "Speaker list must not exceed #{SPEAKER_ENTRIES_LIMIT} entries")
251
+ end
252
+ speakers.each { |speaker|
253
+ if speaker.length > SPEAKER_ENTRY_LENGTH_LIMIT
254
+ raise(ArgumentError, "Speaker name cannot exceed #{SPEAKER_ENTRY_LENGTH_LIMIT} characters")
255
+ end
256
+ }
257
+ end
258
+ end
259
+
260
+ def validate_accents
261
+ if accents
262
+ if accents.length > SUPPORTED_ACCENTS.length
263
+ raise(ArgumentError, "Length of accents list cannot exceed number of supported accents.")
264
+ end
265
+ if accents.any?{ |accent| !Rev::Input::SUPPORTED_ACCENTS.has_value?(accent) }
266
+ raise(ArgumentError, 'Unsupported accent provided')
267
+ end
268
+ end
269
+ end
270
+ end
271
+
272
+ # Notification Info. Optionally you may request that an HTTP post be made to a url of your choice when the order enters
273
+ # a new status (eg being transcribed or reviewed) and when it is complete.
274
+ class Notification < ApiSerializable
275
+ attr_reader :url, :level
276
+
277
+ # Notification levels
278
+ LEVELS = {
279
+ :detailed => 'Detailed',
280
+ :final_only => 'FinalOnly'
281
+ }
282
+
283
+ # @param url [String] The url for notifications. Mandatory if the notifications element is used. Updates will be posted to this URL
284
+ # @param level [String] Optional, specifies which notifications are sent:
285
+ # - :detailed - a notification is sent whenever the order is in a new status or has a new comment
286
+ # - :final_only - (the default), notification is sent only when the order is complete
287
+ def initialize(url, level = nil)
288
+ @url = url
289
+ @level = level ? level : LEVELS[:final_only]
290
+ end
291
+ end
292
+ end