Module: ArchivesSpace::Helpers

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

Instance Method Summary collapse

Instance Method Details

#accessions(options = {}) ⇒ Object



13
14
15
# File 'lib/archivesspace/client/helpers.rb', line 13

def accessions(options = {})
  all('accessions', options)
end

#all(path, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/archivesspace/client/helpers.rb', line 17

def all(path, options = {})
  Enumerator.new do |yielder|
    page = 1
    unlimited_listing = false
    loop do
      result = get(path, options.merge(query: { page: page }))
      results = []

      if result.parsed.respond_to?(:key) && result.parsed.key?('results')
        results = result.parsed['results']
      else
        results = result.parsed
        unlimited_listing = true
      end

      if results.any?
        results.each do |i|
          yielder << i
        end
        raise StopIteration if unlimited_listing

        page += 1
      else
        raise StopIteration
      end
    end
  end.lazy
end

#backend_versionObject



46
47
48
# File 'lib/archivesspace/client/helpers.rb', line 46

def backend_version
  get "version"
end

#batch_import(payload, params = {}) ⇒ Object



50
51
52
# File 'lib/archivesspace/client/helpers.rb', line 50

def batch_import(payload, params = {})
  # create "batch_import", payload, params
end

#digital_objects(options = {}) ⇒ Object



54
55
56
# File 'lib/archivesspace/client/helpers.rb', line 54

def digital_objects(options = {})
  all('digital_objects', options)
end

#group_user_assignment(users_with_roles, params = { with_members: true }) ⇒ Object



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/archivesspace/client/helpers.rb', line 62

def group_user_assignment(users_with_roles, params = { with_members: true })
  updated = []
  groups.each do |group|
    changed = false

    users_with_roles.each do |user, roles|
      if roles.include? group["group_code"]
        unless group["member_usernames"].include? user
          group["member_usernames"] << user
          changed = true
        end
      else
        if group["member_usernames"].include? user
          group["member_usernames"].delete user
          changed = true
        end
      end
    end

    if changed
      id = group["uri"].split("/")[-1]
      response = post( "/groups/#{id}", group, params )
      updated << response.parsed
    end
  end
  updated
end

#groups(options = {}) ⇒ Object



58
59
60
# File 'lib/archivesspace/client/helpers.rb', line 58

def groups(options = {})
  all('groups', options)
end

#loginObject



90
91
92
93
94
95
96
# File 'lib/archivesspace/client/helpers.rb', line 90

def 
  username, password = config.username, config.password
  result = request('POST', "/users/#{username}/login", { query: { password: password } })
  raise ConnectionError.new "Failed to connect to ArchivesSpace backend as #{username} #{password}" unless result.parsed["session"]
  @token = result.parsed["session"]
  self
end

#password_reset(username, password) ⇒ Object

Raises:



98
99
100
101
102
# File 'lib/archivesspace/client/helpers.rb', line 98

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

#repositories(options = {}) ⇒ Object



104
105
106
# File 'lib/archivesspace/client/helpers.rb', line 104

def repositories(options = {})
  all('repositories', options)
end

#repositories_with_agentObject



108
109
110
# File 'lib/archivesspace/client/helpers.rb', line 108

def repositories_with_agent
  #
end

#resources(options = {}) ⇒ Object



112
113
114
# File 'lib/archivesspace/client/helpers.rb', line 112

def resources(options = {})
  all('resources', options)
end

#search(params) ⇒ Object



116
117
118
# File 'lib/archivesspace/client/helpers.rb', line 116

def search(params)
  # get "search", params
end

#users(options = {}) ⇒ Object



120
121
122
# File 'lib/archivesspace/client/helpers.rb', line 120

def users(options = {})
  all('users', options)
end