Class: Yasminaai::Policies::Client
- Inherits:
-
Object
- Object
- Yasminaai::Policies::Client
- Defined in:
- lib/yasminaai/policies/client.rb
Instance Method Summary collapse
- #initialize(client:) ⇒ void constructor
-
#issue_policy(request_options: {}, **params) ⇒ Yasminaai::Types::Policy
For issuing a new policy.
-
#list_policies(request_options: {}, **params) ⇒ Yasminaai::Types::PaginatedPolicyResponse
Listing requested policies.
-
#show_policy(request_options: {}, **params) ⇒ Yasminaai::Types::Policy
Show a specific policy.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/yasminaai/policies/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#issue_policy(request_options: {}, **params) ⇒ Yasminaai::Types::Policy
For issuing a new policy
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/yasminaai/policies/client.rb', line 120 def issue_policy(request_options: {}, **params) params = Yasminaai::Internal::Types::Utils.normalize_keys(params) request = Yasminaai::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "policies", body: Yasminaai::Policies::Types::PostPoliciesRequest.new(params).to_h, 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::Policy.load(response.body) else error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_policies(request_options: {}, **params) ⇒ Yasminaai::Types::PaginatedPolicyResponse
Listing requested policies
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/yasminaai/policies/client.rb', line 71 def list_policies(request_options: {}, **params) params = Yasminaai::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["quote_request_id"] = params[:quote_request_id] if params.key?(:quote_request_id) query_params["quote_price_id"] = params[:quote_price_id] if params.key?(:quote_price_id) query_params["provider_policy_id"] = params[:provider_policy_id] if params.key?(:provider_policy_id) query_params["car_sequence_number"] = params[:car_sequence_number] if params.key?(:car_sequence_number) query_params["new_owner_id"] = params[:new_owner_id] if params.key?(:new_owner_id) query_params["previous_owner_id"] = params[:previous_owner_id] if params.key?(:previous_owner_id) query_params["status"] = params[:status] if params.key?(:status) query_params["min_price"] = params[:min_price] if params.key?(:min_price) query_params["max_price"] = params[:max_price] if params.key?(:max_price) query_params["per_page"] = params[:per_page] if params.key?(:per_page) 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["include_aggregates"] = params[:include_aggregates] if params.key?(:include_aggregates) request = Yasminaai::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "policies", query: query_params, 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::PaginatedPolicyResponse.load(response.body) else error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#show_policy(request_options: {}, **params) ⇒ Yasminaai::Types::Policy
Show a specific policy
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yasminaai/policies/client.rb', line 25 def show_policy(request_options: {}, **params) params = Yasminaai::Internal::Types::Utils.normalize_keys(params) request = Yasminaai::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "policies/#{URI.encode_uri_component(params[:car_policy].to_s)}", 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::Policy.load(response.body) else error_class = Yasminaai::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |