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
data/lib/puree/map.rb DELETED
@@ -1,68 +0,0 @@
1
- module Puree
2
-
3
- # Pure API map
4
- #
5
- class Map
6
-
7
- def initialize
8
- @convention = %w(
9
- event
10
- journal
11
- organisation
12
- person
13
- project
14
- publication
15
- publisher
16
- )
17
-
18
- @api_map = {
19
- resource_type: {
20
- dataset: {
21
- service: 'datasets',
22
- response: 'GetDataSetsResponse',
23
- family: 'dk.atira.pure.modules.datasets.external.model.dataset.DataSet'
24
- },
25
- download: {
26
- service: 'downloadcount',
27
- response: 'GetDownloadCountResponse'
28
- },
29
- server: {
30
- service: 'servermeta',
31
- response: 'GetServerMetaResponse'
32
- },
33
-
34
- }
35
- }
36
-
37
- add_convention
38
- # add_family
39
- end
40
-
41
- # Get
42
- #
43
- # @return [Hash]
44
- def get
45
- @api_map
46
- end
47
-
48
-
49
-
50
- private
51
-
52
- def add_convention
53
- @convention.each do |c|
54
- resource_type = {}
55
- resource_type[:service] = c
56
- resource_type[:response] = 'Get' + c.capitalize + 'Response'
57
- @api_map[:resource_type][c.to_sym] = resource_type
58
- end
59
- end
60
-
61
- # def add_family
62
- # @api_map[:resource_type][:event][:family] = 'dk.atira.pure.api.shared.model.event.Event'
63
- # end
64
-
65
-
66
- end
67
-
68
- end
@@ -1,177 +0,0 @@
1
- module Puree
2
-
3
- # Organisation resource
4
- #
5
- class Organisation < Resource
6
-
7
- # @param base_url [String]
8
- # @param username [String]
9
- # @param password [String]
10
- # @param basic_auth [Boolean]
11
- def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil)
12
- super(api: :organisation,
13
- base_url: base_url,
14
- username: username,
15
- password: password,
16
- basic_auth: basic_auth)
17
- end
18
-
19
- # Address
20
- #
21
- # @return [Array<Hash>]
22
- def address
23
- @metadata['address']
24
- end
25
-
26
- # Email
27
- #
28
- # @return [Array<String>]
29
- def email
30
- @metadata['email']
31
- end
32
-
33
- # Name
34
- #
35
- # @return [String]
36
- def name
37
- @metadata['name']
38
- end
39
-
40
- # Organisation
41
- #
42
- # @return [Array<Hash>]
43
- def organisation
44
- @metadata['organisation']
45
- end
46
-
47
- # Parent
48
- #
49
- # @return [Hash]
50
- def parent
51
- @metadata['parent']
52
- end
53
-
54
- # Phone
55
- #
56
- # @return [Array<String>]
57
- def phone
58
- @metadata['phone']
59
- end
60
-
61
- # Type
62
- #
63
- # @return [String]
64
- def type
65
- @metadata['type']
66
- end
67
-
68
- # URL
69
- #
70
- # @return [Array<String>]
71
- def url
72
- @metadata['url']
73
- end
74
-
75
- # All metadata
76
- #
77
- # @return [Hash]
78
- def metadata
79
- @metadata
80
- end
81
-
82
-
83
- private
84
-
85
- def extract_address
86
- path = '/addresses/classifiedAddress'
87
- xpath_result = xpath_query path
88
-
89
- data = []
90
-
91
- xpath_result.each do |d|
92
- o = {}
93
- o['street'] = d.xpath('street').text.strip
94
- o['building'] = d.xpath('building').text.strip
95
- o['postcode'] = d.xpath('postalCode').text.strip
96
- o['city'] = d.xpath('city').text.strip
97
- o['country'] = d.xpath('country/term/localizedString').text.strip
98
- data << o
99
- end
100
- data.uniq
101
- end
102
-
103
- def extract_email
104
- path = '/emails/classificationDefinedStringFieldExtension/value'
105
- xpath_result = xpath_query path
106
- arr = []
107
- xpath_result.each { |i| arr << i.text.strip }
108
- arr.uniq
109
- end
110
-
111
- def extract_name
112
- path = '/name/localizedString'
113
- xpath_query_for_single_value path
114
- end
115
-
116
- def extract_organisation
117
- path = '/organisations/organisation'
118
- xpath_result = xpath_query path
119
-
120
- data = []
121
-
122
- xpath_result.each do |d|
123
- o = {}
124
- o['uuid'] = d.xpath('@uuid').text.strip
125
- o['name'] = d.xpath('name/localizedString').text.strip
126
- o['type'] = d.xpath('typeClassification/term/localizedString').text.strip
127
- data << o
128
- end
129
- data.uniq
130
- end
131
-
132
- def extract_parent
133
- data = extract_organisation
134
- o = {}
135
- if !data.empty?
136
- o = data.first
137
- end
138
- o
139
- end
140
-
141
- def extract_phone
142
- path = '/phoneNumbers/classificationDefinedStringFieldExtension/value'
143
- xpath_result = xpath_query path
144
- arr = []
145
- xpath_result.each { |i| arr << i.text.strip }
146
- arr.uniq
147
- end
148
-
149
- def extract_type
150
- path = '/typeClassification/term/localizedString'
151
- xpath_query_for_single_value path
152
- end
153
-
154
- def extract_url
155
- path = '/webAddresses/classificationDefinedFieldExtension/value/localizedString'
156
- xpath_result = xpath_query path
157
- arr = []
158
- xpath_result.each { |i| arr << i.text.strip }
159
- arr.uniq
160
- end
161
-
162
- def combine_metadata
163
- o = super
164
- o['address'] = extract_address
165
- o['email'] = extract_email
166
- o['name'] = extract_name
167
- o['organisation'] = extract_organisation
168
- o['parent'] = extract_parent
169
- o['phone'] = extract_phone
170
- o['type'] = extract_type
171
- o['url'] = extract_url
172
- @metadata = o
173
- end
174
-
175
- end
176
-
177
- end
data/lib/puree/person.rb DELETED
@@ -1,136 +0,0 @@
1
- module Puree
2
-
3
- # Person resource
4
- #
5
- class Person < Resource
6
-
7
- # @param base_url [String]
8
- # @param username [String]
9
- # @param password [String]
10
- # @param basic_auth [Boolean]
11
- def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil)
12
- super(api: :person,
13
- base_url: base_url,
14
- username: username,
15
- password: password,
16
- basic_auth: basic_auth)
17
- end
18
-
19
- # Affiliation
20
- #
21
- # @return [Array<Hash>]
22
- def affiliation
23
- @metadata['affiliation']
24
- end
25
-
26
- # Email
27
- #
28
- # @return [Array]
29
- def email
30
- @metadata['email']
31
- end
32
-
33
- # Image URL
34
- #
35
- # @return [Array<String>]
36
- def image
37
- @metadata['image']
38
- end
39
-
40
- # Keyword
41
- #
42
- # @return [Array<String>]
43
- def keyword
44
- @metadata['keyword']
45
- end
46
-
47
- # Name
48
- #
49
- # @return [Hash]
50
- def name
51
- @metadata['name']
52
- end
53
-
54
- # ORCID
55
- #
56
- # @return [String]
57
- def orcid
58
- @metadata['orcid']
59
- end
60
-
61
- # All metadata
62
- #
63
- # @return [Hash]
64
- def metadata
65
- @metadata
66
- end
67
-
68
- private
69
-
70
- def extract_affiliation
71
- path = '//organisation'
72
- xpath_result = xpath_query path
73
- data_arr = []
74
- xpath_result.each { |i|
75
- data = {}
76
- data['uuid'] = i.attr('uuid').strip
77
- data['name'] = i.xpath('name/localizedString').text.strip
78
- data_arr << data
79
- }
80
- data_arr.uniq
81
- end
82
-
83
- def extract_email
84
- path = '//emails/classificationDefinedStringFieldExtension/value'
85
- xpath_result = xpath_query path
86
- data = []
87
- xpath_result.each { |i| data << i.text }
88
- data.uniq
89
- end
90
-
91
- def extract_image
92
- path = '/photos/file/url'
93
- xpath_result = xpath_query path
94
- data = []
95
- xpath_result.each { |i| data << i.text }
96
- data.uniq
97
- end
98
-
99
- def extract_keyword
100
- path = '//keywordGroup/keyword/userDefinedKeyword/freeKeyword'
101
- xpath_result = xpath_query path
102
- data = []
103
- xpath_result.each { |i| data << i.text }
104
- data.uniq
105
- end
106
-
107
- def extract_name
108
- path = '/name'
109
- xpath_result = xpath_query path
110
- first = xpath_result.xpath('firstName').text.strip
111
- last = xpath_result.xpath('lastName').text.strip
112
- o = {}
113
- o['first'] = first
114
- o['last'] = last
115
- o
116
- end
117
-
118
- def extract_orcid
119
- path = '/orcid'
120
- xpath_query_for_single_value path
121
- end
122
-
123
- def combine_metadata
124
- o = super
125
- o['affiliation'] = extract_affiliation
126
- o['email'] = extract_email
127
- o['image'] = extract_image
128
- o['keyword'] = extract_keyword
129
- o['name'] = extract_name
130
- o['orcid'] = extract_orcid
131
- @metadata = o
132
- end
133
-
134
- end
135
-
136
- end
data/lib/puree/project.rb DELETED
@@ -1,231 +0,0 @@
1
- module Puree
2
-
3
- # Project resource
4
- #
5
- class Project < Resource
6
-
7
- # @param base_url [String]
8
- # @param username [String]
9
- # @param password [String]
10
- # @param basic_auth [Boolean]
11
- def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil)
12
- super(api: :project,
13
- base_url: base_url,
14
- username: username,
15
- password: password,
16
- bleeding: false, # stable API does not return person roles
17
- basic_auth: basic_auth)
18
- end
19
-
20
- # Acronym
21
- #
22
- # @return [String]
23
- def acronym
24
- @metadata['acronym']
25
- end
26
-
27
- # Description
28
- #
29
- # @return [String]
30
- def description
31
- @metadata['description']
32
- end
33
-
34
- # Organisation
35
- #
36
- # @return [Array<Hash>]
37
- def organisation
38
- @metadata['organisation']
39
- end
40
-
41
- # Owner
42
- #
43
- # @return [Hash]
44
- def owner
45
- @metadata['owner']
46
- end
47
-
48
- # Person (internal, external, other)
49
- #
50
- # @return [Hash<Array,Array,Array>]
51
- def person
52
- @metadata['person']
53
- end
54
-
55
- # Status
56
- #
57
- # @return [String]
58
- def status
59
- @metadata['status']
60
- end
61
-
62
- # Temporal, expected and actual start and end dates as UTC datetime.
63
- #
64
- # @return [Hash]
65
- def temporal
66
- @metadata['temporal']
67
- end
68
-
69
- # Title
70
- #
71
- # @return [String]
72
- def title
73
- @metadata['title']
74
- end
75
-
76
- # Type
77
- #
78
- # @return [String]
79
- def type
80
- @metadata['type']
81
- end
82
-
83
- # URL
84
- #
85
- # @return [String]
86
- def url
87
- @metadata['url']
88
- end
89
-
90
- # All metadata
91
- #
92
- # @return [Hash]
93
- def metadata
94
- @metadata
95
- end
96
-
97
-
98
- private
99
-
100
- def extract_acronym
101
- path = '/acronym'
102
- xpath_query_for_single_value path
103
- end
104
-
105
- def extract_description
106
- path = '/description/localizedString'
107
- xpath_query_for_single_value path
108
- end
109
-
110
- def extract_organisation
111
- path = '/organisations/association/organisation'
112
- xpath_result = xpath_query path
113
- data = []
114
- xpath_result.each do |i|
115
- o = {}
116
- o['uuid'] = i.xpath('@uuid').text.strip
117
- o['name'] = i.xpath('name/localizedString').text.strip
118
- o['type'] = i.xpath('typeClassification/term/localizedString').text.strip
119
- data << o
120
- end
121
- data
122
- end
123
-
124
- def extract_owner
125
- path = '/owner'
126
- xpath_result = xpath_query path
127
- o = {}
128
- o['uuid'] = xpath_result.xpath('@uuid').text.strip
129
- o['name'] = xpath_result.xpath('name/localizedString').text.strip
130
- o['type'] = xpath_result.xpath('typeClassification/term/localizedString').text.strip
131
- o
132
- end
133
-
134
- def extract_person
135
- data = {}
136
- # internal
137
- path = '/persons/participantAssociation'
138
- xpath_result = xpath_query path
139
- internal = []
140
- external = []
141
- other = []
142
-
143
- xpath_result.each do |i|
144
- o = {}
145
- name = {}
146
- name['first'] = i.xpath('person/name/firstName').text.strip
147
- name['last'] = i.xpath('person/name/lastName').text.strip
148
- o['name'] = name
149
- o['role'] = i.xpath('personRole/term/localizedString').text.strip
150
-
151
- uuid_internal = i.at_xpath('person/@uuid')
152
- uuid_external = i.at_xpath('externalPerson/@uuid')
153
- if uuid_internal
154
- o['uuid'] = uuid_internal.text.strip
155
- internal << o
156
- elsif uuid_external
157
- o['uuid'] = uuid_external.text.strip
158
- external << o
159
- else
160
- other << o
161
- o['uuid'] = ''
162
- end
163
- end
164
- data['internal'] = internal
165
- data['external'] = external
166
- data['other'] = other
167
- data
168
- end
169
-
170
- def extract_status
171
- path = '/status/term/localizedString'
172
- xpath_query_for_single_value path
173
- end
174
-
175
- def extract_temporal
176
- o = {}
177
- o['expected'] = {}
178
- o['actual'] = {}
179
-
180
- path = '/expectedStartDate'
181
- xpath_result = xpath_query path
182
- o['expected']['start'] = xpath_result.text.strip
183
-
184
- path = '/expectedEndDate'
185
- xpath_result = xpath_query path
186
- o['expected']['end'] = xpath_result.text.strip
187
-
188
- path = '/startFinishDate/startDate'
189
- xpath_result = xpath_query path
190
- o['actual']['start'] = xpath_result.text.strip
191
-
192
- path = '/startFinishDate/endDate'
193
- xpath_result = xpath_query path
194
- o['actual']['end'] = xpath_result.text.strip
195
-
196
- o
197
- end
198
-
199
- def extract_title
200
- path = '/title/localizedString'
201
- xpath_query_for_single_value path
202
- end
203
-
204
- def extract_type
205
- path = '/typeClassification/term/localizedString'
206
- xpath_query_for_single_value path
207
- end
208
-
209
- def extract_url
210
- path = '/projectURL'
211
- xpath_query_for_single_value path
212
- end
213
-
214
- def combine_metadata
215
- o = super
216
- o['acronym'] = extract_acronym
217
- o['description'] = extract_description
218
- o['organisation'] = extract_organisation
219
- o['owner'] = extract_owner
220
- o['person'] = extract_person
221
- o['status'] = extract_status
222
- o['temporal'] = extract_temporal
223
- o['title'] = extract_title
224
- o['type'] = extract_type
225
- o['url'] = extract_url
226
- @metadata = o
227
- end
228
-
229
- end
230
-
231
- end