puree 0.20.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/PITCHME.md +43 -21
  4. data/README.md +72 -18
  5. data/lib/puree.rb +66 -21
  6. data/lib/puree/api/api.rb +9 -0
  7. data/lib/puree/api/authentication.rb +33 -0
  8. data/lib/puree/api/configuration.rb +43 -0
  9. data/lib/puree/api/map.rb +76 -0
  10. data/lib/puree/api/request.rb +116 -0
  11. data/lib/puree/extractor/collection.rb +131 -0
  12. data/lib/puree/extractor/dataset.rb +48 -0
  13. data/lib/puree/extractor/download.rb +71 -0
  14. data/lib/puree/extractor/event.rb +33 -0
  15. data/lib/puree/extractor/extractor.rb +10 -0
  16. data/lib/puree/extractor/journal.rb +29 -0
  17. data/lib/puree/extractor/organisation.rb +34 -0
  18. data/lib/puree/extractor/person.rb +32 -0
  19. data/lib/puree/extractor/project.rb +40 -0
  20. data/lib/puree/extractor/publication.rb +40 -0
  21. data/lib/puree/extractor/publisher.rb +27 -0
  22. data/lib/puree/extractor/resource.rb +69 -0
  23. data/lib/puree/extractor/server.rb +56 -0
  24. data/lib/puree/model/address.rb +50 -0
  25. data/lib/puree/model/copyright_license.rb +26 -0
  26. data/lib/puree/model/dataset.rb +84 -0
  27. data/lib/puree/model/download_header.rb +21 -0
  28. data/lib/puree/model/endeavour_person.rb +34 -0
  29. data/lib/puree/model/event.rb +31 -0
  30. data/lib/puree/model/event_header.rb +26 -0
  31. data/lib/puree/model/file.rb +45 -0
  32. data/lib/puree/model/helper/validation.rb +15 -0
  33. data/lib/puree/model/journal.rb +20 -0
  34. data/lib/puree/model/legal_condition.rb +26 -0
  35. data/lib/puree/model/link.rb +26 -0
  36. data/lib/puree/model/model.rb +7 -0
  37. data/lib/puree/model/organisation.rb +34 -0
  38. data/lib/puree/model/organisation_header.rb +34 -0
  39. data/lib/puree/model/person.rb +28 -0
  40. data/lib/puree/model/person_name.rb +52 -0
  41. data/lib/puree/model/project.rb +49 -0
  42. data/lib/puree/model/publication.rb +53 -0
  43. data/lib/puree/model/publication_status.rb +21 -0
  44. data/lib/puree/model/publisher.rb +13 -0
  45. data/lib/puree/model/related_content_header.rb +34 -0
  46. data/lib/puree/model/resource.rb +42 -0
  47. data/lib/puree/model/server.rb +13 -0
  48. data/lib/puree/model/spatial_point.rb +16 -0
  49. data/lib/puree/model/structure.rb +18 -0
  50. data/lib/puree/model/temporal_range.rb +15 -0
  51. data/lib/puree/util/date.rb +86 -0
  52. data/lib/puree/util/util.rb +8 -0
  53. data/lib/puree/version.rb +1 -1
  54. data/lib/puree/xml_extractor/base.rb +47 -0
  55. data/lib/puree/xml_extractor/collection.rb +40 -0
  56. data/lib/puree/xml_extractor/dataset.rb +305 -0
  57. data/lib/puree/xml_extractor/download.rb +42 -0
  58. data/lib/puree/xml_extractor/event.rb +63 -0
  59. data/lib/puree/xml_extractor/journal.rb +33 -0
  60. data/lib/puree/xml_extractor/organisation.rb +75 -0
  61. data/lib/puree/xml_extractor/person.rb +57 -0
  62. data/lib/puree/xml_extractor/project.rb +135 -0
  63. data/lib/puree/xml_extractor/publication.rb +189 -0
  64. data/lib/puree/xml_extractor/publisher.rb +28 -0
  65. data/lib/puree/xml_extractor/resource.rb +71 -0
  66. data/lib/puree/xml_extractor/server.rb +32 -0
  67. data/lib/puree/xml_extractor/shared.rb +31 -0
  68. data/lib/puree/xml_extractor/xml_extractor.rb +10 -0
  69. data/puree.gemspec +11 -8
  70. data/spec/download_http_spec.rb +31 -0
  71. data/spec/open_api_dataset_http_spec.rb +15 -0
  72. data/spec/resource/collection_all_http_spec.rb +77 -0
  73. data/spec/resource/collection_http_spec.rb +65 -0
  74. data/spec/resource/dataset_http_spec.rb +104 -0
  75. data/spec/resource/event_http_spec.rb +52 -0
  76. data/spec/resource/journal_http_spec.rb +36 -0
  77. data/spec/resource/organisation_http_spec.rb +52 -0
  78. data/spec/resource/person_http_spec.rb +48 -0
  79. data/spec/resource/project_http_spec.rb +76 -0
  80. data/spec/resource/publication_http_spec.rb +78 -0
  81. data/spec/resource/publisher_http_spec.rb +26 -0
  82. data/spec/server_http_spec.rb +26 -0
  83. data/spec/spec_helper.rb +106 -21
  84. metadata +110 -46
  85. data/lib/puree/collection.rb +0 -285
  86. data/lib/puree/configuration.rb +0 -15
  87. data/lib/puree/dataset.rb +0 -483
  88. data/lib/puree/date.rb +0 -63
  89. data/lib/puree/download.rb +0 -189
  90. data/lib/puree/event.rb +0 -133
  91. data/lib/puree/journal.rb +0 -75
  92. data/lib/puree/map.rb +0 -68
  93. data/lib/puree/organisation.rb +0 -177
  94. data/lib/puree/person.rb +0 -136
  95. data/lib/puree/project.rb +0 -231
  96. data/lib/puree/publication.rb +0 -258
  97. data/lib/puree/publisher.rb +0 -64
  98. data/lib/puree/resource.rb +0 -261
  99. data/lib/puree/server.rb +0 -156
  100. data/spec/collection_spec.rb +0 -62
  101. data/spec/dataset_spec.rb +0 -148
  102. data/spec/download_spec.rb +0 -33
  103. data/spec/event_spec.rb +0 -108
  104. data/spec/journal_spec.rb +0 -92
  105. data/spec/organisation_spec.rb +0 -112
  106. data/spec/person_spec.rb +0 -104
  107. data/spec/project_spec.rb +0 -120
  108. data/spec/publication_spec.rb +0 -128
  109. data/spec/publisher_spec.rb +0 -89
  110. data/spec/server_spec.rb +0 -36
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Albin-Clark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-03 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -38,10 +38,24 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
- description: Consumes the Pure Research Information System API and puts the metadata
42
- into simple data structures.
43
- email:
44
- - a.albin-clark@lancaster.ac.uk
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |-
56
+ Fetches metadata from the Pure Research Information System and
57
+ extracts it into Ruby data models.
58
+ email: a.albin-clark@lancaster.ac.uk
45
59
  executables: []
