Class: Spree::AgentTools::GetImportStatus

Inherits:
ImportTool show all
Defined in:
app/tools/spree/agent_tools/get_import_status.rb

Overview

Where an import has got to, and what went wrong with it.

A merchant who uploaded a file wants one of two answers: is it done, or why did those rows fail? Both are tedious to assemble from the imports page and easy to say in a sentence.

Constant Summary collapse

SCANNED_ROW_LIMIT =

How many failed rows are read to work out why they failed.

200
FAILED_ROW_SAMPLE =
5

Constants inherited from Spree::AgentTool

Spree::AgentTool::PARENT_ID_DESCRIPTION

Instance Attribute Summary

Attributes inherited from Spree::AgentTool

#context

Instance Method Summary collapse

Methods inherited from Spree::AgentTool

additive!, audience, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #permitted?, tool_name, #unknown_resource

Constructor Details

This class inherits a constructor from Spree::AgentTool

Instance Method Details

#call(id: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/tools/spree/agent_tools/get_import_status.rb', line 23

def call(id: nil)
  import = find_import(id)
  return { error: 'No import found.' } if import.nil?

  refusal = unauthorized_import(import)
  return refusal if refusal

  {
    id: import.prefixed_id,
    number: import.number,
    type: import_kind(import),
    status: import.status,
    rows: import.rows_status_counts,
    # The reasons, not the rows: a merchant fixes a spreadsheet by
    # learning "12 rows have no SKU", not by reading 12 rows back.
    #
    failure_reasons: failure_reasons(import)
  }.compact
end

#summary(arguments) ⇒ Object



43
44
45
# File 'app/tools/spree/agent_tools/get_import_status.rb', line 43

def summary(arguments)
  arguments[:id].present? ? "Check import #{arguments[:id]}" : 'Check the latest import'
end