Class: Scholarsphere::Client::Ingest
- Inherits:
-
Object
- Object
- Scholarsphere::Client::Ingest
- Defined in:
- lib/scholarsphere/client/ingest.rb
Overview
Uploads a complete work into Scholarsphere. If successful, the work will be published and made publicly available.
Publishing a New Work
The most common use case is uploading a single file with the required metadata:
ingest = Scholarsphere::Client::Ingest.new(
metadata: ,
files: files,
depositor: 'abc123'
)
response = ingest.create
If the response is successful, the application returns 200 OK with JSON:
puts response.body
{
"message": "Work was successfully created",
"url": "/resources/0797e99c-7d4f-4e05-8bf6-86aea1029a6a"
}
Creating a new draft
A Work can also be created without publishing it by passing a 'false' parameter.
ingest = Scholarsphere::Client::Ingest.new(
metadata: ,
files: files,
depositor: 'abc123',
publish: false
)
response = ingest.create
If the response is successful, it will return a 201 Created with JSON: puts response.body { "message": "Work was successfully created", "url": "/resources/0797e99c-7d4f-4e05-8bf6-86aea1029a6a", "edit_url": "/dashboard/form/work_versions/8/files" }
Other possible outcomes include:
- work could not be created due to insufficient parameters (422 Unprocessable Entity)
- there was an error with the application (500 Internal Server Error)
If possible, the response will include additional information about which errors occurred and which attributes are required or are incorrect.
Metadata
A hash of descriptive metadata about the work. The minimal amount required in order to publish would be:
{
title: "[descriptive title of the work]",
creators_attributes: [
{
display_name: '[Penn State Person]',
actor_attributes: {
psu_id: 'abc123',
surname: '[family name]',
given_name: '[given name]',
email: 'abc123@psu.edu'
}
}
]
}
For a complete listing of all the possible metadata values, see the OpenAPI docs for Scholarsphere.
Files
[
Pathname.new('MyPaper.pdf'),
Pathname.new('dataset.dat')
]
One or more files are required in order for the work be published. The simplest method is an array of IO
objects. The client then uploads them into S3.
Note: All filenames must have an extension!
Depositor
The depositor is identified by their Penn State access id, which must be active at the time of ingest. In most cases, the depositor will be the same person as the creator specified in the metadata; although, this is not always the case. The depositor may be someone who is uploading on behalf of the creator and is not affiliated with the creation of the work. The depositor is not the client itself, either. The client is identified separately via the API token.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#depositor ⇒ Object
readonly
Returns the value of attribute depositor.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#publish ⇒ Object
readonly
Returns the value of attribute publish.
Instance Method Summary collapse
-
#create ⇒ Faraday::Response
The response from the Scholarsphere application.
-
#initialize(metadata:, files:, depositor:, permissions: {}, publish: true) ⇒ Ingest
constructor
A new instance of Ingest.
Constructor Details
#initialize(metadata:, files:, depositor:, permissions: {}, publish: true) ⇒ Ingest
Returns a new instance of Ingest.
106 107 108 109 110 111 112 |
# File 'lib/scholarsphere/client/ingest.rb', line 106 def initialize(metadata:, files:, depositor:, permissions: {}, publish: true) @content = build_content_hash(files) @metadata = @depositor = depositor @permissions = @publish = publish end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
99 100 101 |
# File 'lib/scholarsphere/client/ingest.rb', line 99 def content @content end |
#depositor ⇒ Object (readonly)
Returns the value of attribute depositor.
99 100 101 |
# File 'lib/scholarsphere/client/ingest.rb', line 99 def depositor @depositor end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
99 100 101 |
# File 'lib/scholarsphere/client/ingest.rb', line 99 def @metadata end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
99 100 101 |
# File 'lib/scholarsphere/client/ingest.rb', line 99 def @permissions end |
#publish ⇒ Object (readonly)
Returns the value of attribute publish.
99 100 101 |
# File 'lib/scholarsphere/client/ingest.rb', line 99 def publish @publish end |
Instance Method Details
#create ⇒ Faraday::Response
Returns The response from the Scholarsphere application.
115 116 117 118 119 120 121 122 |
# File 'lib/scholarsphere/client/ingest.rb', line 115 def create upload_files connection.post do |req| req.url 'ingest' req.body = { metadata: , content: content, depositor: depositor, permissions: , publish: publish }.to_json end end |