datacite 0.1.0 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14676f8f7b74e44521ef3a1501f17799613051797ec254883798eb4582185dd2
4
- data.tar.gz: fa0eb2fa6f505fe8b73f7e765f06311bbf39d2232d05bbad85bbe01e48622993
3
+ metadata.gz: 4b96ed2645004f38cfafa54c6f2f396e4266e3c71d0e6ad7756aec110951694c
4
+ data.tar.gz: f4d578d17e18bce596557cef3c721013a54f1dac2b872f3ca925479ca736b6ea
5
5
  SHA512:
6
- metadata.gz: cd36d5249f1abb5ff9d9c1a498799c0897d1ed9d09ad42adacd75c23055a3414537336602d3f17b48c9fa26de6155eb82695b6e3c2110bc0b12d650224c19885
7
- data.tar.gz: 8688df8c2c3decf2e6b092734397c2f515584b4d0f83d5d6cf62e1f9f69b3d4976d76c196db1665cfda352c0fee5bd56aed8a82a0e8cd27ae2dc77366b436123
6
+ metadata.gz: d32a67f8fac96b39fcaa74bcb7433fad359f04f646685e8dea489abd741f198c8e98a5b383c95f4e4449258b803d65c3fa5efec69173689ecbd23e89120cf74e
7
+ data.tar.gz: f6a2d150048f01be27ffdd300a3bf97effa3aa0d29aea391b174bcb463711b56bc8f11c6dc8a47fdb037b327fa9e41090bd704de1fa37eede0144ef5e860cdbb
data/Gemfile CHANGED
@@ -15,5 +15,3 @@ gem "rubocop-rake", "~> 0.6.0"
15
15
  gem "rubocop-rspec", "~> 2.4"
16
16
 
17
17
  gem "webmock", "~> 3.13"
18
-
19
- gem "faraday_middleware", "~> 1.0"
data/Gemfile.lock CHANGED
@@ -1,9 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datacite (0.1.0)
4
+ datacite (0.2.2)
5
5
  dry-monads (~> 1.3)
6
6
  faraday (~> 1.4)
7
+ faraday_middleware (~> 1.0)
8
+ json_schema (~> 0.21.0)
7
9
  zeitwerk (~> 2.4)
8
10
 
9
11
  GEM
@@ -16,14 +18,12 @@ GEM
16
18
  crack (0.4.5)
17
19
  rexml
18
20
  diff-lcs (1.4.4)
19
- dry-core (0.6.0)
21
+ dry-core (0.7.1)
20
22
  concurrent-ruby (~> 1.0)
21
- dry-equalizer (0.3.0)
22
- dry-monads (1.3.5)
23
+ dry-monads (1.4.0)
23
24
  concurrent-ruby (~> 1.0)
24
- dry-core (~> 0.4, >= 0.4.4)
25
- dry-equalizer
26
- faraday (1.5.0)
25
+ dry-core (~> 0.7)
26
+ faraday (1.7.0)
27
27
  faraday-em_http (~> 1.0)
28
28
  faraday-em_synchrony (~> 1.0)
29
29
  faraday-excon (~> 1.1)
@@ -31,6 +31,7 @@ GEM
31
31
  faraday-net_http (~> 1.0)
32
32
  faraday-net_http_persistent (~> 1.1)
33
33
  faraday-patron (~> 1.0)
34
+ faraday-rack (~> 1.0)
34
35
  multipart-post (>= 1.2, < 3)
35
36
  ruby2_keywords (>= 0.0.4)
36
37
  faraday-em_http (1.0.0)
@@ -38,11 +39,13 @@ GEM
38
39
  faraday-excon (1.1.0)
39
40
  faraday-httpclient (1.0.1)
40
41
  faraday-net_http (1.0.1)
41
- faraday-net_http_persistent (1.1.0)
42
+ faraday-net_http_persistent (1.2.0)
42
43
  faraday-patron (1.0.0)
43
- faraday_middleware (1.0.0)
44
+ faraday-rack (1.0.0)
45
+ faraday_middleware (1.1.0)
44
46
  faraday (~> 1.0)
