root_insurance 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/CHANGELOG.md +4 -0
- data/lib/root_insurance.rb +0 -1
- data/lib/root_insurance/api/application.rb +40 -38
- data/lib/root_insurance/api/call.rb +33 -31
- data/lib/root_insurance/api/claim.rb +227 -225
- data/lib/root_insurance/api/payment.rb +63 -61
- data/lib/root_insurance/api/policy.rb +163 -161
- data/lib/root_insurance/api/policyholder.rb +120 -118
- data/lib/root_insurance/api/quote.rb +84 -83
- data/lib/root_insurance/version.rb +1 -1
- metadata +3 -3
@@ -1,72 +1,74 @@
|
|
1
|
-
module RootInsurance
|
2
|
-
module
|
1
|
+
module RootInsurance
|
2
|
+
module Api
|
3
|
+
module Payment
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
5
|
+
# Create a payment method
|
6
|
+
#
|
7
|
+
# @param [String] policyholder_id The unique identifier of the policy holder.
|
8
|
+
# @param [String] type The payment method type. Curently only +'debit_order'+ is supported. If omitted, defaults to +'debit_order'+ (optional)
|
9
|
+
# @param [Hash] bank_details Bank details to use for the debit order. See below for details.
|
10
|
+
# @param [String] policy_ids The date on the which the incident occured. (optional)
|
11
|
+
# @return [Hash]
|
12
|
+
#
|
13
|
+
## == Bank details
|
14
|
+
# [account_holder (string)] Name of account holder.
|
15
|
+
# [bank (string)] Bank name - one of [+absa+, +capitec+, +fnb+, +investec+, +nedbank+, +postbank+, +standard_bank+]
|
16
|
+
# [branch_code (string)] Branch code for bank account
|
17
|
+
# [account_number (string)] Bank account number
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# bank_details = {
|
21
|
+
# first_name: "Erlich",
|
22
|
+
# last_name: "Bachman",
|
23
|
+
# bank: "absa",
|
24
|
+
# branch_code: "12345",
|
25
|
+
# account_number: "123456789"
|
26
|
+
# }
|
27
|
+
# client.create_payment_method(
|
28
|
+
# policyholder_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
|
29
|
+
# bank_details: bank_details)
|
30
|
+
#
|
31
|
+
def create_payment_method(policyholder_id:, type: 'debit_order', bank_details: {}, policy_ids: nil)
|
32
|
+
validate_bank_details(bank_details)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
data = {
|
35
|
+
type: type,
|
36
|
+
bank_details: bank_details
|
37
|
+
}
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
if policy_ids && policy_ids.is_a?(Array)
|
40
|
+
data.merge!(policy_ids: policy_ids)
|
41
|
+
elsif policy_ids && policy_ids.is_a?(String)
|
42
|
+
data.merge!(policy_ids: [policy_ids])
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
post("policyholders/#{policyholder_id}/payment-methods", data)
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
# Link a payment method to a policy
|
49
|
+
#
|
50
|
+
# @param [String] policy_id The unique identifier of the policy.
|
51
|
+
# @param [String] payment_method_id The unique identifier of the payment method.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# client.link_payment_method(
|
55
|
+
# policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
|
56
|
+
# payment_method_id: "e0b7b222-772f-47ac-b08d-c7ba38aa1b25")
|
57
|
+
#
|
58
|
+
def link_payment_method(policy_id:, payment_method_id:)
|
59
|
+
data = {payment_method_id: payment_method_id}
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
put("policies/#{policy_id}/payment-method", data)
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
private
|
65
|
+
def validate_bank_details(bank_details)
|
66
|
+
[:first_name, :last_name, :bank, :branch_code, :account_number].each do |key|
|
67
|
+
if !(bank_details[key] || bank_details[key.to_sym])
|
68
|
+
raise ArgumentError.new("Bank details need to include #{key}")
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
72
|
-
end
|
74
|
+
end
|
@@ -1,163 +1,165 @@
|
|
1
|
-
module RootInsurance
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
1
|
+
module RootInsurance
|
2
|
+
module Api
|
3
|
+
module Policy
|
4
|
+
|
5
|
+
# Issue a policy
|
6
|
+
#
|
7
|
+
# @param [String] application_id The unique identifier of the application.
|
8
|
+
# @param [Hash, nil] app_data An object containing additional custom data for the policy.
|
9
|
+
# @return [Hash]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# client.issue_policy(
|
13
|
+
# application_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
|
14
|
+
# app_data: {gadget_colour: "Space Grey"})
|
15
|
+
#
|
16
|
+
def issue_policy(application_id:, app_data: nil)
|
17
|
+
data = {
|
18
|
+
application_id: application_id,
|
19
|
+
}
|
20
|
+
|
21
|
+
data.merge!(app_data: app_data) if app_data
|
22
|
+
|
23
|
+
post(:policies, data)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Add a benificiary to a policy
|
27
|
+
#
|
28
|
+
# @param [String] policy_id The unique identifier of the policy.
|
29
|
+
# @param [String] first_name The beneficiary's first name
|
30
|
+
# @param [String] last_name The beneficiary's last name
|
31
|
+
# @param [Hash] id An hash containing the beneficiary's identification number, type and country. See below.
|
32
|
+
# @param [Integer] percentage An integer representing the percentage of a claim payout that the beneficiary should receive.
|
33
|
+
# @param [String] cellphone Hash containing beneficiary's cellphone number and country. See below for details. (optional)
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
## == ID
|
37
|
+
# [type (string or symbol)] Either +:id+ or +:passport+
|
38
|
+
# [number (string)] The id or passport number
|
39
|
+
# [country (string)] The ISO Alpha-2 country code of the country of the id/passport number.
|
40
|
+
#
|
41
|
+
## == Cellphone
|
42
|
+
# [number (string)] The cellphone number
|
43
|
+
# [country (string)] The ISO Alpha-2 country code of the country of the cellphone number.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# client.add_policy_beneficiary(
|
47
|
+
# policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
|
48
|
+
# first_name: "Jared"
|
49
|
+
# last_name: "Dunn",
|
50
|
+
# id: {type: :id, number: "8704094800082", country: "ZA"},
|
51
|
+
# percentage: 100)
|
52
|
+
#
|
53
|
+
def add_policy_beneficiary(policy_id:, id:, first_name:, last_name:, percentage:, cellphone: nil)
|
54
|
+
raise ArgumentError.new('id needs to be a hash') unless id.is_a? Hash
|
55
|
+
|
56
|
+
data = {
|
57
|
+
id: id,
|
58
|
+
first_name: first_name,
|
59
|
+
last_name: last_name,
|
60
|
+
percentage: percentage,
|
61
|
+
cellphone: cellphone
|
62
|
+
}.reject { |k, v| v.nil? }
|
63
|
+
|
64
|
+
put("policies/#{policy_id}/beneficiaries", data)
|
65
|
+
end
|
66
|
+
|
67
|
+
# List policies
|
68
|
+
#
|
69
|
+
# @param [String] id_number The National ID Number of the policyholder (optional)
|
70
|
+
# @return [Array<Hash>]
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# client.list_policies(id_number: "8704094800082")
|
74
|
+
#
|
75
|
+
def list_policies(id_number: nil)
|
76
|
+
query = id_number ? {id_number: id_number} : nil
|
77
|
+
|
78
|
+
get(:policies, query)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Get a policy
|
82
|
+
#
|
83
|
+
# @param [String] id The unique identifier of the policy
|
84
|
+
# @return [Hash]
|
85
|
+
#
|
86
|
+
# @example
|
87
|
+
# client.get_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
|
88
|
+
#
|
89
|
+
def get_policy(id:)
|
90
|
+
get("policies/#{id}")
|
91
|
+
end
|
92
|
+
|
93
|
+
# Cancel a policy
|
94
|
+
#
|
95
|
+
# @param [String] id The unique identifier of the policy
|
96
|
+
# @param [String] reason A reason for why this policy is being cancelled.
|
97
|
+
# @return [Hash]
|
98
|
+
#
|
99
|
+
# @example
|
100
|
+
# client.cancel_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", reason: "Not needed anymore")
|
101
|
+
#
|
102
|
+
def cancel_policy(id:, reason:)
|
103
|
+
data = {reason: reason}
|
104
|
+
|
105
|
+
post("policies/#{id}/cancel", data)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Update a policy.
|
109
|
+
# Currently, only updating the app_data object is supported
|
110
|
+
#
|
111
|
+
# @param [String] id The unique identifier of the policy
|
112
|
+
# @param [Hash] app_data An object containing additional custom data for the policy.
|
113
|
+
# @return [Hash]
|
114
|
+
#
|
115
|
+
# @example
|
116
|
+
# app_data = {gadget_color: "Space Grey", has_screen_cover: true}
|
117
|
+
# client.update_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", app_data: app_data)
|
118
|
+
#
|
119
|
+
def update_policy(id:, app_data:)
|
120
|
+
data = {app_data: app_data}
|
121
|
+
|
122
|
+
patch("policies/#{id}", data)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Update a policy's billing amount.
|
126
|
+
#
|
127
|
+
# @param [String] id The unique identifier of the policy
|
128
|
+
# @param [Integer] billing_amount The billing amount to be set on the policy in cents.
|
129
|
+
# @return [Hash]
|
130
|
+
#
|
131
|
+
# @example
|
132
|
+
# client.update_policy_billing_amount(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", billing_amount: 45000)
|
133
|
+
#
|
134
|
+
def update_policy_billing_amount(id:, billing_amount:)
|
135
|
+
data = {billing_amount: billing_amount}
|
136
|
+
|
137
|
+
post("policies/#{id}/billing_amount", data)
|
138
|
+
end
|
139
|
+
|
140
|
+
# List a policy's bebeficiaries
|
141
|
+
#
|
142
|
+
# @param [String] id The unique identifier of the policy
|
143
|
+
# @return [Array<Hash>]
|
144
|
+
#
|
145
|
+
# @example
|
146
|
+
# client.list_policy_beneficiaries(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
|
147
|
+
#
|
148
|
+
def list_policy_beneficiaries(id:)
|
149
|
+
get("policies/#{id}/beneficiaries")
|
150
|
+
end
|
151
|
+
|
152
|
+
# List all the events which are applicable to this policy.
|
153
|
+
#
|
154
|
+
# @param [String] id The unique identifier of the policy
|
155
|
+
# @return [Array<Hash>]
|
156
|
+
#
|
157
|
+
# @example
|
158
|
+
# client.list_policy_events(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
|
159
|
+
#
|
160
|
+
def list_policy_events(id:)
|
161
|
+
get("policies/#{id}/events")
|
162
|
+
end
|
161
163
|
end
|
162
164
|
end
|
163
|
-
end
|
165
|
+
end
|