Class: Spree::DeliveryRateProvider::ServiceCatalog
- Inherits:
-
Object
- Object
- Spree::DeliveryRateProvider::ServiceCatalog
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- app/models/spree/delivery_rate_provider/service_catalog.rb
Overview
The answer to "which carrier services can this store offer?", as the admin service picker needs it: either the services themselves, or the reason the provider could not list them.
Providers fetch live where their API allows it. When it does not — an unconnected integration, a credential tier that forbids the listing endpoint, a carrier outage — they return ServiceCatalog.unavailable with the seller's own message, and the picker explains the situation instead of showing a silently empty or invented list.
Class Method Summary collapse
- .listing(services) ⇒ ServiceCatalog
-
.none ⇒ ServiceCatalog
A provider that lists no services at all — the merchant enters carrier/service identifiers free-form and every quoted rate is offered.
- .unavailable(message) ⇒ ServiceCatalog
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#error_message ⇒ String?
Why the services could not be listed.
-
#services ⇒ Array<Hash>
[{ carrier:, service:, label: }].
Class Method Details
.listing(services) ⇒ ServiceCatalog
32 33 34 |
# File 'app/models/spree/delivery_rate_provider/service_catalog.rb', line 32 def self.listing(services) new(services: Array(services)) end |
.none ⇒ ServiceCatalog
A provider that lists no services at all — the merchant enters carrier/service identifiers free-form and every quoted rate is offered. Not an error state.
26 27 28 |
# File 'app/models/spree/delivery_rate_provider/service_catalog.rb', line 26 def self.none new end |
.unavailable(message) ⇒ ServiceCatalog
38 39 40 |
# File 'app/models/spree/delivery_rate_provider/service_catalog.rb', line 38 def self.unavailable() new(error_message: ) end |
Instance Method Details
#available? ⇒ Boolean
43 44 45 |
# File 'app/models/spree/delivery_rate_provider/service_catalog.rb', line 43 def available? .blank? end |
#error_message ⇒ String?
Returns why the services could not be listed.
19 |
# File 'app/models/spree/delivery_rate_provider/service_catalog.rb', line 19 attribute :error_message, :string |
#services ⇒ Array<Hash>
Returns [{ carrier:, service:, label: }].
17 |
# File 'app/models/spree/delivery_rate_provider/service_catalog.rb', line 17 attribute :services, default: -> { [] } |