oai 0.0.13 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,42 +1,21 @@
1
- RUBY_OAI_VERSION = '0.0.13'
2
1
 
3
2
  require 'rubygems'
4
3
  require 'rake'
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+
10
+ Bundler::GemHelper.install_tasks
11
+
5
12
  require 'rake/testtask'
6
- require 'rake/rdoctask'
7
- require 'rake/packagetask'
8
- require 'rake/gempackagetask'
13
+ require 'rdoc/task'
9
14
 
10
15
  task :default => ["test"]
11
16
 
12
17
  task :test => ["test:client", "test:provider"]
13
18
 
14
- spec = Gem::Specification.new do |s|
15
- s.name = 'oai'
16
- s.version = RUBY_OAI_VERSION
17
- s.author = 'Ed Summers'
18
- s.email = 'ehs@pobox.com'
19
- s.homepage = 'http://www.textualize.com/ruby_oai_0'
20
- s.platform = Gem::Platform::RUBY
21
- s.summary = 'A ruby library for working with the Open Archive Initiative Protocol for Metadata Harvesting (OAI-PMH)'
22
- s.require_path = 'lib'
23
- s.autorequire = 'oai'
24
- s.bindir = 'bin'
25
- s.executables = 'oai'
26
-
27
- s.add_dependency('builder', '>=2.0.0')
28
-
29
- s.files = %w(README.md Rakefile) +
30
- Dir.glob("{bin,test,lib}/**/*") +
31
- Dir.glob("examples/**/*.rb")
32
- end
33
-
34
- Rake::GemPackageTask.new(spec) do |pkg|
35
- pkg.need_zip = true
36
- pkg.need_tar = true
37
- pkg.gem_spec = spec
38
- end
39
-
40
19
  namespace :test do
41
20
  Rake::TestTask.new('client') do |t|
42
21
  t.libs << ['lib', 'test/client']
@@ -62,13 +41,40 @@ namespace :test do
62
41
  task :coverage do
63
42
  rm_f "coverage"
64
43
  rm_f "coverage.data"
65
- system("rcov --aggregate coverage.data --text-summary -Ilib:test/provider test/provider/tc_*.rb")
66
- system("rcov --aggregate coverage.data --text-summary -Ilib:test/client test/client/tc_*.rb")
67
- system("open coverage/index.html") if PLATFORM['darwin']
44
+ if RUBY_VERSION =~ /^1.8/
45
+ Rake::Task['rcov:client'].invoke
46
+ Rake::Task['rcov:provider'].invoke
47
+ else
48
+ ENV['COVERAGE'] = 'true'
49
+ Rake::Task['test:client'].invoke
50
+ Rake::Task['test:provider'].invoke
51
+ end
52
+
53
+ system("open coverage/index.html") if (PLATFORM['darwin'] if Kernel.const_defined? :PLATFORM) || (RUBY_PLATFORM =~ /darwin/ if Kernel.const_defined? :RUBY_PLATFORM)
68
54
  end
69
55
 
70
56
  end
71
57
 
58
+ if RUBY_VERSION =~ /^1.8/
59
+ require 'rcov/rcovtask'
60
+ namespace :rcov do
61
+ Rcov::RcovTask.new do |t|
62
+ t.name = 'client'
63
+ t.libs << ['lib', 'test/client']
64
+ t.pattern = 'test/client/tc_*.rb'
65
+ t.verbose = true
66
+ t.rcov_opts = ['--aggregate coverage.data', '--text-summary']
67
+ end
68
+
69
+ Rcov::RcovTask.new('provider') do |t|
70
+ t.libs << ['lib', 'test/provider']
71
+ t.pattern = 'test/provider/tc_*.rb'
72
+ t.verbose = true
73
+ t.rcov_opts = ['--aggregate coverage.data', '--text-summary']
74
+ end
75
+ end
76
+ end
77
+
72
78
  task 'test:activerecord_provider' => :create_database
73
79
 
74
80
  task :environment do
@@ -104,7 +110,7 @@ task :load_fixtures => :create_database do
104
110
  end
105
111
 
106
112
  Rake::RDocTask.new('doc') do |rd|
