Class: EmailCenterApi::Nodes::EmailNode

Inherits:
Object
  • Object
show all
Defined in:
lib/email_center_api/nodes/email_node.rb

Constant Summary collapse

TREE_ROOT =
'email'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, node_id, node_class) ⇒ EmailNode

Returns a new instance of EmailNode.



45
46
47
48
49
# File 'lib/email_center_api/nodes/email_node.rb', line 45

def initialize(name, node_id, node_class)
  @name = name
  @node_id = node_id.to_i
  @node_class = node_class
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



43
44
45
# File 'lib/email_center_api/nodes/email_node.rb', line 43

def name
  @name
end

#node_classObject (readonly)

Returns the value of attribute node_class.



43
44
45
# File 'lib/email_center_api/nodes/email_node.rb', line 43

def node_class
  @node_class
end

#node_idObject (readonly)

Returns the value of attribute node_id.



43
44
45
# File 'lib/email_center_api/nodes/email_node.rb', line 43

def node_id
  @node_id
end

Class Method Details

.all(selectors = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/email_center_api/nodes/email_node.rb', line 6

def all(selectors={})
  where(
    selectors[:folder] || 0,
    ->(node) { true }
  )
end

.emails(selectors = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/email_center_api/nodes/email_node.rb', line 20

def emails(selectors={})
  where(
    selectors[:folder] || 0,
    ->(node) { node['nodeClass'] =~ /^email/ }
  )
end

.folders(selectors = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/email_center_api/nodes/email_node.rb', line 13

def folders(selectors={})
  where(
    selectors[:folder] || 0,
    ->(node) { node['nodeClass'] == 'folder' }
  )
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
54
55
# File 'lib/email_center_api/nodes/email_node.rb', line 51

def ==(other)
  name == other.name &&
  node_id == other.node_id &&
  node_class == other.node_class
end

#allObject



57
58
59
60
# File 'lib/email_center_api/nodes/email_node.rb', line 57

def all
  super unless is_folder?
  self.class.all(parent: node_id)
end

#emailsObject



67
68
69
70
# File 'lib/email_center_api/nodes/email_node.rb', line 67

def emails
  super unless is_folder?
  self.class.emails(folder: node_id)
end

#foldersObject



62
63
64
65
# File 'lib/email_center_api/nodes/email_node.rb', line 62

def folders
  super unless is_folder?
  self.class.folders(parent: node_id)
end

#is_folder?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/email_center_api/nodes/email_node.rb', line 77

def is_folder?
  node_class == 'folder'
end

#trigger(email_address, options = {}) ⇒ Object



72
73
74
75
# File 'lib/email_center_api/nodes/email_node.rb', line 72

def trigger(email_address, options={})
  super if is_folder?
  EmailCenterApi::Actions.new.trigger(node_id, email_address, options)
end