Class: ATSD::EntityGroupsService

Inherits:
BaseService show all
Defined in:
lib/atsd/services/entity_groups_service.rb

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from ATSD::BaseService

Instance Method Details

#add_entities(entity_group, entities, parameters = {}) ⇒ self

Add specified entities to entity group.

Parameters:

Options Hash (parameters):

  • :create_entities (Boolean)

    Automatically create new entities from the submitted list if such entities don’t already exist. Default value: true

Returns:

  • (self)

Raises:



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/atsd/services/entity_groups_service.rb', line 110

def add_entities(entity_group, entities, parameters = {})
  entity_group = name_for_entity_group(entity_group)
  parameters = parameters.camelize_keys
  entities = Utils.ensure_array(entities).map do |e|
    e = Entity.new(name: e) if e.is_a? String
    e = Entity.new(e) if e.is_a? Hash
    e = e.to_request_hash
  end
  @client.entity_groups_add_entities(entity_group, entities, parameters)
  self
end

#create_or_replace(entity_group) ⇒ self

Note:

If only a subset of fields is provided for an existing entity group, the remaining properties and tags will be deleted.

Create an entity group with specified properties and tags or replace an existing entity group. This method creates a new entity group or replaces an existing entity group.

Parameters:

Returns:

  • (self)

Raises:



44
45
46
47
48
49
# File 'lib/atsd/services/entity_groups_service.rb', line 44

def create_or_replace(entity_group)
  entity_group = EntityGroup.new(name: entity_group) if entity_group.is_a? String
  entity_group = EntityGroup.new(entity_group) if entity_group.is_a? Hash
  @client.entity_groups_create_or_replace(entity_group.name, entity_group.to_request_hash)
  self
end

#delete(entity_group) ⇒ self

Note:

Entities that are members of the group are retained.

Delete the entity group.

Parameters:

Returns:

  • (self)

Raises:



74
75
76
77
# File 'lib/atsd/services/entity_groups_service.rb', line 74

def delete(entity_group)
  @client.entity_groups_delete(name_for_entity_group(entity_group))
  self
end

#delete_entities(entity_group, entities) ⇒ self

Delete entities from entity group.

Parameters:

Returns:

  • (self)

Raises:



149
150
151
152
153
154
155
156
157
158
# File 'lib/atsd/services/entity_groups_service.rb', line 149

def delete_entities(entity_group, entities)
  entity_group = name_for_entity_group(entity_group)
  entities = Utils.ensure_array(entities).map do |e|
    e = Entity.new(name: e) if e.is_a? String
    e = Entity.new(e) if e.is_a? Hash
    e = e.to_request_hash
  end
  @client.entity_groups_delete_entities(entity_group, entities)
  self
end

#get(entity_group) ⇒ Array<EntityGroup>

Displays entity group properties and all tags.

Parameters:

  • entity_group (String)

Returns:

Raises:



29
30
31
# File 'lib/atsd/services/entity_groups_service.rb', line 29

def get(entity_group)
  EntityGroup.new(@client.entity_groups_get(name_for_entity_group entity_group))
end

#get_entities(entity_group, parameters = {}) ⇒ Array<Entity>

Get entities for entity group

Parameters:

  • entity_group (String, EntityGroup, Hash)
  • parameters (Hash) (defaults to: {})

    a customizable set of options

Options Hash (parameters):

  • :active (Boolean)

    Filter entities by last_insert_time. If active = true, only entities with positive last_insert_time are included in the response

  • :expression (String)

    Use name variable for entity name. Use * placeholder in like expressions

  • :tags (Array)

    Specify entity tags to be included in the response

  • :limit (Integer)

    Limit response to first N entities, ordered by name.

Returns:

Raises:



93
94
95
96
97
98
99
# File 'lib/atsd/services/entity_groups_service.rb', line 93

def get_entities(entity_group, parameters = {})
  entity_group = name_for_entity_group(entity_group)
  parameters = parameters.camelize_keys
  @client.entity_groups_get_entities(entity_group, parameters).map do |json|
    Entity.new json
  end
end

#list(parameters = {}) ⇒ Array<EntityGroup>

Entity groups list.

Parameters:

  • parameters (Hash) (defaults to: {})

    a customizable set of options

Options Hash (parameters):

  • :expression (String)

    Use name variable for entity group name. Use * placeholder in like expressions

  • :tags (Array)

    Specify entity group tags to be included in the response

  • :limit (Integer)

    Limit response to first N entity groups, ordered by name.

Returns:

Raises:



17
18
19
20
21
22
# File 'lib/atsd/services/entity_groups_service.rb', line 17

def list(parameters = {})
  parameters = parameters.camelize_keys
  @client.entity_groups_list(parameters).map do |json|
    EntityGroup.new json
  end
end

#replace_entities(entity_group, entities) ⇒ self

Note:

All existing entities that are not included in the collection will be removed. If the specified collection is empty, all entities are removed from the group (replace with empty collection).

Replace entities in the entity group with the specified collection.

Parameters:

Returns:

  • (self)

Raises:



132
133
134
135
136
137
138
139
140
141
# File 'lib/atsd/services/entity_groups_service.rb', line 132

def replace_entities(entity_group, entities)
  entity_group = name_for_entity_group(entity_group)
  entities = Utils.ensure_array(entities).map do |e|
    e = Entity.new(name: e) if e.is_a? String
    e = Entity.new(e) if e.is_a? Hash
    e = e.to_request_hash
  end
  @client.entity_groups_replace_entities(entity_group, entities)
  self
end

#update(entity_group) ⇒ self

Note:

Properties and tags that are not specified are left unchanged.

Update specified properties and tags for the given entity group. This method updates specified properties and tags for an existing entity group.

Parameters:

Returns:

  • (self)

Raises:



61
62
63
64
65
# File 'lib/atsd/services/entity_groups_service.rb', line 61

def update(entity_group)
  entity_group = EntityGroup.new(entity_group) if entity_group.is_a? Hash
  @client.entity_groups_update(entity_group.name, entity_group.to_request_hash)
  self
end