Class: Dolibarr::Thirdparties
- Defined in:
- lib/dolibarr/thirdparties.rb
Overview
Thirdparties (customers/suppliers): list and fetch. Reads go through the raw
connection (type: nil) so the payload survives the transport's placeholder model.
Constant Summary collapse
- MODE_CODES =
Business-readable #list
modevalues → Dolibarr's integermodefilter. Dolibarr expects an integer (api_thirdparties.class.php@23.0.3): 1=customers, 2=prospects, 4=suppliers. Codes 0 (all) and 3 (neither customer nor prospect) have no business use here and are intentionally not exposed. Sending the raw label instead of the code makes Dolibarr answer HTTP 400. { 'customer' => 1, 'prospect' => 2, 'supplier' => 4 }.freeze
Instance Method Summary collapse
- #all(**filters) ⇒ Array<Thirdparty>
-
#each(limit: 100, **filters, &block) ⇒ Object
Every matching thirdparty, paginating transparently.
-
#find(id:) ⇒ Thirdparty
Fetch a single thirdparty by id.
-
#list(mode: nil, category: nil, sqlfilters: nil, limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC') ⇒ Array<Thirdparty>
One page of thirdparties as Thirdparty value objects.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Dolibarr::Resource
Instance Method Details
#all(**filters) ⇒ Array<Thirdparty>
42 43 44 |
# File 'lib/dolibarr/thirdparties.rb', line 42 def all(**filters) each(**filters).to_a end |
#each(limit: 100, **filters, &block) ⇒ Object
Every matching thirdparty, paginating transparently. Enumerator when no block.
36 37 38 39 |
# File 'lib/dolibarr/thirdparties.rb', line 36 def each(limit: 100, **filters, &block) enum = paginate(limit: limit) { |page, lim| list(page: page, limit: lim, **filters) } block ? enum.each(&block) : enum end |
#find(id:) ⇒ Thirdparty
Fetch a single thirdparty by id.
51 52 53 |
# File 'lib/dolibarr/thirdparties.rb', line 51 def find(id:) Thirdparty.from(get_one("/thirdparties/#{encode(id)}", "thirdparty #{id}")) end |
#list(mode: nil, category: nil, sqlfilters: nil, limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC') ⇒ Array<Thirdparty>
One page of thirdparties as Dolibarr::Thirdparty value objects.
25 26 27 28 29 30 31 32 33 |
# File 'lib/dolibarr/thirdparties.rb', line 25 def list(mode: nil, category: nil, sqlfilters: nil, limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC') get_list( '/thirdparties', 'sortfield' => sortfield, 'sortorder' => sortorder, 'limit' => limit, 'page' => page, 'mode' => mode_code(mode), 'category' => category, 'sqlfilters' => sqlfilters ).map { |raw| Thirdparty.from(raw) } end |