lib/mblox/sms.rb in mblox-0.2.0 vs lib/mblox/sms.rb in mblox-0.2.1
- old
+ new
@@ -19,20 +19,21 @@
:raise_error => Proc.new { raise InvalidMessageError, "Message cannot be longer than #{MAX_LENGTH} characters" },
:truncate => Proc.new { |message| Mblox.log "Truncating message due to length. Message was: \"#{message}\" but will now be \"#{message = message[0,MAX_LENGTH]}\""; [message] },
:split => Proc.new { |message| split_message(message) }
}
- def initialize(phone,message)
+ def initialize(phone, message, batch_id=nil)
phone = phone.to_s
raise InvalidPhoneNumberError, "Phone number must be ten digits" unless /\A[0-9]{10}\z/.match(phone)
raise InvalidPhoneNumberError, "Phone number cannot begin with 0 or 1" if ['0','1'].include?(phone[0].to_s)
raise InvalidMessageError, "Message cannot be blank" if message.empty?
illegal_characters = ILLEGAL_CHARACTERS.match(message).to_a
raise InvalidMessageError, "Message cannot contain the following special characters: #{illegal_characters.uniq.join(', ')}" unless illegal_characters.size.zero?
Mblox.log "WARNING: Some characters may be lost because the message must be broken into at least 1000 sections" if message.size > (999 * MAX_SECTION_LENGTH)
@message = (message.size > MAX_LENGTH) ? ON_MESSAGE_TOO_LONG_HANDLER[Mblox.config.on_message_too_long].call(message) : [message.dup]
@phone = "1#{phone}"
+ @batch_id = batch_id.to_i unless batch_id.blank?
end
def send
@message.collect { |message| commit build(message) }
end
@@ -52,10 +53,10 @@
builder.NotificationRequest(:Version => "3.5") do |nr|
nr.NotificationHeader do |nh|
nh.PartnerName(Mblox.config.partner_name)
nh.PartnerPassword(Mblox.config.password)
end
- nr.NotificationList(:BatchID => 1) do |nl|
+ nr.NotificationList(:BatchID => @batch_id || 1) do |nl|
nl.Notification(:SequenceNumber => 1, :MessageType => :SMS, :Format => :UTF8) do |n|
n.Message do |m|
m.cdata!(message)
end
n.Profile(Mblox.config.profile_id)