Class: MitakeSms::Client
- Inherits:
-
Object
- Object
- MitakeSms::Client
- Defined in:
- lib/mitake_sms/client.rb
Defined Under Namespace
Classes: AuthenticationError, Error, InvalidRequestError, ServerError
Constant Summary collapse
- LINE_BREAK =
The Mitake API represents a line break inside smbody as ASCII code 6.
6.chr
- BATCH_LIMIT =
500- CHARSET =
The API also accepts Big5, but it only labels the payload and never converts it, so sending anything other than UTF8 just invites mojibake.
'UTF8'- FIELD_SEPARATOR =
'$$'- STRUCTURAL_FIELDS =
Every SmBulkSend field except smbody, in wire order. A '$$' or a line break in any of these shifts the remaining fields of the row.
%i[client_id to dlvtime vldtime destname response_url].freeze
Instance Method Summary collapse
-
#batch_send(messages, options = {}) ⇒ MitakeSms::Response+
Send multiple SMS in a single request, splitting at the API's 500 message limit.
-
#initialize(config = nil) ⇒ Client
constructor
Initialize a new MitakeSms::Client.
-
#send_sms(to:, text:, destname: nil, response_url: nil, client_id: nil, **options) ⇒ MitakeSms::Response
Send a single SMS.
Constructor Details
Instance Method Details
#batch_send(messages, options = {}) ⇒ MitakeSms::Response+
Send multiple SMS in a single request, splitting at the API's 500 message limit
70 71 72 73 74 |
# File 'lib/mitake_sms/client.rb', line 70 def batch_send(, = {}) .each_with_index { |msg, index| validate_row!(msg, index) } batch_send_with_limit(, BATCH_LIMIT, ) end |
#send_sms(to:, text:, destname: nil, response_url: nil, client_id: nil, **options) ⇒ MitakeSms::Response
Send a single SMS
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mitake_sms/client.rb', line 46 def send_sms(to:, text:, destname: nil, response_url: nil, client_id: nil, **) form_params = { username: @config.username, password: @config.password, dstaddr: to, smbody: normalize_body(text) } form_params[:destname] = destname if destname form_params[:response] = response_url if response_url form_params[:clientid] = client_id if client_id perform_request('SmSend', params: { CharsetURL: CHARSET }) do |req| req.body = form_params.merge() end end |