harvestdor 0.2.0 → 0.3.0

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
2
  SHA1:
3
- metadata.gz: 679a83bf98701735495c479c2fc24c5d827c2dbb
4
- data.tar.gz: 8abf3ca28f23a3c34c0db09963064302d982ab54
3
+ metadata.gz: 512b556fbe2a3547829f7ea157be1e984d302294
4
+ data.tar.gz: b6512cb57d70adea02eef25519ff0d3265253305
5
5
  SHA512:
6
- metadata.gz: 500eeb2f7a6be780a92960c88a64f16823343437b368660de0f333efe5bf881f10cc2903b728467c44e84f65a5c2eda79b3328ac992f1e629083a338909eba2e
7
- data.tar.gz: 79390d091eef937350a1547d5c5f79d8e0abffa55a183225e556af779f4ccab05ab9ae388d9a2cbeaff225a3cf80b99ec2bda3bffbab756f918a23526a3dec92
6
+ metadata.gz: 27c95f0765aa2c5a44729b5620e59fc942e490096da2d64a066e4bf3ab4babfa9c52d508b8736fcf15d268e3c917a0269ed42cdf189f4add3f933bc17617564e
7
+ data.tar.gz: 7094c91f20e889b729f1c507629fae1875e8f6125a4562bd1163accadd7fe42ceb2162aadc3a055fd3af3f08708bdc9efd6772f9d8b4a9b0c647019357746dff
data/.travis.yml CHANGED
@@ -2,13 +2,8 @@ language: ruby
2
2
  script: rake rspec
3
3
  sudo: false
4
4
  rvm:
5
- - 2.2.2
6
- - 2.1.1
7
- - 2.0.0
8
- - 1.9.3
9
- - jruby-19mode # JRuby in 1.9 mode
5
+ - 2.3.1
10
6
  notifications:
11
7
  email:
12
- - ndushay@stanford.edu
13
8
  - laneymcg@stanford.edu
14
9
  - cbeer@stanford.edu
data/harvestdor.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'confstruct'
21
21
  gem.add_dependency 'nokogiri'
22
+ gem.add_dependency 'faraday'
22
23
 
23
24
  # Development dependencies
24
25
  gem.add_development_dependency "rake"
@@ -13,8 +13,8 @@ module Harvestdor
13
13
  # @return [Nokogiri::XML::Document] the MODS for the fedora object
14
14
  def self.mods druid, purl_url = Harvestdor::PURL_DEFAULT
15
15
  begin
16
- Nokogiri::XML(open("#{purl_url}/#{druid}.mods"),nil,'UTF-8')
17
- rescue OpenURI::HTTPError
16
+ Nokogiri::XML(http_client.get("#{purl_url}/#{druid}.mods").body,nil,'UTF-8')
17
+ rescue Faraday::Error::ClientError
18
18
  raise Harvestdor::Errors::MissingMods.new(druid)
19
19
  end
20
20
  end
@@ -26,10 +26,10 @@ module Harvestdor
26
26
  def self.public_xml druid, purl_url = Harvestdor::PURL_DEFAULT
27
27
  return druid if druid.instance_of?(Nokogiri::XML::Document)
28
28
  begin
29
- ng_doc = Nokogiri::XML(open("#{purl_url}/#{druid}.xml"))
29
+ ng_doc = Nokogiri::XML(http_client.get("#{purl_url}/#{druid}.xml").body)
30
30
  raise Harvestdor::Errors::MissingPublicXml.new(druid) if !ng_doc || ng_doc.children.empty?
31
31
  ng_doc
32
- rescue OpenURI::HTTPError
32
+ rescue Faraday::Error::ClientError
33
33
  raise Harvestdor::Errors::MissingPurlPage.new(druid)
34
34
  end
35
35
  end
@@ -137,5 +137,18 @@ module Harvestdor
137
137
  end
138
138
  pub_xml_ng_doc
139
139
  end
140
+
141
+ def self.http_client
142
+ @http_client ||= Faraday.new do |conn|
143
+ conn.adapter Faraday.default_adapter
144
+ conn.use Faraday::Response::RaiseError
145
+ conn.request :retry, max: 5,
146
+ interval: 0.05,
147
+ interval_randomness: 0.5,
148
+ backoff_factor: 2,
149
+ exceptions: ['Errno::ECONNRESET', 'Errno::ETIMEDOUT', 'Timeout::Error', 'Faraday::Error::TimeoutError', 'Faraday::Error::ConnectionFailed']
150
+ end
151
+ end
152
+ private_class_method :http_client
140
153
 
