Class: SealineInsurance::Operations::Calculate

Inherits:
Base
  • Object
show all
Defined in:
lib/sealine_insurance/operations/calculate.rb

Instance Attribute Summary

Attributes inherited from Base

#response

Instance Method Summary collapse

Methods inherited from Base

#finished?, #result, #success?

Constructor Details

#initialize(config:, product_type:, products:, ticket_price:, options: []) ⇒ Calculate



6
7
8
9
10
11
12
# File 'lib/sealine_insurance/operations/calculate.rb', line 6

def initialize(config:, product_type:, products:, ticket_price:, options: [])
  super(config: config)
  @product_type = product_type
  @products = products
  @ticket_price = ticket_price
  @options = options
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sealine_insurance/operations/calculate.rb', line 14

def call
  raw_response = request.post('/calculate-product',
    product_type: @product_type,
    products: @products,
    options: @options,
    data: {
      ticket_price: @ticket_price.to_i,
    },
  )
  @response = Responses::Calculate.new(raw_response)
  @request_id = @response.request_id
end

#fetch_status!Object



27
28
29
30
31
32
# File 'lib/sealine_insurance/operations/calculate.rb', line 27

def fetch_status!
  return unless @request_id

  raw_response = request.get("/calculate-product/#{@request_id}")
  @response = Responses::Calculate.new(raw_response)
end