Class: PostyCli::Util::Alias

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

Class Method Summary collapse

Class Method Details

.create(json, email, domain, screen) ⇒ Object

ADD a alias to a user


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/posty_cli/util/alias.rb', line 35

def self.create(json, email, domain, screen)
	begin
		#begin to prepare rest or end with a rescue
		url = PostyCli::Util.build_uri("domains/#{domain}/aliases")
		res = RestClient.post(url, json, :content_type => :json, :accept => :json)
		puts "Alias #{screen} for #{email} 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(domain)
	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, domain) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/posty_cli/util/alias.rb', line 53

def self.delete(name, domain)
             begin 
             	#begin to prepare rest or end with a rescue
             	url = PostyCli::Util.build_uri("domains/#{domain}/aliases/#{name}")                    
                 res = RestClient.delete(url) 
                 puts "the alias #{name} is deleted"
	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(domain)
	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

.edit(json, domain, new_name, old, screen) ⇒ Object

EDIT


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/posty_cli/util/alias.rb', line 70

def self.edit(json, domain, new_name, old, screen)
	begin 
		#begin to prepare rest or end with a rescue
		url = PostyCli::Util.build_uri("domains/#{domain}/aliases/#{old}")
		res = RestClient.put(url, json, :content_type => :json, :accept => :json)
		puts("you have edit the alias #{old} into #{screen}")
	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(domain)
	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

.get_all(domain) ⇒ Object

Get all domains


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/posty_cli/util/alias.rb', line 6

def self.get_all(domain)
	#Array to keep the rest-output
	@tabletmp = []
	begin
		url = PostyCli::Util.build_uri("domains/#{domain}/aliases")
		#begin to prepare rest or end with a rescue 
		res = RestClient.get (url) 
		data = JSON.parse(res) 
		data.each do |blub| 
			@tabletmp << blub["virtual_alias"]["source"] +" ==> "+ blub["virtual_alias"]["destination"] +"\@"+ domain
		end 

	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(domain)
	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	
	#output the Domains with index

	tablesel = @tabletmp.map.with_index{ |a, i| [i+1, *a]}
	
	
end