Class: Voice::Actions::Notify
- Inherits:
-
Object
- Object
- Voice::Actions::Notify
- Defined in:
- lib/vonage/voice/actions/notify.rb
Instance Attribute Summary collapse
-
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
-
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
- #action ⇒ Object
- #after_initialize! ⇒ Object
- #create_notify!(builder) ⇒ Object
-
#initialize(attributes = {}) ⇒ Notify
constructor
A new instance of Notify.
- #validate_event_method ⇒ Object
- #validate_event_url ⇒ Object
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
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
6 7 8 |
# File 'lib/vonage/voice/actions/notify.rb', line 6 def eventMethod @eventMethod end |
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
6 7 8 |
# File 'lib/vonage/voice/actions/notify.rb', line 6 def eventUrl @eventUrl end |
#payload ⇒ Object
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
#action ⇒ Object
44 45 46 |
# File 'lib/vonage/voice/actions/notify.rb', line 44 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
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vonage/voice/actions/notify.rb', line 48 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 ⇒ Object
38 39 40 41 42 |
# File 'lib/vonage/voice/actions/notify.rb', line 38 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 ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vonage/voice/actions/notify.rb', line 24 def validate_event_url event_url = self.eventUrl unless event_url.is_a?(Array) && event_url.length == 1 && event_url[0].is_a?(String) raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item") end uri = URI.parse(event_url[0]) raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS) self.eventUrl end |