Class: HTTPClients::AccessioningV1Client

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/http_clients/accessioning_v1_client.rb

Overview

Submits records to EBI for accessioning using v1 of their accessioning API.

Usage: “`rb client = HTTPClients::AccessioningClient.new accession_number = client.submit_and_fetch_accession_number(submission) ““

API documentation: ena-docs.readthedocs.io/en/latest/submit/general-guide/webin-v1.html

Instance Method Summary collapse

Instance Method Details

#connObject



14
15
16
17
18
19
20
# File 'lib/http_clients/accessioning_v1_client.rb', line 14

def conn
  url = configatron.accession.url
  @conn ||= Faraday.new(url:, headers:, proxy:) do |f|
    f.request :multipart
    f.request :url_encoded
  end
end

#submit_and_fetch_accession_number(login, files) ⇒ String

Post the submission to the appropriate accessioning service. It will open the payload of the submission and make sure that the payload is closed afterwards.

Parameters:

  • login (Hash{Symbol => String})

    A hash with :username and :password for basic auth.

  • files (Hash{String => File})

    A hash mapping of file type names to open File objects. The filename in the multipart payload will be the part of the file object's name after the first underscore.

Returns:

  • (String)

    The allocated accession number if successful.

Raises:



31
32
33
34
35
36
37
38
39
40
# File 'lib/http_clients/accessioning_v1_client.rb', line 31

def submit_and_fetch_accession_number(, files)
  # Clone the base connection and add basic auth for this request
  conn_with_auth = conn.dup
  conn_with_auth.request :authorization, :basic, [:user], [:password]

  payload = build_payload(files)
  response = conn_with_auth.post('', payload) # POST to the given API root with the payload as the body
  raise_if_failed(response)
  extract_accession_number(response.body)
end