Class: MISP::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/misp/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Tag

Returns a new instance of Tag.



16
17
18
19
20
21
22
23
24
# File 'lib/misp/tag.rb', line 16

def initialize(**attributes)
  attributes = normalize_attributes(attributes)

  @id = attributes.dig(:id)
  @name = attributes.dig(:name)
  @colour = attributes.dig(:colour)
  @exportable = attributes.dig(:exportable)
  @hide_tag = attributes.dig(:hide_tag)
end

Instance Attribute Details

#colourString

Returns:

  • (String)


10
11
12
# File 'lib/misp/tag.rb', line 10

def colour
  @colour
end

#exportableBoolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/misp/tag.rb', line 12

def exportable
  @exportable
end

#hide_tagBoolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/misp/tag.rb', line 14

def hide_tag
  @hide_tag
end

#idString

Returns:

  • (String)


6
7
8
# File 'lib/misp/tag.rb', line 6

def id
  @id
end

#nameString

Returns:

  • (String)


8
9
10
# File 'lib/misp/tag.rb', line 8

def name
  @name
end

Class Method Details

.create(**attributes) ⇒ Object



100
101
102
# File 'lib/misp/tag.rb', line 100

def create(**attributes)
  new.create attributes
end

.delete(id) ⇒ Object



104
105
106
# File 'lib/misp/tag.rb', line 104

def delete(id)
  Tag.new(id: id).delete
end

.get(id) ⇒ Object



96
97
98
# File 'lib/misp/tag.rb', line 96

def get(id)
  new(id: id).get
end

.update(id, **attributes) ⇒ Object



108
109
110
# File 'lib/misp/tag.rb', line 108

def update(id, **attributes)
  Tag.new(id: id).update attributes
end

Instance Method Details

#create(**attributes) ⇒ MISP::Tag

Create a tag

Parameters:

  • **attributes (Hash)

    attributes

Returns:



57
58
59
# File 'lib/misp/tag.rb', line 57

def create(**attributes)
  _post("/tags/add", wrap(attributes)) { |json| Tag.new json }
end

#deleteHash

Delete a tag

Returns:

  • (Hash)


66
67
68
# File 'lib/misp/tag.rb', line 66

def delete
  _post("/tags/delete/#{id}") { |json| json }
end

#getMISP::Tag

Get a tag

Returns:



46
47
48
# File 'lib/misp/tag.rb', line 46

def get
  _get("/tags/view/#{id}") { |json| Tag.new json }
end

#search(**params) ⇒ MISP::Tag

Search for tags

Parameters:

  • **params (Hash)

    parameters

Returns:



89
90
91
92
93
# File 'lib/misp/tag.rb', line 89

def search(**params)
  _post("/tags/search", params) do |tags|
    tags.map { |tag| Tag.new tag }
  end
end

#to_hHash

Returns a hash representation of the attribute data.

Returns:

  • (Hash)


31
32
33
34
35
36
37
38
39
# File 'lib/misp/tag.rb', line 31

def to_h
  {
    id: id,
    name: name,
    colour: colour,
    exportable: exportable,
    hide_tag: hide_tag,
  }.compact
end

#update(**attributes) ⇒ MISP::Tag

Update a tag

Parameters:

  • **attributes (Hash)

    attributes

Returns:



77
78
79
80
# File 'lib/misp/tag.rb', line 77

def update(**attributes)
  payload = to_h.merge(attributes)
  _post("/tags/edit/#{id}", wrap(payload)) { |json| Tag.new json }
end