lib/rev-api/models/order_request.rb in rev-api-2.2.1 vs lib/rev-api/models/order_request.rb in rev-api-2.3.0
- old
+ new
@@ -4,10 +4,16 @@
# OrderRequest is used for constructing order 'spec' in consumer code and passing it into.
# It consists of three main elements: :payment, :transcription_options and :notification.
# You can also supply reference number, customer comment, and whether standard turnaround time is not required
#
# @note https://www.rev.com/api/ordersposttranscription, https://www.rev.com/api/orderspostcaption
+
+ GLOSSARY_ENTRIES_LIMIT = 1000
+ GLOSSARY_ENTRY_LENGTH_LIMIT = 255
+ SPEAKER_ENTRIES_LIMIT = 100
+ SPEAKER_ENTRY_LENGTH_LIMIT = 15
+
class OrderRequest < ApiSerializable
# see {Rev::Payment}
attr_reader :payment
# see {Rev::TranscriptionOptions}
@@ -109,11 +115,22 @@
# @param info [Hash] of fields to initialize instance. May contain:
# - :verbatim => true/false
# - :timestamps => true/false
def initialize(inputs, info = {})
super inputs, info
+ options_validation(inputs)
end
+
+ private
+
+ def options_validation(inputs)
+ inputs.each { |input|
+ input.validate_glossary
+ input.validate_speakers
+ input.validate_accents
+ }
+ end
end
# Caption options. This section contains the input media that must be transferred to our servers
# using a POST to /inputs, and are referenced using the URIs returned by that call. We also support external links.
# @see https://www.rev.com/api/orderspostcaption
@@ -142,17 +159,25 @@
# - :subtitle_languages
# @see For language codes refer to http://www.loc.gov/standards/iso639-2/php/code_list.php
def initialize(inputs, info = {})
super(inputs, info)
raise(ArgumentError, "invalid format(s)") unless validate_output_formats(info[:output_file_formats])
+ options_validation(inputs)
end
private
def validate_output_formats(formats)
formats.nil? || formats.select{|f| !OUTPUT_FILE_FORMATS.has_value?(f) }.empty?
end
+
+ def options_validation(inputs)
+ inputs.each { |input|
+ input.validate_glossary
+ input.validate_speakers
+ }
+ end
end
# Input for order (aka source file)
class Input < ApiSerializable
# Length of audio in seconds (mandatory in case of inability to determine it automatically).
@@ -167,9 +192,66 @@
# :external_link might substitute :uri for Transcription or Caption.
attr_reader :uri
# External URL, if sources wasn't POSTed as input (YouTube, Vimeo, Dropbox, etc)
attr_reader :external_link
+
+ # Optional, list of glossary entries.
+ attr_reader :glossary
+
+ # Optional, list of speaker names.
+ attr_reader :speakers
+
+ # Optional, list of accents.
+ attr_reader :accents
+
+ SUPPORTED_ACCENTS = {
+ :american_neutral => 'AmericanNeutral',
+ :american_southern => 'AmericanSouthern',
+ :asian => 'Asian',
+ :australian => 'Australian',
+ :british => 'British',
+ :indian => 'Indian',
+ :other => 'Other',
+ :unknown => 'Unknown'
+ }
+
+ def validate_glossary
+ if glossary
+ if glossary.length > GLOSSARY_ENTRIES_LIMIT
+ raise(ArgumentError, "Glossary must not exceed #{GLOSSARY_ENTRIES_LIMIT} entries")
+ end
+ glossary.each { |term|
+ if term.length > GLOSSARY_ENTRY_LENGTH_LIMIT
+ raise(ArgumentError, "Glossary entries cannot exceed #{GLOSSARY_ENTRY_LENGTH_LIMIT} characters")
+ end
+ }
+ end
+ end
+
+ def validate_speakers
+ if speakers
+ if speakers.length > SPEAKER_ENTRIES_LIMIT
+ raise(ArgumentError, "Speaker list must not exceed #{SPEAKER_ENTRIES_LIMIT} entries")
+ end
+ speakers.each { |speaker|
+ if speaker.length > SPEAKER_ENTRY_LENGTH_LIMIT
+ raise(ArgumentError, "Speaker name cannot exceed #{SPEAKER_ENTRY_LENGTH_LIMIT} characters")
+ end
+ }
+ end
+ end
+
+ def validate_accents
+ if accents
+ if accents.length > SUPPORTED_ACCENTS.length
+ raise(ArgumentError, "Length of accents list cannot exceed number of supported accents.")
+ end
+ if accents.any?{ |accent| !Rev::Input::SUPPORTED_ACCENTS.has_value?(accent) }
+ raise(ArgumentError, 'Unsupported accent provided')
+ end
+ end
+ end
end
# Notification Info. Optionally you may request that an HTTP post be made to a url of your choice when the order enters
# a new status (eg being transcribed or reviewed) and when it is complete.
class Notification < ApiSerializable