class Vonage::Voice::Actions::Notify

Attributes

eventMethod[RW]
eventUrl[RW]
payload[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/vonage/voice/actions/notify.rb, line 8
def initialize(attributes = {})
  @payload = attributes.fetch(:payload)
  @eventUrl = attributes.fetch(:eventUrl)
  @eventMethod = attributes.fetch(:eventMethod, nil)

  after_initialize!
end

Public Instance Methods

action() click to toggle source
# File lib/vonage/voice/actions/notify.rb, line 39
def action
  create_notify!(self)
end
after_initialize!() click to toggle source
# File lib/vonage/voice/actions/notify.rb, line 16
def after_initialize!
  validate_event_url

  if self.eventMethod
    validate_event_method
  end
end
create_notify!(builder) click to toggle source
# File lib/vonage/voice/actions/notify.rb, line 43
def create_notify!(builder)
  ncco = [
    {
      action: 'notify',
      payload: builder.payload,
      eventUrl: builder.eventUrl
    }
  ]

  ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod

  ncco
end
validate_event_method() click to toggle source
# File lib/vonage/voice/actions/notify.rb, line 33
def validate_event_method
  valid_methods = ['GET', 'POST']

  raise ClientError.new("Invalid 'eventMethod' value. must be either: 'GET' or 'POST'") unless valid_methods.include?(self.eventMethod.upcase)
end
validate_event_url() click to toggle source
# File lib/vonage/voice/actions/notify.rb, line 24
def validate_event_url
  uri = URI.parse(self.eventUrl[0])

  raise ClientError.new("Expected 'eventUrl' value to be an Array with a single string") unless self.eventUrl.is_a?(Array)
  raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)

  self.eventUrl
end