fieldhand 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -4
- data/lib/fieldhand/network_error.rb +11 -0
- data/lib/fieldhand/paginator.rb +6 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3beca3a7544bc041d0b89472b73e18ba4c682655
|
4
|
+
data.tar.gz: 33ea99b5627312c8073abda6898f50b30b338907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca95ba3dfc8f3ed489edde185c135ec8beb34ba5879fabac66112f5742d63ed1e6ece180711208983882e8ecd636bcd934c3cde7fde8ca502e44ecce502b59d4
|
7
|
+
data.tar.gz: 844fb6b4b2d28b690477fcd58349a67149b2e73a38d2f466f1cde7d70aa8c1e09336cbd5fd048b5f60e905215cc321acbb032451b2c4c6c394807b5235de9e69
|
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.4.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.4'
|
12
12
|
```
|
13
13
|
|
14
14
|
Or, in your `Gemfile`:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'fieldhand', '~> 0.
|
17
|
+
gem 'fieldhand', '~> 0.4'
|
18
18
|
```
|
19
19
|
|
20
20
|
## Usage
|
@@ -88,6 +88,7 @@ repository.get('oai:www.example.com:12345')
|
|
88
88
|
* [`#sets`](#fieldhandheadersets)
|
89
89
|
* [`#response_date`](#fieldhandheaderresponse_date)
|
90
90
|
* [`Fieldhand::NetworkError`](#fieldhandnetworkerror)
|
91
|
+
* [`Fieldhand::NetworkError#response`](#fieldhandnetworkerrorresponse)
|
91
92
|
* [`Fieldhand::ProtocolError`](#fieldhandprotocolerror)
|
92
93
|
* [`Fieldhand::BadArgumentError`](#fieldhandbadargumenterror)
|
93
94
|
* [`Fieldhand::BadResumptionTokenError`](#fieldhandbadresumptiontokenerror)
|
@@ -536,7 +537,25 @@ Return the time and date that the response was sent.
|
|
536
537
|
|
537
538
|
### `Fieldhand::NetworkError`
|
538
539
|
|
539
|
-
An error (descended from `StandardError`) to represent any network issues encountered during interaction with the repository.
|
540
|
+
An error (descended from `StandardError`) to represent any network issues encountered during interaction with the repository.
|
541
|
+
If the HTTP request is not successful (returning a status code other than 200),
|
542
|
+
a `NetworkError` exception will be raised containing the error message and the response object.
|
543
|
+
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).
|
544
|
+
|
545
|
+
#### Fieldhand::NetworkError#response
|
546
|
+
|
547
|
+
```ruby
|
548
|
+
begin
|
549
|
+
repository.records.each do |record|
|
550
|
+
# ...
|
551
|
+
end
|
552
|
+
rescue Fieldhand::NetworkError => e
|
553
|
+
puts e.response
|
554
|
+
#=> #<Net::HTTPServiceUnavailable 503 Service Unavailable readbody=true>
|
555
|
+
end
|
556
|
+
```
|
557
|
+
|
558
|
+
Returns the unsuccessful `Net::HTTPResponse` that caused this error or `nil` if no response was available.
|
540
559
|
|
541
560
|
### `Fieldhand::ProtocolError`
|
542
561
|
|
data/lib/fieldhand/paginator.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'fieldhand/logger'
|
2
|
+
require 'fieldhand/network_error'
|
2
3
|
require 'fieldhand/response_parser'
|
3
4
|
require 'cgi'
|
4
5
|
require 'net/http'
|
5
6
|
require 'uri'
|
6
7
|
|
7
8
|
module Fieldhand
|
8
|
-
NetworkError = ::Class.new(::StandardError)
|
9
|
-
|
10
9
|
# An abstraction over interactions with an OAI-PMH repository, handling requests, responses and paginating over
|
11
10
|
# results using a resumption token.
|
12
11
|
#
|
@@ -81,10 +80,14 @@ module Fieldhand
|
|
81
80
|
request_uri.query = encode_query(query)
|
82
81
|
|
83
82
|
logger.info('Fieldhand') { "GET #{request_uri}" }
|
84
|
-
http.get(request_uri.request_uri)
|
83
|
+
res = http.get(request_uri.request_uri)
|
84
|
+
raise NetworkError.new("Invalid response: #{res.code} #{res.msg}", res) unless res.is_a?(::Net::HTTPSuccess)
|
85
|
+
|
86
|
+
res.body
|
85
87
|
rescue ::Timeout::Error => e
|
86
88
|
raise NetworkError, "timeout requesting #{query}: #{e}"
|
87
89
|
rescue => e
|
90
|
+
raise e if e.is_a?(NetworkError)
|
88
91
|
raise NetworkError, "error requesting #{query}: #{e}"
|
89
92
|
end
|
90
93
|
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fieldhand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
8
8
|
- Maciej Gajewski
|
9
|
+
- Giovanni Derks
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2017-
|
13
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: ox
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- lib/fieldhand/list_sets_parser.rb
|
101
102
|
- lib/fieldhand/logger.rb
|
102
103
|
- lib/fieldhand/metadata_format.rb
|
104
|
+
- lib/fieldhand/network_error.rb
|
103
105
|
- lib/fieldhand/paginator.rb
|
104
106
|
- lib/fieldhand/record.rb
|
105
107
|
- lib/fieldhand/repository.rb
|