Module: NCCO

Defined in:
lib/ncco.rb,
lib/ncco/utils.rb,
lib/ncco/version.rb,
lib/ncco/predicates.rb,
lib/ncco/schemas/talk.rb,
lib/ncco/schemas/input.rb,
lib/ncco/schemas/record.rb,
lib/ncco/schemas/stream.rb,
lib/ncco/schemas/connect.rb,
lib/ncco/schemas/base_schema.rb,
lib/ncco/schemas/conversation.rb

Defined Under Namespace

Modules: Predicates, Schemas, Utils Classes: InvalidActionError

Constant Summary collapse

SCHEMAS_BY_TYPE =

Maps the “action” attribute within an action to the schema which should be used to validate it

{
  "connect" => Schemas::Connect,
  "conversation" => Schemas::Conversation,
  "input" => Schemas::Input,
  "record" => Schemas::Record,
  "stream" => Schemas::Stream,
  "talk" => Schemas::Talk,
}.freeze
VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.build(actions) ⇒ Array<Hash>

A Nexmo Call Control Object (NCCO) is a JSON array that you use to control the flow of a Nexmo call. This method validates an array, ensuring the “actions” inside are valid NCCO actions, either throwing an explanatory error if they’re not, or returning back the array if the input is valid.

This method can be used to pre-emptively ensure that an NCCO is valid before sending it to Nexmo, providing a kind of static analysis.

Raises:

  • (InvalidActionError)

    if any of the actions within the Nexmo Call Control Object is invalid. The error message will include details on which action was invalid and why.



44
45
46
47
48
49
50
# File 'lib/ncco.rb', line 44

def self.build(actions)
  actions.
    map { |action| Utils.deep_transform_keys_to_symbols(action) }.
    each_with_index { |action, index| validate_action!(action, index: index) }

  actions
end