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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cyclid/client/user.rb', line 59 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? # Add the password if one was supplied unless password.nil? user['password'] = if password =~ /\A\$2a\$.+\z/ # Password is already encrypted password else # Encrypt the plaintext password BCrypt::Password.create(password).to_s end end @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
145 146 147 148 149 150 151 |
# File 'lib/cyclid/client/user.rb', line 145 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
41 42 43 44 45 46 47 |
# File 'lib/cyclid/client/user.rb', line 41 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
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cyclid/client/user.rb', line 25 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cyclid/client/user.rb', line 106 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] # Add the password if one was supplied if args.key? :password and args[:password] user['password'] = if args[:password] =~ /\A\$2a\$.+\z/ # Password is already encrypted args[:password] else # Encrypt the plaintext password BCrypt::Password.create(args[:password]).to_s end end @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 |