46
60
  extensions: []
47
61
  extra_rdoc_files: []
@@ -54,36 +68,85 @@ files:
54
68
  - README.md
55
69
  - Rakefile
56
70
  - lib/puree.rb
57
- - lib/puree/collection.rb
58
- - lib/puree/configuration.rb
59
- - lib/puree/dataset.rb
60
- - lib/puree/date.rb
61
- - lib/puree/download.rb
62
- - lib/puree/event.rb
63
- - lib/puree/journal.rb
64
- - lib/puree/map.rb
65
- - lib/puree/organisation.rb
66
- - lib/puree/person.rb
67
- - lib/puree/project.rb
68
- - lib/puree/publication.rb
69
- - lib/puree/publisher.rb
70
- - lib/puree/resource.rb
71
- - lib/puree/server.rb
71
+ - lib/puree/api/api.rb
72
+ - lib/puree/api/authentication.rb
73
+ - lib/puree/api/configuration.rb
74
+ - lib/puree/api/map.rb
75
+ - lib/puree/api/request.rb
76
+ - lib/puree/extractor/collection.rb
77
+ - lib/puree/extractor/dataset.rb
78
+ - lib/puree/extractor/download.rb
79
+ - lib/puree/extractor/event.rb
80
+ - lib/puree/extractor/extractor.rb
81
+ - lib/puree/extractor/journal.rb
82
+ - lib/puree/extractor/organisation.rb
83
+ - lib/puree/extractor/person.rb
84
+ - lib/puree/extractor/project.rb
85
+ - lib/puree/extractor/publication.rb
86
+ - lib/puree/extractor/publisher.rb
87
+ - lib/puree/extractor/resource.rb
88
+ - lib/puree/extractor/server.rb
89
+ - lib/puree/model/address.rb
90
+ - lib/puree/model/copyright_license.rb
91
+ - lib/puree/model/dataset.rb
92
+ - lib/puree/model/download_header.rb
93
+ - lib/puree/model/endeavour_person.rb
94
+ - lib/puree/model/event.rb
95
+ - lib/puree/model/event_header.rb
96
+ - lib/puree/model/file.rb
97
+ - lib/puree/model/helper/validation.rb
98
+ - lib/puree/model/journal.rb
99
+ - lib/puree/model/legal_condition.rb
100
+ - lib/puree/model/link.rb
101
+ - lib/puree/model/model.rb
102
+ - lib/puree/model/organisation.rb
103
+ - lib/puree/model/organisation_header.rb
104
+ - lib/puree/model/person.rb
105
+ - lib/puree/model/person_name.rb
106
+ - lib/puree/model/project.rb
107
+ - lib/puree/model/publication.rb
108
+ - lib/puree/model/publication_status.rb
109
+ - lib/puree/model/publisher.rb
110
+ - lib/puree/model/related_content_header.rb
111
+ - lib/puree/model/resource.rb
112
+ - lib/puree/model/server.rb
113
+ - lib/puree/model/spatial_point.rb
114
+ - lib/puree/model/structure.rb
115
+ - lib/puree/model/temporal_range.rb
116
+ - lib/puree/util/date.rb
117
+ - lib/puree/util/util.rb
72
118
  - lib/puree/version.rb
