Class: Yasminaai::Quotes::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yasminaai/quotes/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/yasminaai/quotes/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#delete_quote(request_options: {}, **params) ⇒ Yasminaai::Quotes::Types::DeleteQuoteRequestsIDResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (Integer)

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/yasminaai/quotes/client.rb', line 55

def delete_quote(request_options: {}, **params)
  params = Yasminaai::Internal::Types::Utils.normalize_keys(params)
  request = Yasminaai::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "quote-requests/#{URI.encode_uri_component(params[:id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Yasminaai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Yasminaai::Quotes::Types::DeleteQuoteRequestsIDResponse.load(response.body)
  else
    error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_quotes(request_options: {}, **params) ⇒ Yasminaai::Types::PaginatedQuoteResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :date_from (String, nil)
  • :date_to (String, nil)
  • :per_page (Integer, nil)
  • :include_aggregates (Boolean, nil)

Returns:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/yasminaai/quotes/client.rb', line 90

def list_quotes(request_options: {}, **params)
  params = Yasminaai::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["date_from"] = params[:date_from] if params.key?(:date_from)
  query_params["date_to"] = params[:date_to] if params.key?(:date_to)
  query_params["per_page"] = params[:per_page] if params.key?(:per_page)
  query_params["include_aggregates"] = params[:include_aggregates] if params.key?(:include_aggregates)

  request = Yasminaai::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "quote-requests",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Yasminaai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Yasminaai::Types::PaginatedQuoteResponse.load(response.body)
  else
    error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#request_quotes(request_options: {}, **params) ⇒ Yasminaai::Types::QuoteResponse

For getting prices with benefits. The Quote IDs can be used later to issue a policy

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/yasminaai/quotes/client.rb', line 132

def request_quotes(request_options: {}, **params)
  params = Yasminaai::Internal::Types::Utils.normalize_keys(params)
  request_data = Yasminaai::Quotes::Types::PostQuoteRequestsRequest.new(params).to_h
  non_body_param_names = %w[Accept-Language]
  body = request_data.except(*non_body_param_names)

  headers = {}
  headers["Accept-Language"] = params[:accept_language] if params[:accept_language]

  request = Yasminaai::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "quote-requests",
    headers: headers,
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Yasminaai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Yasminaai::Types::QuoteResponse.load(response.body)
  else
    error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#show_quote(request_options: {}, **params) ⇒ Yasminaai::Types::QuoteResponse

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (Integer)

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/yasminaai/quotes/client.rb', line 23

def show_quote(request_options: {}, **params)
  params = Yasminaai::Internal::Types::Utils.normalize_keys(params)
  request = Yasminaai::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "quote-requests/#{URI.encode_uri_component(params[:id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Yasminaai::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Yasminaai::Types::QuoteResponse.load(response.body)
  else
    error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end