Class: Twilio::TwiML::TwiML
- Inherits:
-
Object
- Object
- Twilio::TwiML::TwiML
show all
- Defined in:
- lib/twilio-ruby/twiml/twiml.rb
Direct Known Subclasses
Autopilot, Body, Client, Conference, Connect, Dial, Echo, Enqueue, FaxResponse, Gather, GenericNode, Hangup, Identity, Leave, Media, Message, MessagingResponse, Number, Parameter, Pause, Pay, Play, Prompt, Queue, Receive, Record, Redirect, Reject, Room, Say, Sim, Sip, Sms, SsmlBreak, SsmlEmphasis, SsmlLang, SsmlP, SsmlPhoneme, SsmlProsody, SsmlS, SsmlSayAs, SsmlSub, SsmlW, Task, VoiceResponse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**keyword_args) ⇒ TwiML
Returns a new instance of TwiML.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 28
def initialize(**keyword_args)
@overrides = {
aliasAttribute: 'alias',
xmlLang: 'xml:lang',
interpretAs: 'interpret-as',
for_: 'for',
}
@name = self.class.name.split('::').last
@value = nil
@verbs = []
@attrs = {}
keyword_args.each do |key, val|
corrected_key = @overrides.fetch(key, TwiML.to_lower_camel_case(key))
@attrs[corrected_key] = val unless val.nil?
end
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
26
27
28
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 26
def name
@name
end
|
Class Method Details
.to_lower_camel_case(symbol) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 46
def self.to_lower_camel_case(symbol)
result = symbol.to_s
if result.include? '_'
result = result.split('_').map(&:capitalize).join
end
result[0].downcase + result[1..result.length]
end
|
Instance Method Details
#add_child(name, value = nil, **keyword_args) {|node| ... } ⇒ Object
104
105
106
107
108
109
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 104
def add_child(name, value=nil, **keyword_args)
node = GenericNode.new(name, value, **keyword_args)
yield node if block_given?
append(node)
end
|
#add_text(content) ⇒ Object
100
101
102
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 100
def add_text(content)
append(Text.new(content))
end
|
#append(verb) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 87
def append(verb)
unless verb.is_a?(TwiML) || verb.is_a?(LeafNode)
raise TwiMLError, 'Only appending of TwiML is allowed'
end
@verbs << verb
self
end
|
96
97
98
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 96
def (body)
append(Comment.new(body))
end
|
#to_s(xml_declaration = true) ⇒ Object
Also known as:
to_xml
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 55
def to_s(xml_declaration = true)
save_opts = Nokogiri::XML::Node::SaveOptions::DEFAULT_XML
if !xml_declaration
save_opts = save_opts | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
end
opts = { encoding: 'UTF-8', indent: 0, save_with: save_opts }
document = Nokogiri::XML::Document.new
document << self.xml(document)
document.to_xml(opts)
end
|
#xml(document) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/twilio-ruby/twiml/twiml.rb', line 66
def xml(document)
value = (@value.is_a?(String) or @value == nil) ? @value : JSON.generate(@value)
elem = Nokogiri::XML::Node.new(@name, document)
elem.content = value
keys = @attrs.keys.sort
keys.each do |key|
value = @attrs[key]
value_is_boolean = value.is_a?(TrueClass) || value.is_a?(FalseClass)
elem[key] = value_is_boolean ? value.to_s.downcase : value.to_s
end
@verbs.each do |verb|
elem << verb.xml(document)
end
elem
end
|