archivesspace-client 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/archivesspace-client.gemspec +1 -1
- data/examples/export.rb +5 -2
- data/examples/repo_and_user.rb +14 -3
- data/lib/archivesspace/client/client.rb +3 -1
- data/lib/archivesspace/client/helpers.rb +41 -83
- data/lib/archivesspace/client/request.rb +11 -10
- data/lib/archivesspace/client/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19da316e65bd48aaf2efa4268eb7217d051f9e11a1e822b0b4813bae4dd5f906
|
4
|
+
data.tar.gz: 8ea7445f1fa00f42a3c0ea633f3f6938aeee071b679408e3acfcb1e16a7858df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b6c0d669fa21b7df8a55ca888155dc1d15be16283fa050ff87bd68bb0a4c26e028ae6baa27abb4446515ea9afe91204e87054d7db3fa49934d06e65a20dee6
|
7
|
+
data.tar.gz: 27c911770a1bdb0813b913722234d52c8eb948cfc8f925589d877c7b4f0ed78aac31e0275ae135c8bb5762a175a0d3be5249d61e4ef616ed96bc49c04d4d6675
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency "rspec", "3.6.0"
|
24
24
|
spec.add_development_dependency "vcr", "3.0.3"
|
data/examples/export.rb
CHANGED
@@ -19,10 +19,13 @@ client.config.base_repo = "repositories/2"
|
|
19
19
|
|
20
20
|
begin
|
21
21
|
# date -d '2015-07-01 00:00:00' +'%s' # 1435734000
|
22
|
-
client.resources(
|
22
|
+
client.resources.each(query: { modified_since: "1435734000"}) do |resource|
|
23
23
|
# for now we are just printing ...
|
24
24
|
# but you would actually write to a zip file or whatever
|
25
|
-
|
25
|
+
id = resource['uri'].split('/')[-1]
|
26
|
+
opts = { include_unpublished: false }
|
27
|
+
response = client.get("resource_descriptions/#{id}.xml", opts)
|
28
|
+
puts Nokogiri::XML(response.body).to_xml
|
26
29
|
end
|
27
30
|
rescue ArchivesSpace::RequestError => ex
|
28
31
|
puts ex.message
|
data/examples/repo_and_user.rb
CHANGED
@@ -2,8 +2,19 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
2
|
require 'awesome_print'
|
3
3
|
require 'archivesspace/client'
|
4
4
|
|
5
|
+
# official sandbox
|
6
|
+
config = ArchivesSpace::Configuration.new({
|
7
|
+
base_uri: "http://sandbox.archivesspace.org/api",
|
8
|
+
base_repo: "",
|
9
|
+
username: "admin",
|
10
|
+
password: "admin",
|
11
|
+
page_size: 50,
|
12
|
+
throttle: 0,
|
13
|
+
verify_ssl: false,
|
14
|
+
})
|
15
|
+
|
5
16
|
# default client connection: localhost:8089, admin, admin
|
6
|
-
client = ArchivesSpace::Client.new.login
|
17
|
+
client = ArchivesSpace::Client.new(config).login
|
7
18
|
|
8
19
|
ap ArchivesSpace::Template.list # view available templates
|
9
20
|
|
@@ -24,7 +35,7 @@ repository = ArchivesSpace::Template.process_template(:repository_with_agent, re
|
|
24
35
|
|
25
36
|
begin
|
26
37
|
response = client.post('/repositories/with_agent', repository)
|
27
|
-
if response.status_code
|
38
|
+
if response.status_code.to_s =~ /^2/
|
28
39
|
repository = client.repositories.find { |r| r["repo_code"] == "XYZ" }
|
29
40
|
ap repository
|
30
41
|
ap client.delete(repository["uri"])
|
@@ -34,7 +45,7 @@ begin
|
|
34
45
|
|
35
46
|
user = ArchivesSpace::Template.process_template(:user, user_data)
|
36
47
|
response = client.post('users', user, { password: user_password })
|
37
|
-
if response.status_code
|
48
|
+
if response.status_code.to_s =~ /^2/
|
38
49
|
user = client.users.find { |r| r["username"] == "lmessi" }
|
39
50
|
ap user
|
40
51
|
ap client.delete user["uri"]
|
@@ -6,7 +6,9 @@ module ArchivesSpace
|
|
6
6
|
attr_reader :config
|
7
7
|
|
8
8
|
def initialize(config = Configuration.new)
|
9
|
-
|
9
|
+
unless config.kind_of? ArchivesSpace::Configuration
|
10
|
+
raise "Invalid configuration object"
|
11
|
+
end
|
10
12
|
@config = config
|
11
13
|
@token = nil
|
12
14
|
end
|
@@ -10,32 +10,37 @@ module ArchivesSpace
|
|
10
10
|
|
11
11
|
module Helpers
|
12
12
|
|
13
|
-
def accessions(options = {}
|
14
|
-
|
15
|
-
yield record if block_given?
|
16
|
-
end
|
17
|
-
records
|
13
|
+
def accessions(options = {})
|
14
|
+
all('accessions', options)
|
18
15
|
end
|
19
16
|
|
20
|
-
def all(path, options = {}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
17
|
+
def all(path, options = {})
|
18
|
+
Enumerator.new do |yielder|
|
19
|
+
page = 1
|
20
|
+
unlimited_listing = false
|
21
|
+
loop do
|
22
|
+
result = get(path, options.merge(query: { page: page }))
|
23
|
+
results = []
|
24
|
+
|
25
|
+
if result.parsed.respond_to?(:key) && result.parsed.key?('results')
|
26
|
+
results = result.parsed['results']
|
27
|
+
else
|
28
|
+
results = result.parsed
|
29
|
+
unlimited_listing = true
|
30
|
+
end
|
31
|
+
|
32
|
+
if results.any?
|
33
|
+
results.each do |i|
|
34
|
+
yielder << i
|
35
|
+
end
|
36
|
+
raise StopIteration if unlimited_listing
|
37
|
+
|
38
|
+
page += 1
|
39
|
+
else
|
40
|
+
raise StopIteration
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end.lazy
|
39
44
|
end
|
40
45
|
|
41
46
|
def backend_version
|
@@ -46,31 +51,17 @@ module ArchivesSpace
|
|
46
51
|
# create "batch_import", payload, params
|
47
52
|
end
|
48
53
|
|
49
|
-
def
|
50
|
-
|
51
|
-
path = "digital_objects/#{format}/#{id}.xml"
|
52
|
-
get_xml path, options
|
53
|
-
end
|
54
|
-
|
55
|
-
def digital_objects(format = nil, options = {}, &block)
|
56
|
-
path = "digital_objects"
|
57
|
-
format = format ? "#{path}/#{format}" : nil
|
58
|
-
records = all(path, options.merge({ format: format })) do |record|
|
59
|
-
yield record if block_given?
|
60
|
-
end
|
61
|
-
records
|
54
|
+
def digital_objects(options = {})
|
55
|
+
all('digital_objects', options)
|
62
56
|
end
|
63
57
|
|
64
|
-
def groups
|
65
|
-
|
66
|
-
yield record if block_given?
|
67
|
-
end
|
68
|
-
records
|
58
|
+
def groups(options = {})
|
59
|
+
all('groups', options)
|
69
60
|
end
|
70
61
|
|
71
62
|
def group_user_assignment(users_with_roles, params = { with_members: true })
|
72
63
|
updated = []
|
73
|
-
groups do |group|
|
64
|
+
groups.each do |group|
|
74
65
|
changed = false
|
75
66
|
|
76
67
|
users_with_roles.each do |user, roles|
|
@@ -110,59 +101,26 @@ module ArchivesSpace
|
|
110
101
|
post(user["uri"], user, { password: password })
|
111
102
|
end
|
112
103
|
|
113
|
-
def repositories
|
114
|
-
|
115
|
-
yield record if block_given?
|
116
|
-
end
|
117
|
-
records
|
104
|
+
def repositories(options = {})
|
105
|
+
all('repositories', options)
|
118
106
|
end
|
119
107
|
|
120
108
|
def repositories_with_agent
|
121
109
|
#
|
122
110
|
end
|
123
111
|
|
124
|
-
def
|
125
|
-
|
126
|
-
path = format == "ead" ? "resource_descriptions/#{id}.xml" : "resources/#{format}/#{id}.xml"
|
127
|
-
get_xml path, options
|
128
|
-
end
|
129
|
-
|
130
|
-
def resources(format = nil, options = {}, &block)
|
131
|
-
path = 'resources'
|
132
|
-
# the api is inconsistent with the path structure for resource ead (and pdf)
|
133
|
-
if format
|
134
|
-
if format =~ /(ead|pdf)/
|
135
|
-
format = "resource_descriptions"
|
136
|
-
else
|
137
|
-
format = "#{path}/#{format}"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
records = all(path, options.merge({ format: format })) do |record|
|
141
|
-
yield record if block_given?
|
142
|
-
end
|
143
|
-
records
|
112
|
+
def resources(options = {})
|
113
|
+
all('resources', options)
|
144
114
|
end
|
145
115
|
|
146
116
|
def search(params)
|
147
117
|
# get "search", params
|
148
118
|
end
|
149
119
|
|
150
|
-
def users
|
151
|
-
|
152
|
-
yield record if block_given?
|
153
|
-
end
|
154
|
-
records
|
155
|
-
end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
def get_xml(path, options = {})
|
160
|
-
# add xml headers
|
161
|
-
response = get(path, options)
|
162
|
-
raise RequestError.new(response.body) unless response.status_code == 200
|
163
|
-
Nokogiri::XML(response.body).to_xml
|
120
|
+
def users(options = {})
|
121
|
+
all('users', options)
|
164
122
|
end
|
165
123
|
|
166
124
|
end
|
167
125
|
|
168
|
-
end
|
126
|
+
end
|
@@ -21,18 +21,19 @@ module ArchivesSpace
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def initialize(config, method = "GET", path = "", options = {})
|
24
|
-
@config
|
25
|
-
@method
|
26
|
-
@path
|
24
|
+
@config = config
|
25
|
+
@method = method.downcase.to_sym
|
26
|
+
@path = path.gsub(/^\/+/, '')
|
27
|
+
@options = options
|
28
|
+
@options[:headers] = options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
|
29
|
+
@options[:verify] = config.verify_ssl
|
30
|
+
@options[:query] = {} unless options.has_key? :query
|
31
|
+
|
32
|
+
base_uri = (
|
33
|
+
config.base_repo.nil? or config.base_repo.empty?
|
34
|
+
) ? config.base_uri : "#{config.base_uri}/#{config.base_repo}"
|
27
35
|
|
28
|
-
@options = options
|
29
|
-
@options[:headers] = options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
|
30
|
-
@options[:verify] = config.verify_ssl
|
31
|
-
@options[:query] = {} unless options.has_key? :query
|
32
|
-
|
33
|
-
base_uri = (config.base_repo.nil? or config.base_repo.empty?) ? config.base_uri : "#{config.base_uri}/#{config.base_repo}"
|
34
36
|
self.class.base_uri base_uri
|
35
|
-
# self.class.default_params abc: 123
|
36
37
|
end
|
37
38
|
|
38
39
|
def execute
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: archivesspace-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Cooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.6
|
194
|
+
rubygems_version: 2.7.6
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Interact with ArchivesSpace via its RESTful API.
|