Class: SmsPromote::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/smspromote/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient, body) ⇒ Message

creates a new message object with an recipient and a message body

recipient
String

the number to send this message

body
String

the body of the message



9
10
11
12
13
# File 'lib/smspromote/message.rb', line 9

def initialize(recipient, body)
  @recipient = recipient
  @body = body
  @type = :default
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def code
  @code
end

#costObject (readonly)

Returns the value of attribute cost.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def cost
  @cost
end

#countObject (readonly)

Returns the value of attribute count.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def count
  @count
end

#message_idObject (readonly)

Returns the value of attribute message_id.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def message_id
  @message_id
end

#recipientObject (readonly)

Returns the value of attribute recipient.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def recipient
  @recipient
end

#referenceObject (readonly)

Returns the value of attribute reference.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def reference
  @reference
end

#send_timeObject (readonly)

Returns the value of attribute send_time.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def send_time
  @send_time
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/smspromote/message.rb', line 3

def type
  @type
end

Instance Method Details

#after_send(code, message_id, cost, count) ⇒ Object

sets the message information after the message has been send

code
Fixnum

the message code (e.g. 100)

message_id
String

the message id string

cost
Float

the cost for sending the message

count
Fixnum

the count of smsparts that have been sended



51
52
53
54
55
56
57
58
# File 'lib/smspromote/message.rb', line 51

def after_send(code, message_id, cost, count)
  @send_time = Time.now
  @send = true
  @code = code
  @message_id = message_id
  @cost = cost
  @count = count
end

#delivered?Boolean

returns true if the message was delivered, false otherwise

Returns:

  • (Boolean)


31
32
33
# File 'lib/smspromote/message.rb', line 31

def delivered?
  @code == 100
end

#encode!(from = "UTF-8", to = "ISO-8859-1") ⇒ Object

encode the the content of the body according to the interface spec



36
37
38
39
40
41
42
43
44
# File 'lib/smspromote/message.rb', line 36

def encode!(from = "UTF-8", to = "ISO-8859-1")
  # ruby 1.9 and higher
  if "".respond_to?(:encode) && "".respond_to?(:force_encoding)
    @body = @body.force_encoding(from).encode(to)
  else # ruby 1.8
    require "iconv"
    @body = Iconv.iconv(to, from, @body).first
  end
end

#multipart?Boolean

returns true if the sms has to be send in multiple parts

Returns:

  • (Boolean)


21
22
23
# File 'lib/smspromote/message.rb', line 21

def multipart?
  @body.length > 160
end

#send?Boolean

returns true if the message was send

Returns:

  • (Boolean)


26
27
28
# File 'lib/smspromote/message.rb', line 26

def send?
  @send
end

#valid?Boolean

returns true if the message is valid, false otherwise

Returns:

  • (Boolean)


16
17
18
# File 'lib/smspromote/message.rb', line 16

def valid?
  !@body.nil? && !@recipient.nil?
end