Class: Mailersend::SMS

Inherits:
Object
  • Object
show all
Defined in:
lib/mailersend/sms/sms.rb

Overview

Send an SMS through MailerSend API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = Mailersend::Client.new) ⇒ SMS

Returns a new instance of SMS.



12
13
14
15
16
17
18
# File 'lib/mailersend/sms/sms.rb', line 12

def initialize(client = Mailersend::Client.new)
  @client = client
  @from = {}
  @to = []
  @text = {}
  @personalization = []
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/mailersend/sms/sms.rb', line 6

def client
  @client
end

#fromObject

Returns the value of attribute from.



6
7
8
# File 'lib/mailersend/sms/sms.rb', line 6

def from
  @from
end

#personalizationObject

Returns the value of attribute personalization.



6
7
8
# File 'lib/mailersend/sms/sms.rb', line 6

def personalization
  @personalization
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/mailersend/sms/sms.rb', line 6

def text
  @text
end

#toObject

Returns the value of attribute to.



6
7
8
# File 'lib/mailersend/sms/sms.rb', line 6

def to
  @to
end

Instance Method Details

#add_from(from) ⇒ Object



20
21
22
# File 'lib/mailersend/sms/sms.rb', line 20

def add_from(from)
  @from = from
end

#add_personalization(personalization) ⇒ Object



32
33
34
# File 'lib/mailersend/sms/sms.rb', line 32

def add_personalization(personalization)
  @personalization << personalization
end

#add_text(text) ⇒ Object



28
29
30
# File 'lib/mailersend/sms/sms.rb', line 28

def add_text(text)
  @text = text
end

#add_to(to) ⇒ Object



24
25
26
# File 'lib/mailersend/sms/sms.rb', line 24

def add_to(to)
  @to << to
end

#sendObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mailersend/sms/sms.rb', line 36

def send
  message = {
    'from' => @from,
    'to' => @to,
    'text' => @text,
    'personalization' => @personalization
  }

  response = client.http.post("#{MAILERSEND_API_URL}/sms", json: message.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} })
  puts response
end