Class: RunApi::Core::Pricing
- Inherits:
-
Object
- Object
- RunApi::Core::Pricing
- Includes:
- ResourceHelpers
- Defined in:
- lib/runapi/core/pricing.rb
Direct Known Subclasses
Defined Under Namespace
Classes: QuoteEnvelope, QuoteResponse, Schedule, ScheduleListResponse, ScheduleNotModifiedResponse
Constant Summary collapse
- SCHEDULES_ENDPOINT =
"/api/v1/price_schedules"- QUOTES_ENDPOINT =
"/api/v1/price_quotes"
Instance Method Summary collapse
-
#initialize(http) ⇒ Pricing
constructor
A new instance of Pricing.
- #list(service: nil, action: nil, model: nil, options: nil) ⇒ Object
- #quote(service:, action:, model: nil, params: {}, options: nil) ⇒ Object
Constructor Details
#initialize(http) ⇒ Pricing
Returns a new instance of Pricing.
54 55 56 |
# File 'lib/runapi/core/pricing.rb', line 54 def initialize(http) @http = http end |
Instance Method Details
#list(service: nil, action: nil, model: nil, options: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/runapi/core/pricing.rb', line 58 def list(service: nil, action: nil, model: nil, options: nil) query = URI.encode_www_form(compact_params(service:, action:, model:)) path = query.empty? ? SCHEDULES_ENDPOINT : "#{SCHEDULES_ENDPOINT}?#{query}" = ( || RequestOptions.new).dup .allow_not_modified = true response = @http.request(:get, path, options: ) payload = response.is_a?(Core::Response) ? response.body : response response_class = payload["not_modified"] ? ScheduleNotModifiedResponse : ScheduleListResponse result = RunApi::Core::BaseModel.coerce(payload, as: response_class) result.with_response_headers(response.response_headers) if response.is_a?(Core::Response) result end |
#quote(service:, action:, model: nil, params: {}, options: nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/runapi/core/pricing.rb', line 71 def quote(service:, action:, model: nil, params: {}, options: nil) response = request( :post, QUOTES_ENDPOINT, body: compact_params(service:, action:, model:, params:), options:, response_class: QuoteEnvelope ) response.price_quote end |