Class: MitakeApi::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Message

Returns a new instance of Message.



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

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

Instance Method Details

#responseObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mitake_api/message.rb', line 14

def response
  response_arr = @response.body.split(/[\r\n]+/)
  hash = {}
  hash[:uuid] = response_arr.shift.gsub(/\[|\]/, '')
  response_arr.each do |value|
    key_value = value.split('=')
    hash[key_value[0].underscore.to_sym] = key_value[1]
    if key_value[0] == 'statuscode'
      hash[:response_message] =
        I18n.t(key_value[1], scope: %i[mitake_api status_flag])
    end
  end
  hash
end

#response=(response) ⇒ Object



9
10
11
12
# File 'lib/mitake_api/message.rb', line 9

def response=(response)
  @response = response
  message.response = self.response
end

#to_hObject



29
30
31
32
33
34
35
36
# File 'lib/mitake_api/message.rb', line 29

def to_h
  {
    dstaddr: message.to,
    dlvtime: message.deliver_at.try(:strftime, '%Y%m%d%H%M%S') || '',
    smbody: message.content,
    clientid: message.uuid
  }
end