class InfobipApi::SmsClient
Public Class Methods
InfobipApi::InfobipApiClient::new
# File lib/infobipapi/client.rb, line 167 def initialize(username, password, base_url=nil) super(username, password, base_url) end
Public Instance Methods
.codepoints.map { |c| “%02x %02x” % [c / 256,c % 256] }.join “ ”
# File lib/infobipapi/client.rb, line 223 def compute_sms_usage(str) # single SMS length per SMS (GSM7): 160 # multiple SMS length per SMS (GSM7): 153 # single SMS length per SMS (UCS-2): 70 # multiple SMS length per SMS (UCS-2): 67 sms_lengths = Hash.new # ! has_unicode_char sms_lengths[false] = Hash.new sms_lengths[false][true] = 153 # need_more_than_one_sms sms_lengths[false][false] = 160 # ! need_more_than_one_sms # has_unicode_char sms_lengths[true] = Hash.new sms_lengths[true][true] = 67 # need_more_than_one_sms sms_lengths[true][false] = 70 # ! need_more_than_one_sms { :single_gsm7 => 160, :multi_gsm7 => 153, :single_ucs2 => 70, :multi_ucs2 => 67 } has_unicode_char = false need_more_than_one_sms = false str.each_char { |c| if not Utils.in_gsm7_set?(c) then has_unicode_char = true break end } if has_unicode_char then need_more_than_one_sms = str.length > 70 format = :unicode else need_more_than_one_sms = str.length > 160 format = :gsm7 end return { :format => format, :length => str.length, :length_by_sms => sms_lengths[has_unicode_char][need_more_than_one_sms], :number_of_sms => (str.length.to_f / sms_lengths[has_unicode_char][need_more_than_one_sms].to_f).ceil } end
Get delivery reports cf: dev.infobip.com/docs/delivery-reports parm fields names :
-
bulkId: string The ID that uniquely identifies the request. Bulk ID will be received only when you send a message to more than one destination address.
-
messageId: string
The ID that uniquely identifies the message sent.
-
limit: string Number of returned delivery reports. Default value is 50. Max number per request is 10000.
# File lib/infobipapi/client.rb, line 383 def delivery_reports(params) req = {} # safety parameters treatment req[:bulkId] = params[:bulkId] if params.has_key?:bulkId req[:messageId] = params[:messageId] if params.has_key?:messageId req[:limit] = params[:limit] if params.has_key?:limit is_success, result = execute_GET("/sms/1/reports", req) convert_from_json(DeliveryReportList,result, !is_success) end
send multiple sms message to one or many destination addresses. cf: dev.infobip.com/docs/send-multiple-sms param fields names, array of :
-
from: string Represents sender ID and it can be alphanumeric or numeric. Alphanumeric sender ID length should be between 3 and 11 characters (Example: CompanyName). Numeric sender ID length should be between 3 and 14 characters.
-
to: `required` array of strings Array of message destination addresses. If you want to send a message to one destination, a single String is supported instead of an Array. Destination addresses must be in international format (Example: 41793026727).
-
text: string Text of the message that will be sent. (Developper comment: chars must be 7bits or comportment is not predictable on the receiving phones)
# File lib/infobipapi/client.rb, line 204 def multiple_text_sms(smss) params = { :messages => [] } smss.each { |sms| params[:messages].push({ :from => sms.from, :to => sms.to, :text => sms.text }) } is_success, result = execute_POST( "/sms/1/text/multi", params ) convert_from_json(SimpleSMSAnswer, result, !is_success) end
send multiple sms message to one or many destination addresses. TEXT in UTF-8 format if all chars are gsm7 encoding compatible then the SMS is sent with gsm7 encoding. Else it will be sent in Unicode binary format. cf: dev.infobip.com/docs/send-multiple-sms param fields names, array of :
-
from: string Represents sender ID and it can be alphanumeric or numeric. Alphanumeric sender ID length should be between 3 and 11 characters (Example: CompanyName). Numeric sender ID length should be between 3 and 14 characters.
-
to: `required` array of strings Array of message destination addresses. If you want to send a message to one destination, a single String is supported instead of an Array. Destination addresses must be in international format (Example: 41793026727).
-
text: string utf-8 encoded Text of the message that will be sent. (Developper comment: chars must be 7bits or comportment is not predictable on the receiving phones)
Return an array of 2 results :
one for a /sms/1/text/multi query (nil if none is sent as text) second one for a /sms/1/binary/multi query (nil if none is sent as binary)
# File lib/infobipapi/client.rb, line 324 def multiple_utf8_sms(smss) params = { :text => { :uri => "/sms/1/text/multi", :messages => [] }, :binary => { :uri => "/sms/1/binary/multi", :messages => [] } } smss.each { |sms| usage = self.compute_sms_usage(sms.text) if usage[:format] == :gsm7 then params[:text][:messages].push({ :from => sms.from, :to => sms.to, :text => sms.text }) else text_array = sms.text.force_encoding('utf-8').codepoints.map { |c| sprintf('%02x', c) } params[:binary][:messages].push({ :from => sms.from, :to => sms.to, :binary => { :hex => text_array.join(' '), :dataCoding => 8, :esmClass => 0 } }) end } results = [] if params[:text][:messages].length > 0 then is_success, result = execute_POST( params[:text][:uri] , params[:text][:messages] ) results.push(convert_from_json(SimpleSMSAnswer, result, !is_success)) else results.push(nil) end if params[:binary][:messages].length > 0 then is_success, result = execute_POST( params[:binary][:uri] , params[:binary][:messages] ) results.push(convert_from_json(SimpleSMSAnswer, result, !is_success)) else results.push(nil) end return results end
send single sms message to one or many destination addresses. cf: dev.infobip.com/docs/send-single-sms param fields names:
-
from: string Represents sender ID and it can be alphanumeric or numeric. Alphanumeric sender ID length should be between 3 and 11 characters (Example: CompanyName). Numeric sender ID length should be between 3 and 14 characters.
-
to: `required` array of strings Array of message destination addresses. If you want to send a message to one destination, a single String is supported instead of an Array. Destination addresses must be in international format (Example: 41793026727).
-
text: string Text of the message that will be sent. (Developper comment: chars must be 7bits or comportment is not predictable on the receiving phones)
# File lib/infobipapi/client.rb, line 182 def single_text_sms(sms) params = { :from => sms.from, :to => sms.to, :text => sms.text } is_success, result = execute_POST( "/sms/1/text/single", params ) convert_from_json(SimpleSMSAnswer, result, !is_success) end
send single sms message to one or many destination addresses. TEXT in UTF-8 format if all chars are gsm7 encoding compatible then the SMS is sent with gsm7 encoding. Else it will be sent in Unicode binary format. cf: dev.infobip.com/docs/send-single-sms cf: dev.infobip.com/docs/send-single-binary-sms param fields names:
-
from: string Represents sender ID and it can be alphanumeric or numeric. Alphanumeric sender ID length should be between 3 and 11 characters (Example: CompanyName). Numeric sender ID length should be between 3 and 14 characters.
-
to: `required` array of strings Array of message destination addresses. If you want to send a message to one destination, a single String is supported instead of an Array. Destination addresses must be in international format (Example: 41793026727).
-
text: string utf-8 encoded Text of the message that will be sent. (Developper comment: chars must be 7bits or comportment is not predictable on the receiving phones)
# File lib/infobipapi/client.rb, line 281 def single_utf8_sms(sms) usage = self.compute_sms_usage(sms.text) if usage[:format] == :gsm7 then params = { :from => sms.from, :to => sms.to, :text => sms.text } uri = "/sms/1/text/single" else text_array = sms.text.force_encoding('utf-8').codepoints.map { |c| sprintf('%02x', c) } params = { :from => sms.from, :to => sms.to, :binary => { :hex => text_array.join(' '), :dataCoding => 8, :esmClass => 0 } } uri = "/sms/1/binary/single" end is_success, result = execute_POST(uri , params ) convert_from_json(SimpleSMSAnswer, result, !is_success) end