Class: Superset::Tag::AddToObject

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/tag/add_to_object.rb

Constant Summary

Constants inherited from Request

Request::PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num

Instance Method Summary collapse

Methods inherited from Request

call, #query_params, #result, #superset_host

Methods included from Display

#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title

Constructor Details

#initialize(object_type_id:, object_id:, tags: []) ⇒ AddToObject

Returns a new instance of AddToObject.



9
10
11
12
13
# File 'lib/superset/tag/add_to_object.rb', line 9

def initialize(object_type_id:, object_id:, tags: [])
  @object_type_id = object_type_id
  @object_id = object_id
  @tags = tags
end

Instance Attribute Details

#object_idObject (readonly)

Returns the value of attribute object_id.



7
8
9
# File 'lib/superset/tag/add_to_object.rb', line 7

def object_id
  @object_id
end

#object_type_idObject (readonly)

Returns the value of attribute object_type_id.



7
8
9
# File 'lib/superset/tag/add_to_object.rb', line 7

def object_type_id
  @object_type_id
end

#tagsObject (readonly)

Returns the value of attribute tags.



7
8
9
# File 'lib/superset/tag/add_to_object.rb', line 7

def tags
  @tags
end

Instance Method Details

#paramsObject



25
26
27
28
29
# File 'lib/superset/tag/add_to_object.rb', line 25

def params
  {
    "properties": { "tags": tags }
  }
end

#performObject



15
16
17
18
19
# File 'lib/superset/tag/add_to_object.rb', line 15

def perform
  validate_constructor_args

  response  # NOTE API response for success is {} .. not particularly informative
end

#responseObject



21
22
23
# File 'lib/superset/tag/add_to_object.rb', line 21

def response
  @response ||= client.post(route, params)
end

#validate_constructor_argsObject



31
32
33
34
35
36
37
# File 'lib/superset/tag/add_to_object.rb', line 31

def validate_constructor_args
  raise InvalidParameterError, "object_type_id integer is required" unless object_type_id.present? && object_type_id.is_a?(Integer)
  raise InvalidParameterError, "object_type_id is not a known value" unless ObjectType.list.include?(object_type_id)
  raise InvalidParameterError, "object_id integer is required" unless object_id.present? && object_id.is_a?(Integer)
  raise InvalidParameterError, "tags array is required" unless tags.present? && tags.is_a?(Array)
  raise InvalidParameterError, "tags array must contain string only values" unless tags.all? { |item| item.is_a?(String) }
end