Module: Stem::Tag

Extended by:
Tag
Includes:
Util
Included in:
Tag
Defined in:
lib/stem/tag.rb

Instance Method Summary collapse

Methods included from Util

#get_filter_opts, #swirl, #tags_to_filter, #tagset_to_hash

Instance Method Details

#create(resource_ids, tags) ⇒ Object



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

def create resource_ids, tags
  resource_ids = [ resource_ids ] unless resource_ids.is_a? Array
  swirl.call("CreateTags", tag_opts(tags).merge("ResourceId" => resource_ids) )
end

#destroy(resource_ids, tags) ⇒ Object



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

def destroy resource_ids, tags
  resource_ids = [ resource_ids ] unless resource_ids.is_a? Array
  swirl.call("DeleteTags", tag_opts(tags).merge("ResourceId" => resource_ids) )
end

#tag_opts(tags) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stem/tag.rb', line 16

def tag_opts(tags)
  if tags.is_a? Hash
    { "Tag.#.Key" => tags.keys.map(&:to_s),
      "Tag.#.Value" => tags.values.map(&:to_s) }
  elsif tags.is_a? Array
    {
      "Tag.#.Key" => tags.map(&:to_s),
      "Tag.#.Value" => (1..tags.size).map { '' }
    }
  else
    { "Tag.1.Key" => tags.to_s, "Tag.1.Value" => '' }
  end
end