oai 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.md +28 -23
  2. data/Rakefile +14 -40
  3. data/examples/providers/dublin_core.rb +63 -63
  4. data/lib/oai/client.rb +131 -97
  5. data/lib/oai/client/list_identifiers.rb +1 -0
  6. data/lib/oai/client/list_records.rb +6 -5
  7. data/lib/oai/client/list_sets.rb +6 -5
  8. data/lib/oai/client/record.rb +6 -7
  9. data/lib/oai/client/response.rb +7 -4
  10. data/lib/oai/client/resumable.rb +42 -0
  11. data/lib/oai/harvester/shell.rb +40 -41
  12. data/lib/oai/provider.rb +85 -67
  13. data/lib/oai/provider/metadata_format/oai_dc.rb +5 -6
  14. data/lib/oai/provider/model/activerecord_caching_wrapper.rb +23 -25
  15. data/lib/oai/provider/model/activerecord_wrapper.rb +99 -51
  16. data/lib/oai/provider/response.rb +33 -31
  17. data/lib/oai/provider/response/get_record.rb +7 -7
  18. data/lib/oai/provider/response/list_records.rb +5 -4
  19. data/lib/oai/provider/response/record_response.rb +14 -14
  20. data/test/activerecord_provider/config/connection.rb +8 -4
  21. data/test/activerecord_provider/database/{ar_migration.rb → 0001_oaipmh_tables.rb} +17 -12
  22. data/test/activerecord_provider/helpers/providers.rb +2 -3
  23. data/test/activerecord_provider/helpers/set_provider.rb +10 -22
  24. data/test/activerecord_provider/helpers/transactional_test_case.rb +34 -0
  25. data/test/activerecord_provider/models/dc_field.rb +4 -4
  26. data/test/activerecord_provider/models/dc_set.rb +3 -2
  27. data/test/activerecord_provider/models/exclusive_set_dc_field.rb +11 -0
  28. data/test/activerecord_provider/tc_ar_provider.rb +67 -28
  29. data/test/activerecord_provider/tc_ar_sets_provider.rb +104 -18
  30. data/test/activerecord_provider/tc_caching_paging_provider.rb +6 -10
  31. data/test/activerecord_provider/tc_simple_paging_provider.rb +7 -11
  32. data/test/activerecord_provider/test_helper.rb +10 -0
  33. data/test/client/helpers/provider.rb +44 -47
  34. data/test/client/helpers/test_wrapper.rb +4 -16
  35. data/test/client/tc_http_client.rb +90 -2
  36. data/test/client/tc_list_identifiers.rb +22 -3
  37. data/test/client/tc_list_records.rb +17 -4
  38. data/test/client/tc_list_sets.rb +17 -2
  39. data/test/provider/models.rb +32 -30
  40. data/test/provider/tc_exceptions.rb +30 -20
  41. data/test/provider/tc_functional_tokens.rb +11 -6
  42. data/test/provider/tc_provider.rb +58 -24
  43. data/test/provider/tc_resumption_tokens.rb +6 -6
  44. data/test/provider/tc_simple_provider.rb +51 -26
  45. data/test/provider/test_helper.rb +7 -0
  46. metadata +67 -128
  47. data/test/activerecord_provider/config/database.yml +0 -6
  48. data/test/activerecord_provider/database/oaipmhtest +0 -0
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class ResumptionTokenTest < Test::Unit::TestCase
4
4
  include REXML
5
5
  include OAI::Provider
6
-
6
+
7
7
  def setup
8
8
  @token = ResumptionToken.new(
9
9
  :from => Time.utc(2005,"jan",1,17,0,0),
10
10
  :until => Time.utc(2005,"jan",31,17,0,0),
11
11
  :set => "A",
12
- :metadata_prefix => "oai_dc",
12
+ :metadata_prefix => "oai_dc",
13
13
  :last => 1
14
14
  )
15
15
  end
@@ -18,11 +18,11 @@ class ResumptionTokenTest < Test::Unit::TestCase
18
18
  assert_equal "oai_dc.s(A).f(2005-01-01T17:00:00Z).u(2005-01-31T17:00:00Z)",
19
19
  @token.to_s
20
20
  end
21
-
21
+
22
22
  def test_resumption_token_next_method
23
23
  assert_equal 100, @token.next(100).last
24
24
  end
