Class: Cellular::Backends::CoolSMS
- Defined in:
- lib/cellular/backends/cool_sms.rb
Overview
Cool SMS backend (www.coolsms.com)
Constant Summary collapse
- GATEWAY_URL =
Documentation: www.coolsms.com/support/dokumentation/http-gateway.sms
'https://sms.coolsmsc.dk/'.freeze
Class Method Summary collapse
- .coolsms_config ⇒ Object
- .defaults_with(options) ⇒ Object
- .deliver(options = {}) ⇒ Object
- .parse_response(response) ⇒ Object
- .recipients_batch(options) ⇒ Object
Methods inherited from Backend
Class Method Details
.coolsms_config ⇒ Object
33 34 35 36 37 38 |
# File 'lib/cellular/backends/cool_sms.rb', line 33 def self.coolsms_config { username: Cellular.config.username, password: Cellular.config.password } end |
.defaults_with(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cellular/backends/cool_sms.rb', line 40 def self.defaults_with() { from: [:sender], to: [:batch], message: [:message], charset: 'utf-8', resulttype: 'xml', lang: 'en' }.merge!(coolsms_config) end |
.deliver(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cellular/backends/cool_sms.rb', line 10 def self.deliver( = {}) request_queue = {} recipients_batch().each_with_index do |recipient, index| [:batch] = recipient result = HTTParty.get(GATEWAY_URL, query: defaults_with()) request_queue[index] = { recipient: recipient, response: parse_response(result.parsed_response['smsc']) } end # return first response for now request_queue[0][:response] end |
.parse_response(response) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/cellular/backends/cool_sms.rb', line 26 def self.parse_response(response) [ response['status'], response['result'] || response['message']['result'] ] end |
.recipients_batch(options) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/cellular/backends/cool_sms.rb', line 51 def self.recipients_batch() if [:recipients].blank? [[:recipient]] else [:recipients] end end |