class Sms

Public Class Methods

check_can_send() click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# File lib/mobily/sms.rb, line 29
def self.send(recipient_mobile, message)
  if check_can_send
    begin
      sms = MobilySMS.new( $mobily_credentials )
      sms.add_number(recipient_mobile)

      sms.sender = $smshost

      sms.msg = message
      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) click to toggle source
# 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) click to toggle source
# 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