summaryrefslogtreecommitdiff
path: root/contrib/smsweb/smswsc/sms_message.rb
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/smsweb/smswsc/sms_message.rb')
-rw-r--r--contrib/smsweb/smswsc/sms_message.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/contrib/smsweb/smswsc/sms_message.rb b/contrib/smsweb/smswsc/sms_message.rb
new file mode 100644
index 0000000..787b58b
--- /dev/null
+++ b/contrib/smsweb/smswsc/sms_message.rb
@@ -0,0 +1,62 @@
+require 'smswsc/builder'
+require 'rexml/document'
+require 'base64'
+
+module SMSWSC
+
+ class SMSMessage
+ attr_accessor :message_status
+ attr_accessor :addr_type
+ attr_accessor :addr
+ attr_accessor :user_data
+ attr_accessor :uri
+
+ def initialize(options = {})
+ @message_status = options["message_status"]
+ @addr_type = options["addr-type"]
+ @addr = options["addr"]
+ @user_data = options["user-data"]
+ end
+
+ def uri=(value)
+ @uri = value
+ end
+
+ def self.load_xml(parent)
+ message = SMSMessage.new
+
+ parent.each_element do |element|
+ case element.name
+ when "message-status"
+ message.message_status = element.text.to_s
+ when "addr-type"
+ message.addr_type = element.text.to_s
+ when "addr"
+ message.addr = element.text.to_s
+ when "user-data"
+ message.user_data = Base64.decode64(element.text.to_s)
+ when "uri"
+ message.uri = URI.parse(element.text.to_s)
+ end
+ end
+
+ return message
+ end
+
+ def to_xml(builder = nil, element = "sms-message")
+ xml = ""
+ unless builder
+ builder = SMSWSC.new_builder(xml)
+ end
+
+ builder.tag!(element.to_s) {
+ builder.tag! "message-status", @message_status
+ builder.tag! "addr-type", @addr_type
+ builder.tag! "addr", @addr
+ builder.tag! "user-data", Base64.encode64(@user_data)
+ }
+
+ return xml
+ end
+ end
+end