45
47
  hashdiff (1.0.1)
48
+ json_schema (0.21.0)
46
49
  multipart-post (2.1.1)
47
50
  parallel (1.20.1)
48
51
  parser (3.0.1.1)
@@ -82,7 +85,7 @@ GEM
82
85
  rubocop (~> 1.0)
83
86
  rubocop-ast (>= 1.1.0)
84
87
  ruby-progressbar (1.11.0)
85
- ruby2_keywords (0.0.4)
88
+ ruby2_keywords (0.0.5)
86
89
  unicode-display_width (2.0.0)
87
90
  webmock (3.13.0)
88
91
  addressable (>= 2.3.6)
@@ -96,7 +99,6 @@ PLATFORMS
96
99
 
97
100
  DEPENDENCIES
98
101
  datacite!
99
- faraday_middleware (~> 1.0)
100
102
  rake (~> 13.0)
101
103
  rspec (~> 3.0)
102
104
  rubocop (~> 1.7)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Datacite Ruby Client
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/datacite.svg)](https://badge.fury.io/rb/datacite)
4
+
3
5
  This is a Ruby client for interfacing with the DataCite REST API. https://support.datacite.org/docs/api
4
6
 
5
7
  ## Installation
@@ -20,15 +22,65 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
25
+ ### Initialize the client
26
+ ```ruby
27
+ client = Datacite::Client.new(username: "foo",
28
+ password: "bar",
29
+ host: "api.test.datacite.org")
30
+ ```
31
+
32
+ ### Create a Draft DOI
33
+
34
+ ```ruby
35
+ result = client.register_doi(prefix: '10.0001', suffix: 'bc123df4567')
36
+
37
+ result.either(
38
+ -> response { response.doi },
39
+ -> response { raise("Something went wrong", response.status) }
40
+ )
41
+ ```
42
+
43
+ #### Auto-generated DOI's
44
+
23
45
  ```ruby
24
- client = Datacite::Client.new(username: "foo", password: "bar")
25
- result = client.autogenerate_doi
46
+ result = client.autogenerate_doi(prefix: '10.0001')
47
+
26
48
  result.either(
27
49
  -> response { response.doi },
28
50
  -> response { raise("Something went wrong", response.status) }
29
51
  )
30
52
  ```
31
53
 
54
+ ### Update DOI's
55
+
56
+ ```ruby
57
+ # See https://support.datacite.org/reference/dois-2#put_dois-id for the attributes
58
+ attributes = {
59
+ relatedIdentifiers: [
60
+ {
61
+ relatedIdentifier: "https://doi.org/10.xxxx/xxxxx",
62
+ relatedIdentifierType: "DOI",
63
+ relationType: "References",
64
+ resourceTypeGeneral: "Dataset"
65
+ }
66
+ ]
67
+ }
68
+ result = client.update(id: '10.0001/bc123df4567', attributes: attributes)
69
+
70
+ result.either(
71
+ -> response { response.doi },
72
+ -> response { raise("Something went wrong", response.status) }
73
+ )
74
+ ```
75
+
76
+ ### Validation
77
+ This gem validates using a json schema from https://github.com/datacite/schema/blob/master/source/json/kernel-4.3/datacite_4.3_schema.json
78
+
79
+ We've made the following changes:
80
+ * relax the required fields (https://github.com/datacite/schema/issues/97)
81
+ * add event property (https://github.com/datacite/schema/issues/100)
82
+ * add url property (https://github.com/datacite/schema/issues/101)
83
+
32
84
  ## Development
33
85
 
34
86
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/datacite.gemspec CHANGED
@@ -30,5 +30,7 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency "dry-monads", "~> 1.3"
32
32
  spec.add_dependency "faraday", "~> 1.4"
33
+ spec.add_dependency "faraday_middleware", "~> 1.0"
34
+ spec.add_dependency "json_schema", "~> 0.21.0"
33
35
  spec.add_dependency "zeitwerk", "~> 2.4"
34
36
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Datacite
4
- # The JSON request to create a DOI
5
- class AutogenerateDoi
6
- # @param [Prefix] prefix
4
+ # The JSON request to create a random DOI
5
+ class AutogenerateDoiRequestBody
6
+ # @param [String] prefix
7
7
  def initialize(prefix:)
8
8
  @prefix = prefix
9
9
  end
@@ -3,6 +3,7 @@
3
3
  require "faraday"
4
4
  require "faraday_middleware"
5
5
  require "dry/monads"
6
+ require "json_schema"
6
7
 
7
8
  module Datacite
8
9
  # The connection to DataCite API
@@ -23,15 +24,47 @@ module Datacite
23
24
  end
24
25
  end
25
26
 
27
+ # Creates a random DOI
28
+ # @param [String] prefix
26
29
  # @returns [Dry::Monads::Result]
27
30
  def autogenerate_doi(prefix:)
28
- request_body = AutogenerateDoi.new(prefix: prefix).to_json
29
- response = conn.post("/dois", request_body)
31
+ request_body = AutogenerateDoiRequestBody.new(prefix: prefix).to_json
32
+ register(request_body)
33
+ end
34
+
35
+ # Creates a specific DOI
36
+ # @param [String] prefix
37
+ # @param [String] suffix
38
+ # @returns [Dry::Monads::Result]
39
+ def register_doi(prefix:, suffix:)
40
+ request_body = RegisterDoiRequestBody.new(prefix: prefix, suffix: suffix).to_json
41
+ register(request_body)
42
+ end
43
+
44
+ # Update a DOI
45
+ # @param [String] id
46
+ # @param [String] value
47
+ # @returns [Dry::Monads::Result]
48
+ def update(id:, attributes:)
49
+ Validator.validate!(attributes)
50
+ request_body = {
51
+ data: {
52
+ attributes: attributes
53
+ }
54
+ }
55
+
56
+ response = conn.put("/dois/#{id}", request_body.to_json)
30
57
  response.success? ? Success(Response.new(response)) : Failure(response)
31
58
  end
32
59
 
33
60
  private
34
61
 
62
+ # @returns [Dry::Monads::Result]
63
+ def register(request_body)
64
+ response = conn.post("/dois", request_body)
65
+ response.success? ? Success(Response.new(response)) : Failure(response)
66
+ end
67
+
35
68
  def headers
36
69
  {
37
70
  "Content-Type" => "application/vnd.api+json",
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datacite
4
+ # The JSON request to create a specific DOI
5
+ class RegisterDoiRequestBody
6
+ # @param [String] prefix
7
+ # @param [String] suffix
8
+ def initialize(prefix:, suffix:)
9
+ @prefix = prefix
10
+ @suffix = suffix
11
+ end
12
+
13
+ # @returns [Hash]
14
+ def to_json(*_args)
15
+ {
16
+ data: {
17
+ type: "dois",
18
+ attributes: {
19
+ doi: "#{prefix}/#{suffix}"
20
+ }
21
+ }
22
+ }
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :prefix, :suffix
28
+ end
29
+ end
@@ -0,0 +1,481 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+
4
+ "definitions": {
5
+ "nameType": {
6
+ "type": "string",
7
+ "enum": [
8
+ "Organizational",
9
+ "Personal"
10
+ ]
11
+ },
12
+ "nameIdentifiers": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "properties": {
17
+ "nameIdentifier": {"type": "string"},
18
+ "nameIdentifierScheme": {"type": "string"},
19
+ "schemeURI": {"type": "string", "format": "uri"}
20
+ },
21
+ "required": ["nameIdentifier", "nameIdentifierScheme"]
22
+ },
23
+ "uniqueItems": true
24
+ },
25
+ "affiliations": {
26
+ "type": "array",
27
+ "items": {
28
+ "type": "object",
29
+ "properties": {
30
+ "affiliation": {"type": "string"}
31
+ },
32
+ "required": ["affiliation"]
33
+ },
34
+ "uniqueItems": true
35
+ },
36
+ "titleType": {
37
+ "type": "string",
38
+ "enum": [
39
+ "AlternativeTitle",
40
+ "Subtitle",
41
+ "TranslatedTitle",
42
+ "Other"
43
+ ]
44
+ },
45
+ "contributorType": {
46
+ "type": "string",
47
+ "enum": [
48
+ "ContactPerson",
49
+ "DataCollector",
50
+ "DataCurator",
51
+ "DataManager",
52
+ "Distributor",
53
+ "Editor",
54
+ "HostingInstitution",
55
+ "Producer",
56
+ "ProjectLeader",
57
+ "ProjectManager",
58
+ "ProjectMember",
59
+ "RegistrationAgency",
60
+ "RegistrationAuthority",
61
+ "RelatedPerson",
62
+ "Researcher",
63
+ "ResearchGroup",
64
+ "RightsHolder",
65
+ "Sponsor",
66
+ "Supervisor",
67
+ "WorkPackageLeader",
68
+ "Other"
69
+ ]
70
+ },
71
+ "date": {
72
+ "type": "string",
73
+ "anyOf": [
74
+ {"format": "date"},
75
+ {"format": "date-time"}
76
+ ]
77
+ },
78
+ "dateType": {
79
+ "type": "string",
80
+ "enum": [
81
+ "Accepted",
82
+ "Available",
83
+ "Copyrighted",
84
+ "Collected",
85
+ "Created",
86
+ "Issued",
87
+ "Submitted",
88
+ "Updated",
89
+ "Valid",
90
+ "Withdrawn",
91
+ "Other"
92
+ ]
93
+ },
94
+ "resourceTypeGeneral": {
95
+ "type": "string",
96
+ "enum": [
97
+ "Audiovisual",
98
+ "Collection",
99
+ "DataPaper",
100
+ "Dataset",
101
+ "Event",
102
+ "Image",
103
+ "InteractiveResource",
104
+ "Model",
105
+ "PhysicalObject",
106
+ "Service",
107
+ "Software",
108
+ "Sound",
109
+ "Text",
110
+ "Workflow",
111
+ "Other"
112
+ ]
113
+ },
114
+ "relatedIdentifierType": {
115
+ "type": "string",
116
+ "enum": [
117
+ "ARK",
118
+ "arXiv",
119
+ "bibcode",
120
+ "DOI",
121
+ "EAN13",
122
+ "EISSN",
123
+ "Handle",
124
+ "IGSN",
125
+ "ISBN",
126
+ "ISSN",
127
+ "ISTC",
128
+ "LISSN",
129
+ "LSID",
130
+ "PMID",
131
+ "PURL",
132
+ "UPC",
133
+ "URL",
134
+ "URN",
135
+ "w3id"
136
+ ]
137
+ },
138
+ "relationType": {
139
+ "type": "string",
140
+ "enum": [
141
+ "IsCitedBy",
142
+ "Cites",
143
+ "IsSupplementTo",
144
+ "IsSupplementedBy",
145
+ "IsContinuedBy",
146
+ "Continues",
147
+ "IsDescribedBy",
148
+ "Describes",
149
+ "HasMetadata",
150
+ "IsMetadataFor",
151
+ "HasVersion",
152
+ "IsVersionOf",
153
+ "IsNewVersionOf",
154
+ "IsPreviousVersionOf",
155
+ "IsPartOf",
156
+ "HasPart",
157
+ "IsReferencedBy",
158
+ "References",
159
+ "IsDocumentedBy",
160
+ "Documents",
161
+ "IsCompiledBy",
162
+ "Compiles",
163
+ "IsVariantFormOf",
164
+ "IsOriginalFormOf",
165
+ "IsIdenticalTo",
166
+ "IsReviewedBy",
167
+ "Reviews",
168
+ "IsDerivedFrom",
169
+ "IsSourceOf",
170
+ "IsRequiredBy",
171
+ "Requires",
172
+ "IsObsoletedBy",
173
+ "Obsoletes"
174
+ ]
175
+ },
176
+ "descriptionType": {
177
+ "type": "string",
178
+ "enum": [
179
+ "Abstract",
180
+ "Methods",
181
+ "SeriesInformation",
182
+ "TableOfContents",
183
+ "TechnicalInfo",
184
+ "Other"
185
+ ]
186
+ },
187
+ "geoLocationPoint": {
188
+ "type": "object",
189
+ "properties": {
190
+ "pointLongitude": {"$ref": "#/definitions/longitude"},
191
+ "pointLatitude": {"$ref": "#/definitions/latitude"}
192
+ },
193
+ "required": ["pointLongitude", "pointLatitude"]
194
+ },
195
+ "longitude": {
196
+ "type": "number",
197
+ "minimum": -180,
198
+ "maximum": 180
199
+ },
200
+ "latitude": {
201
+ "type": "number",
202
+ "minimum": -90,
203
+ "maximum": 90
204
+ },
205
+ "funderIdentifierType": {
206
+ "type": "string",
207
+ "enum": [
208
+ "ISNI",
209
+ "GRID",
210
+ "Crossref Funder ID",
211
+ "Other"
212
+ ]
213
+ }
214
+ },
215
+
216
+ "type": "object",
217
+
218
+ "properties": {
219
+ "event": {
220
+ "type": "string",
221
+ "enum": ["publish", "register", "hide"]
222
+ },
223
+ "url": {
224
+ "type": "string"
225
+ },
226
+ "types": {
227
+ "type": "object",
228
+ "properties": {
229
+ "resourceType": {"type": "string"},
230
+ "resourceTypeGeneral": {"$ref": "#/definitions/resourceTypeGeneral"}
231
+ },
232
+ "required": ["resourceType", "resourceTypeGeneral"]
233
+ },
234
+ "identifiers": {
235
+ "type": "array",
236
+ "items":{
237
+ "type": "object",
238
+ "properties": {
239
+ "identifier": {"type": "string"},
240
+ "identifierType": {"type": "string"}
241
+ },
242
+ "required": ["identifier", "identifierType"]
243
+ },
244
+ "minItems": 1,
245
+ "uniqueItems": true
246
+ },
247
+ "creators": {
248
+ "type": "array",
249
+ "items": {
250
+ "type": "object",
251
+ "properties": {
252
+ "name": {"type": "string"},
253
+ "nameType": {"$ref": "#/definitions/nameType"},
254
+ "givenName": {"type": "string"},
255
+ "familyName": {"type": "string"},
256
+ "nameIdentifiers": {"$ref": "#/definitions/nameIdentifiers"},
257
+ "affiliations": {"$ref": "#/definitions/affiliations"},
258
+ "lang": {"type": "string"}
259
+ },
260
+ "required": ["name"]
261
+ },
262
+ "minItems": 1,
263
+ "uniqueItems": true
264
+ },
265
+ "titles": {
266
+ "type": "array",
267
+ "items": {
268
+ "type": "object",
269
+ "properties": {
270
+ "title": {"type": "string"},
271
+ "titleType": {"$ref": "#/definitions/titleType"},
272
+ "lang": {"type": "string"}
273
+ },
274
+ "required": ["title"]
275
+ },
276
+ "minItems": 1,
277
+ "uniqueItems": true
278
+ },
279
+ "publisher": {
280
+ "type": "string"
281
+ },
282
+ "publicationYear": {
283
+ "type": "string"
284
+ },
285
+ "subjects": {
286
+ "type": "array",
287
+ "items": {
288
+ "type": "object",
289
+ "properties": {
290
+ "subject": {"type": "string"},
291
+ "subjectScheme": {"type": "string"},
292
+ "schemeURI": {"type": "string", "format": "uri"},
293
+ "valueURI": {"type": "string", "format": "uri"},
294
+ "lang": {"type": "string"}
295
+ },
296
+ "required": ["subject"]
297
+ },
298
+ "uniqueItems": true
299
+ },
300
+ "contributors": {
301
+ "type": "array",
302
+ "items": {
303
+ "type": "object",
304
+ "properties": {
305
+ "contributorType": {"$ref": "#/definitions/contributorType"},
306
+ "name": {"type": "string"},
307
+ "nameType": {"$ref": "#/definitions/nameType"},
308
+ "givenName": {"type": "string"},
309
+ "familyName": {"type": "string"},
310
+ "nameIdentifiers": {"$ref": "#/definitions/nameIdentifiers"},
311
+ "affiliations": {"$ref": "#/definitions/affiliations"},
312
+ "lang": {"type": "string"}
313
+ },
314
+ "required": ["contributorType", "name"]
315
+ },
316
+ "uniqueItems": true
317
+ },
318
+ "dates": {
319
+ "type": "array",
320
+ "items": {
321
+ "type": "object",
322
+ "properties": {
323
+ "date": {"$ref": "#/definitions/date"},
324
+ "dateType": {"$ref": "#/definitions/dateType"},
325
+ "dateInformation": {"type": "string"}
326
+ },
327
+ "required": ["date", "dateType"]
328
+ },
329
+ "uniqueItems": true
330
+ },
331
+ "language": {
332
+ "type": "string",
333
+ "$comment": "Primary language of the resource. Allowed values are taken from IETF BCP 47, ISO 639-1 language codes."
334
+ },
335
+ "alternateIdentifiers": {
336
+ "type": "array",
337
+ "items": {
338
+ "type": "object",
339
+ "properties": {
340
+ "alternateIdentifier": {"type": "string"},
341
+ "alternateIdentifierType": {"type": "string"}
342
+ },
343
+ "required": ["alternateIdentifier", "alternateIdentifierType"]
344
+ },
345
+ "uniqueItems": true
346
+ },
347
+ "relatedIdentifiers": {
348
+ "type": "array",
349
+ "items": {
350
+ "type": "object",
351
+ "properties": {
352
+ "relatedIdentifier": {"type": "string"},
353
+ "relatedIdentifierType": {"$ref": "#/definitions/relatedIdentifierType"},
354
+ "relationType": {"$ref": "#/definitions/relationType"},
355
+ "relatedMetadataScheme": {"type": "string"},
356
+ "schemeURI": {"type": "string", "format": "uri"},
357
+ "schemeType": {"type": "string"},
358
+ "resourceTypeGeneral": {"$ref": "#/definitions/resourceTypeGeneral"}
359
+ },
360
+ "required": ["relatedIdentifier", "relatedIdentifierType", "relationType"],
361
+ "if": {
362
+ "properties": {
363
+ "relationType": {"enum": ["HasMetadata", "IsMetadataFor"]}
364
+ }
365
+ },
366
+ "else": {
367
+ "$comment": "these properties may only be used with relation types HasMetadata/IsMetadataFor",
368
+ "properties": {
369
+ "relatedMetadataScheme": false,
370
+ "schemeURI": false,
371
+ "schemeType": false
372
+ }
373
+ }
374
+ },
375
+ "uniqueItems": true
376
+ },
377
+ "sizes": {
378
+ "type": "array",
379
+ "items": {
380
+ "type": "string"
381
+ },
382
+ "uniqueItems": true
383
+ },
384
+ "formats": {
385
+ "type": "array",
386
+ "items": {
387
+ "type": "string"
388
+ },
389
+ "uniqueItems": true
390
+ },
391
+ "version": {
392
+ "type": "string"
393
+ },
394
+ "rightsList": {
395
+ "type": "array",
396
+ "items": {
397
+ "type": "object",
398
+ "properties": {
399
+ "rights": {"type": "string"},
400
+ "rightsURI": {"type": "string", "format": "uri"},
401
+ "rightsIdentifier": {"type": "string"},
402
+ "rightsIdentifierScheme": {"type": "string"},
403
+ "schemeURI": {"type": "string", "format": "uri"},
404
+ "lang": {"type": "string"}
405
+ }
406
+ },
407
+ "uniqueItems": true
408
+ },
409
+ "descriptions": {
410
+ "type": "array",
411
+ "items": {
412
+ "type": "object",
413
+ "properties": {
414
+ "description": {"type": "string"},
415
+ "descriptionType": {"$ref": "#/definitions/descriptionType"},
416
+ "lang": {"type": "string"}
417
+ },
418
+ "required": ["description", "descriptionType"]
419
+ },
420
+ "uniqueItems": true
421
+ },
422
+ "geoLocations": {
423
+ "type": "array",
424
+ "items": {
425
+ "type": "object",
426
+ "properties": {
427
+ "geoLocationPlace": {"type": "string"},
428
+ "geoLocationPoint": {"$ref": "#/definitions/geoLocationPoint"},
429
+ "geoLocationBox": {
430
+ "type": "object",
431
+ "properties": {
432
+ "westBoundLongitude": {"$ref": "#/definitions/longitude"},
433
+ "eastBoundLongitude": {"$ref": "#/definitions/longitude"},
434
+ "southBoundLatitude": {"$ref": "#/definitions/latitude"},
435
+ "northBoundLatitude": {"$ref": "#/definitions/latitude"}
436
+ },
437
+ "required": ["westBoundLongitude", "eastBoundLongitude", "southBoundLatitude", "northBoundLatitude"]
438
+ },
439
+ "geoLocationPolygons": {
440
+ "type": "array",
441
+ "items": {
442
+ "type": "object",
443
+ "properties": {
444
+ "polygonPoints": {
445
+ "type": "array",
446
+ "items": {"$ref": "#/definitions/geoLocationPoint"},
447
+ "minItems": 4
448
+ },
449
+ "inPolygonPoint": {"$ref": "#/definitions/geoLocationPoint"}
450
+ },
451
+ "required": ["polygonPoints"]
452
+ },
453
+ "uniqueItems": true
454
+ }
455
+ }
456
+ },
457
+ "uniqueItems": true
458
+ },
459
+ "fundingReferences": {
460
+ "type": "array",
461
+ "items": {
462
+ "type": "object",
463
+ "properties": {
464
+ "funderName": {"type": "string"},
465
+ "funderIdentifier": {"type": "string"},
466
+ "funderIdentifierType": {"$ref": "#/definitions/funderIdentifierType"},
467
+ "awardNumber": {"type": "string"},
468
+ "awardURI": {"type": "string", "format": "uri"},
469
+ "awardTitle": {"type": "string"}
470
+ },
471
+ "required": ["funderName"]
472
+ },
473
+ "uniqueItems": true
474
+ },
475
+ "schemaVersion": {
476
+ "type": "string",
477
+ "const": "http://datacite.org/schema/kernel-4"
478
+ }
479
+ },
480
+ "additionalProperties": false
481
+ }
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json_schema"
4
+
5
+ module Datacite
6
+ # Validates the request data is valid
7
+ class Validator
8
+ def self.validate!(data)
9
+ # Schema from https://github.com/datacite/schema/blob/master/source/json/kernel-4.3/datacite_4.3_schema.json
10
+ # with changes:
11
+ # 1. Remove invalid formats https://github.com/datacite/schema/issues/96
12
+ # 2. Remove required fields https://github.com/datacite/schema/issues/97
13
+ # 3. Added "additionalProperties": false
14
+
15
+ schema_data = JSON.parse(File.read("#{__dir__}/schema.json"))
16
+ schema = JsonSchema.parse!(schema_data)
17
+ schema.validate!(data)
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Datacite
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-08 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json_schema
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.21.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.21.0
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: zeitwerk
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -71,9 +99,12 @@ files:
71
99
  - bin/setup
72
100
  - datacite.gemspec
73
101
  - lib/datacite.rb
74
- - lib/datacite/autogenerate_doi.rb
102
+ - lib/datacite/autogenerate_doi_request_body.rb
75
103
  - lib/datacite/client.rb
104
+ - lib/datacite/register_doi_request_body.rb
76
105
  - lib/datacite/response.rb
106
+ - lib/datacite/schema.json
107
+ - lib/datacite/validator.rb
77
108
  - lib/datacite/version.rb
78
109
  homepage: https://github.com/sul-dlss/datacite-ruby
79
110
  licenses: []