Class: Rumeme::SmsMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/rumeme/sms_message.rb

Overview

This class represents an SMS message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SmsMessage

Constructor.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rumeme/sms_message.rb', line 7

def initialize args
  # this defaults must be moved to global configuration
  defaults = {:phone_number => nil, :message => nil, :message_id => 0, :delay => 0, :validity_period => ValidityPeriod::THREE_DAYS, :delivery_report => false}
  params = defaults.merge args
  defaults.keys.each {|key| instance_variable_set("@#{key.to_s}".to_sym, params[key])}

  raise ArgumentError.new("phone_number is empty") if @phone_number.nil? || @phone_number.empty?
  raise ArgumentError.new("message is empty") if @message.nil? || @message.empty?

  @message = @message.gsub("\n",'\n').gsub("\r",'\r').gsub("\\",'\\\\')
end

Instance Attribute Details

#delayObject (readonly)

Returns the value of attribute delay.



4
5
6
# File 'lib/rumeme/sms_message.rb', line 4

def delay
  @delay
end

#delivery_reportObject (readonly)

Returns the value of attribute delivery_report.



4
5
6
# File 'lib/rumeme/sms_message.rb', line 4

def delivery_report
  @delivery_report
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/rumeme/sms_message.rb', line 4

def message
  @message
end

#message_idObject (readonly)

Returns the value of attribute message_id.



4
5
6
# File 'lib/rumeme/sms_message.rb', line 4

def message_id
  @message_id
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



4
5
6
# File 'lib/rumeme/sms_message.rb', line 4

def phone_number
  @phone_number
end

#validity_periodObject (readonly)

Returns the value of attribute validity_period.



4
5
6
# File 'lib/rumeme/sms_message.rb', line 4

def validity_period
  @validity_period
end

Instance Method Details

#post_stringObject



19
20
21
# File 'lib/rumeme/sms_message.rb', line 19

def post_string
  "#{@message_id} #{@phone_number} #{@delay} #{@validity_period} #{@delivery_report ? 1 : 0} #{@message}\r\n"
end