Class: DogapiDemo::V1::TagService

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

Constant Summary collapse

API_VERSION =
"v1"

Instance Method Summary collapse

Methods inherited from APIService

#connect, #initialize, #request, #suppress_error_if_silent

Constructor Details

This class inherits a constructor from DogapiDemo::APIService

Instance Method Details

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

Adds a list of tags to a host



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dogapi-demo/v1/tag.rb', line 59

def add(host_id, tags, source=nil)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }
    if source
      params['source'] = source
    end

    body = {
      :tags => tags
    }

    request(Net::HTTP::Post, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, body, true)
  rescue Exception => e
    if @silent
      warn e
      return -1, {}
    else
      raise e
    end
  end
end

#detach(host_id, source = nil) ⇒ Object

Remove all tags from a host



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/dogapi-demo/v1/tag.rb', line 117

def detach(host_id, source=nil)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }
    if source
      params['source'] = source
    end

    request(Net::HTTP::Delete, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, nil, false)
  rescue Exception => e
    if @silent
      warn e
      return -1, {}
    else
      raise e
    end
  end
end

#detatch(host_id) ⇒ Object

DEPRECATED: Spelling mistake temporarily preserved as an alias.



111
112
113
114
# File 'lib/dogapi-demo/v1/tag.rb', line 111

def detatch(host_id)
  warn "[DEPRECATION] DogapiDemo::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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dogapi-demo/v1/tag.rb', line 34

def get(host_id, source=nil, by_source=false)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }
    if source
      params['source'] = source
    end
    if by_source
      params['by_source'] = 'true'
    end

    request(Net::HTTP::Get, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, nil, false)
  rescue Exception => e
    if @silent
      warn e
      return -1, {}
    else
      raise e
    end
  end
end

#get_all(source = nil) ⇒ Object

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dogapi-demo/v1/tag.rb', line 12

def get_all(source=nil)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }
    if source
      params['source'] = source
    end

    request(Net::HTTP::Get, '/api/' + API_VERSION + '/tags/hosts', params, nil, false)
  rescue Exception => e
    if @silent
      warn e
      return -1, {}
    else
      raise e
    end
  end
end

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

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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/dogapi-demo/v1/tag.rb', line 85

def update(host_id, tags, source=nil)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }
    if source
      params['source'] = source
    end

    body = {
      :tags => tags
    }

    request(Net::HTTP::Put, '/api/' + API_VERSION + '/tags/hosts/' + host_id.to_s, params, body, true)
  rescue Exception => e
    if @silent
      warn e
      return -1, {}
    else
      raise e
    end
  end
end