fieldhand 0.7.0 → 0.8.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 +5 -5
- data/README.md +10 -9
- data/lib/fieldhand/options.rb +41 -0
- data/lib/fieldhand/paginator.rb +12 -6
- data/lib/fieldhand/repository.rb +13 -7
- data/spec/fieldhand/options_spec.rb +59 -0
- data/spec/fieldhand/paginator_spec.rb +36 -0
- data/spec/fieldhand/repository_spec.rb +36 -0
- data/spec/spec_helper.rb +1 -0
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 48341fcf65a936b5bc42a7f6cdcc9881d2d3f11ef29352a14f0f545f1318b5a0
|
4
|
+
data.tar.gz: 17ce75aba6b336de464b496604aec0bbda5d673ff98d6c8ee1a659b0f75fb425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fddd10cde8fc771c259234deadef079468f8a3517174a82e92dd480a29d5ccbbd655dfeb5f1f4fceeda85b1e4d9707ab715ddde8baf6fa2e43fd2fedd6867121
|
7
|
+
data.tar.gz: 9f201592dc6968fdf41c5bd8134c67496f4eed2c89077442474b0491ef83417e170a182da2c1262aaca3d811ad6dd2e756a18e1e8e025a799e4cbd6e1ef2f616
|
data/README.md
CHANGED
@@ -2,19 +2,19 @@
|
|
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.
|
5
|
+
**Current version:** 0.8.0
|
6
6
|
**Supported Ruby versions:** 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
10
|
```
|
11
|
-
gem install fieldhand -v '~> 0.
|
11
|
+
gem install fieldhand -v '~> 0.8'
|
12
12
|
```
|
13
13
|
|
14
14
|
Or, in your `Gemfile`:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'fieldhand', '~> 0.
|
17
|
+
gem 'fieldhand', '~> 0.8'
|
18
18
|
```
|
19
19
|
|
20
20
|
## Usage
|
@@ -43,7 +43,7 @@ repository.get('oai:www.example.com:12345')
|
|
43
43
|
## API Documentation
|
44
44
|
|
45
45
|
* [`Fieldhand::Repository`](#fieldhandrepository)
|
46
|
-
* [`.new(uri[,
|
46
|
+
* [`.new(uri[, options])`](#fieldhandrepositorynewuri-options)
|
47
47
|
* [`#identify`](#fieldhandrepositoryidentify)
|
48
48
|
* [`#metadata_formats([identifier])`](#fieldhandrepositorymetadata_formatsidentifier)
|
49
49
|
* [`#sets`](#fieldhandrepositorysets)
|
@@ -109,19 +109,20 @@ A class to represent [an OAI-PMH repository](https://www.openarchives.org/OAI/op
|
|
109
109
|
> requests [...]. A repository is managed by a data provider to expose metadata
|
110
110
|
> to harvesters.
|
111
111
|
|
112
|
-
#### `Fieldhand::Repository.new(uri[,
|
112
|
+
#### `Fieldhand::Repository.new(uri[, options])`
|
113
113
|
|
114
114
|
```ruby
|
115
115
|
Fieldhand::Repository.new('http://www.example.com/oai')
|
116
116
|
Fieldhand::Repository.new(URI('http://www.example.com/oai'))
|
117
|
-
Fieldhand::Repository.new('http://www.example.com/oai', Logger.new(STDOUT))
|
117
|
+
Fieldhand::Repository.new('http://www.example.com/oai', :logger => Logger.new(STDOUT), :timeout => 10)
|
118
118
|
```
|
119
119
|
|
120
120
|
Return a new [`Repository`](#fieldhandrepository) instance accessible at the given `uri` (specified
|
121
121
|
either as a [`URI`][URI] or
|
122
|
-
something that can be coerced into a `URI` such as a `String`) with
|
123
|
-
|
124
|
-
`logger
|
122
|
+
something that can be coerced into a `URI` such as a `String`) with two options passed as a `Hash`:
|
123
|
+
|
124
|
+
* `:logger`: a [`Logger`](http://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)-compatible `logger`, defaults to a platform-specific null logger;
|
125
|
+
* `:timeout`: a `Numeric` number of seconds to wait before timing out any HTTP requests, defaults to 60.
|
125
126
|
|
126
127
|
#### `Fieldhand::Repository#identify`
|
127
128
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fieldhand/logger'
|
2
|
+
|
3
|
+
module Fieldhand
|
4
|
+
# A wrapper around Repository and Paginator options for backward-compatibility.
|
5
|
+
#
|
6
|
+
# In short, this handles passing a Logger directly or passing it and a timeout as a hash.
|
7
|
+
# Note this attempts to preserve the previous behaviour of passing nil/falsey values as a
|
8
|
+
# logger even though this will cause errors if someone tries to use it that way.
|
9
|
+
class Options
|
10
|
+
attr_reader :logger_or_options
|
11
|
+
|
12
|
+
# Return a new, normalized set of options based on the given value.
|
13
|
+
#
|
14
|
+
# This supports both a `Logger`-compatible object to use for logging directly and a hash of options:
|
15
|
+
#
|
16
|
+
# * :logger - A `Logger`-compatible class for logging the activity of the library, defaults to a platform-specific
|
17
|
+
# null logger
|
18
|
+
# * :timeout - A `Numeric` number of seconds to wait for any HTTP requests, defaults to 60 seconds
|
19
|
+
def initialize(logger_or_options = {})
|
20
|
+
@logger_or_options = logger_or_options
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return the current timeout in seconds.
|
24
|
+
def timeout
|
25
|
+
options.fetch(:timeout, 60)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Return the current logger.
|
29
|
+
def logger
|
30
|
+
options.fetch(:logger) { Logger.null }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def options
|
36
|
+
return logger_or_options if logger_or_options.is_a?(Hash)
|
37
|
+
|
38
|
+
{ :logger => logger_or_options }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/fieldhand/paginator.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'fieldhand/logger'
|
2
1
|
require 'fieldhand/network_errors'
|
2
|
+
require 'fieldhand/options'
|
3
3
|
require 'fieldhand/response_parser'
|
4
4
|
require 'cgi'
|
5
5
|
require 'net/http'
|
@@ -11,17 +11,23 @@ module Fieldhand
|
|
11
11
|
#
|
12
12
|
# See https://www.openarchives.org/OAI/openarchivesprotocol.html#FlowControl
|
13
13
|
class Paginator
|
14
|
-
attr_reader :uri, :logger, :http
|
14
|
+
attr_reader :uri, :logger, :timeout, :http
|
15
15
|
|
16
|
-
# Return a new paginator for the given repository base URI and optional logger.
|
16
|
+
# Return a new paginator for the given repository base URI and optional logger and timeout.
|
17
17
|
#
|
18
18
|
# The URI can be passed as either a `URI` or something that can be parsed as a URI such as a string.
|
19
19
|
#
|
20
|
-
# The logger will default to a null logger appropriate to this platform.
|
21
|
-
def initialize(uri,
|
20
|
+
# The logger will default to a null logger appropriate to this platform and timeout will default to 60 seconds.
|
21
|
+
def initialize(uri, logger_or_options = {})
|
22
22
|
@uri = uri.is_a?(::URI) ? uri : URI(uri)
|
23
|
-
|
23
|
+
|
24
|
+
options = Options.new(logger_or_options)
|
25
|
+
@logger = options.logger
|
26
|
+
@timeout = options.timeout
|
27
|
+
|
24
28
|
@http = ::Net::HTTP.new(@uri.host, @uri.port)
|
29
|
+
@http.read_timeout = @timeout
|
30
|
+
@http.open_timeout = @timeout
|
25
31
|
@http.use_ssl = true if @uri.scheme == 'https'
|
26
32
|
end
|
27
33
|
|
data/lib/fieldhand/repository.rb
CHANGED
@@ -5,7 +5,7 @@ require 'fieldhand/list_identifiers_parser'
|
|
5
5
|
require 'fieldhand/list_metadata_formats_parser'
|
6
6
|
require 'fieldhand/list_records_parser'
|
7
7
|
require 'fieldhand/list_sets_parser'
|
8
|
-
require 'fieldhand/
|
8
|
+
require 'fieldhand/options'
|
9
9
|
require 'fieldhand/paginator'
|
10
10
|
require 'uri'
|
11
11
|
|
@@ -14,16 +14,22 @@ module Fieldhand
|
|
14
14
|
#
|
15
15
|
# See https://www.openarchives.org/OAI/openarchivesprotocol.html
|
16
16
|
class Repository
|
17
|
-
attr_reader :uri, :logger
|
17
|
+
attr_reader :uri, :logger, :timeout
|
18
18
|
|
19
|
-
# Return a new repository with the given base URL and an optional logger.
|
19
|
+
# Return a new repository with the given base URL and an optional logger and timeout.
|
20
20
|
#
|
21
21
|
# The base URL can be passed as a `URI` or anything that can be parsed as a URI such as a string.
|
22
22
|
#
|
23
|
-
#
|
24
|
-
|
23
|
+
# For backward compatibility, the second argument can either be a logger or a hash containing
|
24
|
+
# a logger and timeout.
|
25
|
+
#
|
26
|
+
# Defaults to using a null logger specific to this platform and a timeout of 60 seconds.
|
27
|
+
def initialize(uri, logger_or_options = {})
|
25
28
|
@uri = uri.is_a?(::URI) ? uri : URI(uri)
|
26
|
-
|
29
|
+
|
30
|
+
options = Options.new(logger_or_options)
|
31
|
+
@logger = options.logger
|
32
|
+
@timeout = options.timeout
|
27
33
|
end
|
28
34
|
|
29
35
|
# Send an Identify request to the repository and return an `Identify` response.
|
@@ -127,7 +133,7 @@ module Fieldhand
|
|
127
133
|
private
|
128
134
|
|
129
135
|
def paginator
|
130
|
-
@paginator ||= Paginator.new(uri, logger)
|
136
|
+
@paginator ||= Paginator.new(uri, :logger => logger, :timeout => timeout)
|
131
137
|
end
|
132
138
|
end
|
133
139
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'fieldhand/options'
|
2
|
+
|
3
|
+
module Fieldhand
|
4
|
+
RSpec.describe Options do
|
5
|
+
describe '#timeout' do
|
6
|
+
it 'defaults to 60 seconds' do
|
7
|
+
options = described_class.new({})
|
8
|
+
|
9
|
+
expect(options.timeout).to eq(60)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can be overridden by passing an option' do
|
13
|
+
options = described_class.new(:timeout => 10)
|
14
|
+
|
15
|
+
expect(options.timeout).to eq(10)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can be set to nil' do
|
19
|
+
options = described_class.new(:timeout => nil)
|
20
|
+
|
21
|
+
expect(options.timeout).to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#logger' do
|
26
|
+
it 'defaults to a null logger' do
|
27
|
+
options = described_class.new({})
|
28
|
+
|
29
|
+
expect(options.logger).to be_a(::Logger)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can be overridden by passing a logger directly' do
|
33
|
+
logger = ::Logger.new(STDOUT)
|
34
|
+
options = described_class.new(logger)
|
35
|
+
|
36
|
+
expect(options.logger).to eq(logger)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can be overridden by passing a logger in an option' do
|
40
|
+
logger = ::Logger.new(STDOUT)
|
41
|
+
options = described_class.new(:logger => logger)
|
42
|
+
|
43
|
+
expect(options.logger).to eq(logger)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can be set to nil directly' do
|
47
|
+
options = described_class.new(nil)
|
48
|
+
|
49
|
+
expect(options.logger).to be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'can be set to nil through an option' do
|
53
|
+
options = described_class.new(:logger => nil)
|
54
|
+
|
55
|
+
expect(options.logger).to be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -109,5 +109,41 @@ module Fieldhand
|
|
109
109
|
expect(error.response.body).to eq('Retry after 5 seconds')
|
110
110
|
end
|
111
111
|
end
|
112
|
+
|
113
|
+
describe '#timeout' do
|
114
|
+
it 'defaults to 60 seconds' do
|
115
|
+
paginator = described_class.new('http://www.example.com/oai')
|
116
|
+
|
117
|
+
expect(paginator.timeout).to eq(60)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'can be overridden with an option' do
|
121
|
+
paginator = described_class.new('http://www.example.com/oai', :timeout => 10)
|
122
|
+
|
123
|
+
expect(paginator.timeout).to eq(10)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#logger' do
|
128
|
+
it 'defaults to a null logger' do
|
129
|
+
paginator = described_class.new('http://www.example.com/oai')
|
130
|
+
|
131
|
+
expect(paginator.logger).to be_a(::Logger)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'can be overridden with an option' do
|
135
|
+
logger = ::Logger.new(STDOUT)
|
136
|
+
paginator = described_class.new('http://www.example.com/oai', :logger => logger)
|
137
|
+
|
138
|
+
expect(paginator.logger).to eq(logger)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'can be overridden by passing as a second argument for historic reasons' do
|
142
|
+
logger = ::Logger.new(STDOUT)
|
143
|
+
paginator = described_class.new('http://www.example.com/oai', logger)
|
144
|
+
|
145
|
+
expect(paginator.logger).to eq(logger)
|
146
|
+
end
|
147
|
+
end
|
112
148
|
end
|
113
149
|
end
|
@@ -187,5 +187,41 @@ module Fieldhand
|
|
187
187
|
to have_attributes(:identifier => 'oai:oai.datacite.org:32356')
|
188
188
|
end
|
189
189
|
end
|
190
|
+
|
191
|
+
describe '#timeout' do
|
192
|
+
it 'defaults to 60 seconds' do
|
193
|
+
repository = described_class.new('http://www.example.com/oai')
|
194
|
+
|
195
|
+
expect(repository.timeout).to eq(60)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'can be overridden with an option' do
|
199
|
+
repository = described_class.new('http://www.example.com/oai', :timeout => 10)
|
200
|
+
|
201
|
+
expect(repository.timeout).to eq(10)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe '#logger' do
|
206
|
+
it 'defaults to a null logger' do
|
207
|
+
repository = described_class.new('http://www.example.com/oai')
|
208
|
+
|
209
|
+
expect(repository.logger).to be_a(::Logger)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'can be overridden with an option' do
|
213
|
+
logger = ::Logger.new(STDOUT)
|
214
|
+
repository = described_class.new('http://www.example.com/oai', :logger => logger)
|
215
|
+
|
216
|
+
expect(repository.logger).to eq(logger)
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'can be overridden by passing as a second argument for historic reasons' do
|
220
|
+
logger = ::Logger.new(STDOUT)
|
221
|
+
repository = described_class.new('http://www.example.com/oai', logger)
|
222
|
+
|
223
|
+
expect(repository.logger).to eq(logger)
|
224
|
+
end
|
225
|
+
end
|
190
226
|
end
|
191
227
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fieldhand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
8
8
|
- Maciej Gajewski
|
9
9
|
- Giovanni Derks
|
10
|
+
- Abeer Salameh
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2018-05-12 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: ox
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- lib/fieldhand/logger.rb
|
103
104
|
- lib/fieldhand/metadata_format.rb
|
104
105
|
- lib/fieldhand/network_errors.rb
|
106
|
+
- lib/fieldhand/options.rb
|
105
107
|
- lib/fieldhand/paginator.rb
|
106
108
|
- lib/fieldhand/record.rb
|
107
109
|
- lib/fieldhand/repository.rb
|
@@ -112,6 +114,7 @@ files:
|
|
112
114
|
- spec/fieldhand/header_spec.rb
|
113
115
|
- spec/fieldhand/identify_spec.rb
|
114
116
|
- spec/fieldhand/metadata_format_spec.rb
|
117
|
+
- spec/fieldhand/options_spec.rb
|
115
118
|
- spec/fieldhand/paginator_spec.rb
|
116
119
|
- spec/fieldhand/record_spec.rb
|
117
120
|
- spec/fieldhand/repository_spec.rb
|
@@ -137,18 +140,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
140
|
version: '0'
|
138
141
|
requirements: []
|
139
142
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.7.3
|
141
144
|
signing_key:
|
142
145
|
specification_version: 4
|
143
146
|
summary: An OAI-PMH harvester
|
144
147
|
test_files:
|
145
|
-
- spec/
|
146
|
-
- spec/fieldhand/
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/fieldhand/set_spec.rb
|
150
|
+
- spec/fieldhand/repository_spec.rb
|
151
|
+
- spec/fieldhand/options_spec.rb
|
147
152
|
- spec/fieldhand/header_spec.rb
|
148
|
-
- spec/fieldhand/identify_spec.rb
|
149
|
-
- spec/fieldhand/metadata_format_spec.rb
|
150
153
|
- spec/fieldhand/paginator_spec.rb
|
154
|
+
- spec/fieldhand/arguments_spec.rb
|
151
155
|
- spec/fieldhand/record_spec.rb
|
152
|
-
- spec/fieldhand/
|
153
|
-
- spec/fieldhand/
|
154
|
-
- spec/
|
156
|
+
- spec/fieldhand/identify_spec.rb
|
157
|
+
- spec/fieldhand/datestamp_spec.rb
|
158
|
+
- spec/fieldhand/metadata_format_spec.rb
|