Class: RunApi::Core::Pricing

Inherits:
Object
  • Object
show all
Includes:
ResourceHelpers
Defined in:
lib/runapi/core/pricing.rb

Direct Known Subclasses

PricingClient

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

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}"
  request_options = (options || RequestOptions.new).dup
  request_options.allow_not_modified = true
  response = @http.request(:get, path, options: request_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