Class: Datacite::Client
- Inherits:
-
Object
- Object
- Datacite::Client
- Defined in:
- lib/datacite/client.rb
Overview
The connection to DataCite API
Instance Method Summary collapse
-
#autogenerate_doi(prefix:) ⇒ Object
Creates a random DOI.
-
#initialize(username:, password:, host: "api.test.datacite.org") ⇒ Client
constructor
A new instance of Client.
-
#register_doi(prefix:, suffix:) ⇒ Object
Creates a specific DOI.
-
#update(id:, attributes:) ⇒ Object
Update a DOI.
Constructor Details
#initialize(username:, password:, host: "api.test.datacite.org") ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/datacite/client.rb', line 15 def initialize(username:, password:, host: "api.test.datacite.org") @conn = Faraday.new( url: "https://#{host}", headers: headers ) do |conn| conn.request :json conn.request :authorization, :basic, username, password conn.response :json end end |
Instance Method Details
#autogenerate_doi(prefix:) ⇒ Object
Creates a random DOI
29 30 31 32 |
# File 'lib/datacite/client.rb', line 29 def autogenerate_doi(prefix:) request_body = AutogenerateDoiRequestBody.new(prefix: prefix).to_json register(request_body) end |
#register_doi(prefix:, suffix:) ⇒ Object
Creates a specific DOI
38 39 40 41 |
# File 'lib/datacite/client.rb', line 38 def register_doi(prefix:, suffix:) request_body = RegisterDoiRequestBody.new(prefix: prefix, suffix: suffix).to_json register(request_body) end |
#update(id:, attributes:) ⇒ Object
Update a DOI
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/datacite/client.rb', line 47 def update(id:, attributes:) Validator.validate!(attributes) request_body = { data: { attributes: attributes } } response = conn.put("/dois/#{id}", request_body.to_json) response.success? ? Success(Response.new(response)) : Failure(response) end |