Class: PostyCli::Command::Alias

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

Instance Method Summary collapse

Instance Method Details

#add(name, ali) ⇒ Object


27
28
29
30
31
32
33
34
35
# File 'lib/posty_cli/command/alias.rb', line 27

def add(name, ali)
	split = name.split("\@")
	if(PostyCli::Util::check_name(name))									
		json = {source: ali, destination: split[0]}.to_json				
		PostyCli::Util::Alias.create(json, name, split[1], ali)									
	else
		puts "you have to enter a valid email adress, like [email protected]"
	end
end

#delete(name) ⇒ Object


62
63
64
65
66
67
68
69
70
71
# File 'lib/posty_cli/command/alias.rb', line 62

def delete(name)
	split = name.split("\@")
	if(name =~ /\@/ && split.length < 3 )
		name_del = split[0]
		domain = split[1]
		if(yes? "Are you sure you want to delete #{name}? Yes\\No")
			PostyCli::Util::Alias.delete(name_del, domain)				
		end
	end
end

#edit(name, new_name) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/posty_cli/command/alias.rb', line 44

def edit(name, new_name)
	split = name.split("\@")
	if(name =~ /\@/ && split.length < 3 )
		domain = split[1]
		old_name = split[0]
		json = {source: new_name}.to_json
		PostyCli::Util::Alias.edit(json, domain, new_name, old_name, new_name)								
	else
		puts "you have to enter a valid email adress like [email protected]"
	end
end

#list(domain) ⇒ Object


13
14
15
16
# File 'lib/posty_cli/command/alias.rb', line 13

def list(domain)
	out = PostyCli::Util::Alias.get_all(domain)
	print_table(out)
end