107
- rd.rdoc_files.include("lib/**/*.rb", "README")
108
- rd.main = 'README'
113
+ rd.rdoc_files.include("lib/**/*.rb", "README.md")
114
+ rd.main = 'README.md'
109
115
  rd.rdoc_dir = 'doc'
110
116
  end
@@ -1,6 +1,6 @@
1
1
  # External dependencies
2
2
  require 'uri'
3
- require 'net/http'
3
+ require 'faraday'
4
4
  require 'cgi'
5
5
  require 'iconv'
6
6
 
@@ -67,6 +67,11 @@ module OAI
67
67
  # back XML::Node objects
68
68
  #
69
69
  # client = OAI::Client.new 'http://example.com', :parser => 'libxml'
70
+ #
71
+ # You can configure the Faraday HTTP client by providing an alternate
72
+ # Faraday instance:
73
+ #
74
+ # client = OAI::Client.new 'http://example.com', :http => Faraday.new { |c| }
70
75
  #
71
76
  # === HIGH PERFORMANCE
72
77
  #
@@ -77,7 +82,18 @@ module OAI
77
82
  @base = URI.parse base_url
78
83
  @debug = options.fetch(:debug, false)
79
84
  @parser = options.fetch(:parser, 'rexml')
85
+
80
86
  @follow_redirects = options.fetch(:redirects, true)
87
+ @http_client = options.fetch(:http, Faraday.new(@base))
88
+
89
+ if !options.key?(:http) and @follow_redirects
90
+
91
+ count = @folow_redirects if @folow_redirects.is_a? Fixnum
92
+ count ||= 5
93
+
94
+ require 'faraday_middleware'
95
+ @http_client.use FaradayMiddleware::FollowRedirects, :limit => count
96
+ end
81
97
 
82
98
  # load appropriate parser
83
99
  case @parser
@@ -98,7 +114,7 @@ module OAI
98
114
 
99
115
  # Equivalent to a Identify request. You'll get back a OAI::IdentifyResponse
100
116
  # object which is essentially just a wrapper around a REXML::Document
101
- # for the response. If you are created your client using the libxml
117
+ # for the response. If you created your client using the libxml
102
118
  # parser then you will get an XML::Node object instead.
103
119
 
104
120
  def identify
@@ -207,21 +223,8 @@ module OAI
207
223
 
208
224
  # Do the actual HTTP get, following any temporary redirects
209
225
  def get(uri)
210
- response = Net::HTTP.get_response(uri)
211
- case response
212
- when Net::HTTPSuccess
213
- return response.body
214
- when Net::HTTPMovedPermanently
215
- if @follow_redirects
216
- response = get(URI.parse(response['location']))
217
- else
218
- raise ArgumentError, "Permanently Redirected to [#{response['location']}]"
219
- end
220
- when Net::HTTPTemporaryRedirect
221
- response = get(URI.parse(response['location']))
222
- else
223
- raise ArgumentError, "#{response.code_type} [#{response.code}]"
224
- end
226
+ response = @http_client.get uri
227
+ response.body
225
228
  end
226
229
 
227
230
  def debug(msg)
@@ -1,4 +1,24 @@
1
1
  module OAI
2
+
3
+ # An OAI::Response contains entries and a resumption token. If a resumption token is present,
4
+ # then you must use it to fetch the rest of the entries for your query. For example:
5
+ # # List all records
6
+ # i = 1
7
+ # begin
8
+ # response = client.list_records
9
+ # while response.entries.size > 0
10
+ # response.entries.each { |entry|
11
+ # puts "<b>#{i}</b> #{entry.header.identifier}<br/>"
12
+ # i +=1
13
+ # }
14
+ # token = response.resumption_token
15
+ # response = client.list_records :resumption_token => token if token
16
+ # end
17
+ # rescue OAI::Exception => e
18
+ # puts 'No records to process'
19
+ # end
20
+ # puts "Done processing #{i} records"
21
+
2
22
  class Response
3
23
  include OAI::XPath
4
24
  attr_reader :doc, :resumption_token
@@ -9,3 +9,10 @@ module Test::Unit
9
9
  end
10
10
 
