Class: Ledger::Sdk::Models::Import

Inherits:
Base
  • Object
show all
Defined in:
lib/ledger/sdk/models/import.rb

Overview

Represents the collection of imports from the Ledger API.

Imports are the SDK's only write path into positions and movements: the Ledger REST routes for both are +index+/+show+ only, so every line that reaches the ledger goes through POST /imports. The import also creates the container and the accounts it names, on first sight, by natural key — there is no separate "create a container" call to make.

Processing is asynchronous: a fresh import comes back pending and the returned data carries the counts (+total_count+, imported_count, failure_count), the status and the lines, each with its own error once processed.

Examples:

Push lines and read the outcome

import = Ledger::Sdk.Import.create(filename: 'model-resilience.json', positions: [position])
import.data['status']        # => 'pending'
Ledger::Sdk.Import(import.data['id']).data['failure_count']

Inspect and replay a single failed line

line = Ledger::Sdk.Import(42).lines(7)
line.data['error_details']
line.retry

Defined Under Namespace

Classes: Instance

Instance Method Summary collapse

Methods inherited from Base

#initialize, #list

Constructor Details

This class inherits a constructor from Ledger::Sdk::Models::Base

Instance Method Details

#create(filename:, positions: [], movements: [], provider_id: nil) ⇒ Instance

Creates an import from position and/or movement lines.

The body is posted FLAT — unlike Fee#create, which wraps its attributes under a fee key. Ledger's ImportsController reads params[:filename], params[:positions] and params[:movements] at the top level: wrapping them would post an import with no lines at all, answered by a 422 no_lines_provided.

The line shapes are not validated here: Ledger's own JSON schema is the gate, and a second copy of it in the SDK would drift from it. Sending two empty lists yields a 422 no_lines_provided.

Parameters:

  • filename (String)

    a name identifying the batch, used to find the import later

  • positions (Array<Hash>) (defaults to: [])

    position lines

  • movements (Array<Hash>) (defaults to: [])

    movement lines

  • provider_id (Integer, nil) (defaults to: nil)

    the producer's Mosaic id, stored as mosaic_id. Optional and omitted from the payload when absent: Ledger already records the calling gateway client on every import.

Returns:

  • (Instance)

    the created import, carrying the API response