Class: Wfirma::Client
- Inherits:
-
Object
- Object
- Wfirma::Client
- Defined in:
- lib/wfirma/client.rb
Overview
Public entry point.
# Production:
client = Wfirma::Client.new(access_key: "...", secret_key: "...",
app_key: "...", company_id: 123)
# Or, with Wfirma.configure having named them once:
client = Wfirma::Client.new
client = Wfirma::Client.new(company_id: 456) # a second company
# Development (no HTTP, no keys):
client = Wfirma::Client.new(driver: Wfirma::Drivers::Fake.new)
contractor = client.contractors.upsert(name: "ACME", nip: "…", …)
result = client.invoices.create({ contractor_id: contractor.record_id, … },
draft: true)
pdf = client.invoices.pdf(result.invoice_id)
client.invoices.send_email(result.invoice_id, email: "buyer@example.com")
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
- #call(module_name, action, payload, params = {}, id = nil) ⇒ Object
- #contractors ⇒ Object
-
#download(module_name, action, payload, params = {}, id = nil) ⇒ Object
Binary actions (invoices/download); returns raw file bytes.
-
#initialize(access_key: nil, secret_key: nil, app_key: nil, company_id: nil, base_url: nil, open_timeout: nil, read_timeout: nil, driver: nil) ⇒ Client
constructor
Anything passed here wins over Wfirma.configure; anything left out falls back to it, and then to the driver's own defaults.
- #invoices ⇒ Object
Constructor Details
#initialize(access_key: nil, secret_key: nil, app_key: nil, company_id: nil, base_url: nil, open_timeout: nil, read_timeout: nil, driver: nil) ⇒ Client
Anything passed here wins over Wfirma.configure; anything left out falls back to it, and then to the driver's own defaults. An injected driver is used as-is and reads no configuration at all.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wfirma/client.rb', line 26 def initialize(access_key: nil, secret_key: nil, app_key: nil, company_id: nil, base_url: nil, open_timeout: nil, read_timeout: nil, driver: nil) given = { access_key: access_key, secret_key: secret_key, app_key: app_key, company_id: company_id, base_url: base_url, open_timeout: open_timeout, read_timeout: read_timeout }.compact @driver = driver || Drivers::Http.new(**Wfirma.config.to_h.merge(given)) end |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
21 22 23 |
# File 'lib/wfirma/client.rb', line 21 def driver @driver end |
Instance Method Details
#call(module_name, action, payload, params = {}, id = nil) ⇒ Object
37 38 39 |
# File 'lib/wfirma/client.rb', line 37 def call(module_name, action, payload, params = {}, id = nil) driver.call(module_name, action, payload, params, id) end |
#contractors ⇒ Object
50 51 52 |
# File 'lib/wfirma/client.rb', line 50 def contractors @contractors ||= Contractors.new(self) end |
#download(module_name, action, payload, params = {}, id = nil) ⇒ Object
Binary actions (invoices/download); returns raw file bytes.
42 43 44 |
# File 'lib/wfirma/client.rb', line 42 def download(module_name, action, payload, params = {}, id = nil) driver.download(module_name, action, payload, params, id) end |