archivesspace-client 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9b4ca0ba3d8d057c3e6173cfec463660ab5edca6
4
- data.tar.gz: 78fb789484fb50bf3892e1a2e9d0d3eb56a8bc88
2
+ SHA256:
3
+ metadata.gz: 19da316e65bd48aaf2efa4268eb7217d051f9e11a1e822b0b4813bae4dd5f906
4
+ data.tar.gz: 8ea7445f1fa00f42a3c0ea633f3f6938aeee071b679408e3acfcb1e16a7858df
5
5
  SHA512:
6
- metadata.gz: cc2d5f97f7f2d444b1779db3bbd41052862f066051dd408b358f6d38fe85a0daa13c39d110d9a534f98c5e2bb8b47688316e2acefa05ee205a8956af7ad1bdb5
7
- data.tar.gz: 71d430fba940727214d3a46fd5d249d7e580a9463418087e66c69ad27c0b5685cb7e2d12465f0f2c002977d4a5e05a999f88f91f1f11eaf288ef802e11ea8c2a
6
+ metadata.gz: 79b6c0d669fa21b7df8a55ca888155dc1d15be16283fa050ff87bd68bb0a4c26e028ae6baa27abb4446515ea9afe91204e87054d7db3fa49934d06e65a20dee6
7
+ data.tar.gz: 27c911770a1bdb0813b913722234d52c8eb948cfc8f925589d877c7b4f0ed78aac31e0275ae135c8bb5762a175a0d3be5249d61e4ef616ed96bc49c04d4d6675
data/README.md CHANGED
@@ -110,7 +110,7 @@ bundle exec rake
110
110
  Bump version in `lib/archivesspace/client/version.rb` then:
111
111
 
112
112
  ```bash
113
- VERSION=0.1.4
113
+ VERSION=0.1.5
114
114
  gem build archivesspace-client
115
115
  gem push archivesspace-client-$VERSION.gem
116
116
  git tag v$VERSION
@@ -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", "~> 1.10"
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"
@@ -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("ead", { query: { modified_since: "1435734000" } }) do |ead|
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
- ap ead
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
@@ -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 == 201
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 == 201
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
- raise "Invalid configuration object" unless config.kind_of? ArchivesSpace::Configuration
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 = {}, &block)
14
- records = all('accessions', options) do |record|
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 = {}, &block)
21
- all = []
22
- format = options.delete(:format)
23
- parse_id = options.delete(:parse_id)
24
- # options[:headers] -- add xml headers if format
25
-
26
- result = get(path, options.merge({ query: { all_ids: true } } ))
27
- raise RequestError.new(result.body) if result.status_code != 200
28
- ids = result.parsed
29
- ids = ids.map{ |object| object["uri"].split("/")[-1] } if parse_id
30
- ids.each do |id|
31
- path_with_id = format ? "#{format}/#{id}.xml" : "#{path}/#{id}"
32
- result = get(path_with_id, options)
33
- raise RequestError.new(result.body) if result.status_code != 200
34
- record = format ? Nokogiri::XML(result.body).to_xml : result.parsed
35
- yield record if block_given?
36
- all << record
37
- end
38
- all
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 digital_object_to_xml(digital_object, format = "dublin_core", options = {})
50
- id = digital_object["uri"].split("/")[-1]
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
- records = all('groups', { parse_id: true }) do |record|
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
- records = get('repositories').parsed.each do |record|
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 resource_to_xml(resource, format = "ead", options = {})
125
- id = resource["uri"].split("/")[-1]
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
- records = all('users') do |record|
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 = config
25
- @method = method.downcase.to_sym
26
- @path = path.gsub(/^\/+/, '')
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
@@ -1,5 +1,5 @@
1
1
  module ArchivesSpace
2
2
  class Client
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
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
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: 2018-08-08 00:00:00.000000000 Z
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: '1.10'
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: '1.10'
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.13
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.