Sha256: 6eae630c61f5de9323c1f6036c984c610d01d9fe6814ab67d882dd719bdfc3c5

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module MerlinGateway

	class SmsMessage
		attr_accessor :target_number, :message, :price
		attr_reader   :client

		def initialize(target_number, message, options={})
			@target_number = target_number
			@message = message
			@client = options[:client]
			@price = options[:price] || 0
		end
		
		def deliver!
			xml_data = self.to_xml
			response = Typhoeus::Request.post(
				'http://www.mobile-entry.com/gate/service', 
				#:method   => :post,
				:headers  => {'Content-type' => 'text/xml'},
				:username => client.username,
				:password => client.password,
				:body => xml_data
			)
		end
		
		def to_xml
			builder = Builder::XmlMarkup.new#(:indent=>2)
			builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
			xml_data = builder.gate do |gate|
				gate.country client.country
				gate.accessNumber client.access_number
				gate.senderNumber client.sender_number
				gate.targetNumber target_number
				gate.price price
				gate.sms do |sms|
					sms.content do |content|
						content.cdata! message
					end
				end
			end
		end
	end
	
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
merlin_gateway-0.1.3 lib/merlin_gateway/sms_message.rb