Class: Voice::Actions::Notify

Inherits:
Object
  • Object
show all
Defined in:
lib/vonage/voice/actions/notify.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Notify

Returns a new instance of Notify.



8
9
10
11
12
13
14
# 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

Instance Attribute Details

#eventMethodObject

Returns the value of attribute eventMethod.



6
7
8
# File 'lib/vonage/voice/actions/notify.rb', line 6

def eventMethod
  @eventMethod
end

#eventUrlObject

Returns the value of attribute eventUrl.



6
7
8
# File 'lib/vonage/voice/actions/notify.rb', line 6

def eventUrl
  @eventUrl
end

#payloadObject

Returns the value of attribute payload.



6
7
8
# File 'lib/vonage/voice/actions/notify.rb', line 6

def payload
  @payload
end

Instance Method Details

#actionObject



39
40
41
# File 'lib/vonage/voice/actions/notify.rb', line 39

def action
  create_notify!(self)
end

#after_initialize!Object



16
17
18
19
20
21
22
# 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) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# 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_methodObject

Raises:



33
34
35
36
37
# 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_urlObject

Raises:



24
25
26
27
28
29
30
31
# 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