collectionspace-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: a866877142a63cd6d01e906a45da80642ba7863f
4
- data.tar.gz: e063df2beeb9c3dc6e794ce85123077f95dfe523
2
+ SHA256:
3
+ metadata.gz: 102021d7f34434b3f5a79382333ec7677ef7fba8dcdfd2f73daff1a7faa10b59
4
+ data.tar.gz: 2510a4f0c3932bb08545e9c263c4357faccad8c6183f43f2e8122bef740dc34c
5
5
  SHA512:
6
- metadata.gz: 56aff1dad9eafc9a964f684fe64c000c38c957e59ee9691293592ba8a0b5c236d9ce55deebb4c3291e7d57dd7c29d815a9937cf486c858f2c36aaf0411d4eba3
7
- data.tar.gz: '0184331cdb6aa7305e879175cc26e4f3165e988f1560d61ccdee663e87e65c1216b4914ccbb8edcf36223f028681fdb5ede8e93f480ff17115fea834770aec77'
6
+ metadata.gz: 90419be95bd910c0f17e9f0adc9918f702d985278a7b91d0cd531179bacac3e2ce1a1c08aa98510fb7ed66b258451f31923a2013c488110b4e7262383d199feb
7
+ data.tar.gz: 031e9d9b52bbe9a83a8c3234bc52f9cbcc5a09c89340c7016dc9d8e5075582954945632cdc133426f42fcbeb6d2fc56995fe1cc7059ca2ba1e30eee47f2b62ca
data/README.md CHANGED
@@ -81,7 +81,7 @@ Publishing
81
81
  Bump version in `lib/collectionspace/client/version.rb` then:
82
82
 
83
83
  ```bash
84
- VERSION=0.1.4
84
+ VERSION=0.1.5
85
85
  gem build collectionspace-client
86
86
  gem push collectionspace-client-$VERSION.gem
87
87
  git tag v$VERSION
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "json"
23
23
  spec.add_dependency "nokogiri"
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "bundler"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "rspec"
28
28
  spec.add_development_dependency "vcr"
data/examples/demo.rb CHANGED
@@ -13,12 +13,8 @@ if response.status_code == 200
13
13
  ap response.xml
14
14
  end
15
15
 
16
- # GET ALL ACQUISITIONS AND PRINT TO CONSOLE
17
- acquisitions = client.all('acquisitions')
18
- ap acquisitions
19
-
20
16
  # GET ALL INTAKE RECORDS AND PROCESS PER PAGE (INSTEAD OF WAITING FOR ALL)
21
- client.all('intakes') do |item|
17
+ client.all('media').each do |item|
22
18
  uri = item["uri"]
23
19
  intake = client.get uri
24
20
  ap intake.parsed
data/examples/export.rb CHANGED
@@ -21,7 +21,7 @@ client = CollectionSpace::Client.new
21
21
  client.config.throttle = 1
22
22
 
23
23
  # GET ALL CATALOGING RECORDS AND DUMP THE XML IF UPDATED SINCE 3 DAYS AGO
24
- client.all('collectionobjects') do |item|
24
+ client.all('collectionobjects').each do |item|
25
25
  updated = Date.parse item["updatedAt"]
26
26
  if updated > Date.parse(14.days.ago.to_s)
27
27
  collectionobject = client.get item["uri"]
@@ -6,8 +6,9 @@ require 'collectionspace/client'
6
6
  client = CollectionSpace::Client.new
7
7
  client.config.throttle = 1
8
8
 
9
- client.all('vocabularies') do |item|
9
+ client.all('vocabularies').each do |item|
10
10
  uri = item["uri"]
11
+ puts "Checking vocabulary: #{uri}"
11
12
  if client.count("#{uri}/items") == 0
12
13
  puts "Purging empty vocabulary:\t#{item['displayName']} (#{item['csid']})"
13
14
  # YOU WOULD UNCOMMENT THIS TO ACTUALLY PERFORM THE PURGE ...
@@ -19,29 +19,23 @@ module CollectionSpace
19
19
  module Helpers
20
20
 
21
21
  # get ALL records at path by paging through record set
22
- # can pass block to act on each page of results
23
- def all(path, options = {}, &block)
24
- all = []
22
+ def all(path, options = {})
25
23
  list_type, list_item = get_list_types(path)
26
-
27
- result = request('GET', path, options)
28
- raise RequestError.new result.status if result.status_code != 200 or result.parsed[list_type].nil?
29
-
30
- total = result.parsed[list_type]['totalItems'].to_i
31
- items = result.parsed[list_type]['itemsInPage'].to_i
32
- return all if total == 0
33
-
34
- pages = (total / config.page_size) + 1
35
- (0 .. pages - 1).each do |i|
36
- options[:query][:pgNum] = i
37
- result = request('GET', path, options)
38
- raise RequestError.new result.status if result.status_code != 200
39
- list_items = result.parsed[list_type][list_item]
40
- list_items = [ list_items ] if items == 1
41
- list_items.each { |item| yield item if block_given? }
42
- all.concat list_items
43
- end
44
- all
24
+ Enumerator.new do |yielder|
25
+ page = 0
26
+ loop do
27
+ result = request('GET', path, options.merge(query: { pgNum: page }))
28
+ raise StopIteration unless result.parsed[list_type].key?('itemsInPage')
29
+
30
+ items = result.parsed[list_type]['itemsInPage'].to_i
31
+ raise StopIteration if items == 0
32
+
33
+ list_items = result.parsed[list_type][list_item]
34
+ list_items = [list_items] if items == 1
35
+ list_items.each { |item| yielder << item }
36
+ page += 1
37
+ end
38
+ end.lazy
45
39
  end
46
40
 
47
41
  def count(path)
@@ -21,9 +21,9 @@ module CollectionSpace
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
27
 
28
28
  @auth = {
29
29
  username: config.username,
@@ -1,5 +1,5 @@
1
1
  module CollectionSpace
2
2
  class Client
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cooper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.10'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.10'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 2.6.13
187
+ rubygems_version: 2.7.6
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: CollectionSpace API client.