11
11
  end
12
+
13
+ unless $provider_server_already_started
14
+ $provider_server_already_started = true
15
+ ProviderServer.start(3333)
16
+ sleep 2
17
+ end
18
+
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class HttpClientTest < Test::Unit::TestCase
4
+
5
+ def test_pluggable_http_client
6
+ oai_response = <<-eos
7
+ <Identify>
8
+ <repositoryName>Mock OAI Provider</repositoryName>
9
+ <baseURL>http://nowhere.example.com</baseURL>
10
+ </Identify>
11
+ eos
12
+
13
+ faraday_stub = Faraday.new do |builder|
14
+ builder.adapter :test do |stub|
15
+ stub.get('/oai?verb=Identify') { [200, {}, oai_response] }
16
+ end
17
+ end
18
+ client = OAI::Client.new 'http://localhost:3333/oai', :http => faraday_stub
19
+ response = client.identify
20
+
21
+ assert_kind_of OAI::IdentifyResponse, response
22
+ assert_equal 'Mock OAI Provider [http://nowhere.example.com]', response.to_s
23
+
24
+ end
25
+ end
26
+
@@ -5,6 +5,7 @@ class UTF8Test < Test::Unit::TestCase
5
5
  def test_escaping_invalid_utf_8_characters
6
6
  client = OAI::Client.new 'http://localhost:3333/oai' #, :parser => 'libxml'
7
7
  invalid_utf_8 = [2, 3, 4, 104, 5, 101, 6, 108, 66897, 108, 66535, 111, 1114112, 33, 55234123, 33].pack("U*")
8
+ invalid_utf_8 = invalid_utf_8.force_encoding("binary") if invalid_utf_8.respond_to? :force_encoding
8
9
  assert_equal("hello!!", client.send(:strip_invalid_utf_8_chars, invalid_utf_8).gsub(/\?/, ''))
9
10
  end
10
11
 
@@ -1,5 +1,13 @@
1
+ if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
2
+ require 'simplecov'
3
+ require 'simplecov-rcov'
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
6
+ SimpleCov.start
7
+ end
8
+
1
9
  require 'oai'
2
10
  require 'test/unit'
3
11
 
4
12
  require File.dirname(__FILE__) + '/helpers/provider'
5
- require File.dirname(__FILE__) + '/helpers/test_wrapper'
13
+ require File.dirname(__FILE__) + '/helpers/test_wrapper'
@@ -112,7 +112,7 @@ class TestModel < OAI::Provider::Model
112
112
  end
113
113
 
114
114
  def generate_records(number, timestamp = Time.now.utc.xmlschema, sets = [], deleted = false)
115
- @earliest = timestamp.dup if @earliest.nil? || timestamp.to_s < @earliest
115
+ @earliest = timestamp.dup if @earliest.nil? || timestamp.to_s < @earliest.to_s
116
116
  @earliest = timestamp.dup if @earliest.nil?
117
117
 
118
118
  # Add any sets we don't already have
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ProviderExceptions < Test::Unit::TestCase
4
- include Singleton
5
4
 
6
5
  def setup
7
6
  @provider = ComplexProvider.new
metadata CHANGED
@@ -1,161 +1,215 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oai
3
- version: !ruby/object:Gem::Version
4
- hash: 5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 13
10
- version: 0.0.13
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Ed Summers
14
9
  autorequire: oai
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-09 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: builder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
24
25
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 15
29
- segments:
30
- - 2
31
- - 0
32
- - 0
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
33
29
  version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday_middleware
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
34
54
  type: :runtime
35
- version_requirements: *id001
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rdoc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
36
94
  description:
37
95
  email: ehs@pobox.com
38
- executables:
96
+ executables:
39
97
  - oai
40
98
  extensions: []
41
-
42
99
  extra_rdoc_files: []
43
-
44
- files:
100
+ files:
45
101
  - README.md
46
102
  - Rakefile
47
103
  - bin/oai
