r4digitalnz 1.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.
Files changed (8) hide show
  1. data/README +21 -0
  2. data/TODO +2 -0
  3. data/copying.txt +22 -0
  4. data/lib/r4digitalnz.rb +149 -0
  5. data/rakefile +36 -0
  6. data/test/data.rb +317 -0
  7. data/test/test.rb +81 -0
  8. metadata +82 -0
data/README ADDED
@@ -0,0 +1,21 @@
1
+ = Ruby 4 Digital NZ
2
+
3
+ Ruby 4 Digital NZ is an interface to the Digital NZ public API. See http://www.digitalnz.org/developer
4
+
5
+ The rubyforge project : http://r4digitalnz.rubyforge.org
6
+
7
+ You will require an api key to use this gem. See http://www.digitalnz.org/developer/getting-started/
8
+
9
+ = Installation
10
+ Type this in a console (you might need to be superuser)
11
+ gem install r4digitalnz
12
+
13
+ = Usage
14
+
15
+ require 'rubygems'
16
+ require 'r4digitalnz'
17
+
18
+ api_key = "your_api_key"
19
+ @digitalNZ = DigitalNZ.new api_key
20
+ r = @digitalNZ.search "Karori photograph", :num_results => 5, :start => 10
21
+
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ == General
2
+ * Facets with Active Resource style interface
data/copying.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 Henry Maddocks
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,149 @@
1
+ require 'net/http'
2
+ require 'cgi'
3
+
4
+ require 'rubygems'
5
+ require 'json'
6
+ require 'active_support'
7
+
8
+ module R4DigitalNZ
9
+ class APIException < StandardError; end
10
+
11
+ class DigitalNZ
12
+ def initialize api_key
13
+ @api_key = api_key
14
+ @debug = false
15
+ end
16
+
17
+ def search query, options = {}
18
+ command = "/records/v1.json/?api_key=#{@api_key}&search_text=#{CGI.escape query}"
19
+ unless options.nil?
20
+ o = options.collect do |k,v|
21
+ "&#{k.to_s}=#{v}"
22
+ end
23
+ command += o.to_s
24
+ end
25
+
26
+ SearchResult.new JSON.parse(send(command))
27
+ end
28
+
29
+ def meta_data id
30
+ command = "/records/v1/#{id}.xml/?api_key=#{@api_key}"
31
+ res = send(command)
32
+ MetaData.new(Hash.from_xml(res))
33
+ end
34
+
35
+ def content_partners
36
+ command = "/content_partners/v1.json/?api_key=#{@api_key}"
37
+ send command
38
+ end
39
+
40
+ private
41
+ def send command
42
+ p command if @debug
43
+ dnz_url = URI.parse "http://api.digitalnz.org/"
44
+
45
+ @client = Net::HTTP.new dnz_url.host, dnz_url.port
46
+ res = @client.get(command)
47
+ p "#{res.code}: #{res.body}" if @debug
48
+ case res.code.to_i
49
+ when 200
50
+ res.body
51
+ when 404
52
+ raise APIException, res.code
53
+ else
54
+ raise APIException, "#{res.code}: #{res.body}"
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ class SearchResult
61
+ include Enumerable
62
+
63
+ attr :num_results_requested
64
+ attr :result_count
65
+ attr :start
66
+
67
+ def initialize res
68
+ @num_results_requested = res['num_results_requested']
69
+ @result_count = res['result_count']
70
+ @start = res['start']
71
+
72
+ @results = res["results"].collect do |r|
73
+ Result.new r
74
+ end
75
+ end
76
+
77
+ def each
78
+ @results.each {|r| yield r}
79
+ end
80
+
81
+ def [] index
82
+ @results[index]
83
+ end
84
+ end
85
+
86
+ class Result
87
+ attr_accessor :title
88
+ attr_accessor :category
89
+ attr_accessor :content_provider
90
+ attr_accessor :date
91
+ attr_accessor :description
92
+ attr_accessor :display_url
93
+ attr_accessor :id
94
+ attr_accessor :metadata_url
95
+ attr_accessor :source_url
96
+ attr_accessor :thumbnail_url
97
+ attr_accessor :syndication_date
98
+
99
+ def initialize res
100
+ res.each do |k,v|
101
+ self.send("#{k.gsub('-', '_').to_sym}=", v)
102
+ end
103
+ end
104
+
105
+ end
106
+
107
+ class Section
108
+ attr :id
109
+ attr :mime_type
110
+ attr :mdtype
111
+
112
+ def initialize hash
113
+ @id = hash['ID']
114
+ @mime_type = hash['mdWrap']['MIMETYPE']
115
+ @mdtype = hash['mdWrap']['MDTYPE']
116
+
117
+ hash['mdWrap']['xmlData'].each do |k,v|
118
+ (class << self; self;end).class_eval do
119
+ define_method(k.to_sym) { v }
120
+ end
121
+ end
122
+
123
+ end
124
+ end
125
+
126
+ class MetaData
127
+ include Enumerable
128
+
129
+ attr :objid
130
+ attr :profile
131
+
132
+ def initialize hash
133
+ @objid = hash['mets']['OBJID']
134
+ @profile = hash['mets']['PROFILE']
135
+ @sections = hash['mets']['dmdSec'].collect do |s|
136
+ Section.new s
137
+ end
138
+ end
139
+
140
+ def each
141
+ @sections.each {|s| yield s}
142
+ end
143
+
144
+ def section section_id
145
+ self.find {|s| s.id == section_id}
146
+ end
147
+ end
148
+
149
+ end # R4DigitalNZ
data/rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+ #require 'rake/packagetask'
4
+ require 'rake/gempackagetask'
5
+
6
+
7
+ Rake::TestTask.new 'test' do |t|
8
+ t.pattern = 'test/**/test*.rb'
9
+ end
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.summary = "An interface to the Digital NZ public API."
13
+ s.description = "An interface to the Digital NZ public API. See http://www.digitalnz.org/"
14
+ s.name = "r4digitalnz"
15
+ s.author = "Henry Maddocks"
16
+ s.email = "henry.maddocks@gmail.com"
17
+ s.homepage = "http://r4digitalnz.rubyforge.org"
18
+ s.rubyforge_project = "r4digitalnz"
19
+ s.version = 1.0
20
+ s.files = FileList["lib/r4digitalnz.rb", "copying.txt", "README", "TODO", "rakefile", "test/*.rb"].to_a
21
+ s.test_files = FileList["test/*.rb"].to_a
22
+ s.add_dependency('json', '>=1.1.6')
23
+ s.add_dependency('activesupport', '>=2.1.0')
24
+ s.requirements = ['JSON', 'Active Support']
25
+ end
26
+
27
+ Rake::RDocTask.new do |rd|
28
+ rd.rdoc_files.include "README", "lib/flickraw.rb", "TODO"
29
+ rd.options << "--inline-source"
30
+ end
31
+
32
+ Rake::GemPackageTask.new spec do |p|
33
+ p.need_tar_gz = true
34
+ end
35
+
36
+ task 'default' => ['test']
data/test/data.rb ADDED
@@ -0,0 +1,317 @@
1
+ $mets = {"mets"=>
2
+ {"xmlns:xlink"=>"http://www.w3.org/1999/xlink",
3
+ "xsi:schemaLocation"=>
4
+ "http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd",
5
+ "PROFILE"=>"GDL-NLNZ",
6
+ "dmdSec"=>
7
+ [{"mdWrap"=>
8
+ {"xmlData"=>
9
+ {"format"=>" 1 b&amp;w original negative(s). Glass negative..",
10
+ "coverage"=>["Karori Road", "1882/1883"],
11
+ "title"=>
12
+ "Karori Road, Karori, Wellington, soon after it was constructed",
13
+ "rights"=>
14
+ ["http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?OUTPUTXSL=help-using.xslt",
15
+ "Alexander Turnbull Library"],
16
+ "relation"=>"PA-Group-00076",
17
+ "date"=>"[ca 1882/3]",
18
+ "type"=>"StillImage",
19
+ "xmlns:dc"=>"http://www.example.com/example",
20
+ "description"=>
21
+ "Karori Road, Karori, Wellington, soon after it was constructed, circa 1882/3. Photograph taken by William Williams.",
22
+ "identifier"=>["1/2-140324-G", "timeframes:26617"]},
23
+ "MIMETYPE"=>"text/xml",
24
+ "MDTYPE"=>"DC"},
25
+ "ID"=>"dc"},
26
+ {"mdWrap"=>
27
+ {"xmlData"=>
28
+ {"category"=>"Images",
29
+ "content_partner"=>"Alexander Turnbull Library",
30
+ "xmlns:dnz"=>"http://www.example.com/example",
31
+ "rights"=>"Some rights reserved",
32
+ "object_url"=>
33
+ "http://digital.natlib.govt.nz/get/23442?profile=access",
34
+ "rights_url"=>
35
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?OUTPUTXSL=help-using.xslt",
36
+ "landing_url"=>
37
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&amp;OUTPUTXSL=object.xslt&amp;pm_RC=REPO02DB&amp;pm_OI=26617&amp;pm_GT=Y&amp;pm_IAC=Y&amp;api_1=GET_OBJECT_XML&amp;num_result=0&amp;Object_Layout=viewimage_object",
38
+ "thumbnail_url"=>
39
+ "http://digital.natlib.govt.nz/get/23442?profile=thumb",
40
+ "collection"=>"Timeframes"},
41
+ "MIMETYPE"=>"text/xml",
42
+ "MDTYPE"=>"OTHER"},
43
+ "ID"=>"dnz"}],
44
+ "OBJID"=>"timeframes:26617",
45
+ "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
46
+ "xmlns"=>"http://www.loc.gov/METS/"}}
47
+
48
+ $data = {"results"=>
49
+ [{"metadata_url"=>"http://api.digitalnz.org/records/v1/71382",
50
+ "category"=>"Images",
51
+ "title"=>"Karori Road, Karori, Wellington, soon after it was constructed",
52
+ "content_provider"=>"Alexander Turnbull Library",
53
+ "source_url"=>"http://api.digitalnz.org/records/v1/71382/source",
54
+ "syndication_date"=>"2009-03-25T03:40:14.023Z",
55
+ "id"=>"71382",
56
+ "date"=>"",
57
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/23442?profile=thumb",
58
+ "description"=>
59
+ "Karori Road, Karori, Wellington, soon after it was constructed, circa 1882/3. Photograph taken by...",
60
+ "display_url"=>
61
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=26617&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
62
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/98664",
63
+ "category"=>"Images",
64
+ "title"=>"Karori Normal School children counting cars",
65
+ "content_provider"=>"Alexander Turnbull Library",
66
+ "source_url"=>"http://api.digitalnz.org/records/v1/98664/source",
67
+ "syndication_date"=>"2009-03-25T04:40:21.017Z",
68
+ "id"=>"98664",
69
+ "date"=>"",
70
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/71704?profile=thumb",
71
+ "description"=>
72
+ "Karori Normal School Children counting cars on Karori Road. Photographed by an Evening Post staff...",
73
+ "display_url"=>
74
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=75493&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
75
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/63515",
76
+ "category"=>"Images",
77
+ "title"=>"Karori reservoir in Wellington",
78
+ "content_provider"=>"Alexander Turnbull Library",
79
+ "source_url"=>"http://api.digitalnz.org/records/v1/63515/source",
80
+ "syndication_date"=>"2009-03-25T03:20:19.860Z",
81
+ "id"=>"63515",
82
+ "date"=>"",
83
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/8563?profile=thumb",
84
+ "description"=>
85
+ "Karori reservoir in Karori, Wellington. Photograph taken by Sydney Charles Smith between 1912 and...",
86
+ "display_url"=>
87
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=14104&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
88
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/95241",
89
+ "category"=>"Images",
90
+ "title"=>"Karori Cemetery, Wellington",
91
+ "content_provider"=>"Alexander Turnbull Library",
92
+ "source_url"=>"http://api.digitalnz.org/records/v1/95241/source",
93
+ "syndication_date"=>"2009-03-25T04:30:27.850Z",
94
+ "id"=>"95241",
95
+ "date"=>"",
96
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/36425?profile=thumb",
97
+ "description"=>
98
+ "Karori Cemetery, Wellington, circa 1910, photographed by Isaac Henry Bowen Jeffares.",
99
+ "display_url"=>
100
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=60914&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
101
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/110244",
102
+ "category"=>"Images",
103
+ "title"=>"Karori, Wellington",
104
+ "content_provider"=>"Alexander Turnbull Library",
105
+ "source_url"=>"http://api.digitalnz.org/records/v1/110244/source",
106
+ "syndication_date"=>"2009-03-25T05:10:13.230Z",
107
+ "id"=>"110244",
108
+ "date"=>"1910-01-01T00:00:00.000Z",
109
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/77497?profile=thumb",
110
+ "description"=>
111
+ "Karori, Wellington, circa 1910. Shows a woman standing on the road by a house. Spiers' coaches are...",
112
+ "display_url"=>
113
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=82826&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
114
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/101403",
115
+ "category"=>"Images",
116
+ "title"=>"Trolley bus depot site at Karori",
117
+ "content_provider"=>"Alexander Turnbull Library",
118
+ "source_url"=>"http://api.digitalnz.org/records/v1/101403/source",
119
+ "syndication_date"=>"2009-03-25T04:50:12.877Z",
120
+ "id"=>"101403",
121
+ "date"=>"",
122
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/62520?profile=thumb",
123
+ "description"=>
124
+ "Karori trolley bus depot site in the foreground looking south towards Karori Road and a large part of...",
125
+ "display_url"=>
126
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=68276&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
127
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/70640",
128
+ "category"=>"Images",
129
+ "title"=>"Ngaio, or possibly Karori, Wellington",
130
+ "content_provider"=>"Alexander Turnbull Library",
131
+ "source_url"=>"http://api.digitalnz.org/records/v1/70640/source",
132
+ "syndication_date"=>"2009-03-25T03:40:10.737Z",
133
+ "id"=>"70640",
134
+ "date"=>"1910-01-01T00:00:00.000Z",
135
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/29366?profile=thumb",
136
+ "description"=>
137
+ "Ngaio, or possibly Karori, Wellington, circa 1910. Photographer unidentified.",
138
+ "display_url"=>
139
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=25580&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
140
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/123870",
141
+ "category"=>"Images",
142
+ "title"=>"The Karori Store (1893)",
143
+ "content_provider"=>"New Zealand Electronic Text Centre",
144
+ "source_url"=>"http://api.digitalnz.org/records/v1/123870/source",
145
+ "syndication_date"=>"2009-03-25T05:40:14.475Z",
146
+ "id"=>"123870",
147
+ "date"=>"2005-01-02T13:00:00.000Z",
148
+ "thumbnail_url"=>
149
+ "http://www.nzetc.org/etexts/ManLife/ManLife_P005a(w150).jpg",
150
+ "description"=>
151
+ "[Black and white photograph of the the Karori General Store and Bakery]",
152
+ "display_url"=>
153
+ "http://www.nzetc.org/tm/scholarly/ManLife-fig-ManLife_P005a.html"},
154
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/58939",
155
+ "category"=>"Images",
156
+ "title"=>
157
+ "Overlooking the Karori Reservoir and surrounding area, Karori, Wellington",
158
+ "content_provider"=>"Alexander Turnbull Library",
159
+ "source_url"=>"http://api.digitalnz.org/records/v1/58939/source",
160
+ "syndication_date"=>"2009-03-25T03:10:19.955Z",
161
+ "id"=>"58939",
162
+ "date"=>"",
163
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/19081?profile=thumb",
164
+ "description"=>
165
+ "Overlooking the Karori Reservoir and surrounding area, Karori, Wellington, circa 1880s. Photograph...",
166
+ "display_url"=>
167
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=7762&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
168
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/62361",
169
+ "category"=>"Images",
170
+ "title"=>"Karori Reservoir and surrounding grounds, Karori, Wellington",
171
+ "content_provider"=>"Alexander Turnbull Library",
172
+ "source_url"=>"http://api.digitalnz.org/records/v1/62361/source",
173
+ "syndication_date"=>"2009-03-25T03:20:13.630Z",
174
+ "id"=>"62361",
175
+ "date"=>"",
176
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/23750?profile=thumb",
177
+ "description"=>
178
+ "Karori Reservoir, including valve tower, and surrounding grounds, Karori, Wellington, photographed by...",
179
+ "display_url"=>
180
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=12458&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
181
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/64611",
182
+ "category"=>"Images",
183
+ "title"=>"Men standing with a horse and cart outside Karori Store, Karori",
184
+ "content_provider"=>"Alexander Turnbull Library",
185
+ "source_url"=>"http://api.digitalnz.org/records/v1/64611/source",
186
+ "syndication_date"=>"2009-03-25T03:20:25.273Z",
187
+ "id"=>"64611",
188
+ "date"=>"",
189
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/21060?profile=thumb",
190
+ "description"=>
191
+ "Men standing with a horse and cart outside Karori Store, Karori. Taken by an unidentified...",
192
+ "display_url"=>
193
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=15433&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
194
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/61161",
195
+ "category"=>"Images",
196
+ "title"=>
197
+ "New school building, Karori Normal School - Photograph taken by Jo Head",
198
+ "content_provider"=>"Alexander Turnbull Library",
199
+ "source_url"=>"http://api.digitalnz.org/records/v1/61161/source",
200
+ "syndication_date"=>"2009-03-25T03:20:07.129Z",
201
+ "id"=>"61161",
202
+ "date"=>"",
203
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/71703?profile=thumb",
204
+ "description"=>
205
+ "Karori Normal School children sitting in front of their new school building, Karori, Wellington, New...",
206
+ "display_url"=>
207
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=75711&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
208
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/102568",
209
+ "category"=>"Images",
210
+ "title"=>"Pet fawn",
211
+ "content_provider"=>"Alexander Turnbull Library",
212
+ "source_url"=>"http://api.digitalnz.org/records/v1/102568/source",
213
+ "syndication_date"=>"2009-03-25T04:50:18.362Z",
214
+ "id"=>"102568",
215
+ "date"=>"",
216
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/66563?profile=thumb",
217
+ "description"=>
218
+ "Pet fawn at Karori, Wellington photographed December 1951 by an Evening Post photographer.",
219
+ "display_url"=>
220
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=69467&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
221
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/73093",
222
+ "category"=>"Images",
223
+ "title"=>
224
+ "Chapel of Futuna, Karori, Wellington - Photograph taken by Phil Reid",
225
+ "content_provider"=>"Alexander Turnbull Library",
226
+ "source_url"=>"http://api.digitalnz.org/records/v1/73093/source",
227
+ "syndication_date"=>"2009-03-25T03:40:21.818Z",
228
+ "id"=>"73093",
229
+ "date"=>"",
230
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/45302?profile=thumb",
231
+ "description"=>
232
+ "Exterior view of the Chapel of Futuna in Karori, Wellington. Photograph taken circa 29 May 1986 by...",
233
+ "display_url"=>
234
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=75565&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
235
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/88550",
236
+ "category"=>"Images",
237
+ "title"=>"Diana Pope at polling booth, Karori",
238
+ "content_provider"=>"Alexander Turnbull Library",
239
+ "source_url"=>"http://api.digitalnz.org/records/v1/88550/source",
240
+ "syndication_date"=>"2009-03-25T04:20:14.904Z",
241
+ "id"=>"88550",
242
+ "date"=>"",
243
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/30732?profile=thumb",
244
+ "description"=>
245
+ "Diana Pope, holding stuffed toys, outside a polling booth in Karori, photographed 27 October 1990 by...",
246
+ "display_url"=>
247
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=52668&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
248
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/97210",
249
+ "category"=>"Images",
250
+ "title"=>"Karori school, Wellington, damaged by Wahine storm",
251
+ "content_provider"=>"Alexander Turnbull Library",
252
+ "source_url"=>"http://api.digitalnz.org/records/v1/97210/source",
253
+ "syndication_date"=>"2009-03-25T04:40:13.075Z",
254
+ "id"=>"97210",
255
+ "date"=>"",
256
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/35066?profile=thumb",
257
+ "description"=>
258
+ "Prefab classroom at Karori School, Wellington, destroyed by the Wahine storm, photographed 11 April...",
259
+ "display_url"=>
260
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=75412&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
261
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/97211",
262
+ "category"=>"Images",
263
+ "title"=>"Karori school, Wellington, damaged by Wahine storm",
264
+ "content_provider"=>"Alexander Turnbull Library",
265
+ "source_url"=>"http://api.digitalnz.org/records/v1/97211/source",
266
+ "syndication_date"=>"2009-03-25T04:40:13.078Z",
267
+ "id"=>"97211",
268
+ "date"=>"",
269
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/72816?profile=thumb",
270
+ "description"=>
271
+ "Prefab classroom at Karori School, Wellington, destroyed by the Wahine storm, photographed 11 April...",
272
+ "display_url"=>
273
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=75413&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
274
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/99877",
275
+ "category"=>"Images",
276
+ "title"=>"Tram barn, Karori",
277
+ "content_provider"=>"Alexander Turnbull Library",
278
+ "source_url"=>"http://api.digitalnz.org/records/v1/99877/source",
279
+ "syndication_date"=>"2009-03-25T04:50:05.629Z",
280
+ "id"=>"99877",
281
+ "date"=>"",
282
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/55388?profile=thumb",
283
+ "description"=>
284
+ "The construction site for the tram barn in Karori photographed in 1950 by an Evening Post...",
285
+ "display_url"=>
286
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=66726&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
287
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/101866",
288
+ "category"=>"Images",
289
+ "title"=>"Lawn cemetery at Karori",
290
+ "content_provider"=>"Alexander Turnbull Library",
291
+ "source_url"=>"http://api.digitalnz.org/records/v1/101866/source",
292
+ "syndication_date"=>"2009-03-25T04:50:15.301Z",
293
+ "id"=>"101866",
294
+ "date"=>"",
295
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/64401?profile=thumb",
296
+ "description"=>
297
+ "The lawn cemetery at Karori in Wellington photographed circa 7 Sep 1951 by an Evening Post staff...",
298
+ "display_url"=>
299
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=68752&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"},
300
+ {"metadata_url"=>"http://api.digitalnz.org/records/v1/101867",
301
+ "category"=>"Images",
302
+ "title"=>"Lawn cemetery at Karori",
303
+ "content_provider"=>"Alexander Turnbull Library",
304
+ "source_url"=>"http://api.digitalnz.org/records/v1/101867/source",
305
+ "syndication_date"=>"2009-03-25T04:50:15.304Z",
306
+ "id"=>"101867",
307
+ "date"=>"",
308
+ "thumbnail_url"=>"http://digital.natlib.govt.nz/get/64402?profile=thumb",
309
+ "description"=>
310
+ "The lawn cemetery at Karori in Wellington photographed circa 7 Sep 1951 by an Evening Post staff...",
311
+ "display_url"=>
312
+ "http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=68753&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"}],
313
+ "num_results_requested"=>20,
314
+ "result_count"=>232,
315
+ "start"=>0,
316
+ "api_call"=>
317
+ "http://api.digitalnz.org/records/v1.json/?api_key=85be61818d438f9a821a4da98836e8f0&search_text=Karori+photograph"}
data/test/test.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'test/unit'
2
+ require 'r4digitalnz'
3
+
4
+ include R4DigitalNZ
5
+
6
+ class Test_DigitalNZ < Test::Unit::TestCase
7
+ def setup
8
+ api_key = "your_api_key"
9
+ @digitalNZ = DigitalNZ.new api_key
10
+ end
11
+
12
+ def test_simple_search
13
+ assert_nothing_raised do
14
+ r = @digitalNZ.search "Karori photograph"
15
+ assert_equal 20, r.num_results_requested
16
+ assert_equal 232, r.result_count
17
+ assert_equal 0, r.start
18
+ assert_equal "71382", r[0].id
19
+ end
20
+ end
21
+
22
+ def test_result
23
+ data = {"metadata_url"=>"http://api.digitalnz.org/records/v1/71382", "category"=>"Images", "title"=>"Karori Road, Karori, Wellington, soon after it was constructed", "content_provider"=>"Alexander Turnbull Library", "source_url"=>"http://api.digitalnz.org/records/v1/71382/source", "syndication_date"=>"2009-03-25T03:40:14.023Z", "id"=>"71382", "date"=>"", "thumbnail_url"=>"http://digital.natlib.govt.nz/get/23442?profile=thumb", "description"=>"Karori Road, Karori, Wellington, soon after it was constructed, circa 1882/3. Photograph taken by...", "display_url"=>"http://timeframes.natlib.govt.nz/logicrouter/servlet/LogicRouter?PAGE=object&OUTPUTXSL=object.xslt&pm_RC=REPO02DB&pm_OI=26617&pm_GT=Y&pm_IAC=Y&api_1=GET_OBJECT_XML&num_result=0&Object_Layout=viewimage_object"}
24
+
25
+ r = Result.new data
26
+
27
+ assert_equal "Karori Road, Karori, Wellington, soon after it was constructed", r.title
28
+ assert_equal "Alexander Turnbull Library", r.content_provider
29
+ end
30
+
31
+ def test_api_key_exception
32
+ digitalNZ = DigitalNZ.new "badkey"
33
+ assert_raise APIException do
34
+ digitalNZ.search "Karori photograph"
35
+ end
36
+ end
37
+
38
+ def test_search_with_options
39
+ r = @digitalNZ.search "Karori photograph", :num_results => 5, :start => 10
40
+ assert_equal 5, r.num_results_requested
41
+ assert_equal 232, r.result_count
42
+ assert_equal 10, r.start
43
+
44
+ assert_equal "64611", r[0].id
45
+ end
46
+
47
+ def test_search_enumerable
48
+ require 'test/data.rb'
49
+ s = SearchResult.new $data
50
+ assert s.respond_to? :collect
51
+
52
+ assert_not_nil s.find {|r| r.title.include?('Futuna')}
53
+
54
+ ids = ["71382", "98664", "63515", "95241", "110244", "101403", "70640", "123870", "58939", "62361", "64611", "61161", "102568", "73093", "88550", "97210", "97211", "99877", "101866", "101867"]
55
+ assert_equal ids, s.collect { |d| d.id}
56
+ end
57
+
58
+ def test_metadata
59
+ require 'test/data.rb'
60
+
61
+ meta_data = MetaData.new $mets
62
+ # assert_equal 2, meta_data.sections.length
63
+
64
+ assert_equal "timeframes:26617", meta_data.objid
65
+ assert_equal 'GDL-NLNZ', meta_data.profile
66
+
67
+ section = meta_data.section 'dc'
68
+ assert_equal 'dc', section.id
69
+ assert_equal 'text/xml', section.mime_type
70
+ assert_equal 'DC', section.mdtype
71
+ assert_equal ["Karori Road", "1882/1883"], section.coverage
72
+ assert_equal "StillImage", section.type
73
+
74
+ assert !section.respond_to?(:rights_url)
75
+ assert meta_data.section('dnz').respond_to?(:rights_url)
76
+ end
77
+
78
+ def test_content_partners
79
+ assert @digitalNZ.content_partners.include? "Unknown origin"
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r4digitalnz
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Henry Maddocks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-06 00:00:00 +12:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.6
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ version:
35
+ description: An interface to the Digital NZ public API. See http://www.digitalnz.org/
36
+ email: henry.maddocks@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/r4digitalnz.rb
45
+ - copying.txt
46
+ - README
47
+ - TODO
48
+ - rakefile
49
+ - test/data.rb
50
+ - test/test.rb
51
+ has_rdoc: true
52
+ homepage: http://r4digitalnz.rubyforge.org
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements:
73
+ - JSON
74
+ - Active Support
75
+ rubyforge_project: r4digitalnz
76
+ rubygems_version: 1.3.4
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: An interface to the Digital NZ public API.
80
+ test_files:
81
+ - test/data.rb
82
+ - test/test.rb