Module: Infobip::SmsApi::Messages
- Defined in:
- lib/infobip/sms_api/messages.rb
Class Method Summary collapse
- .post(url, body) ⇒ Object
- .post_multi(endpoint, messages) ⇒ Object
- .post_single(class_name, endpoint, message) ⇒ Object
- .send_multiple(messages) ⇒ Object
- .send_multiple_binary_messages(messages) ⇒ Object
- .send_multiple_text_messages(messages) ⇒ Object
- .send_single(message) ⇒ Object
- .send_single_binary_message(message) ⇒ Object
- .send_single_text_message(message) ⇒ Object
- .valid_messages?(messages, object_class) ⇒ Boolean
Class Method Details
.post(url, body) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/infobip/sms_api/messages.rb', line 54 def self.post(url, body) Infobip::SmsApi.configuration.connection.post do |req| req.url url req.body = body.to_json req.headers['Accept'] = 'application/json' req.headers['Content-Type'] = 'application/json' end end |
.post_multi(endpoint, messages) ⇒ Object
49 50 51 52 |
# File 'lib/infobip/sms_api/messages.rb', line 49 def self.post_multi(endpoint, ) response = self.post(endpoint, { messages: .map(&:to_hash) }) Response::Base.new(response.status, JSON.parse(response.body)) end |
.post_single(class_name, endpoint, message) ⇒ Object
43 44 45 46 47 |
# File 'lib/infobip/sms_api/messages.rb', line 43 def self.post_single(class_name, endpoint, ) raise UnknownArgumentError, "Unsupported Message Type: #{.class}" unless .class == class_name response = self.post(endpoint, ) Response::Base.new(response.status, JSON.parse(response.body)) end |
.send_multiple(messages) ⇒ Object
15 16 17 18 19 |
# File 'lib/infobip/sms_api/messages.rb', line 15 def self.send_multiple() return if (, Infobip::SmsApi::TextMessage) return if (, Infobip::SmsApi::BinaryMessage) raise MalformedArgumentError, 'When sending multiple messages, all messages need to be of the same type' end |
.send_multiple_binary_messages(messages) ⇒ Object
39 40 41 |
# File 'lib/infobip/sms_api/messages.rb', line 39 def self.() post_multi('/sms/1/binary/multi', ) end |
.send_multiple_text_messages(messages) ⇒ Object
35 36 37 |
# File 'lib/infobip/sms_api/messages.rb', line 35 def self.() post_multi('/sms/1/text/multi', ) end |
.send_single(message) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/infobip/sms_api/messages.rb', line 5 def self.send_single() if .class == Infobip::SmsApi::TextMessage return elsif .class == Infobip::SmsApi::BinaryMessage return else raise UnknownArgumentError, "Unknown message type: #{.class}" end end |
.send_single_binary_message(message) ⇒ Object
31 32 33 |
# File 'lib/infobip/sms_api/messages.rb', line 31 def self.() post_single(Infobip::SmsApi::BinaryMessage, '/sms/1/binary/single', ) end |
.send_single_text_message(message) ⇒ Object
27 28 29 |
# File 'lib/infobip/sms_api/messages.rb', line 27 def self.() post_single(Infobip::SmsApi::TextMessage, '/sms/1/text/single', ) end |
.valid_messages?(messages, object_class) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/infobip/sms_api/messages.rb', line 21 def self.(, object_class) .all? do || .class == object_class end end |