Class: Dolibarr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dolibarr/client.rb,
lib/dolibarr/client/error.rb,
lib/dolibarr/client/forbidden.rb,
lib/dolibarr/client/not_found.rb

Overview

Note:

Business domains (invoices, payments, thirdparties, documents, supplier invoices) are layered on top of the dolibarr-api transport. They are wired in once that dependency lands; this class currently owns configuration and the single error surface (Error).

The business-facing Dolibarr client. One instance targets one Dolibarr instance; there is no global singleton, so several may coexist.

Configuration is read from the environment by default — DOLIBARR_BASE_URL and DOLAPIKEY — and may be overridden per instance.

Examples:

dolibarr = Dolibarr::Client.new                       # from ENV
dolibarr = Dolibarr::Client.new(                      # explicit
  base_url: "https://erp.example.com/api/index.php",
  token:    "xxxxxxxx",
)

Defined Under Namespace

Classes: Error, Forbidden, NotFound

Constant Summary collapse

ENV_BASE_URL =

Environment variable holding the Dolibarr API base URL (e.g. https://erp.example.com/api/index.php).

'DOLIBARR_BASE_URL'
ENV_TOKEN =

Environment variable holding the Dolibarr API key (sent as the DOLAPIKEY header).

'DOLAPIKEY'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: ENV.fetch(ENV_BASE_URL, nil), token: ENV.fetch(ENV_TOKEN, nil)) ⇒ Client

Returns a new instance of Client.

Parameters:

  • base_url (String) (defaults to: ENV.fetch(ENV_BASE_URL, nil))

    Dolibarr API base URL; defaults to ENV

  • token (String) (defaults to: ENV.fetch(ENV_TOKEN, nil))

    Dolibarr API key; defaults to ENV

Raises:



35
36
37
38
# File 'lib/dolibarr/client.rb', line 35

def initialize(base_url: ENV.fetch(ENV_BASE_URL, nil), token: ENV.fetch(ENV_TOKEN, nil))
  @base_url = require_config!(base_url, ENV_BASE_URL)
  @token    = require_config!(token, ENV_TOKEN)
end

Instance Attribute Details

#base_urlString (readonly)

Returns the Dolibarr API base URL.

Returns:

  • (String)

    the Dolibarr API base URL



30
31
32
# File 'lib/dolibarr/client.rb', line 30

def base_url
  @base_url
end

Instance Method Details

#connectionDolibarr::Api::Connection

The raw transport connection — the single HTTP choke-point domains call through (with type: nil) to sidestep the transport's placeholder typed models.

Returns:

  • (Dolibarr::Api::Connection)


53
54
55
# File 'lib/dolibarr/client.rb', line 53

def connection
  transport.connection
end

#documentsDolibarr::Documents

Returns documents domain.

Returns:



73
74
75
# File 'lib/dolibarr/client.rb', line 73

def documents
  @documents ||= Documents.new(self)
end

#invoicesDolibarr::Invoices

Returns customer invoices domain.

Returns:



58
59
60
# File 'lib/dolibarr/client.rb', line 58

def invoices
  @invoices ||= Invoices.new(self)
end

#paymentsDolibarr::Payments

Returns payments domain.

Returns:



63
64
65
# File 'lib/dolibarr/client.rb', line 63

def payments
  @payments ||= Payments.new(self)
end

#recurring_invoicesDolibarr::RecurringInvoices

Returns recurring/template invoices domain (read-only: Dolibarr 23.0.3 exposes no write endpoint for templates).

Returns:

  • (Dolibarr::RecurringInvoices)

    recurring/template invoices domain (read-only: Dolibarr 23.0.3 exposes no write endpoint for templates).



84
85
86
# File 'lib/dolibarr/client.rb', line 84

def recurring_invoices
  @recurring_invoices ||= RecurringInvoices.new(self)
end

#supplier_invoicesDolibarr::SupplierInvoices

Returns supplier invoices domain (read-only).

Returns:



78
79
80
# File 'lib/dolibarr/client.rb', line 78

def supplier_invoices
  @supplier_invoices ||= SupplierInvoices.new(self)
end

#thirdpartiesDolibarr::Thirdparties

Returns thirdparties domain.

Returns:



68
69
70
# File 'lib/dolibarr/client.rb', line 68

def thirdparties
  @thirdparties ||= Thirdparties.new(self)
end

#transportDolibarr::Api::Client

The underlying dolibarr-api transport client. Lazily built and memoised, one per instance (no global state). The token is handed to the transport as api_key (the auth scheme the spec declares).

Returns:

  • (Dolibarr::Api::Client)


45
46
47
# File 'lib/dolibarr/client.rb', line 45

def transport
  @transport ||= Dolibarr::Api::Client.new(base_url: @base_url, api_key: @token)
end