141
154
  end # module Harvestdor
@@ -1,3 +1,3 @@
1
1
  module Harvestdor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/harvestdor.rb CHANGED
@@ -6,7 +6,7 @@ require 'harvestdor/client'
6
6
  require 'confstruct'
7
7
  # stdlib
8
8
  require 'logger'
9
- require 'open-uri'
9
+ require 'faraday'
10
10
  require 'yaml'
11
11
 
12
12
  module Harvestdor
@@ -40,7 +40,7 @@ describe Harvestdor::Client do
40
40
  end
41
41
  end
42
42
  it "raises Harvestdor::Errors::MissingPublicXML if purl page returns nil document" do
43
- expect_any_instance_of(URI::HTTP).to receive(:open).and_return(nil)
43
+ expect(Harvestdor.send(:http_client)).to receive(:get).and_return(double(body: nil))
44
44
  expect { Harvestdor.public_xml(@fake_druid, @purl) }.to raise_error(Harvestdor::Errors::MissingPublicXml)
45
45
  end
46
46
  end
@@ -89,7 +89,7 @@ describe Harvestdor::Client do
89
89
  end
90
90
  end
91
91
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
92
- expect_any_instance_of(URI::HTTP).not_to receive(:open)
92
+ expect(Harvestdor.send(:http_client)).not_to receive(:get)
93
93
  im = Harvestdor.identity_metadata(@ng_pub_xml)
94
94
  expect(im).to be_kind_of(Nokogiri::XML::Document)
95
95
  expect(im.root.name).to eql('identityMetadata')
@@ -110,7 +110,7 @@ describe Harvestdor::Client do
110
110
  end
111
111
  end
112
112
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
113
- expect_any_instance_of(URI::HTTP).not_to receive(:open)
113
+ expect(Harvestdor.send(:http_client)).not_to receive(:get)
114
114
  rm = Harvestdor.rights_metadata(@ng_pub_xml)
115
115
  expect(rm).to be_kind_of(Nokogiri::XML::Document)
116
116
  expect(rm.root.name).to eql('rightsMetadata')
@@ -131,7 +131,7 @@ describe Harvestdor::Client do
131
131
  end
132
132
  end
133
133
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
134
- expect_any_instance_of(URI::HTTP).not_to receive(:open)
134
+ expect(Harvestdor.send(:http_client)).not_to receive(:get)
135
135
  rdf = Harvestdor.rdf(@ng_pub_xml)
136
136
  expect(rdf).to be_kind_of(Nokogiri::XML::Document)
137
137
  expect(rdf.root.name).to eql('RDF')
@@ -153,7 +153,7 @@ describe Harvestdor::Client do
153
153
  end
154
154
  end
155
155
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
156
- expect_any_instance_of(URI::HTTP).not_to receive(:open)
156
+ expect(Harvestdor.send(:http_client)).not_to receive(:get)
157
157
  dc = Harvestdor.dc(@ng_pub_xml)
158
158
  expect(dc).to be_kind_of(Nokogiri::XML::Document)
159
159
  expect(dc.root.name).to eql('dc')
@@ -199,7 +199,7 @@ describe Harvestdor::Client do
199
199
  @client.mods(@druid)
200
200
  end
201
201
  it "methods for parts of public_xml should work with Nokogiri::XML::Document arg (and not fetch)" do
202
- expect_any_instance_of(URI::HTTP).not_to receive(:open)
202
+ expect(Harvestdor.send(:http_client)).not_to receive(:get)
203
203
  expect(@client.content_metadata(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
204
204
  expect(@client.identity_metadata(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
205
205
  expect(@client.rights_metadata(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harvestdor
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
  - Naomi Dushay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2016-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: confstruct
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -219,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
233
  version: '0'
220
234
  requirements: []
221
235
  rubyforge_project:
222
- rubygems_version: 2.4.5.1
236
+ rubygems_version: 2.5.1
223
237
  signing_key:
224
238
  specification_version: 4
225
239
  summary: Harvest DOR object metadata
@@ -236,4 +250,3 @@ test_files:
236
250
  - spec/harvestdor_client_spec.rb
237
251
  - spec/purl_xml_spec.rb
238
252
  - spec/spec_helper.rb
239
- has_rdoc: