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

def batch_import(payload, params = {})

# TODO: create "batch_import", payload, params

end



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/archivesspace/client/task.rb', line 10

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.to_json)
    updated << response
  end
  updated
end

#loginObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/archivesspace/client/task.rb', line 38

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, "Failed to connect to ArchivesSpace backend as #{username} #{password}"
  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:



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.status unless user

  post(user['uri'], user.to_json, { password: password })
end