25
-
25
+
26
26
  def test_resumption_token_to_condition_hash
27
27
  hash = @token.to_conditions_hash
28
28
  assert_equal @token.from, hash[:from]
@@ -37,10 +37,10 @@ class ResumptionTokenTest < Test::Unit::TestCase
37
37
  )
38
38
  assert_equal @token, new_token
39
39
  end
40
-
40
+
41
41
  def test_resumption_token_to_xml
42
42
  doc = REXML::Document.new(@token.to_xml)
43
43
  assert_equal "#{@token.to_s}:#{@token.last}", doc.elements['/resumptionToken'].text
44
44
  end
45
-
45
+
46
46
  end
@@ -6,18 +6,18 @@ class TestSimpleProvider < Test::Unit::TestCase
6
6
  @simple_provider = SimpleProvider.new
7
7
  @model = @simple_provider.class.model
8
8
  end
9
-
9
+
10
10
  def test_identify
11
11
  doc = REXML::Document.new(@simple_provider.identify)
12
12
  assert_equal @simple_provider.class.name,
13
13
  doc.elements["/OAI-PMH/Identify/repositoryName"].text
14
14
  assert_equal SimpleModel.new.earliest.to_s,
15
15
  doc.elements["/OAI-PMH/Identify/earliestDatestamp"].text
16
-
16
+
17
17
  # PC
18
18
  # lambda { REXML::Document.new(@simple_provider.identify(:set => 'A')) }
19
-
20
-
19
+
20
+
21
21
  end
22
22
 
23
23
  def test_list_sets
@@ -26,72 +26,97 @@ class TestSimpleProvider < Test::Unit::TestCase
26
26
  assert_equal @model.sets.size, sets.size
27
27
  assert_equal @model.sets[0].name, sets[0].elements["//setName"].text
28
28
  end
29
-
29
+
30
30
  def test_metadata_formats
31
31
  assert_nothing_raised { REXML::Document.new(@simple_provider.list_metadata_formats) }
32
32
  doc = REXML::Document.new(@simple_provider.list_metadata_formats)
33
33
  assert_equal "oai_dc",
34
34
  doc.elements['/OAI-PMH/ListMetadataFormats/metadataFormat/metadataPrefix'].text
35
35
  end
36
-
36
+
37
37
  def test_metadata_formats_for_document
38
38
  assert_nothing_raised { REXML::Document.new(@simple_provider.list_metadata_formats(:identifier => "oai:test/1")) }
39
39
  doc = REXML::Document.new(@simple_provider.list_metadata_formats)
40
40
  assert_equal "oai_dc",
41
41
  doc.elements['/OAI-PMH/ListMetadataFormats/metadataFormat/metadataPrefix'].text
42
42
  end
43
-
43
+
44
44
  def test_list_records_without_constraints