119
+ - lib/puree/xml_extractor/base.rb
120
+ - lib/puree/xml_extractor/collection.rb
121
+ - lib/puree/xml_extractor/dataset.rb
122
+ - lib/puree/xml_extractor/download.rb
123
+ - lib/puree/xml_extractor/event.rb
124
+ - lib/puree/xml_extractor/journal.rb
125
+ - lib/puree/xml_extractor/organisation.rb
126
+ - lib/puree/xml_extractor/person.rb
127
+ - lib/puree/xml_extractor/project.rb
128
+ - lib/puree/xml_extractor/publication.rb
129
+ - lib/puree/xml_extractor/publisher.rb
130
+ - lib/puree/xml_extractor/resource.rb
131
+ - lib/puree/xml_extractor/server.rb
132
+ - lib/puree/xml_extractor/shared.rb
133
+ - lib/puree/xml_extractor/xml_extractor.rb
73
134
  - puree.gemspec
74
- - spec/collection_spec.rb
75
- - spec/dataset_spec.rb
76
- - spec/download_spec.rb
77
- - spec/event_spec.rb
78
- - spec/journal_spec.rb
79
- - spec/organisation_spec.rb
80
- - spec/person_spec.rb
81
- - spec/project_spec.rb
82
- - spec/publication_spec.rb
83
- - spec/publisher_spec.rb
84
- - spec/server_spec.rb
135
+ - spec/download_http_spec.rb
136
+ - spec/open_api_dataset_http_spec.rb
137
+ - spec/resource/collection_all_http_spec.rb
138
+ - spec/resource/collection_http_spec.rb
139
+ - spec/resource/dataset_http_spec.rb
140
+ - spec/resource/event_http_spec.rb
141
+ - spec/resource/journal_http_spec.rb
142
+ - spec/resource/organisation_http_spec.rb
143
+ - spec/resource/person_http_spec.rb
144
+ - spec/resource/project_http_spec.rb
145
+ - spec/resource/publication_http_spec.rb
146
+ - spec/resource/publisher_http_spec.rb
147
+ - spec/server_http_spec.rb
85
148
  - spec/spec_helper.rb
86
- homepage: https://aalbinclark.gitbooks.io/puree
149
+ homepage: https://github.com/lulibrary/puree
87
150
  licenses:
88
151
  - MIT
89
152
  metadata: {}
@@ -106,18 +169,19 @@ rubyforge_project:
106
169
  rubygems_version: 2.2.2
107
170
  signing_key:
108
171
  specification_version: 4
109
- summary: A client for the Pure Research Information System API.
172
+ summary: Metadata extraction from the Pure Research Information System.
110
173
  test_files:
