Class: MerlinGateway::SmsMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/merlin_gateway/sms_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_number, message, options = {}) ⇒ SmsMessage

Returns a new instance of SmsMessage.


7
8
9
10
11
12
# File 'lib/merlin_gateway/sms_message.rb', line 7

def initialize(target_number, message, options={})
	@target_number = target_number
	@message = message
	@client = options[:client]
	@price = options[:price] || 0
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


5
6
7
# File 'lib/merlin_gateway/sms_message.rb', line 5

def client
  @client
end

#messageObject

Returns the value of attribute message


4
5
6
# File 'lib/merlin_gateway/sms_message.rb', line 4

def message
  @message
end

#priceObject

Returns the value of attribute price


4
5
6
# File 'lib/merlin_gateway/sms_message.rb', line 4

def price
  @price
end

#target_numberObject

Returns the value of attribute target_number


4
5
6
# File 'lib/merlin_gateway/sms_message.rb', line 4

def target_number
  @target_number
end

Instance Method Details

#deliver!Object


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/merlin_gateway/sms_message.rb', line 14

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

#to_xmlObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/merlin_gateway/sms_message.rb', line 26

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