collectionspace-client 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 624c2100ab4de83a3748eea7ec37a0fd4743cdda9365e8ccd29d452b11f0b8ad
4
- data.tar.gz: 7f25d8c31ad74c28999de4bb5c5822f655f947154828174a3351d818e036a5f1
3
+ metadata.gz: e63c182e9731f5868556d805eed65b8c85d32789363c90f4ac763cff06e2b693
4
+ data.tar.gz: 00d6e5804a0131adad73d28eee0dd32a95dd9b9a05346bf4e1374d54bfa1f2b5
5
5
  SHA512:
6
- metadata.gz: d65eaf040bb629d702085af054b47b2f39411784c0f8f7cdb032f48af79f99b846ef1f803ef357634d477f4b4d7c9f585e07c1d5b5e9476f22247b67ae0cd00c
7
- data.tar.gz: 0661b69f11ea60a5ce5edc94f753a048a7ec6ce2585c855c69af25e4cfb1998106a13132e42fdbe8b70a5184a6032c817650253ebf215930a83ba7e1dd73a42d
6
+ metadata.gz: fa76fc6c2b8f1761c01dc195198445eba31698d0d530d0993c5fa64ceb1ace2fbc44153a7d8c4dd29fe3d272463e1f82d3185f5a8d46ddfbec9252f0b8ec0ca5
7
+ data.tar.gz: b67294a65c42c52804af6e429f45e2ea9bcb1a5e4ea4d78fb3da0cfeafb8018221d835a29b81c48fea6e43b287b88e549e6bfd746f124a9814c1079fdae3abc7
data/README.md CHANGED
@@ -37,7 +37,7 @@ bundle exec rake
37
37
  Bump version in `lib/collectionspace/client/version.rb` then:
38
38
 
39
39
  ```bash
40
- VERSION=0.2.0
40
+ VERSION=0.3.0
41
41
  git add .
42
42
  git commit -m "Bump version: v${VERSION}"
43
43
  git push origin master
@@ -9,14 +9,12 @@ client = CollectionSpace::Client.new(
9
9
  password: 'Administrator'
10
10
  )
11
11
  )
12
- client.config.throttle = 1
13
12
 
14
13
  # GET REQUEST FOR CONDITIONCHECK RECORDS AND PRINT THE PARSED RESPONSE AND XML
15
14
  response = client.get('conditionchecks')
16
15
  ap response.parsed if response.result.success?
17
16
 
18
- # GET ALL INTAKE RECORDS AND PROCESS PER PAGE (INSTEAD OF WAITING FOR ALL)
19
- client.all('personauthorities').each do |item|
20
- i = client.get item['uri']
21
- ap i.parsed
17
+ # GET ALL PERSON RECORDS AND PROCESS PER PAGE (INSTEAD OF WAITING FOR ALL)
18
+ client.all('personauthorities/urn:cspace:name(person)/items').each do |item|
19
+ puts item
22
20
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+ require 'awesome_print'
5
+ require 'base64'
6
+ require 'collectionspace/client'
7
+
8
+ CS_CFG_URL = ENV.fetch('CS_CFG_URL', 'https://core.dev.collectionspace.org/cspace-services')
9
+ CS_CFG_USER = ENV.fetch('CS_CFG_USER', 'admin@core.collectionspace.org')
10
+ CS_CFG_PASS = ENV.fetch('CS_CFG_PASS', 'Administrator')
11
+ CS_UPD_USER = ENV.fetch('CS_UPD_USER', 'admin@core.collectionspace.org')
12
+ CS_UPD_PASS = Base64.encode64(ENV.fetch('CS_UPD_PASS', 'Administrator')).chomp
13
+
14
+ client = CollectionSpace::Client.new(
15
+ CollectionSpace::Configuration.new(
16
+ base_uri: CS_CFG_URL,
17
+ username: CS_CFG_USER,
18
+ password: CS_CFG_PASS
19
+ )
20
+ )
21
+
22
+ PAYLOAD = <<~XML
23
+ <ns2:accounts_common xmlns:ns2="http://collectionspace.org/services/account">
24
+ <userId>#{CS_UPD_USER}</userId>
25
+ <password>#{CS_UPD_PASS}</password>
26
+ </ns2:accounts_common>
27
+ XML
28
+
29
+ client.all('accounts').each do |item|
30
+ next unless item['email'] == CS_UPD_USER
31
+
32
+ ap client.put(item['uri'], PAYLOAD).parsed
33
+ end
@@ -4,37 +4,34 @@ module CollectionSpace
4
4
  # get ALL records at path by paging through record set
5
5
  def all(path, options = {})
6
6
  list_type, list_item = get_list_types(path)
7
- Enumerator.new do |yielder|
8
- page = 0
9
- loop do
10
- response = request('GET', path, options.merge(query: { pgNum: page }))
11
- unless response.result.success?
12
- raise CollectionSpace::RequestError, response.result.body
13
- end
7
+ iterations = (count(path).to_f / config.page_size).ceil
8
+ return [] unless iterations.positive?
14
9
 
15
- items = response.parsed[list_type].fetch('itemsInPage', 0).to_i
16
- raise StopIteration if items.zero?
17
-
18
- list_items = response.parsed[list_type][list_item]
19
- list_items = [list_items] if items == 1
20
- list_items.each { |item| yielder << item }
21
- page += 1
10
+ Enumerator::Lazy.new(0...iterations) do |yielder, i|
11
+ response = request('GET', path, options.merge(query: { pgNum: i }))
12
+ unless response.result.success?
13
+ raise CollectionSpace::RequestError, response.result.body
22
14
  end
23
- end.lazy
15
+
16
+ items_in_page = response.parsed[list_type].fetch('itemsInPage', 0).to_i
17
+ list_items = items_in_page.positive? ? response.parsed[list_type][list_item] : []
18
+ list_items = [list_items] if items_in_page == 1
19
+
20
+ yielder << list_items.shift until list_items.empty?
21
+ end
24
22
  end
25
23
 
26
24
  def count(path)
27
25
  list_type, = get_list_types(path)
28
- response = request('GET', path, query: { pgSz: 1 })
26
+ response = request('GET', path, query: { pgNum: 0, pgSz: 1 })
29
27
  response.parsed[list_type]['totalItems'].to_i if response.result.success?
30
28
  end
31
29
 
32
30
  def get_list_types(path)
33
- if path == 'relations'
34
- %w[relations_common_list relation_list_item]
35
- else
36
- %w[abstract_common_list list_item]
37
- end
31
+ {
32
+ 'accounts' => %w[accounts_common_list account_list_item],
33
+ 'relations' => %w[relations_common_list relation_list_item],
34
+ }.fetch(path, %w[abstract_common_list list_item])
38
35
  end
39
36
 
40
37
  def prepare_query(query, options = {})
@@ -1,5 +1,5 @@
1
1
  module CollectionSpace
2
2
  class Client
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collectionspace-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cooper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -170,6 +170,7 @@ files:
170
170
  - examples/media_with_external_file.rb
171
171
  - examples/purge_empty_vocabs.rb
172
172
  - examples/search.rb
173
+ - examples/update_password.rb
173
174
  - lib/collectionspace/client.rb
174
175
  - lib/collectionspace/client/client.rb
175
176
  - lib/collectionspace/client/configuration.rb
@@ -197,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
198
  - !ruby/object:Gem::Version
198
199
  version: '0'
199
200
  requirements: []
200
- rubyforge_project:
201
- rubygems_version: 2.7.6
201
+ rubygems_version: 3.0.3
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: CollectionSpace API client.