class DogapiDemo::V1::TagService

Constants

API_VERSION

Public Instance Methods

add(host_id, tags, source=nil) click to toggle source

Adds a list of tags to a host

   # File lib/dogapi-demo/v1/tag.rb
59 def add(host_id, tags, source=nil)
60   begin
61     params = {
62       :api_key => @api_key,
63       :application_key => @application_key
64     }
65     if source
66       params['source'] = source
67     end
68 
69     body = {
70       :tags => tags
71     }
72 
73     request(Net::HTTP::Post, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, body, true)
74   rescue Exception => e
75     if @silent
76       warn e
77       return -1, {}
78     else
79       raise e
80     end
81   end
82 end
detach(host_id, source=nil) click to toggle source

Remove all tags from a host

    # File lib/dogapi-demo/v1/tag.rb
117 def detach(host_id, source=nil)
118   begin
119     params = {
120       :api_key => @api_key,
121       :application_key => @application_key
122     }
123     if source
124       params['source'] = source
125     end
126 
127     request(Net::HTTP::Delete, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, nil, false)
128   rescue Exception => e
129     if @silent
130       warn e
131       return -1, {}
132     else
133       raise e
134     end
135   end
136 end
detatch(host_id) click to toggle source

DEPRECATED: Spelling mistake temporarily preserved as an alias.

    # File lib/dogapi-demo/v1/tag.rb
111 def detatch(host_id)
112   warn "[DEPRECATION] DogapiDemo::V1::TagService.detatch() is deprecated. Use `detach` instead."
113   detach(host_id)
114 end
get(host_id, source=nil, by_source=false) click to toggle source

Gets all tags for a given host

   # File lib/dogapi-demo/v1/tag.rb
34 def get(host_id, source=nil, by_source=false)
35   begin
36     params = {
37       :api_key => @api_key,
38       :application_key => @application_key
39     }
40     if source
41       params['source'] = source
42     end
43     if by_source
44       params['by_source'] = 'true'
45     end
46 
47     request(Net::HTTP::Get, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, nil, false)
48   rescue Exception => e
49     if @silent
50       warn e
51       return -1, {}
52     else
53       raise e
54     end
55   end
56 end
get_all(source=nil) click to toggle source

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

   # File lib/dogapi-demo/v1/tag.rb
12 def get_all(source=nil)
13   begin
14     params = {
15       :api_key => @api_key,
16       :application_key => @application_key
17     }
18     if source
19       params['source'] = source
20     end
21 
22     request(Net::HTTP::Get, '/api/' + API_VERSION + '/tags/hosts', params, nil, false)
23   rescue Exception => e
24     if @silent
25       warn e
26       return -1, {}
27     else
28       raise e
29     end
30   end
31 end
update(host_id, tags, source=nil) click to toggle source

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

    # File lib/dogapi-demo/v1/tag.rb
 85 def update(host_id, tags, source=nil)
 86   begin
 87     params = {
 88       :api_key => @api_key,
 89       :application_key => @application_key
 90     }
 91     if source
 92       params['source'] = source
 93     end
 94 
 95     body = {
 96       :tags => tags
 97     }
 98 
 99     request(Net::HTTP::Put, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, body, true)
100   rescue Exception => e
101     if @silent
102       warn e
103       return -1, {}
104     else
105       raise e
106     end
107   end
108 end