Class: Infobip::Sms::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/infobip/sms/connection.rb

Instance Method Summary collapse

Instance Method Details

#call(path:, method: :post, body: nil, query: nil) ⇒ Object



6
7
8
# File 'lib/infobip/sms/connection.rb', line 6

def call(path:, method: :post, body: nil, query: nil)
  ::Infobip::Sms::Request.new(method: method, body: body, query: query).make_request(path: path)
end

#get_reports(query:) ⇒ Object

Check report for bulk or for message_id ‘123’, messageId: ‘123’ /sms/1/reports?bulkId={recentBulkId}&messageId={recentMessageId}&limit=453367 LOGS CAN ONLY BE QUERIED ONCE ! after that results are empty

Parameters:

  • query (Ruby Hash)


57
58
59
# File 'lib/infobip/sms/connection.rb', line 57

def get_reports(query:)
  call(path: ::Infobip::Sms::Request.configuration.sms_reports_endpoint || "/sms/1/reports", method: :get, query: query)
end

#send_bulk_sms(phone_numbers_with_prefix:, content:, custom_identifier: nil) ⇒ Object

Send sms message - bulk sms

Parameters:

  • phone_numbers_with_prefix (Array)
  • content (String)
  • custom_identifier (String) (defaults to: nil)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/infobip/sms/connection.rb', line 35

def send_bulk_sms(phone_numbers_with_prefix:, content:, custom_identifier: nil)
  body = { "messages": [] }
  phone_numbers_with_prefix.each do |phone_number|
    body[:"messages"] << {
      "from": custom_identifier || ::Infobip::Sms::Request.configuration.sms_identifier,
      "destinations": [
        {
          "to": phone_number
        }
      ],
      "text": content
    }
  end
  
  call(path: ::Infobip::Sms::Request.configuration.sms_endpoint || "/sms/2/text/advanced", method: :post, body: body)
end

#send_single_sms(phone_number_with_prefix:, content:, custom_identifier: nil) ⇒ Object

Send sms message - single sms

Parameters:

  • phone_number_with_prefix (String)
  • content (String)
  • custom_identifier (String) (defaults to: nil)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/infobip/sms/connection.rb', line 14

def send_single_sms(phone_number_with_prefix:, content:, custom_identifier: nil)
  body = {
    "messages": [
      {
        "from": custom_identifier || ::Infobip::Sms::Request.configuration.sms_identifier,
        "destinations": [
          {
            "to": phone_number_with_prefix
          }
        ],
        "text": content
      }
    ]
  }
  call(path: ::Infobip::Sms::Request.configuration.sms_endpoint || "/sms/2/text/advanced", method: :post, body: body)
end