Class: PostyCli::Util::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/posty_cli/util/domain.rb

Class Method Summary collapse

Class Method Details

.create(name, screen) ⇒ Object

ADD


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/posty_cli/util/domain.rb', line 27

def self.create(name, screen)
	begin
		url = PostyCli::Util.build_uri("domains")
		response = RestClient.post(url, 
			name, :content_type => :json, :accept => :json)
			puts "Domain #{screen} is created"

	rescue SocketError => e #error for no network connection
		puts "Could not contact the server. Please check connectivity!"
		exit 1
	rescue URI::Error => e
		PostyCli::Util.check_url(url)
	rescue Exception => e #error that pass the http code and the message to the Util class
		PostyCli::Util.check_response_code(e.message, e.response)				
	end				
end

.delete(name) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/posty_cli/util/domain.rb', line 44

def self.delete(name)
             begin 
		url = PostyCli::Util.build_uri("domains/#{name}")
                 response = RestClient.delete(url) 
                 puts "domain #{name} is deleted"

	rescue SocketError => e
		puts "Could not contact the server. Please check connectivity!"
		exit 1
	rescue Exception => e 
		PostyCli::Util.check_response_code(e.message, e.response )
             end
end

.edit(name, new_name, screen) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/posty_cli/util/domain.rb', line 58

def self.edit(name, new_name, screen)
	begin
		url = PostyCli::Util.build_uri("domains/#{name}")
		response = RestClient.put(url, new_name, :content_type => :json, :accept => :json)
		puts("you have edit the domain #{name} into #{screen}")
	rescue SocketError => e
		puts "Could not contact the server. Please check connectivity!"
		exit 1
	rescue Exception => e
		PostyCli::Util.check_response_code(e.message, e.response )
	end
end

.get_allObject

Get all Domains


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/posty_cli/util/domain.rb', line 6

def self.get_all()
	@tabletmp = []
	begin
		url = PostyCli::Util.build_uri("domains")
		response = RestClient.get (url)
	rescue SocketError => e #error for no network connection
		puts "Could not contact the server. Please check connectivity!"
		exit 1
	rescue URI::Error => e
		PostyCli::Util.check_url(url)
	rescue Exception => e #error that pass the http code and the message to the Util class
		PostyCli::Util.check_response_code(e.message, e.response)				
	end	
	data = JSON.parse(response)
	data.each do |blub|
		@tabletmp << blub["virtual_domain"]["name"]
	end
	tablesel = @tabletmp.map.with_index{ |a, i| [i+1, *a]}
	
end