Class: Infobip::SmsApi::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Message

Returns a new instance of Message.



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

def initialize(attributes)
  self.from = attributes[:from]
  self.to = attributes[:to]
  self.text = attributes[:text]
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



8
9
10
# File 'lib/infobip/sms_api/message.rb', line 8

def from
  @from
end

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/infobip/sms_api/message.rb', line 8

def text
  @text
end

#toObject

Returns the value of attribute to.



8
9
10
# File 'lib/infobip/sms_api/message.rb', line 8

def to
  @to
end

Instance Method Details

#send_textObject



24
25
26
27
28
29
30
31
32
# File 'lib/infobip/sms_api/message.rb', line 24

def send_text
  response = Infobip::SmsApi.configuration.connection.post do |req|
    req.url '/sms/1/text/single'
    req.body = self.to_hash.to_json
    req.headers['Accept'] = 'application/json'
    req.headers['Content-Type'] = 'application/json'
  end
  Infobip::SmsApi::Response::Base.new(response.status, JSON.parse(response.body))
end

#to_hashObject



16
17
18
19
20
21
22
# File 'lib/infobip/sms_api/message.rb', line 16

def to_hash
  hash = {}
  self.instance_variables.each do |var|
    hash[var.to_s.delete('@')] = self.instance_variable_get(var)
  end
  hash
end