48
- - test/client/tc_get_record.rb
49
- - test/client/tc_identify.rb
104
+ - test/activerecord_provider/config/connection.rb
105
+ - test/activerecord_provider/config/database.yml
106
+ - test/activerecord_provider/database/ar_migration.rb
107
+ - test/activerecord_provider/database/oaipmhtest
108
+ - test/activerecord_provider/fixtures/dc.yml
109
+ - test/activerecord_provider/helpers/providers.rb
110
+ - test/activerecord_provider/helpers/set_provider.rb
111
+ - test/activerecord_provider/models/dc_field.rb
112
+ - test/activerecord_provider/models/dc_set.rb
113
+ - test/activerecord_provider/models/oai_token.rb
114
+ - test/activerecord_provider/tc_ar_provider.rb
115
+ - test/activerecord_provider/tc_ar_sets_provider.rb
116
+ - test/activerecord_provider/tc_caching_paging_provider.rb
117
+ - test/activerecord_provider/tc_simple_paging_provider.rb
118
+ - test/activerecord_provider/test_helper.rb
50
119
  - test/client/helpers/provider.rb
51
120
  - test/client/helpers/test_wrapper.rb
121
+ - test/client/tc_exception.rb
122
+ - test/client/tc_get_record.rb
123
+ - test/client/tc_http_client.rb
124
+ - test/client/tc_identify.rb
125
+ - test/client/tc_libxml.rb
52
126
  - test/client/tc_list_identifiers.rb
53
- - test/client/tc_utf8_escaping.rb
54
- - test/client/tc_list_sets.rb
55
- - test/client/test_helper.rb
127
+ - test/client/tc_list_metadata_formats.rb
56
128
  - test/client/tc_list_records.rb
57
- - test/client/tc_libxml.rb
129
+ - test/client/tc_list_sets.rb
58
130
  - test/client/tc_low_resolution_dates.rb
59
- - test/client/tc_exception.rb
60
- - test/client/tc_list_metadata_formats.rb
131
+ - test/client/tc_utf8_escaping.rb
61
132
  - test/client/tc_xpath.rb
62
- - test/provider/tc_simple_provider.rb
133
+ - test/client/test_helper.rb
63
134
  - test/provider/models.rb
135
+ - test/provider/tc_exceptions.rb
64
136
  - test/provider/tc_functional_tokens.rb
65
137
  - test/provider/tc_provider.rb
66
138
  - test/provider/tc_resumption_tokens.rb
139
+ - test/provider/tc_simple_provider.rb
67
140
  - test/provider/test_helper.rb
68
- - test/provider/tc_exceptions.rb
69
141
  - test/test.xml
70
- - test/activerecord_provider/fixtures/dc.yml
71
- - test/activerecord_provider/helpers/providers.rb
72
- - test/activerecord_provider/helpers/set_provider.rb
73
- - test/activerecord_provider/tc_caching_paging_provider.rb
74
- - test/activerecord_provider/tc_ar_sets_provider.rb
75
- - test/activerecord_provider/models/oai_token.rb
76
- - test/activerecord_provider/models/dc_set.rb
77
- - test/activerecord_provider/models/dc_field.rb
78
- - test/activerecord_provider/test_helper.rb
79
- - test/activerecord_provider/tc_simple_paging_provider.rb
80
- - test/activerecord_provider/database/oaipmhtest
81
- - test/activerecord_provider/database/ar_migration.rb
82
- - test/activerecord_provider/tc_ar_provider.rb
83
- - test/activerecord_provider/config/connection.rb
84
- - test/activerecord_provider/config/database.yml
85
- - lib/oai/set.rb
86
- - lib/oai/xpath.rb
87
- - lib/oai/harvester/logging.rb
88
- - lib/oai/harvester/mailer.rb
89
- - lib/oai/harvester/harvest.rb
90
- - lib/oai/harvester/shell.rb
91
- - lib/oai/harvester/config.rb
92
- - lib/oai/client/list_identifiers.rb
93
- - lib/oai/client/list_records.rb
142
+ - lib/oai/client/get_record.rb
94
143
  - lib/oai/client/header.rb
95
144
  - lib/oai/client/identify.rb
96
- - lib/oai/client/record.rb
97
- - lib/oai/client/get_record.rb
98
- - lib/oai/client/response.rb
99
- - lib/oai/client/metadata_format.rb
145
+ - lib/oai/client/list_identifiers.rb
100
146
  - lib/oai/client/list_metadata_formats.rb
