Module: ArchivesSpace::Task

Included in:
Client
Defined in:
lib/archivesspace/client/task.rb

Overview

Perform specific API tasks

Instance Method Summary collapse

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

#loginObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/archivesspace/client/task.rb', line 34

def 
  username = config.username
  password = config.password
  base_repo = config.base_repo
  use_global_repository # ensure we're in the global scope to login
  result = request("POST", "/users/#{username}/login", {query: {password: password}})
  unless result.parsed["session"]
    raise ConnectionError, "API client login failed as user [#{username}], check username and password are correct"
  end

  config.base_repo = base_repo # reset repo as set by the cfg
  @token = result.parsed["session"]
  self
end

#password_reset(username, password) ⇒ Object

Raises:



49
50
51
52
53
54
# File 'lib/archivesspace/client/task.rb', line 49

def password_reset(username, password)
  user = all("users").find { |u| u["username"] == username }
  raise RequestError, user.status unless user

  post(user["uri"], user, {password: password})
end