Class: PostyCli::Util::User
- Inherits:
-
Object
- Object
- PostyCli::Util::User
- Defined in:
- lib/posty_cli/util/user.rb
Class Method Summary collapse
-
.create(json, domain, screen) ⇒ Object
ADD a user to domain.
- .delete(name, domain) ⇒ Object
-
.edit(json, domain, new_name, old, screen) ⇒ Object
EDIT.
-
.get_all(domain) ⇒ Object
Get all Users.
Class Method Details
.create(json, domain, screen) ⇒ Object
ADD a user to domain
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/posty_cli/util/user.rb', line 29 def self.create(json, domain, screen) begin #begin to prepare rest or end with a rescue url = PostyCli::Util.build_uri("domains/#{domain}/users") @response = RestClient.post(url, json, :content_type => :json, :accept => :json) puts "User #{screen} in #{domain} 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., e.response) end end |
.delete(name, domain) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/posty_cli/util/user.rb', line 46 def self.delete(name, domain) begin #begin to prepare rest or end with a rescue url = PostyCli::Util.build_uri("domains/#{domain}/users/#{name}") response = RestClient.delete(url) puts "the user #{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., e.response) end end |
.edit(json, domain, new_name, old, screen) ⇒ Object
EDIT
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/posty_cli/util/user.rb', line 65 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}/users/#{old}") response = RestClient.put(url, json, :content_type => :json, :accept => :json) puts("you have edit the user #{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., e.response) end end |
.get_all(domain) ⇒ Object
Get all Users
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/posty_cli/util/user.rb', line 6 def self.get_all(domain) #Array to keep the rest-output @tabletmp = [] #begin to prepare rest or end with a rescue begin url = PostyCli::Util.build_uri("domains/#{domain}/users") response = RestClient.get (url) data = JSON.parse(response) data.each do |blub| @tabletmp << blub["virtual_user"]["name"] +"\@"+ 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 puts e rescue Exception => e #error that pass the http code and the message to the Util class PostyCli::Util.check_response_code(e., e.response ) end tablesel = @tabletmp.map.with_index{ |a, i| [i+1, *a]} end |