Class: SmswayApi::Message

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

Direct Known Subclasses

Sms, Vcard, WapPush

Defined Under Namespace

Classes: Sms, Vcard, WapPush

Constant Summary collapse

TYPES =
[:flashsms, :sms, :vcard, :wappush]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = :sms) ⇒ Message

Returns a new instance of Message.



10
11
12
13
14
# File 'lib/smsway_api/message.rb', line 10

def initialize(type = :sms)
  self.type = type
  @sender = SmswayApi.default_sender
  @recepients = []
end

Instance Attribute Details

#recepientsObject (readonly)

Returns the value of attribute recepients.



5
6
7
# File 'lib/smsway_api/message.rb', line 5

def recepients
  @recepients
end

#senderObject

Returns the value of attribute sender.



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

def sender
  @sender
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/smsway_api/message.rb', line 6

def type
  @type
end

Instance Method Details

#add_recipient(recepient = {}) ⇒ Object

add recepient recepient (Hash or String) options for recipient allowed options are:

phone: phone number
client_id: sms id in your system
time_send: Time of sms sending
validity_period: Date of

if String is given than it means only phone



38
39
40
41
42
43
44
45
46
47
# File 'lib/smsway_api/message.rb', line 38

def add_recipient(recepient = {})
  if recepient.is_a?(String)
    # convert string value to correct hash
    recepient = {phone: recepient}
  end
  recepient[:phone] = format_phone(recepient[:phone])
  @recepients.push(recepient)
  # time-send format: YYYY-MM-DD HH:MM
  # validity_period format: YYYY-MM-DD HH:MM
end

#build(xml, start_index = 0) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/smsway_api/message.rb', line 20

def build(xml, start_index = 0)
  xml.message(type: @type) do
    xml.sender @sender
    yield(xml)
    @recepients.each.with_index do |r, index|
      xml.abonent(r.merge(number_sms: start_index + index))
    end
  end
end