Module: Smartbill::Sdk::Services
- Defined in:
- lib/smartbill/sdk/services.rb,
lib/smartbill/sdk/services/base_service.rb,
lib/smartbill/sdk/services/email_service.rb,
lib/smartbill/sdk/services/stocks_service.rb,
lib/smartbill/sdk/services/invoices_service.rb,
lib/smartbill/sdk/services/payments_service.rb,
lib/smartbill/sdk/services/estimates_service.rb,
lib/smartbill/sdk/services/configuration_service.rb
Overview
Per-resource endpoint logic.
Each service builds a Transport::Request for an endpoint and parses the response into a model. Services are instantiated by Client with a reference to the client (the “executor”) which provides base_url, auth_header and #execute.
Each service lives in its own file (e.g. ‘services/invoices_service.rb` defines `InvoicesService`) and is autoloaded by Zeitwerk.
Defined Under Namespace
Classes: BaseService, ConfigurationService, EmailService, EstimatesService, InvoicesService, PaymentsService, StocksService
Class Method Summary collapse
-
.dump_model(model, envelope_key: nil) ⇒ Object
Serialize a model, optionally wrapping it in an envelope.
-
.parse(payload, model_class) ⇒ Object
Parse a payload into a model instance.
Class Method Details
.dump_model(model, envelope_key: nil) ⇒ Object
Serialize a model, optionally wrapping it in an envelope.
16 17 18 19 |
# File 'lib/smartbill/sdk/services.rb', line 16 def self.dump_model(model, envelope_key: nil) data = model.to_h envelope_key ? { envelope_key => data } : data end |
.parse(payload, model_class) ⇒ Object
Parse a payload into a model instance.
22 23 24 25 26 27 |
# File 'lib/smartbill/sdk/services.rb', line 22 def self.parse(payload, model_class) return model_class.new if payload.nil? return model_class.new(payload) if payload.is_a?(Hash) model_class.new(message: payload.to_s) end |