Module: Smslist::Client::Sms

Included in:
Smslist::Client
Defined in:
lib/smslist/client/sms.rb

Instance Method Summary collapse

Instance Method Details

#send_sms(text, recipients = [], options = {}) ⇒ Hash

Send sms message for a list of recipients

Examples:

Send message to a list of users

client = Smslist.new(token: 'secret', sender: '4040')

recipients = %w(79031234567 79032345678)
client.send_sms('Message', recipients)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/smslist/client/sms.rb', line 15

def send_sms(text, recipients = [], options = {})
  unless sms_sender = sender
    raise Smslist::NoSenderError.new('You must set a sender')
  end

  body = build_xml_body do |xml|
    xml.message(type:"#{ 'flash' if options[:flash] }sms") {
      xml.sender sms_sender
      xml.text_ text.encode(xml: :text)
      recipients.each_with_index do |recipient, index|
        xml.abonent phone: recipient, number_sms: index + 1
      end
    }
  end

  response = parse_xml(post body.to_xml)
  parse_send_sms_response(response, recipients)
end