Class: Accession::Request
- Inherits:
-
Object
- Object
- Accession::Request
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/accession/accession/request.rb
Overview
Does what is says on the tin. Accepts an Accession::Submission and creates a resource based on the service submission. The resource will be a RestClient::Resource which will relate to the specified accessioning service.
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#submission ⇒ Object
readonly
Returns the value of attribute submission.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(submission) ⇒ Request
constructor
A new instance of Request.
-
#post ⇒ Object
Post the submission to the appropriate accessioning service It will open the payload of the submission.
Constructor Details
#initialize(submission) ⇒ Request
Returns a new instance of Request.
22 23 24 25 26 27 28 29 |
# File 'lib/accession/accession/request.rb', line 22 def initialize(submission) @submission = submission if valid? @resource = rest_client.new(submission.service.url, submission.service.login) set_proxy end end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
11 12 13 |
# File 'lib/accession/accession/request.rb', line 11 def resource @resource end |
#submission ⇒ Object (readonly)
Returns the value of attribute submission.
11 12 13 |
# File 'lib/accession/accession/request.rb', line 11 def submission @submission end |
Class Method Details
.post(submission) ⇒ Object
18 19 20 |
# File 'lib/accession/accession/request.rb', line 18 def self.post(submission) new(submission).post end |
Instance Method Details
#post ⇒ Object
Post the submission to the appropriate accessioning service It will open the payload of the submission. If the service errors it will return a NullResponse Makes sure that the payload is closed.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/accession/accession/request.rb', line 35 def post if valid? begin Accession::Response.new(resource.post(submission.payload.open)) rescue StandardError => e Rails.logger.error(e.) Accession::NullResponse.new ensure submission.payload.close! end end end |