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



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

def attachments_jsns
  @item.attachments.all.map do |attachment|
    h = {
      part: attachment.part,
      mid: attachment.mid,
      aid: attachment.aid,
      ct: attachment.ct,
      s: attachment.s,
      filename: attachment.filename,
      ci: attachment.ci,
      cd: attachment.cd
    }
    h.compact!
    h
  end
end

#body_jsnsObject



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

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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zm/client/message/message_jsns_builder.rb', line 43

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

  @item.recipients.all.map do |recipient|
    h = {
      t: recipient.field,
      a: recipient.email,
      p: recipient.display_name
    }
    h.compact!
    h
  end
end

#to_jsnsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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
  }
  jsns.compact!

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

  jsns
end

#to_spamObject



71
72
73
74
75
76
77
78
# File 'lib/zm/client/message/message_jsns_builder.rb', line 71

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

  build(attrs)
end

#to_unspamObject



80
81
82
83
84
85
86
87
# File 'lib/zm/client/message/message_jsns_builder.rb', line 80

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

  build(attrs)
end