Class: Zm::Client::MessageJsnsInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/message/message_jsns_initializer.rb

Overview

class for initialize account message

Class Method Summary collapse

Class Method Details

.create(parent, json) ⇒ Object



8
9
10
11
# File 'lib/zm/client/message/message_jsns_initializer.rb', line 8

def create(parent, json)
  item = Message.new(parent)
  update(item, json)
end

.update(item, json) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zm/client/message/message_jsns_initializer.rb', line 13

def update(item, json)
  item.id = json[:id]
  item.d = json[:d]
  item.l    = json[:l]
  item.su   = json[:su]
  item.fr   = json[:fr]
  item.autoSendTime = json[:autoSendTime]
  item.mid  = json[:mid]
  item.idnt = json[:idnt]
  item.f = json[:f]
  item.tn = json[:tn].to_s.split(',')

  json[:e].each do |e|
    recipient = Recipient.new(e[:t], e[:a], e[:p])
    item.recipients.add(recipient)
  end

  update_mps(item, json[:mp])

  item
end

.update_attachment(item, json) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/zm/client/message/message_jsns_initializer.rb', line 56

def update_attachment(item, json)
  pj = Zm::Client::Message::Attachment.new(self)
  pj.mid  = json[:mid]
  pj.aid  = json[:aid]
  pj.ct   = json[:ct]
  pj.s    = json[:s]
  pj.filename = json[:filename]
  pj.ci   = json[:ci]
  pj.cd   = json[:cd]
  pj.part = json[:part]
  item.attachments.add(pj)
end

.update_body(item, json) ⇒ Object



51
52
53
54
# File 'lib/zm/client/message/message_jsns_initializer.rb', line 51

def update_body(item, json)
  item.body.text = json[:content] if json[:ct] == ContentType::TEXT
  item.body.html = json[:content] if json[:ct] == ContentType::HTML
end

.update_mps(item, mps) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zm/client/message/message_jsns_initializer.rb', line 35

def update_mps(item, mps)
  return if mps.nil?

  mps = [mps] unless mps.is_a?(Array)

  mps.each do |mp|
    if ContentType::ALL.include?(mp[:ct])
      update_body(item, mp)
    elsif mp[:cd] == 'attachment'
      update_attachment(item, mp)
    else
      update_mps(item, mp[:mp])
    end
  end
end