Class: Sms
- Inherits:
-
Object
- Object
- Sms
- Defined in:
- lib/mobily/sms.rb
Class Method Summary collapse
- .check_can_send ⇒ Object
- .schedule(mobile, password, recipient_mobile) ⇒ Object
-
.send(recipient_mobile, message) ⇒ Object
class << self attr_accessor :configuration end.
- .send_formatted(mobile, password, recipient_one, recipient_two) ⇒ Object
- .send_scheduled_formatted(mobile, password, recipient_one, recipient_two) ⇒ Object
Class Method Details
.check_can_send ⇒ Object
49 50 51 52 |
# File 'lib/mobily/sms.rb', line 49 def self.check_can_send return true if MobilySMS.can_send? false end |
.schedule(mobile, password, recipient_mobile) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/mobily/sms.rb', line 54 def self.schedule(mobile, password, recipient_mobile) sms = MobilySMS.new(MobilyApiAuth.new(mobile, password)) sms.add_number(recipient_mobile) sms.sender = $smshost sms.msg = 'Testing تجريب ^&**\nFrom Ruby, scheduled' sms.schedule_to_send_on(25, 12, 2020, 12, 0, 0) sms.delete_key = '666' sms.send end |
.send(recipient_mobile, message) ⇒ Object
class << self
attr_accessor :configuration
end
def self.configuration
@configuration ||= Configuration.new
end
def self.reset
@configuration = Configuration.new
end
def self.configure
yield(configuration)
end
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mobily/sms.rb', line 29 def self.send(recipient_mobile, ) if check_can_send begin sms = MobilySMS.new( $mobily_credentials ) sms.add_number(recipient_mobile) sms.sender = $smshost sms.msg = sms.send return 'sms' rescue => e Rails.logger.debug "ERROR: #{e}" Rails.logger.debug "sms sender: #{sms.sender}" Rails.logger.debug "sms: #{sms.inspect}" end end return { error_code: '1302' } end |
.send_formatted(mobile, password, recipient_one, recipient_two) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mobily/sms.rb', line 64 def self.send_formatted(mobile, password, recipient_one, recipient_two) auth = MobilyApiAuth.new(mobile, password) msg = 'Hi (1), your subscription will end on (2).' sms = MobilyFormattedSMS.new(auth, [recipient_one, recipient_two], $smshost) sms.add_variable_for_number(recipient_one, '(1)', 'Martin') sms.add_variable_for_number(recipient_one, '(2)', '31/12/2017') sms.add_variable_for_number(recipient_two, '(1)', 'Tim') sms.add_variable_for_number(recipient_two, '(2)', '01/11/2020') sms.send end |
.send_scheduled_formatted(mobile, password, recipient_one, recipient_two) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mobily/sms.rb', line 76 def self.send_scheduled_formatted(mobile, password, recipient_one, recipient_two) auth = MobilyApiAuth.new(mobile, password) msg = 'Hi (1), your subscription will end on (2)..' sms = MobilyFormattedSMS.new(auth, [recipient_one, recipient_two], $smshost, msg ) sms.add_variable_for_number(recipient_one, '(1)', 'Lee') sms.add_variable_for_number(recipient_one, '(2)', '31/11/2019') sms.add_variable_for_number(recipient_two, '(1)', 'James') sms.add_variable_for_number(recipient_two, '(2)', '03/10/2017') sms.delete_key = '666' sms.schedule_to_send_on(25, 12, 2020, 12, 0, 0) sms.send end |