lib/zenvia/sms.rb in zenvia-rb-0.0.10 vs lib/zenvia/sms.rb in zenvia-rb-0.0.11
- old
+ new
@@ -5,17 +5,16 @@
module Zenvia
class SMS
attr_writer :from, :number, :message
# function to send the message
- def self.send_message(from = nil, number, message)
+ def self.send_message(number, message, from = nil)
begin
@from = from.nil? ? Zenvia.config.from : from
@message = message
# create numbers array and push onto it number(s) from parameters
- numbers = Array.new
- number.is_a?(Array) ? numbers = number : numbers.push(number)
+ numbers = number.is_a?(Array) ? number : number.split
numbers.each do |nb|
@number = nb
response = self.send_sms
response = JSON.parse(response.body)
puts "Response for #{nb}: #{response['sendSmsResponse']['detailDescription']}"
@@ -32,26 +31,27 @@
# if not found
@number = @number.to_s unless @number.is_a? String
patterns = ['(', ')', ' ', '-']
patterns.each {|p| @number = @number.gsub(p, '')}
@number.insert(0, '55') unless /^55/.match(@number)
+ puts "THE NUMBER: #{@number}"
# retrieve auth value set in Config class
@auth = Zenvia.config.auth
endpoint = 'https://api-rest.zenvia360.com.br/services/send-sms'
HTTParty.post(endpoint,
- body: {
- sendSmsRequest: {
- from: @from,
- to: @number,
- msg: @message,
- callbackOption: 'NONE'
- }
- }.to_json,
- headers: {
- 'Content-Type' => 'application/json',
- 'Authorization' => "Basic #{@auth}",
- 'Accept' => 'application/json'
- }
+ body: {
+ sendSmsRequest: {
+ from: @from,
+ to: @number,
+ msg: @message,
+ callbackOption: 'NONE'
+ }
+ }.to_json,
+ headers: {
+ 'Content-Type' => 'application/json',
+ 'Authorization' => "Basic #{@auth}",
+ 'Accept' => 'application/json'
+ }
)
end
end
end
\ No newline at end of file