Class: Dolibarr::Client
- Inherits:
-
Object
- Object
- Dolibarr::Client
- Defined in:
- lib/dolibarr/client.rb,
lib/dolibarr/client/error.rb,
lib/dolibarr/client/forbidden.rb,
lib/dolibarr/client/not_found.rb
Overview
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.
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
DOLAPIKEYheader). 'DOLAPIKEY'
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
The Dolibarr API base URL.
Instance Method Summary collapse
-
#connection ⇒ Dolibarr::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. -
#documents ⇒ Dolibarr::Documents
Documents domain.
-
#initialize(base_url: ENV.fetch(ENV_BASE_URL, nil), token: ENV.fetch(ENV_TOKEN, nil)) ⇒ Client
constructor
A new instance of Client.
-
#invoices ⇒ Dolibarr::Invoices
Customer invoices domain.
-
#payments ⇒ Dolibarr::Payments
Payments domain.
-
#recurring_invoices ⇒ Dolibarr::RecurringInvoices
Recurring/template invoices domain (read-only: Dolibarr 23.0.3 exposes no write endpoint for templates).
-
#supplier_invoices ⇒ Dolibarr::SupplierInvoices
Supplier invoices domain (read-only).
-
#thirdparties ⇒ Dolibarr::Thirdparties
Thirdparties domain.
-
#transport ⇒ Dolibarr::Api::Client
The underlying dolibarr-api transport client.
Constructor Details
#initialize(base_url: ENV.fetch(ENV_BASE_URL, nil), token: ENV.fetch(ENV_TOKEN, nil)) ⇒ Client
Returns a new instance of Client.
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_url ⇒ String (readonly)
Returns the Dolibarr API base URL.
30 31 32 |
# File 'lib/dolibarr/client.rb', line 30 def base_url @base_url end |
Instance Method Details
#connection ⇒ Dolibarr::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.
53 54 55 |
# File 'lib/dolibarr/client.rb', line 53 def connection transport.connection end |
#documents ⇒ Dolibarr::Documents
Returns documents domain.
73 74 75 |
# File 'lib/dolibarr/client.rb', line 73 def documents @documents ||= Documents.new(self) end |
#invoices ⇒ Dolibarr::Invoices
Returns customer invoices domain.
58 59 60 |
# File 'lib/dolibarr/client.rb', line 58 def invoices @invoices ||= Invoices.new(self) end |
#payments ⇒ Dolibarr::Payments
Returns payments domain.
63 64 65 |
# File 'lib/dolibarr/client.rb', line 63 def payments @payments ||= Payments.new(self) end |
#recurring_invoices ⇒ Dolibarr::RecurringInvoices
Returns 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_invoices ⇒ Dolibarr::SupplierInvoices
Returns supplier invoices domain (read-only).
78 79 80 |
# File 'lib/dolibarr/client.rb', line 78 def supplier_invoices @supplier_invoices ||= SupplierInvoices.new(self) end |
#thirdparties ⇒ Dolibarr::Thirdparties
Returns thirdparties domain.
68 69 70 |
# File 'lib/dolibarr/client.rb', line 68 def thirdparties @thirdparties ||= Thirdparties.new(self) end |
#transport ⇒ Dolibarr::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).
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 |