Class: Nordlet::Migration::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nordlet/migration/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/nordlet/migration/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#check_a_historical_books_package_without_writing_anything(request_options: {}, **params) ⇒ Nordlet::Migration::Types::PostV1MigrationBooksValidateResponse

Runs every check the import runs (accounts, partners, balances, open invoices, assets, stock) and returns the same summary and warnings, then rolls everything back. Nothing is stored.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nordlet/migration/client.rb', line 25

def check_a_historical_books_package_without_writing_anything(request_options: {}, **params)
  params = Nordlet::Internal::Types::Utils.normalize_keys(params)
  request = Nordlet::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/migration/books/validate",
    body: Nordlet::Migration::Types::PostV1MigrationBooksValidateRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Nordlet::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Nordlet::Migration::Types::PostV1MigrationBooksValidateResponse.load(response.body)
  else
    error_class = Nordlet::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#import_historical_books_from_a_previous_accounting_system(request_options: {}, **params) ⇒ Nordlet::Migration::Types::PostV1MigrationBooksImportResponse

Brings a company over from another system in one call: chart of accounts, partners, items, opening balances (or the full journal history), open customer and supplier invoices, fixed assets with their accumulated depreciation, and stock on hand. The whole package is written in one database transaction — if any row fails, nothing is stored.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/nordlet/migration/client.rb', line 62

def import_historical_books_from_a_previous_accounting_system(request_options: {}, **params)
  params = Nordlet::Internal::Types::Utils.normalize_keys(params)
  request = Nordlet::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/migration/books/import",
    body: Nordlet::Migration::Types::PostV1MigrationBooksImportRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Nordlet::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Nordlet::Migration::Types::PostV1MigrationBooksImportResponse.load(response.body)
  else
    error_class = Nordlet::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end