45
- assert_nothing_raised { REXML::Document.new(@simple_provider.list_records) }
45
+ assert_nothing_raised { REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc')) }
46
46
 
47
47
  total = @model.find(:all).size
48
- doc = REXML::Document.new(@simple_provider.list_records)
48
+ doc = REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc'))
49
49
  assert_equal total, doc.elements['OAI-PMH/ListRecords'].size
50
50
  end
51
-
51
+
52
52
  def test_list_records_with_set_equal_a
53
53
  total = @model.find(:all, :set => 'A').size
54
- doc = REXML::Document.new(@simple_provider.list_records(:set => 'A'))
54
+ doc = REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc', :set => 'A'))
55
55
  assert_equal total, doc.elements['OAI-PMH/ListRecords'].size
56
56
  end
57
-
57
+
58
58
  def test_list_record_with_set_equal_ab
59
59
  total = @model.find(:all, :set => 'A:B').size
60
- doc = REXML::Document.new(@simple_provider.list_records(:set => 'A:B'))
60
+ doc = REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc', :set => 'A:B'))
61
61
  assert_equal total, doc.elements['OAI-PMH/ListRecords'].size
62
62
  end
63
63
 
64
64
  def test_list_identifiers_without_constraints
65
- assert_nothing_raised { REXML::Document.new(@simple_provider.list_identifiers) }
65
+ assert_nothing_raised { REXML::Document.new(@simple_provider.list_identifiers(:metadata_prefix => 'oai_dc')) }
66
66
 
67
67
  total = @model.find(:all).size
68
- doc = REXML::Document.new(@simple_provider.list_identifiers)
68
+ doc = REXML::Document.new(@simple_provider.list_identifiers(:metadata_prefix => 'oai_dc'))
69
69
  assert_equal total, doc.elements['OAI-PMH/ListIdentifiers'].to_a.size
70
70
  end
71
-
71
+
72
72
  def test_list_identifiers_with_set_equal_a
73
73
  total = @model.find(:all, :set => 'A').size
74
- doc = REXML::Document.new(@simple_provider.list_identifiers(:set => 'A'))
74
+ doc = REXML::Document.new(@simple_provider.list_identifiers(:metadata_prefix => 'oai_dc', :set => 'A'))
75
75
  assert_equal total, doc.elements['OAI-PMH/ListIdentifiers'].to_a.size
76
76
  end
77
-
77
+
78
78
  def test_list_indentifiers_with_set_equal_ab
79
79
  total = @model.find(:all, :set => 'A:B').size
80
- doc = REXML::Document.new(@simple_provider.list_identifiers(:set => 'A:B'))
80
+ doc = REXML::Document.new(@simple_provider.list_identifiers(:metadata_prefix => 'oai_dc', :set => 'A:B'))
81
81
  assert_equal total, doc.elements['OAI-PMH/ListIdentifiers'].to_a.size
82
82
  end
83
83
 
84
84
  def test_get_record
85
- assert_nothing_raised { REXML::Document.new(@simple_provider.get_record(:identifier => 'oai:test/1')) }
86
- doc = REXML::Document.new(@simple_provider.get_record(:identifier => 'oai:test/1'))
87
- assert_equal 'oai:test/1', doc.elements['OAI-PMH/GetRecord/record/header/identifier'].text
85
+ assert_nothing_raised do
86
+ REXML::Document.new(
87
+ @simple_provider.get_record(
88
+ :identifier => 'oai:test/1',
89
+ :metadataPrefix => 'oai_dc'
90
+ )
91
+ )
92
+ end
93
+ doc = REXML::Document.new(
94
+ @simple_provider.get_record(
95
+ :identifier => 'oai:test/1',
96
+ :metadataPrefix => 'oai_dc'
97
+ )
98
+ )
99
+ assert_equal 'oai:test/1',
100
+ doc.elements['OAI-PMH/GetRecord/record/header/identifier'].text
88
101
  end
89
-
102
+
90
103
  def test_deleted_record
91
- assert_nothing_raised { REXML::Document.new(@simple_provider.get_record(:identifier => 'oai:test/6')) }
92
- doc = REXML::Document.new(@simple_provider.get_record(:identifier => 'oai:test/5'))
104
+ assert_nothing_raised do
105
+ REXML::Document.new(
106
+ @simple_provider.get_record(
107
+ :identifier => 'oai:test/6',
108
+ :metadataPrefix => 'oai_dc'
109
+ )
110
+ )
111
+ end
112
+ doc = REXML::Document.new(
113
+ @simple_provider.get_record(
114
+ :identifier => 'oai:test/5',
115
+ :metadataPrefix => 'oai_dc'
116
+ )
117
+ )
93
118
  assert_equal 'oai:test/5', doc.elements['OAI-PMH/GetRecord/record/header/identifier'].text
94
119
  assert_equal 'deleted', doc.elements['OAI-PMH/GetRecord/record/header'].attributes["status"]
95
120
  end
96
-
121
+
97
122
  end
@@ -1,3 +1,10 @@
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
1
8
  require 'oai'
2
9
  require 'test/unit'
3
10
 
metadata CHANGED
@@ -1,143 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oai
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
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-07-31 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ requirement: !ruby/object:Gem::Requirement
22
17
  none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 15
27
- segments:
28
- - 2
29
- - 0
30
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
31
21
  version: 2.0.0
32
- prerelease: false
33
22
  type: :runtime
34
- name: builder
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
23
  prerelease: false
47
- type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
48
31
  name: faraday
49
- requirement: *id002
50
- - !ruby/object:Gem::Dependency
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
52
33
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- prerelease: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
61
38
  type: :runtime
62
- name: faraday_middleware
63
- requirement: *id003
64
- - !ruby/object:Gem::Dependency
65
- version_requirements: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
39
  prerelease: false
75
- type: :development
76
- name: rake
77
- requirement: *id004
78
- - !ruby/object:Gem::Dependency
79
- version_requirements: &id005 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
80
41
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- prerelease: false
89
- type: :development
90
- name: activerecord
91
- requirement: *id005
92
- - !ruby/object:Gem::Dependency
93
- version_requirements: &id006 !ruby/object:Gem::Requirement
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
94
49
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
102
55
  prerelease: false
103
- type: :development
104
- name: sqlite3
105
- requirement: *id006
106
- - !ruby/object:Gem::Dependency
107
- version_requirements: &id007 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
108
57
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
116
- prerelease: false
117
- type: :development
118
- name: rdoc
119
- requirement: *id007
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
120
62
  description:
121
63
  email: ehs@pobox.com
122
- executables:
64
+ executables:
123
65
  - oai
124
66
  extensions: []
125
-
126
67
  extra_rdoc_files: []
127
-
128
- files:
68
+ files:
129
69
  - README.md
130
70
  - Rakefile
131
71
  - bin/oai
132
72
  - test/activerecord_provider/config/connection.rb
133
- - test/activerecord_provider/config/database.yml
134
- - test/activerecord_provider/database/ar_migration.rb
135
- - test/activerecord_provider/database/oaipmhtest
73
+ - test/activerecord_provider/database/0001_oaipmh_tables.rb
136
74
  - test/activerecord_provider/fixtures/dc.yml
137
75
  - test/activerecord_provider/helpers/providers.rb
138
76
  - test/activerecord_provider/helpers/set_provider.rb
77
+ - test/activerecord_provider/helpers/transactional_test_case.rb
139
78
  - test/activerecord_provider/models/dc_field.rb
140
79
  - test/activerecord_provider/models/dc_set.rb
80
+ - test/activerecord_provider/models/exclusive_set_dc_field.rb
141
81
  - test/activerecord_provider/models/oai_token.rb
142
82
  - test/activerecord_provider/tc_ar_provider.rb
143
83
  - test/activerecord_provider/tc_ar_sets_provider.rb
@@ -177,6 +117,7 @@ files:
177
117
  - lib/oai/client/metadata_format.rb
178
118
  - lib/oai/client/record.rb
179
119
  - lib/oai/client/response.rb
120
+ - lib/oai/client/resumable.rb
180
121
  - lib/oai/client.rb
181
122
  - lib/oai/constants.rb
182
123
  - lib/oai/exception.rb
@@ -211,36 +152,34 @@ files:
211
152
  - examples/providers/dublin_core.rb
212
153
  homepage: http://github.com/code4lib/ruby-oai
213
154
  licenses: []
214
-
215
155
  post_install_message:
216
156
  rdoc_options: []
217
-
218
- require_paths:
157
+ require_paths:
219
158
  - lib
220
- required_ruby_version: !ruby/object:Gem::Requirement
159
+ required_ruby_version: !ruby/object:Gem::Requirement
221
160
  none: false
222
- requirements:
223
- - - ">="
224
- - !ruby/object:Gem::Version
225
- hash: 3
226
- segments:
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ segments:
227
166
  - 0
228
- version: "0"
229
- required_rubygems_version: !ruby/object:Gem::Requirement
167
+ hash: -2108195439113391200
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
169
  none: false
231
- requirements:
232
- - - ">="
233
- - !ruby/object:Gem::Version
234
- hash: 3
235
- segments:
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ segments:
236
175
  - 0
237
- version: "0"
176
+ hash: -2108195439113391200
238
177
  requirements: []
239
-
240
178
  rubyforge_project:
241
- rubygems_version: 1.8.24
179
+ rubygems_version: 1.8.23
242
180
  signing_key:
243
181
  specification_version: 3
244
- summary: A ruby library for working with the Open Archive Initiative Protocol for Metadata Harvesting (OAI-PMH)
182
+ summary: A ruby library for working with the Open Archive Initiative Protocol for
183
+ Metadata Harvesting (OAI-PMH)
245
184
  test_files: []
246
-
185
+ has_rdoc:
@@ -1,6 +0,0 @@
1
- # Test database connection, this database will be created and
2
- # dropped by the activerecord units tests.
3
- adapter: sqlite3
4
- database: test/activerecord_provider/database/oaipmhtest
5
- username:
6
- password: