fieldhand 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: a1f8b4934a70d78dda2f03bb151deea7ed553424
4
- data.tar.gz: f39842d9de77f6a43203f6795ef35836ac5efbff
3
+ metadata.gz: c1ca08a8fb6ab7682f308d7cb2ffe4ac3cc0829d
4
+ data.tar.gz: dea8d65de365fb51ef9788e4cfd4c34dd11af2b4
5
5
  SHA512:
6
- metadata.gz: 6ce68385c9352deabd07c6f60ef904853c934a79d1488a88abbffaed9c1802e59f06437501cc23f79b68bbacc801608c758085753373525e9484d4c0b566c181
7
- data.tar.gz: 22c515794f85150b621f0a8ef0d7af25505590a707ff86b8972e5751c69cf5a0bc46508cfb53b5d8ebe5458be778d10b9d69c1cfd13e731b92806b1de69e7cec
6
+ metadata.gz: e797e8d9625730ac9bed36bbeaae6fb8d490695e6b165a94f7e48ea0b743d8c4f95322bbd3c119533a2a446a5014a1e90fd1adcc96a003bceba83cc61a8a9fa1
7
+ data.tar.gz: '0295cc11eb9ad3f6c6782022cf1f06953aa4675ef608a32c9dc9cb363f1733750f08bedd3e69870d1973d031e8ed6366a1ff509a951818bcb3985fe72d1db6c6'
data/README.md CHANGED
@@ -2,9 +2,21 @@
2
2
 
