Class: SMS::Incoming

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, sender, sent, text) ⇒ Incoming

Returns a new instance of Incoming.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubysms/message/incoming.rb', line 10

def initialize(backend, sender, sent, text)
  
  # move all arguments into read-only
  # attributes. ugly, but Struct only
  # supports read/write attrs
  @backend = backend
  @sent = sent
  @text = text
  
  # Sets @sender, transforming _sender_ into an SMS::Person if
  # it isn't already (to enable persistance between :Outgoing
  # and/or SMS::Incoming objects)
  @sender = sender.is_a?(SMS::Person) ? sender : SMS::Person.fetch(backend, sender)
  
  # assume that the message was
  # received right now, since we
  # don't have an incoming buffer
  @received = Time.now
  
  # initialize a place for responses
  # to this message to live, to be
  # extracted (for logging?) later
  @responses = []
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



8
9
10
# File 'lib/rubysms/message/incoming.rb', line 8

def backend
  @backend
end

#receivedObject (readonly)

Returns the value of attribute received.



7
8
9
# File 'lib/rubysms/message/incoming.rb', line 7

def received
  @received
end

#responsesObject (readonly)

Returns the value of attribute responses.



8
9
10
# File 'lib/rubysms/message/incoming.rb', line 8

def responses
  @responses
end

#senderObject (readonly)

Returns the value of attribute sender.



8
9
10
# File 'lib/rubysms/message/incoming.rb', line 8

def sender
  @sender
end

#sentObject (readonly)

Returns the value of attribute sent.



7
8
9
# File 'lib/rubysms/message/incoming.rb', line 7

def sent
  @sent
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/rubysms/message/incoming.rb', line 7

def text
  @text
end

Instance Method Details

#create_response(response_text) ⇒ Object

Creates an SMS::Outgoing object, adds it to _@responses_, and links it back to this SMS::Incoming object via Outgoing#in_response_to. IMPORTANT: This method doesn’t actually SEND the message, it just creates it - use Incoming#respond to create an send in one call. This is most useful when you want to quickly create a response, modify it a bit, and send it.



41
42
43
44
45
46
# File 'lib/rubysms/message/incoming.rb', line 41

def create_response(response_text)
  og = SMS::Outgoing.new(backend, sender, response_text)
  og.in_response_to = self
  @responses.push(og)
  og
end

#phone_numberObject

Returns the phone number of the sender of this message.



54
55
56
# File 'lib/rubysms/message/incoming.rb', line 54

def phone_number
  sender.phone_number
end

#respond(response_text) ⇒ Object

Same as Incoming#respond, but also sends the message.



49
50
51
# File 'lib/rubysms/message/incoming.rb', line 49

def respond(response_text)
  create_response(response_text).send!
end