Class: IletiMerkezi::Sms

Inherits:
Object
  • Object
show all
Includes:
XmlBuilder
Defined in:
lib/ileti_merkezi/actions/sms.rb

Overview

Sms

Constant Summary collapse

PATH =
'/send-sms'

Constants included from XmlBuilder

XmlBuilder::XML_TAG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XmlBuilder

#hash_to_xml

Constructor Details

#initialize(params = {}) ⇒ Sms

Returns a new instance of Sms.



12
13
14
15
16
# File 'lib/ileti_merkezi/actions/sms.rb', line 12

def initialize(params = {})
  @messages      = build_messages(params)
  @send_datetime = params.fetch(:send_datetime, Time.now.strftime('%d/%m/%Y %H:%M'))
  @sender        = params.fetch(:sender, IletiMerkezi.configuration.sender)
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



8
9
10
# File 'lib/ileti_merkezi/actions/sms.rb', line 8

def messages
  @messages
end

#send_datetimeObject (readonly)

Returns the value of attribute send_datetime.



8
9
10
# File 'lib/ileti_merkezi/actions/sms.rb', line 8

def send_datetime
  @send_datetime
end

#senderObject (readonly)

Returns the value of attribute sender.



8
9
10
# File 'lib/ileti_merkezi/actions/sms.rb', line 8

def sender
  @sender
end

Instance Method Details

#sendObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ileti_merkezi/actions/sms.rb', line 18

def send
  request = Request.new(
    path: PATH,
    payload: hash_to_xml(
      sender: sender,
      sendDateTime: send_datetime,
      message: messages.map(&:to_h)
    )
  )
  request.call
end