Class: Fal::Price
- Inherits:
-
Object
- Object
- Fal::Price
- Defined in:
- lib/fal/price.rb
Overview
Represents pricing information for a model endpoint. Fetches data from the Platform API at /models and /models/pricing.
Defined Under Namespace
Modules: Unit
Constant Summary collapse
- MODELS_PATH =
"/models"- PRICING_PATH =
"/models/pricing"
Instance Attribute Summary collapse
- #currency ⇒ String readonly
- #endpoint_id ⇒ String readonly
- #unit ⇒ String readonly
- #unit_price ⇒ Float readonly
Class Method Summary collapse
-
.all(client: Fal.client) ⇒ Array<Fal::Price>
Return an array of all prices.
-
.each(client: Fal.client) {|Fal::Price| ... } ⇒ void
Iterate over all prices by paging through models and fetching pricing in batches.
-
.find_by(endpoint_id:, client: Fal.client) ⇒ Fal::Price?
Find pricing for a specific model endpoint.
Instance Method Summary collapse
-
#initialize(attributes, client: Fal.client) ⇒ Price
constructor
A new instance of Price.
Constructor Details
#initialize(attributes, client: Fal.client) ⇒ Price
Returns a new instance of Price.
34 35 36 37 |
# File 'lib/fal/price.rb', line 34 def initialize(attributes, client: Fal.client) @client = client reset_attributes(attributes) end |
Instance Attribute Details
#currency ⇒ String (readonly)
30 31 32 |
# File 'lib/fal/price.rb', line 30 def currency @currency end |
#endpoint_id ⇒ String (readonly)
24 25 26 |
# File 'lib/fal/price.rb', line 24 def endpoint_id @endpoint_id end |
#unit ⇒ String (readonly)
28 29 30 |
# File 'lib/fal/price.rb', line 28 def unit @unit end |
#unit_price ⇒ Float (readonly)
26 27 28 |
# File 'lib/fal/price.rb', line 26 def unit_price @unit_price end |
Class Method Details
.all(client: Fal.client) ⇒ Array<Fal::Price>
Return an array of all prices.
76 77 78 79 80 |
# File 'lib/fal/price.rb', line 76 def all(client: Fal.client) results = [] each(client: client) { |price| results << price } results end |
.each(client: Fal.client) {|Fal::Price| ... } ⇒ void
This method returns an undefined value.
Iterate over all prices by paging through models and fetching pricing in batches.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fal/price.rb', line 54 def each(client: Fal.client, &block) cursor = nil loop do models_response = client.get_api(MODELS_PATH, query: { limit: 50, cursor: cursor }.compact) models = Array(models_response && models_response["models"]) endpoint_ids = models.map { |m| m["endpoint_id"] }.compact if endpoint_ids.any? pricing_response = client.get_api(PRICING_PATH, query: { endpoint_id: endpoint_ids }) Array(pricing_response && pricing_response["prices"]).each do |attributes| block.call(new(attributes, client: client)) end end cursor = models_response && models_response["next_cursor"] break if cursor.nil? end end |
.find_by(endpoint_id:, client: Fal.client) ⇒ Fal::Price?
Find pricing for a specific model endpoint.
44 45 46 47 48 |
# File 'lib/fal/price.rb', line 44 def find_by(endpoint_id:, client: Fal.client) response = client.get_api(PRICING_PATH, query: { endpoint_id: endpoint_id }) entry = Array(response && response["prices"]).find { |p| p["endpoint_id"] == endpoint_id } entry ? new(entry, client: client) : nil end |