Module: ArchivesSpace::Task
- Included in:
- Client
- Defined in:
- lib/archivesspace/client/task.rb
Overview
Perform specific API tasks
Instance Method Summary collapse
- #group_user_assignment(users_with_roles) ⇒ Object
- #login ⇒ Object
- #password_reset(username, password) ⇒ Object
Instance Method Details
#group_user_assignment(users_with_roles) ⇒ Object
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/archivesspace/client/task.rb', line 6 def group_user_assignment(users_with_roles) updated = [] groups.each do |group| group = get("groups/#{uri_to_id(group["uri"])}").parsed update = false users_with_roles.each do |user, roles| # should the user still belong to this group? if group["member_usernames"].include?(user) unless roles.include? group["group_code"] group["member_usernames"].delete user update = true end # should the user be added to this group? elsif roles.include? group["group_code"] group["member_usernames"] << user update = true end end next unless update response = post("/groups/#{uri_to_id(group["uri"])}", group) updated << response end updated end |
#login ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/archivesspace/client/task.rb', line 34 def login username = config.username password = config.password previous_context = @context @context = nil begin result = request("POST", "/users/#{username}/login", {query: {password: password}}) unless result.parsed["session"] raise AuthenticationError, "Login failed as user [#{username}] (status #{result.status_code}); check username and password" end @token = result.parsed["session"] self ensure @context = previous_context end end |
#password_reset(username, password) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/archivesspace/client/task.rb', line 53 def password_reset(username, password) user = all("users").find { |u| u["username"] == username } raise RequestError, "User not found: #{username}" unless user post(user["uri"], user, {password: password}) end |