Class: Zm::Client::MessageJsnsBuilder

Inherits:
BaseAccountJsnsBuilder show all
Defined in:
lib/zm/client/message/message_jsns_builder.rb

Overview

class for account message jsns builder

Instance Method Summary collapse

Methods inherited from BaseAccountJsnsBuilder

#build, #to_color, #to_delete, #to_move, #to_patch, #to_rename, #to_tag, #to_trash

Constructor Details

#initialize(item) ⇒ MessageJsnsBuilder

Returns a new instance of MessageJsnsBuilder.



7
8
9
# File 'lib/zm/client/message/message_jsns_builder.rb', line 7

def initialize(item)
  @item = item
end

Instance Method Details

#attachments_jsnsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zm/client/message/message_jsns_builder.rb', line 25

def attachments_jsns
  @item.attachments.all.map do |attachment|
    {
      part: attachment.part,
      mid: attachment.mid,
      aid: attachment.aid,
      ct: attachment.ct,
      s: attachment.s,
      filename: attachment.filename,
      ci: attachment.ci,
      cd: attachment.cd
    }.reject { |_, v| v.nil? }
  end
end

#body_jsnsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zm/client/message/message_jsns_builder.rb', line 52

def body_jsns
  return nil if @item.body.text.nil? && @item.body.html.nil?

  text_jsns = @item.body.text.nil? ? nil : { ct: ContentType::TEXT, content: { _content: @item.body.text } }
  html_jsns = @item.body.html.nil? ? nil : { ct: ContentType::HTML, content: { _content: @item.body.html } }

  [
    {
      ct: ContentPart::ALTERNATIVE,
      mp: [text_jsns, html_jsns].compact
    }
  ]
end

#recipients_jsnsObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zm/client/message/message_jsns_builder.rb', line 40

def recipients_jsns
  return nil if @item.recipients.all.empty?

  @item.recipients.all.map do |recipient|
    {
      t: recipient.field,
      a: recipient.email,
      p: recipient.display_name
    }.reject { |_, v| v.nil? }
  end
end

#to_jsnsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/zm/client/message/message_jsns_builder.rb', line 11

def to_jsns
  jsns = {
    id: @item.id,
    attach: attachments_jsns,
    e: recipients_jsns,
    su: { _content: @item.su },
    mp: body_jsns
  }.delete_if { |_, v| v.nil? }

  jsns[:did] = @item.id if @item.l.to_i == FolderDefault::DRAFTS[:id]

  jsns
end

#to_spamObject



66
67
68
69
70
71
72
73
# File 'lib/zm/client/message/message_jsns_builder.rb', line 66

def to_spam
  attrs = {
    op: :spam,
    id: @item.id
  }

  build(attrs)
end

#to_unspamObject



75
76
77
78
79
80
81
82
# File 'lib/zm/client/message/message_jsns_builder.rb', line 75

def to_unspam
  attrs = {
    op: '!spam',
    id: @item.id
  }

  build(attrs)
end