Class: Accession::Request

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(submission) ⇒ Request


21
22
23
24
25
26
27
28
# File 'lib/accession/accession/request.rb', line 21

def initialize(submission)
  @submission = submission

  if valid?
    @resource = rest_client.new(submission.service.url, submission.service.)
    set_proxy
  end
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource


10
11
12
# File 'lib/accession/accession/request.rb', line 10

def resource
  @resource
end

#submissionObject (readonly)

Returns the value of attribute submission


10
11
12
# File 'lib/accession/accession/request.rb', line 10

def submission
  @submission
end

Class Method Details

.post(submission) ⇒ Object


17
18
19
# File 'lib/accession/accession/request.rb', line 17

def self.post(submission)
  new(submission).post
end

Instance Method Details

#postObject

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.


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/accession/accession/request.rb', line 34

def post
  if valid?
    begin
      Accession::Response.new(resource.post(submission.payload.open))
    rescue StandardError => e
      Accession::NullResponse.new
    ensure
      submission.payload.close!
    end
  end
end