Module: Cyclid::Client::User
- Included in:
- Tilapia
- Defined in:
- lib/cyclid/client/user.rb
Overview
User related methods
Instance Method Summary collapse
-
#user_add(username, email, name = nil, password = nil, secret = nil) ⇒ Hash
Create a new user.
-
#user_delete(username) ⇒ Hash
Delete a user.
-
#user_get(username) ⇒ Hash
Get details of a specific user.
-
#user_list ⇒ Array
Retrieve the list of users from a server.
-
#user_modify(username, args) ⇒ Hash
Modify a user.
Instance Method Details
#user_add(username, email, name = nil, password = nil, secret = nil) ⇒ Hash
Create a new user
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cyclid/client/user.rb', line 56 def user_add(username, email, name = nil, password = nil, secret = nil) # Create the user object user = { 'username' => username, 'email' => email } # Add the real name is one was supplied user['name'] = name unless name.nil? # Add the HMAC secret if one was supplied user['secret'] = secret unless secret.nil? # Encrypt & add the password if one was supplied user['password'] = BCrypt::Password.create(password).to_s unless password.nil? @logger.debug user # Sign & send the request uri = server_uri('/users') res_data = api_json_post(uri, user) @logger.debug res_data return res_data end |
#user_delete(username) ⇒ Hash
Delete a user
125 126 127 128 129 130 131 |
# File 'lib/cyclid/client/user.rb', line 125 def user_delete(username) uri = server_uri("/users/#{username}") res_data = api_delete(uri) @logger.debug res_data return res_data end |
#user_get(username) ⇒ Hash
Get details of a specific user
39 40 41 42 43 44 45 |
# File 'lib/cyclid/client/user.rb', line 39 def user_get(username) uri = server_uri("/users/#{username}") res_data = api_get(uri) @logger.debug res_data return res_data end |
#user_list ⇒ Array
Retrieve the list of users from a server
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cyclid/client/user.rb', line 23 def user_list uri = server_uri('/users') res_data = api_get(uri) @logger.debug res_data users = [] res_data.each do |item| users << item['username'] end return users end |
#user_modify(username, args) ⇒ Hash
Modify a user
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cyclid/client/user.rb', line 93 def user_modify(username, args) # Create the user object user = {} # Add the real name is one was supplied user['name'] = args[:name] if args.key? :name and args[:name] # Add the email address if one was supplied user['email'] = args[:email] if args.key? :email and args[:email] # Add the HMAC secret if one was supplied user['secret'] = args[:secret] if args.key? :secret and args[:secret] # Encrypt & add the password if one was supplied user['password'] = BCrypt::Password.create(args[:password]).to_s \ if args.key? :password and args[:password] @logger.debug user # Sign & send the request uri = server_uri("/users/#{username}") res_data = api_json_put(uri, user) @logger.debug res_data return res_data end |