3
3
  A Ruby library for harvesting metadata from [OAI-PMH](https://www.openarchives.org/OAI/openarchivesprotocol.html) repositories.
4
4
 
5
- **Current version:** 0.1.0
5
+ **Current version:** 0.2.0
6
6
  **Supported Ruby versions:** 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2
7
7
 
8
+ ## Installation
9
+
10
+ ```
11
+ gem install fieldhand -v '~> 0.2'
12
+ ```
13
+
14
+ Or, in your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'fieldhand', '~> 0.2'
18
+ ```
19
+
8
20
  ## Usage
9
21
 
10
22
  ```ruby
@@ -48,14 +60,17 @@ repository.get('oai:www.example.com:12345')
48
60
  * [`#admin_emails`](#fieldhandidentifyadmin_emails)
49
61
  * [`#compression`](#fieldhandidentifycompression)
50
62
  * [`#descriptions`](#fieldhandidentifydescriptions)
63
+ * [`#response_date`](#fieldhandidentifyresponse_date)
51
64
  * [`Fieldhand::MetadataFormat`](#fieldhandmetadataformat)
52
65
  * [`#prefix`](#fieldhandmetadataformatprefix)
53
66
  * [`#schema`](#fieldhandmetadataformatschema)
54
67
  * [`#namespace`](#fieldhandmetadataformatnamespace)
68
+ * [`#response_date`](#fieldhandmetadataformatresponse_date)
55
69
  * [`Fieldhand::Set`](#fieldhandset)
56
70
  * [`#spec`](#fieldhandsetspec)
57
71
  * [`#name`](#fieldhandsetname)
58
72
  * [`#descriptions`](#fieldhandsetdescriptions)
73
+ * [`#response_date`](#fieldhandsetresponse_date)
59
74
  * [`Fieldhand::Record`](#fieldhandrecord)
60
75
  * [`#deleted?`](#fieldhandrecorddeleted)
61
76
  * [`#status`](#fieldhandrecordstatus)
@@ -64,12 +79,14 @@ repository.get('oai:www.example.com:12345')
64
79
  * [`#sets`](#fieldhandrecordsets)
65
80
  * [`#metadata`](#fieldhandrecordmetadata)
66
81
  * [`#about`](#fieldhandrecordabout)
82
+ * [`#response_date`](#fieldhandrecordresponse_date)
67
83
  * [`Fieldhand::Header`](#fieldhandheader)
68
84
  * [`#deleted?`](#fieldhandheaderdeleted)
69
85
  * [`#status`](#fieldhandheaderstatus)
70
86
  * [`#identifier`](#fieldhandheaderidentifier)
71
87
  * [`#datestamp`](#fieldhandheaderdatestamp)
72
88
  * [`#sets`](#fieldhandheadersets)
89
+ * [`#response_date`](#fieldhandheaderresponse_date)
73
90
  * [`Fieldhand::NetworkError`](#fieldhandnetworkerror)
74
91
  * [`Fieldhand::ProtocolError`](#fieldhandprotocolerror)
75
92
  * [`Fieldhand::BadArgumentError`](#fieldhandbadargumenterror)
@@ -276,6 +293,15 @@ Returns XML elements describing this repository as an `Array` of [`Ox::Element`]
276
293
 
277
294
  As descriptions can be in any format, Fieldhand doesn't attempt to parse descriptions but leaves parsing to the client.
278
295
 
296
+ #### `Fieldhand::Identify#response_date`
297
+
298
+ ```ruby
299
+ repository.identify.response_date
300
+ #=> 2017-05-08 11:21:38 +0100
301
+ ```
302
+
303
+ Return the time and date that the response was sent.
304
+
279
305
  ### `Fieldhand::MetadataFormat`
280
306
 
281
307
  A class to represent a metadata format available from a repository.
@@ -307,6 +333,15 @@ repository.metadata_formats.first.namespace
307
333
 
308
334
  Return the XML Namespace URI for the format as a [`URI`][URI].
309
335
 
336
+ #### `Fieldhand::MetadataFormat#response_date`
337
+
338
+ ```ruby
339
+ repository.metadata_formats.first.response_date
340
+ #=> 2017-05-08 11:21:38 +0100
341
+ ```
342
+
343
+ Return the time and date that the response was sent.
344
+
310
345
  ### `Fieldhand::Set`
311
346
 
312
347
  A class representing an optional construct for grouping items for the purpose of selective harvesting.
@@ -338,6 +373,15 @@ repository.sets.first.descriptions
338
373
 
339
374
  Return an `Array` of [`Ox::Element`][Element]s of any optional and repeatable containers that may hold community-specific XML-encoded data about the set.
340
375
 
376
+ #### `Fieldhand::Set#response_date`
377
+
378
+ ```ruby
379
+ repository.sets.first.response_date
380
+ #=> 2017-05-08 11:21:38 +0100
381
+ ```
382
+
383
+ Return the time and date that the response was sent.
384
+
341
385
  ### `Fieldhand::Record`
342
386
 
343
387
  A class representing a [record](https://www.openarchives.org/OAI/openarchivesprotocol.html#Record) from the repository:
@@ -411,6 +455,15 @@ repository.records.first.about
411
455
 
412
456
  Return an `Array` of [`Ox::Element`][Element]s of any optional and repeatable containers holding data about the metadata part of the record.
413
457
 
458
+ #### `Fieldhand::Record#response_date`
459
+
460
+ ```ruby
461
+ repository.records.first.response_date
462
+ #=> 2017-05-08 11:21:38 +0100
463
+ ```
464
+
465
+ Return the time and date that the response was sent.
466
+
414
467
  ### `Fieldhand::Header`
415
468
 
416
469
  A class representing the [header](https://www.openarchives.org/OAI/openarchivesprotocol.html#header) of a record:
@@ -472,6 +525,15 @@ repository.identifiers.first.sets
472
525
 
473
526
  Return an `Array` of `String` [set specs](#fieldhandsetspec) indicating set memberships of this record.
474
527
 
528
+ #### `Fieldhand::Header#response_date`
529
+
530
+ ```ruby
531
+ repository.identifiers.first.response_date
532
+ #=> 2017-05-08 11:21:38 +0100
533
+ ```
534
+
535
+ Return the time and date that the response was sent.
536
+
475
537
  ### `Fieldhand::NetworkError`
476
538
 
477
539
  An error (descended from `StandardError`) to represent any network issues encountered during interaction with the repository. Any underlying exception is exposed in Ruby 2.1 onwards through [`Exception#cause`](https://ruby-doc.org/core-2.1.0/Exception.html#method-i-cause).
@@ -13,10 +13,11 @@ module Fieldhand
13
13
  #
14
14
  # See https://www.openarchives.org/OAI/openarchivesprotocol.html#header
15
15
  class Header
16
- attr_reader :element
16
+ attr_reader :element, :response_date
17
17
 
18
- def initialize(element)
18
+ def initialize(element, response_date = Time.now)
19
19
  @element = element
20
+ @response_date = response_date
20
21
  end
21
22
 
22
23
  def deleted?
@@ -6,10 +6,11 @@ module Fieldhand
6
6
  #
7
7
  # See https://www.openarchives.org/OAI/openarchivesprotocol.html#Identify
8
8
  class Identify
9
- attr_reader :element
9
+ attr_reader :element, :response_date
10
10
 
11
- def initialize(element)
11
+ def initialize(element, response_date = Time.now)
12
12
  @element = element
13
+ @response_date = response_date
13
14
  end
14
15
 
15
16
  def name
@@ -5,10 +5,11 @@ module Fieldhand
5
5
  #
6
6
  # See https://www.openarchives.org/OAI/openarchivesprotocol.html#ListMetadataFormats
7
7
  class MetadataFormat
8
- attr_reader :element
8
+ attr_reader :element, :response_date
9
9
 
10
- def initialize(element)
10
+ def initialize(element, response_date = Time.now)
11
11
  @element = element
12
+ @response_date = response_date
12
13
  end
13
14
 
14
15
  def to_s
@@ -1,3 +1,4 @@
1
+ require 'fieldhand/datestamp'
1
2
  require 'fieldhand/logger'
2
3
  require 'ox'
3
4
  require 'cgi'
@@ -46,13 +47,14 @@ module Fieldhand
46
47
 
47
48
  loop do
48
49
  document = ::Ox.parse(request(query.merge('verb' => verb)))
50
+ response_date = document.root.locate('responseDate[0]/^String').map { |date| Datestamp.parse(date) }.first
49
51
 
50
52
  document.root.locate('error').each do |error|
51
53
  convert_error(error)
52
54
  end
53
55
 
54
56
  document.root.locate(path).each do |item|
55
- yield item
57
+ yield item, response_date
56
58
  end
57
59
 
58
60
  resumption_token = document.root.locate('?/resumptionToken/^String').first
@@ -5,10 +5,11 @@ module Fieldhand
5
5
  #
6
6
  # See https://www.openarchives.org/OAI/openarchivesprotocol.html#Record
7
7
  class Record
8
- attr_reader :element
8
+ attr_reader :element, :response_date
9
9
 
10
- def initialize(element)
10
+ def initialize(element, response_date = Time.now)
11
11
  @element = element
12
+ @response_date = response_date
12
13
  end
13
14
 
14
15
  def deleted?
@@ -23,7 +23,7 @@ module Fieldhand
23
23
  def identify
24
24
  paginator.
25
25
  items('Identify', 'Identify').
26
- map { |identify| Identify.new(identify) }.
26
+ map { |identify, response_date| Identify.new(identify, response_date) }.
27
27
  first
28
28
  end
29
29
 
@@ -35,8 +35,8 @@ module Fieldhand
35
35
 
36
36
  paginator.
37
37
  items('ListMetadataFormats', 'ListMetadataFormats/metadataFormat', arguments).
38
- each do |format|
39
- yield MetadataFormat.new(format)
38
+ each do |format, response_date|
39
+ yield MetadataFormat.new(format, response_date)
40
40
  end
41
41
  end
42
42
 
@@ -45,8 +45,8 @@ module Fieldhand
45
45
 
46
46
  paginator.
47
47
  items('ListSets', 'ListSets/set').
48
- each do |set|
49
- yield Set.new(set)
48
+ each do |set, response_date|
49
+ yield Set.new(set, response_date)
50
50
  end
51
51
  end
52
52
 
@@ -57,8 +57,8 @@ module Fieldhand
57
57
 
58
58
  paginator.
59
59
  items('ListRecords', 'ListRecords/record', query).
60
- each do |record|
61
- yield Record.new(record)
60
+ each do |record, response_date|
61
+ yield Record.new(record, response_date)
62
62
  end
63
63
  end
64
64
 
@@ -69,8 +69,8 @@ module Fieldhand
69
69
 
70
70
  paginator.
71
71
  items('ListIdentifiers', 'ListIdentifiers/header', query).
72
- each do |header|
73
- yield Header.new(header)
72
+ each do |header, response_date|
73
+ yield Header.new(header, response_date)
74
74
  end
75
75
  end
76
76
 
@@ -82,7 +82,7 @@ module Fieldhand
82
82
 
83
83
  paginator.
84
84
  items('GetRecord', 'GetRecord/record', query).
85
- map { |record| Record.new(record) }.
85
+ map { |record, response_date| Record.new(record, response_date) }.
86
86
  first
87
87
  end
88
88
 
@@ -3,10 +3,11 @@ module Fieldhand
3
3
  #
4
4
  # See https://www.openarchives.org/OAI/openarchivesprotocol.html#Set
5
5
  class Set
6
- attr_reader :element
6
+ attr_reader :element, :response_date
7
7
 
8
- def initialize(element)
8
+ def initialize(element, response_date = Time.now)
9
9
  @element = element
10
+ @response_date = response_date
10
11
  end
11
12
 
12
13
  def to_s
@@ -34,5 +34,14 @@ module Fieldhand
34
34
  expect(header.datestamp).to eq(::Date.new(2001, 1, 1))
35
35
  end
36
36
  end
37
+
38
+ describe '#response_date' do
39
+ it 'returns the passed response date' do
40
+ element = ::Ox.parse('<header/>')
41
+ header = described_class.new(element, ::Time.utc(2001, 1, 1, 0, 0, 0))
42
+
43
+ expect(header.response_date).to eq(::Time.utc(2001, 1, 1, 0, 0, 0))
44
+ end
45
+ end
37
46
  end
38
47
  end
@@ -39,5 +39,14 @@ module Fieldhand
39
39
  expect(identify.earliest_datestamp).to eq(::Date.new(1990, 2, 1))
40
40
  end
41
41
  end
42
+
43
+ describe '#response_date' do
44
+ it 'returns the passed response date' do
45
+ element = ::Ox.parse('<Identify/>')
46
+ identify = described_class.new(element, ::Time.utc(2001, 1, 1, 0, 0, 0))
47
+
48
+ expect(identify.response_date).to eq(::Time.utc(2001, 1, 1, 0, 0, 0))
49
+ end
50
+ end
42
51
  end
43
52
  end
@@ -11,5 +11,14 @@ module Fieldhand
11
11
  expect(format.to_s).to eq('xoai')
12
12
  end
13
13
  end
14
+
15
+ describe '#response_date' do
16
+ it 'returns the passed response date' do
17
+ element = ::Ox.parse('<metadataFormat/>')
18
+ format = described_class.new(element, ::Time.utc(2001, 1, 1, 0, 0, 0))
19
+
20
+ expect(format.response_date).to eq(::Time.utc(2001, 1, 1, 0, 0, 0))
21
+ end
22
+ end
14
23
  end
15
24
  end
@@ -34,5 +34,14 @@ module Fieldhand
34
34
  expect(record.about.size).to eq(2)
35
35
  end
36
36
  end
37
+
38
+ describe '#response_date' do
39
+ it 'returns the passed response date' do
40
+ element = ::Ox.parse('<record/>')
41
+ record = described_class.new(element, ::Time.utc(2001, 1, 1, 0, 0, 0))
42
+
43
+ expect(record.response_date).to eq(::Time.utc(2001, 1, 1, 0, 0, 0))
44
+ end
45
+ end
37
46
  end
38
47
  end
@@ -27,5 +27,14 @@ module Fieldhand
27
27
  expect(set.to_s).to eq('A')
28
28
  end
29
29
  end
30
+
31
+ describe '#response_date' do
32
+ it 'returns the passed response date' do
33
+ element = ::Ox.parse('<set/>')
34
+ set = described_class.new(element, ::Time.utc(2001, 1, 1, 0, 0, 0))
35
+
36
+ expect(set.response_date).to eq(::Time.utc(2001, 1, 1, 0, 0, 0))
37
+ end
38
+ end
30
39
  end
31
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fieldhand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-07 00:00:00.000000000 Z
12
+ date: 2017-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ox
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.5.1
131
+ rubygems_version: 2.6.11
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: An OAI-PMH harvester