Class: Dogapi::V1::TagService

Inherits:
APIService show all
Defined in:
lib/dogapi/v1/tag.rb

Constant Summary collapse

API_VERSION =
'v1'

Instance Attribute Summary

Attributes inherited from APIService

#api_key, #application_key

Instance Method Summary collapse

Methods inherited from APIService

#connect, #handle_redirect, #handle_response, #initialize, #prepare_params, #prepare_request, #request, #should_set_api_and_app_keys_in_params?, #suppress_error_if_silent

Constructor Details

This class inherits a constructor from Dogapi::APIService

Instance Method Details

#add(host_id, tags, source = nil) ⇒ Object

Adds a list of tags to a host



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dogapi/v1/tag.rb', line 37

def add(host_id, tags, source=nil)
  extra_params = {}
  if source
    extra_params['source'] = source
  end

  body = {
    :tags => tags
  }

  request(Net::HTTP::Post, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, extra_params, body, true)
end

#detach(host_id, source = nil) ⇒ Object

Remove all tags from a host



71
72
73
74
75
76
77
78
# File 'lib/dogapi/v1/tag.rb', line 71

def detach(host_id, source=nil)
  extra_params = {}
  if source
    extra_params['source'] = source
  end

  request(Net::HTTP::Delete, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, extra_params, nil, false)
end

#detatch(host_id) ⇒ Object

DEPRECATED: Spelling mistake temporarily preserved as an alias.



65
66
67
68
# File 'lib/dogapi/v1/tag.rb', line 65

def detatch(host_id)
  warn '[DEPRECATION] Dogapi::V1::TagService.detatch() is deprecated. Use `detach` instead.'
  detach(host_id)
end

#get(host_id, source = nil, by_source = false) ⇒ Object

Gets all tags for a given host



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dogapi/v1/tag.rb', line 24

def get(host_id, source=nil, by_source=false)
  extra_params = {}
  if source
    extra_params['source'] = source
  end
  if by_source
    extra_params['by_source'] = 'true'
  end

  request(Net::HTTP::Get, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, extra_params, nil, false)
end

#get_all(source = nil) ⇒ Object

Gets all tags in your org and the hosts tagged with them



14
15
16
17
18
19
20
21
# File 'lib/dogapi/v1/tag.rb', line 14

def get_all(source=nil)
  extra_params = {}
  if source
    extra_params['source'] = source
  end

  request(Net::HTTP::Get, '/api/' + API_VERSION + '/tags/hosts', extra_params, nil, false)
end

#update(host_id, tags, source = nil) ⇒ Object

Remove all tags from a host and replace them with a new list



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dogapi/v1/tag.rb', line 51

def update(host_id, tags, source=nil)
  extra_params = {}
  if source
    extra_params['source'] = source
  end

  body = {
    :tags => tags
  }

  request(Net::HTTP::Put, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, extra_params, body, true)
end