Class: Mailflow::Tag

Inherits:
Object
  • Object
show all
Includes:
APIOperations
Defined in:
lib/mailflow-ruby/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations

included

Constructor Details

#initialize(attributes) ⇒ Tag

Returns a new instance of Tag.



39
40
41
# File 'lib/mailflow-ruby/tag.rb', line 39

def initialize(attributes)
  @name = attributes["name"]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/mailflow-ruby/tag.rb', line 9

def name
  @name
end

Class Method Details

.create(tags, params = {}, trigger = false) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mailflow-ruby/tag.rb', line 19

def create(tags, params = {}, trigger = false)
  tags = tags.map { |tag| {name: tag}}
  body = {tags: tags}
  body.merge!(params)
  body.merge!({trigger: trigger}) if trigger
  
  response = post_request('tags', body)
  raise UnprocessableError if (response.code == 422 || response.code == 404)
  response.parsed_response.map do |attributes|
    Tag.new(attributes)
  end
end

.list(options = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/mailflow-ruby/tag.rb', line 12

def list(options = {})
  response = get_request('tags', options)
  response.parsed_response.map do |attributes|
    Tag.new(attributes)
  end
end

.untag(tags, params = {}) ⇒ Object



32
33
34
35
# File 'lib/mailflow-ruby/tag.rb', line 32

def untag(tags, params = {})
  tags = tags.map { |tag| {name: tag}}
  delete_request('tags', {tags: tags}.merge(params))
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/mailflow-ruby/tag.rb', line 43

def ==(other)
  self.name == other.name
end

#deleteObject



47
48
49
50
# File 'lib/mailflow-ruby/tag.rb', line 47

def delete
  Mailflow::Tag.delete_request('tags', {tags: [{name: name}]})
  return true
end