Class: ServerRegistryClient::ServerProcessor::V1
- Inherits:
-
Base
- Object
- Base
- ServerRegistryClient::ServerProcessor::V1
show all
- Defined in:
- lib/server-registry-client/server_processor/v1.rb
Instance Attribute Summary
Attributes inherited from Base
#api_version, #last_response, #server_registry_url_root
Instance Method Summary
collapse
Constructor Details
#initialize(server_registry_url) ⇒ V1
Returns a new instance of V1.
4
5
6
7
|
# File 'lib/server-registry-client/server_processor/v1.rb', line 4
def initialize(server_registry_url)
super
self.api_version = "v1"
end
|
Instance Method Details
#add_server_to_categories(server, category_names) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/server-registry-client/server_processor/v1.rb', line 29
def add_server_to_categories(server, category_names)
server_json_hash = server_to_json_hash(server)
server_json_hash[:categories] = (category_names.kind_of?(Array) ? category_names : [category_names])
server_json = jsonify(server_json_hash)
make_web_request("/api/#{api_version}/servers", {
:method => :post,
:body => server_json
}) do |response, response_body|
unless response.success?
raise ServerRegistryClient::ServerCommunicationError, "Server responded: #{print_typhoeus_response(response)}"
end
end
end
|
#get_all_servers ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/server-registry-client/server_processor/v1.rb', line 21
def get_all_servers
response_json = make_web_request("/api/#{api_version}/servers")
return response_json.map do |server_json|
server_from_json(server_json)
end
end
|
#remove_server_from_category(server, category_name) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/server-registry-client/server_processor/v1.rb', line 45
def remove_server_from_category(server, category_name)
server_name = server.hostname || server.ip_address
server_removed = true
make_web_request("/api/#{api_version}/category/#{category_name}/server/#{server_name}", {
:method => :delete
}) do |response, response_body|
unless response.success?
server_removed = false
end
end
return server_removed
end
|
#remove_servers_like(server_to_match) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/server-registry-client/server_processor/v1.rb', line 60
def remove_servers_like(server_to_match)
all_servers = get_all_servers
servers_to_delete = all_servers.find_all do |server|
server_to_match.matches?(server)
end
servers_to_delete.each do |server|
make_web_request("/api/#{api_version}/server/#{server.id}", {
:method => :delete
})
end
end
|
#servers_in_category(category) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/server-registry-client/server_processor/v1.rb', line 9
def servers_in_category(category)
response_json = make_web_request("/api/#{api_version}/category/#{category}")
if response_json.nil? || last_response.response_code == 404
return []
else
return response_json[:servers].map do |server_json|
server_from_json(server_json)
end
end
end
|