Class: FolioClient::DataImport
- Inherits:
-
Object
- Object
- FolioClient::DataImport
- Defined in:
- lib/folio_client/data_import.rb
Overview
Imports MARC records into FOLIO
Constant Summary collapse
- JOB_PROFILE_ATTRIBUTES =
%w[id name description dataType].freeze
Instance Method Summary collapse
-
#import(records:, job_profile_id:, job_profile_name:) ⇒ JobStatus
A job status instance to get information about the data import job.
-
#initialize(client) ⇒ DataImport
constructor
A new instance of DataImport.
-
#job_profiles ⇒ Array<Hash<String,String>>
A list of job profile hashes.
Constructor Details
#initialize(client) ⇒ DataImport
Returns a new instance of DataImport.
12 13 14 |
# File 'lib/folio_client/data_import.rb', line 12 def initialize(client) @client = client end |
Instance Method Details
#import(records:, job_profile_id:, job_profile_name:) ⇒ JobStatus
Returns a job status instance to get information about the data import job.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/folio_client/data_import.rb', line 20 def import(records:, job_profile_id:, job_profile_name:) response_hash = client.post("/data-import/uploadDefinitions", {fileDefinitions: [{name: marc_filename}]}) upload_definition_id = response_hash.dig("fileDefinitions", 0, "uploadDefinitionId") job_execution_id = response_hash.dig("fileDefinitions", 0, "jobExecutionId") file_definition_id = response_hash.dig("fileDefinitions", 0, "id") upload_file_response_hash = client.post( "/data-import/uploadDefinitions/#{upload_definition_id}/files/#{file_definition_id}", marc_binary(records), content_type: "application/octet-stream" ) client.post( "/data-import/uploadDefinitions/#{upload_definition_id}/processFiles", { uploadDefinition: upload_file_response_hash, jobProfileInfo: { id: job_profile_id, name: job_profile_name, dataType: "MARC" } } ) JobStatus.new(client, job_execution_id: job_execution_id) end |
#job_profiles ⇒ Array<Hash<String,String>>
Returns a list of job profile hashes.
48 49 50 51 52 53 |
# File 'lib/folio_client/data_import.rb', line 48 def job_profiles client .get("/data-import-profiles/jobProfiles") .fetch("jobProfiles", []) .map { |profile| profile.slice(*JOB_PROFILE_ATTRIBUTES) } end |