147
+ - lib/oai/client/list_records.rb
101
148
  - lib/oai/client/list_sets.rb
102
- - lib/oai/provider/model.rb
149
+ - lib/oai/client/metadata_format.rb
150
+ - lib/oai/client/record.rb
151
+ - lib/oai/client/response.rb
152
+ - lib/oai/client.rb
153
+ - lib/oai/constants.rb
154
+ - lib/oai/exception.rb
155
+ - lib/oai/harvester/config.rb
156
+ - lib/oai/harvester/harvest.rb
157
+ - lib/oai/harvester/logging.rb
158
+ - lib/oai/harvester/mailer.rb
159
+ - lib/oai/harvester/shell.rb
160
+ - lib/oai/harvester.rb
161
+ - lib/oai/provider/metadata_format/oai_dc.rb
162
+ - lib/oai/provider/metadata_format.rb
103
163
  - lib/oai/provider/model/activerecord_caching_wrapper.rb
104
164
  - lib/oai/provider/model/activerecord_wrapper.rb
105
- - lib/oai/provider/response/list_identifiers.rb
106
- - lib/oai/provider/response/list_records.rb
107
- - lib/oai/provider/response/record_response.rb
108
- - lib/oai/provider/response/identify.rb
165
+ - lib/oai/provider/model.rb
166
+ - lib/oai/provider/partial_result.rb
109
167
  - lib/oai/provider/response/error.rb
110
168
  - lib/oai/provider/response/get_record.rb
169
+ - lib/oai/provider/response/identify.rb
170
+ - lib/oai/provider/response/list_identifiers.rb
111
171
  - lib/oai/provider/response/list_metadata_formats.rb
172
+ - lib/oai/provider/response/list_records.rb
112
173
  - lib/oai/provider/response/list_sets.rb
113
- - lib/oai/provider/metadata_format/oai_dc.rb
114
- - lib/oai/provider/resumption_token.rb
174
+ - lib/oai/provider/response/record_response.rb
115
175
  - lib/oai/provider/response.rb
116
- - lib/oai/provider/partial_result.rb
117
- - lib/oai/provider/metadata_format.rb
118
- - lib/oai/constants.rb
119
- - lib/oai/client.rb
176
+ - lib/oai/provider/resumption_token.rb
120
177
  - lib/oai/provider.rb
121
- - lib/oai/harvester.rb
122
- - lib/oai/exception.rb
123
- - lib/test.rb
178
+ - lib/oai/set.rb
179
+ - lib/oai/xpath.rb
124
180
  - lib/oai.rb
125
- - examples/providers/dublin_core.rb
181
+ - lib/test.rb
126
182
  - examples/models/file_model.rb
127
- homepage: http://www.textualize.com/ruby_oai_0
183
+ - examples/providers/dublin_core.rb
184
+ homepage: http://github.com/code4lib/ruby-oai
128
185
  licenses: []
129
-
130
186
  post_install_message:
131
187
  rdoc_options: []
132
-
133
- require_paths:
188
+ require_paths:
134
189
  - lib
135
- required_ruby_version: !ruby/object:Gem::Requirement
190
+ required_ruby_version: !ruby/object:Gem::Requirement
136
191
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ segments:
142
197
  - 0
143
- version: "0"
144
- required_rubygems_version: !ruby/object:Gem::Requirement
198
+ hash: -1260822851612593558
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
200
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ segments:
151
206
  - 0
152
- version: "0"
207
+ hash: -1260822851612593558
153
208
  requirements: []
154
-
155
209
  rubyforge_project:
156
- rubygems_version: 1.7.2
210
+ rubygems_version: 1.8.24
157
211
  signing_key:
158
212
  specification_version: 3
159
- summary: A ruby library for working with the Open Archive Initiative Protocol for Metadata Harvesting (OAI-PMH)
213
+ summary: A ruby library for working with the Open Archive Initiative Protocol for
214
+ Metadata Harvesting (OAI-PMH)
160
215
  test_files: []
161
-