111
- - spec/collection_spec.rb
112
- - spec/dataset_spec.rb
113
- - spec/download_spec.rb
114
- - spec/event_spec.rb
115
- - spec/journal_spec.rb
116
- - spec/organisation_spec.rb
117
- - spec/person_spec.rb
118
- - spec/project_spec.rb
119
- - spec/publication_spec.rb
120
- - spec/publisher_spec.rb
121
- - spec/server_spec.rb
174
+ - spec/download_http_spec.rb
175
+ - spec/open_api_dataset_http_spec.rb
176
+ - spec/resource/collection_all_http_spec.rb
177
+ - spec/resource/collection_http_spec.rb
178
+ - spec/resource/dataset_http_spec.rb
179
+ - spec/resource/event_http_spec.rb
180
+ - spec/resource/journal_http_spec.rb
181
+ - spec/resource/organisation_http_spec.rb
182
+ - spec/resource/person_http_spec.rb
183
+ - spec/resource/project_http_spec.rb
184
+ - spec/resource/publication_http_spec.rb
185
+ - spec/resource/publisher_http_spec.rb
186
+ - spec/server_http_spec.rb
122
187
  - spec/spec_helper.rb
123
- has_rdoc:
@@ -1,285 +0,0 @@
1
- module Puree
2
-
3
- # Collection of resources
4
- #
5
- class Collection
6
-
7
- # @param resource [Symbol]
8
- # @param base_url [String]
9
- # @param username [String]
10
- # @param password [String]
11
- # @param basic_auth [Boolean]
12
- def initialize(resource: nil,
13
- base_url: nil,
14
- username: nil,
15
- password: nil,
16
- basic_auth: nil)
17
- @resource_type = resource
18
- @api_map = Puree::Map.new.get
19
- @base_url = base_url.nil? ? Puree.base_url : base_url
20
- @basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth
21
- if @basic_auth === true
22
- @username = username.nil? ? Puree.username : username
23
- @password = password.nil? ? Puree.password : password
24
- end
25
- @uuids = []
26
- end
27
-
28
- # Gets an array of objects of resource type specified in constructor
29
- #
30
- # @param limit [Integer]
31
- # @param offset [Integer]
32
- # @param created_start [String]
33
- # @param created_end [String]
34
- # @param modified_start [String]
35
- # @param modified_end [String]
36
- # @param full [Boolean]
37
- # @param instance [Boolean]
38
- # @return [Array<Object>]
39
- # @return [Array<Resource subclass>]
40
- def get(
41
- limit: 20,
42
- offset: 0,
43
- created_start: nil,
44
- created_end: nil,
45
- modified_start: nil,
46
- modified_end: nil,
47
- full: true,
48
- instance: false,
49
- rendering: :xml_long
50
- )
51
-
52
- @options = {
53
- basic_auth: @basic_auth,
54
- latest_api: true,
55
- resource_type: @resource_type.to_sym,
56
- rendering: :system,
57
- limit: limit,
58
- offset: offset,
59
- created_start: created_start,
60
- created_end: created_end,
61
- modified_start: modified_start,
62
- modified_end: modified_end,
63
- full: full,
64
- instance: instance,
65
- record_rendering: rendering
66
- }
67
-
68
- reset
69
-
70
- missing = missing_credentials
71
- if !missing.empty?
72
- missing.each do |m|
73
- puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}"
74
- end
75
- exit
76
- end
77
-
78
- # strip any trailing slash
79
- @base_url = @base_url.sub(/(\/)+$/, '')
80
-
81
- headers = {}
82
- headers['Accept'] = 'application/xml'
83
-
84
- if @options[:basic_auth] === true
85
- @auth = Base64::strict_encode64(@username + ':' + @password)
86
- headers['Authorization'] = 'Basic ' + @auth
87
- end
88
-
89
- query = {}
90
-
91
- query['rendering'] = @options[:rendering]
92
-
93
- if @options[:limit] >= 0
94
- query['window.size'] = @options[:limit]
95
- end
96
-
97
- if @options[:offset]
98
- query['window.offset'] = @options[:offset]
99
- end
100
-
101
- if @options[:created_start]
102
- query['createdDate.fromDate'] = @options[:created_start]
103
- end
104
-
105
- if @options[:created_end]
106
- query['createdDate.toDate'] = @options[:created_end]
107
- end
108
-
109
- if @options[:modified_start]
110
- query['modifiedDate.fromDate'] = @options[:modified_start]
111
- end
112
-
113
- if @options[:modified_end]
114
- query['modifiedDate.toDate'] = @options[:modified_end]
115
- end
116
-
117
- if @options['rendering']
118
- query['rendering'] = @options['rendering']
119
- end
120
-
121
- begin
122
- url = build_url
123
- req = HTTP.headers accept: 'application/xml'
124
- if @options[:basic_auth]
125
- req = req.auth headers['Authorization']
126
- end
127
- @response = req.get(url, params: query)
128
- @doc = Nokogiri::XML @response.body
129
- @doc.remove_namespaces!
130
-
131
- @count = extract_count
132
-
133
- rescue HTTP::Error => e
134
- puts 'HTTP::Error '+ e.message
135
- end
136
-
137
- if @options[:full]
138
- collect_resource
139
- else
140
- data = []
141
- uuid.each do |u|
142
- o = {}
143
- o['uuid'] = u
144
- data << o
145
- end
146
- data
147
- end
148
-
149
- end
150
-
151
-
152
- # Count of records available for a resource type
153
- #
154
- # @return [Integer]
155
- def count
156
- @count ||= get_count
157
- end
158
-
159
- private
160
-
161
- def get_count
162
- find limit: 0
163
- extract_count
164
- end
165
-
166
- def extract_count
167
- path = '//count'
168
- xpath_query_for_single_value(path).to_i
169
- end
170
-
171
-
172
- # Array of UUIDs
173
- #
174
- # @return [Array<String>]
175
- def uuid
176
- collect_uuid
177
- @uuids
178
- end
179
-
180
-
181
- def collect_resource
182
- data = []
183
- resource_class = 'Puree::' + @resource_type.to_s.capitalize
184
-
185
- # if @options[:basic_auth] === true
186
- # r = Object.const_get(resource_class).new base_url: @base_url,
187
- # username: @username,
188
- # password: @password,
189
- # basic_auth: true
190
- # else
191
- # r = Object.const_get(resource_class).new base_url: @base_url
192
- # end
193
- # whitelist symbol
194
- if @api_map[:resource_type].has_key?(@resource_type)
195
- uuid.each do |u|
196
- if @options[:basic_auth] === true
197
- r = Object.const_get(resource_class).new base_url: @base_url,
198
- username: @username,
199
- password: @password,
200
- basic_auth: true
201
- else
202
- r = Object.const_get(resource_class).new base_url: @base_url
203
- end
204
- record = r.find uuid: u,
205
- rendering: @options[:record_rendering]
206
- # puts JSON.pretty_generate( record, :indent => ' ')
207
- # p u
208
- if @options[:instance]
209
- data << r
210
- else
211
- # just the data
212
- data << record
213
- end
214
- end
215
- data
216
- else
217
- puts 'Invalid resource class'
218
- exit
219
- end
220
- end
221
-
222
- def collect_uuid
223
- @uuids = []
224
- path = '//renderedItem/@renderedContentUUID'
225
- xpath_result = xpath_query path
226
- xpath_result.each { |i| @uuids << i.text.strip }
227
- end
228
-
229
- def service_name
230
- resource_type = @options[:resource_type]
231
- @api_map[:resource_type][resource_type][:service]
232
- end
233
-
234
- def service_response_name
235
- resource_type = @options[:resource_type]
236
- @api_map[:resource_type][resource_type][:response]
237
- end
238
-
239
- def build_url
240
- service = service_name
241
- if @options[:latest_api] === false
242
- service_api_mode = service
243
- else
244
- service_api_mode = service + '.current'
245
- end
246
- @base_url + '/' + service_api_mode
247
- end
248
-
249
- def xpath_query(path)
250
- @doc.xpath path
251
- end
252
-
253
- def xpath_query_for_single_value(path)
254
- xpath_result = xpath_query path
255
- xpath_result ? xpath_result.text.strip : ''
256
- end
257
-
258
-
259
- def missing_credentials
260
- missing = []
261
- if @base_url.nil?
262
- missing << 'base_url'
263
- end
264
-
265
- if @options[:basic_auth] === true
266
- if @username.nil?
267
- missing << 'username'
268
- end
269
- if @password.nil?
270
- missing << 'password'
271
- end
272
- end
273
-
274
- missing
275
- end
276
-
277
- def reset
278
- @response = nil
279
- @count = nil
280
- end
281
-
282
- alias :find :get
283
-
284
- end
285
- end