Class: ZeroClick::Sellers::UsageItem
- Inherits:
-
Object
- Object
- ZeroClick::Sellers::UsageItem
- Defined in:
- lib/zeroclick/sellers/contracts.rb
Overview
What a request will be charged for.
Exactly one of quantity or max_quantity, or neither to defer to the
meter's configured per-request ceiling. Declaring both is meaningless.
Instance Attribute Summary collapse
-
#max_quantity ⇒ Object
readonly
Returns the value of attribute max_quantity.
-
#meter_slug ⇒ Object
readonly
Returns the value of attribute meter_slug.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
Instance Method Summary collapse
-
#initialize(meter_slug:, quantity: nil, max_quantity: nil) ⇒ UsageItem
constructor
A new instance of UsageItem.
- #to_wire ⇒ Object
Constructor Details
#initialize(meter_slug:, quantity: nil, max_quantity: nil) ⇒ UsageItem
Returns a new instance of UsageItem.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/zeroclick/sellers/contracts.rb', line 169 def initialize(meter_slug:, quantity: nil, max_quantity: nil) Sellers.require_slug!(meter_slug, "meter_slug", "UsageItem") if !quantity.nil? && !max_quantity.nil? raise Error.new("malformed_input", operation: "UsageItem", message: "Provide at most one of quantity or max_quantity", meter_slug: meter_slug) end Sellers.require_positive_integer!(quantity, "quantity", "UsageItem") unless quantity.nil? Sellers.require_positive_integer!(max_quantity, "max_quantity", "UsageItem") unless max_quantity.nil? @meter_slug = meter_slug @quantity = quantity @max_quantity = max_quantity freeze end |
Instance Attribute Details
#max_quantity ⇒ Object (readonly)
Returns the value of attribute max_quantity.
167 168 169 |
# File 'lib/zeroclick/sellers/contracts.rb', line 167 def max_quantity @max_quantity end |
#meter_slug ⇒ Object (readonly)
Returns the value of attribute meter_slug.
167 168 169 |
# File 'lib/zeroclick/sellers/contracts.rb', line 167 def meter_slug @meter_slug end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
167 168 169 |
# File 'lib/zeroclick/sellers/contracts.rb', line 167 def quantity @quantity end |
Instance Method Details
#to_wire ⇒ Object
185 186 187 188 189 190 |
# File 'lib/zeroclick/sellers/contracts.rb', line 185 def to_wire wire = { "meterSlug" => @meter_slug } wire["quantity"] = @quantity unless @quantity.nil? wire["maxQuantity"] = @max_quantity unless @max_quantity.nil? wire end |