root_insurance 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 83e11151b5e0dfc73c7c6bb39f3cdffe7f6eaa8d
4
- data.tar.gz: 5994e4790ce33bc2e9d84fd02714c6847d07e823
2
+ SHA256:
3
+ metadata.gz: 43f2f4cfd0a00e352d6bac7655f2540d05f99267de17f176480e75af8066224a
4
+ data.tar.gz: c5f51cfd206b9c2ff52e05a97971a6cfa7795214cc8bc1eeda4a1aaf034adc21
5
5
  SHA512:
6
- metadata.gz: 00cd75bcdf23ada86c37514f49cfbc975f12c703f94b452cb30af76b1542654b26182c260570d537610f981c9d68753a0943f9c19bd43d8a79f147ee87d28a59
7
- data.tar.gz: 7a36f4b2fa357d39465404e95996e7dc1ffdc957d61af07dc3e0583832487c6d2b5015a546b32f1cfcd4325da29b932954981109c00797b3c501bfafa02512a6
6
+ metadata.gz: 220a4a92e4c53322581fdfd5a65b5c720d2387ef816b567e7c3b1c4692fa5ace284417985ba0b9d3b1a6c12c31d610faf64d26d4d95336b091fcf34563d2e806
7
+ data.tar.gz: c32163c099e0e2ab01286b137b2b630aff9171aade7053264a1a7ccdcfa3df3ebb511b771fd03486643781096143b9e1d2801f1fad6c0f8b95394c6d9125cbdd
data/.gitignore CHANGED
@@ -10,3 +10,6 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ # semvergen
15
+ .gem_server
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ # 1.9.1 - Release date: 2018-10-03
4
+ * Fixed module nesting to avoid rails autoloading weirdness
5
+
6
+
3
7
  # 1.9.0 - Release date: 2018-01-06
4
8
  * Changed all instances of policy_holder to policyholder to be more consistent
5
9
 
@@ -4,5 +4,4 @@ require 'root_insurance/exceptions'
4
4
 
5
5
  module RootInsurance
6
6
 
7
-
8
7
  end
@@ -1,44 +1,46 @@
1
- module RootInsurance::Api
2
- module Application
1
+ module RootInsurance
2
+ module Api
3
+ module Application
3
4
 
4
- # Create an application
5
- #
6
- # @param [String] policyholder_id The policy holder id
7
- # @param [String] quote_package_id The quote package id
8
- # @param [Integer] monthly_premium The monthly premium (in cents)
9
- # @param [String] serial_number The device to insure's serial number. (for the gadgets module)
10
- # @param [String] spouse_id SA ID number of the policyholder's spouse. Required if has_spouse is true on the quote.
11
- # @param [Array<String>] children_ids SA ID numbers of the policyholder's children. Required if +number_of_children+ is greater than 0 on the quote. All children must be younger than 21.
12
- # @param [Array<String>] extended_famliy_ids SA ID number of the policyholder's extended family members. Required if the length of +extended_family_ages+ is greater than 0 on the quote. The ages inferred from the ID numbers must match the ages given in the quote step.
13
- # @return [Hash]
14
- #
15
- # @example
16
- # client.create_application(
17
- # policyholder_id: "bf1ada91-eecb-4f47-9bfa-1258bb1e0055",
18
- # quote_package_id: "f4397823-db4a-4d6a-a06b-08e1a2a3172c",
19
- # monthly_premium: 50000,
20
- # serial_number: "1234567890")
21
- def create_application(policyholder_id:, quote_package_id:, monthly_premium:,
22
- serial_number: nil, spouse_id: nil, children_ids: nil, extended_famliy_ids: nil)
23
- data = {
24
- policyholder_id: policyholder_id,
25
- quote_package_id: quote_package_id,
26
- monthly_premium: monthly_premium
27
- }
5
+ # Create an application
6
+ #
7
+ # @param [String] policyholder_id The policy holder id
8
+ # @param [String] quote_package_id The quote package id
9
+ # @param [Integer] monthly_premium The monthly premium (in cents)
10
+ # @param [String] serial_number The device to insure's serial number. (for the gadgets module)
11
+ # @param [String] spouse_id SA ID number of the policyholder's spouse. Required if has_spouse is true on the quote.
12
+ # @param [Array<String>] children_ids SA ID numbers of the policyholder's children. Required if +number_of_children+ is greater than 0 on the quote. All children must be younger than 21.
13
+ # @param [Array<String>] extended_famliy_ids SA ID number of the policyholder's extended family members. Required if the length of +extended_family_ages+ is greater than 0 on the quote. The ages inferred from the ID numbers must match the ages given in the quote step.
14
+ # @return [Hash]
15
+ #
16
+ # @example
17
+ # client.create_application(
18
+ # policyholder_id: "bf1ada91-eecb-4f47-9bfa-1258bb1e0055",
19
+ # quote_package_id: "f4397823-db4a-4d6a-a06b-08e1a2a3172c",
20
+ # monthly_premium: 50000,
21
+ # serial_number: "1234567890")
22
+ def create_application(policyholder_id:, quote_package_id:, monthly_premium:,
23
+ serial_number: nil, spouse_id: nil, children_ids: nil, extended_famliy_ids: nil)
24
+ data = {
25
+ policyholder_id: policyholder_id,
26
+ quote_package_id: quote_package_id,
27
+ monthly_premium: monthly_premium
28
+ }
28
29
 
29
- module_data = if serial_number
30
- {serial_number: serial_number}
31
- elsif spouse_id || children_ids || extended_famliy_ids
32
- {
33
- spouse_id: spouse_id,
34
- children_ids: children_ids,
35
- extended_famliy_ids: extended_famliy_ids
36
- }.reject { |key, value| value.nil? }
37
- end
30
+ module_data = if serial_number
31
+ {serial_number: serial_number}
32
+ elsif spouse_id || children_ids || extended_famliy_ids
33
+ {
34
+ spouse_id: spouse_id,
35
+ children_ids: children_ids,
36
+ extended_famliy_ids: extended_famliy_ids
37
+ }.reject { |key, value| value.nil? }
38
+ end
38
39
 
39
- data = module_data ? data.merge(module_data) : data
40
+ data = module_data ? data.merge(module_data) : data
40
41
 
41
- post(:applications, data)
42
+ post(:applications, data)
43
+ end
42
44
  end
43
45
  end
44
- end
46
+ end
@@ -1,35 +1,37 @@
1
- module RootInsurance::Api
2
- module Call
3
- # List all the logged calls
4
- #
5
- # @return [Hash]
6
- #
7
- # @example
8
- # client.list_calls
9
- def list_calls
10
- get(:calls)
11
- end
1
+ module RootInsurance
2
+ module Api
3
+ module Call
4
+ # List all the logged calls
5
+ #
6
+ # @return [Hash]
7
+ #
8
+ # @example
9
+ # client.list_calls
10
+ def list_calls
11
+ get(:calls)
12
+ end
12
13
 
13
- # Get a specific call
14
- #
15
- # @param [String] id The unique identifier of the call
16
- # @return [Hash]
17
- #
18
- # @example
19
- # client.get_call(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')
20
- def get_call(id:)
21
- get("calls/#{id}")
22
- end
14
+ # Get a specific call
15
+ #
16
+ # @param [String] id The unique identifier of the call
17
+ # @return [Hash]
18
+ #
19
+ # @example
20
+ # client.get_call(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')
21
+ def get_call(id:)
22
+ get("calls/#{id}")
23
+ end
23
24
 
24
- # List a call's events
25
- #
26
- # @param [String] id The unique identifier of the call
27
- # @return [Hash]
28
- #
29
- # @example
30
- # client.list_call_events(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')
31
- def list_call_events(id:)
32
- get("calls/#{id}/events")
25
+ # List a call's events
26
+ #
27
+ # @param [String] id The unique identifier of the call
28
+ # @return [Hash]
29
+ #
30
+ # @example
31
+ # client.list_call_events(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')
32
+ def list_call_events(id:)
33
+ get("calls/#{id}/events")
34
+ end
33
35
  end
34
36
  end
35
- end
37
+ end
@@ -1,230 +1,232 @@
1
1
  require 'mimemagic'
2
2
 
3
- module RootInsurance::Api
4
- module Claim
5
-
6
- # List all claims
7
- #
8
- # @param [String, Symbol] status Either +:open+, +:closed+, +:finalized+, +:acknowledged+ or +:all+. If omitted defaults to +:all+
9
- # @param [String, Symbol] approval Either +:approved+, +:repudiated+, +:'ex-gratia'+, +:'no-claim'+, +:pending+ or +:all+. If omitted defaults to +:all+
10
- # @return [Array<Hash>]
11
- #
12
- # @example
13
- # client.list_claims(status: :open)
14
- #
15
- def list_claims(status: nil, approval: nil)
16
- query = {
17
- claim_status: status,
18
- approval_status: approval
19
- }.reject { |key, value| value.nil? }
20
-
21
- get(:claims, query)
22
- end
23
-
24
- # Get a specific claim
25
- #
26
- # @param [String] id The claim's id
27
- # @return [Hash]
28
- # @example
29
- # client.get_claim(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')
30
- #
31
- def get_claim(id:)
32
- get("claims/#{id}")
33
- end
34
-
35
- # Open a claim
36
- #
37
- # @param [String] policy_id The ID of the policy under which the claim is being made. (optional)
38
- # @param [String] policyholder_id The ID of the policyholder for whom the claim is being made. (optional)
39
- # @param [String] incident_type A description of the incident type. (optional)
40
- # @param [String] incident_cause A description of the cause of the incident. (optional)
41
- # @param [String] incident_date The date on the which the incident occured. (optional)
42
- # @param [String] app_data An object containing additional custom data for the claim. (optional)
43
- # @param [String] claimant Object containing claimants's first name, last name, email and/or cellphone. See below for details. (optional)
44
- # @param [String] requested_amount The requested payout amount (in cents) for the claim. (optional)
45
- # @return [Hash]
46
- #
47
- ## == Claimant
48
- # [first_name (string)] The name of the claimant
49
- # [last_name (string)] The last name of the claimant
50
- # [email (string)] The claimant's email address
51
- # [cellphone (string)] The claimant's cellphone number
52
- #
53
- # @example
54
- # client.open_claim(
55
- # policy_id: "8349345c-a6c5-4bf9-8ebb-6bbfc1628715",
56
- # incident_type: "Theft",
57
- # incident_cause: "Device stolen during burglary",
58
- # incident_date: "2017-10-16T10:12:02.872Z",
59
- # requested_amount: 13000000,
60
- # app_data: {
61
- # key1: "value 1"
62
- # key2: "value 2"})
63
- #
64
- def open_claim(policy_id: nil, policyholder_id: nil, incident_type: nil, incident_cause: nil,
65
- incident_date: nil, app_data: nil, claimant: nil, requested_amount: nil)
66
- data = {
67
- policy_id: policy_id,
68
- policyholder_id: policyholder_id,
69
- incident_type: incident_type,
70
- incident_cause: incident_cause,
71
- incident_date: incident_date,
72
- app_data: app_data,
73
- claimant: claimant,
74
- requested_amount: requested_amount
75
- }.reject { |key, value| value.nil? }
76
-
77
- post(:claims, data)
78
- end
79
-
80
- # Update a claim
81
- #
82
- # @param [String] claim_id The unique identifier of the claim.
83
- # @param [String] incident_type A description of the incident type. (optional)
84
- # @param [String] incident_cause A description of the cause of the incident. (optional)
85
- # @param [String] incident_date The date on the which the incident occured. (optional)
86
- # @param [String] app_data An object containing additional custom data for the claim. (optional)
87
- # @param [String] requested_amount The requested payout amount (in cents) for the claim. (optional)
88
- # @return [Hash]
89
- #
90
- # @example
91
- # client.update_claim(
92
- # claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225",
93
- # incident_type: "Theft",
94
- # incident_cause: "Device stolen during burglary",
95
- # incident_date: "2017-10-16T10:12:02.872Z",
96
- # app_data: {key3: "value 3"},
97
- # requested_amount: 13000000)
98
- #
99
- def update_claim(claim_id:, incident_type: nil, incident_cause: nil, incident_date: nil,
100
- app_data: nil, requested_amount: nil)
101
- data = {
102
- incident_type: incident_type,
103
- incident_cause: incident_cause,
104
- incident_date: incident_date,
105
- app_data: app_data,
106
- requested_amount: requested_amount
107
- }.reject { |key, value| value.nil? }
108
-
109
- patch("claims/#{claim_id}", data)
110
- end
3
+ module RootInsurance
4
+ module Api
5
+ module Claim
6
+
7
+ # List all claims
8
+ #
9
+ # @param [String, Symbol] status Either +:open+, +:closed+, +:finalized+, +:acknowledged+ or +:all+. If omitted defaults to +:all+
10
+ # @param [String, Symbol] approval Either +:approved+, +:repudiated+, +:'ex-gratia'+, +:'no-claim'+, +:pending+ or +:all+. If omitted defaults to +:all+
11
+ # @return [Array<Hash>]
12
+ #
13
+ # @example
14
+ # client.list_claims(status: :open)
15
+ #
16
+ def list_claims(status: nil, approval: nil)
17
+ query = {
18
+ claim_status: status,
19
+ approval_status: approval
20
+ }.reject { |key, value| value.nil? }
21
+
22
+ get(:claims, query)
23
+ end
24
+
25
+ # Get a specific claim
26
+ #
27
+ # @param [String] id The claim's id
28
+ # @return [Hash]
29
+ # @example
30
+ # client.get_claim(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')
31
+ #
32
+ def get_claim(id:)
33
+ get("claims/#{id}")
34
+ end
35
+
36
+ # Open a claim
37
+ #
38
+ # @param [String] policy_id The ID of the policy under which the claim is being made. (optional)
39
+ # @param [String] policyholder_id The ID of the policyholder for whom the claim is being made. (optional)
40
+ # @param [String] incident_type A description of the incident type. (optional)
41
+ # @param [String] incident_cause A description of the cause of the incident. (optional)
42
+ # @param [String] incident_date The date on the which the incident occured. (optional)
43
+ # @param [String] app_data An object containing additional custom data for the claim. (optional)
44
+ # @param [String] claimant Object containing claimants's first name, last name, email and/or cellphone. See below for details. (optional)
45
+ # @param [String] requested_amount The requested payout amount (in cents) for the claim. (optional)
46
+ # @return [Hash]
47
+ #
48
+ ## == Claimant
49
+ # [first_name (string)] The name of the claimant
50
+ # [last_name (string)] The last name of the claimant
51
+ # [email (string)] The claimant's email address
52
+ # [cellphone (string)] The claimant's cellphone number
53
+ #
54
+ # @example
55
+ # client.open_claim(
56
+ # policy_id: "8349345c-a6c5-4bf9-8ebb-6bbfc1628715",
57
+ # incident_type: "Theft",
58
+ # incident_cause: "Device stolen during burglary",
59
+ # incident_date: "2017-10-16T10:12:02.872Z",
60
+ # requested_amount: 13000000,
61
+ # app_data: {
62
+ # key1: "value 1"
63
+ # key2: "value 2"})
64
+ #
65
+ def open_claim(policy_id: nil, policyholder_id: nil, incident_type: nil, incident_cause: nil,
66
+ incident_date: nil, app_data: nil, claimant: nil, requested_amount: nil)
67
+ data = {
68
+ policy_id: policy_id,
69
+ policyholder_id: policyholder_id,
70
+ incident_type: incident_type,
71
+ incident_cause: incident_cause,
72
+ incident_date: incident_date,
73
+ app_data: app_data,
74
+ claimant: claimant,
75
+ requested_amount: requested_amount
76
+ }.reject { |key, value| value.nil? }
77
+
78
+ post(:claims, data)
79
+ end
80
+
81
+ # Update a claim
82
+ #
83
+ # @param [String] claim_id The unique identifier of the claim.
84
+ # @param [String] incident_type A description of the incident type. (optional)
85
+ # @param [String] incident_cause A description of the cause of the incident. (optional)
86
+ # @param [String] incident_date The date on the which the incident occured. (optional)
87
+ # @param [String] app_data An object containing additional custom data for the claim. (optional)
88
+ # @param [String] requested_amount The requested payout amount (in cents) for the claim. (optional)
89
+ # @return [Hash]
90
+ #
91
+ # @example
92
+ # client.update_claim(
93
+ # claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225",
94
+ # incident_type: "Theft",
95
+ # incident_cause: "Device stolen during burglary",
96
+ # incident_date: "2017-10-16T10:12:02.872Z",
97
+ # app_data: {key3: "value 3"},
98
+ # requested_amount: 13000000)
99
+ #
100
+ def update_claim(claim_id:, incident_type: nil, incident_cause: nil, incident_date: nil,
101
+ app_data: nil, requested_amount: nil)
102
+ data = {
103
+ incident_type: incident_type,
104
+ incident_cause: incident_cause,
105
+ incident_date: incident_date,
106
+ app_data: app_data,
107
+ requested_amount: requested_amount
108
+ }.reject { |key, value| value.nil? }
109
+
110
+ patch("claims/#{claim_id}", data)
111
+ end
112
+
113
+ # Link a claim and a policy
114
+ #
115
+ # @param [String] claim_id The unique identifier of the claim.
116
+ # @param [String] policy_id The unique identifier of the policy.
117
+ # @return [Hash]
118
+ #
119
+ # @example
120
+ # client.link_policy_to_claim(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225", policy_id: "8349345c-a6c5-4bf9-8ebb-6bbfc1628715")
121
+ #
122
+ def link_policy_to_claim(claim_id:, policy_id:)
123
+ data = {policy_id: policy_id}
124
+
125
+ post("claims/#{claim_id}/policy", data)
126
+ end
127
+
128
+
129
+ # Link a claim and a policy holder
130
+ #
131
+ # @param [String] claim_id The unique identifier of the claim.
132
+ # @param [String] policyholder_id The unique identifier of the policy holder.
133
+ # @return [Hash]
134
+ #
135
+ # @example
136
+ # client.link_policyholder_to_claim(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225", policyholder_id: "808f75dc-cb8a-4808-93e9-e13f8eea84de")
137
+ #
138
+ def link_policyholder_to_claim(claim_id:, policyholder_id:)
139
+ data = {policyholder_id: policyholder_id}
140
+
141
+ post("claims/#{claim_id}/policyholder", data)
142
+ end
143
+
144
+ # List all claim events
145
+ #
146
+ # @param [String] claim_id The unique identifier of the claim.
147
+ # @return [Array<Hash>]
148
+ #
149
+ # @example
150
+ # client.list_claim_events(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225")
151
+ #
152
+ def list_claim_events(id: nil, claim_id: nil)
153
+ claim_id = claim_id || id
154
+ get("claims/#{claim_id}/events")
155
+ end
156
+
157
+ # Create a claim attachment
158
+ #
159
+ # The file data can be passed using either +path+, +file+, +bytes+ or +base64+.
160
+ #
161
+ # @param [String] claim_id The unique identifier of the claim
162
+ # @param [String] path The full path to the file's location
163
+ # @param [File] file instance of a File object
164
+ # @param [String] bytes The raw butes of the file
165
+ # @param [String] base64 The base64 encoded file
166
+ # @param [String] file_name The file's name (only required when not using +path+ or +file+)
167
+ # @param [String] file_type The file's mime type (only required when using +base64+)
168
+ # @param [String] description A description of the file
169
+ # @return [Hash]
170
+ #
171
+ def create_claim_attachment(claim_id:, path: nil, file: nil, bytes: nil, base64: nil, file_name: nil, file_type: nil, description: '')
172
+ data = if path
173
+ claim_attachment_from_path(path)
174
+ elsif file
175
+ claim_attachment_from_file(file)
176
+ elsif bytes
177
+ raise ArgumentError.new("file_name is required when supplying bytes") unless file_name
178
+ claim_attachment_from_bytes(bytes, file_name, file_type)
179
+ elsif base64
180
+ raise ArgumentError.new("file_name is required when supplying base64") unless file_name
181
+ raise ArgumentError.new("file_type is required when supplying base64") unless file_type
182
+ claim_attachment_from_base46(base64, file_name, file_type)
183
+ else
184
+ {}
185
+ end.merge({description: description})
186
+
187
+ post("claims/#{claim_id}/attachments", data)
188
+ end
189
+
190
+ private
191
+ def claim_attachment_from_path(path)
192
+ encoded_data = Base64.encode64(File.binread(path))
193
+ file_name = File.basename(path)
194
+
195
+ {
196
+ file_base64: encoded_data,
197
+ file_name: file_name,
198
+ file_type: MimeMagic.by_magic(File.open(path)).type
199
+ }
200
+ end
201
+
202
+ def claim_attachment_from_file(file)
203
+ encoded_data = Base64.encode64(file.read)
204
+
205
+ {
206
+ file_base64: encoded_data,
207
+ file_name: File.basename(file.path),
208
+ file_type: MimeMagic.by_magic(file).type
209
+ }
210
+ end
211
+
212
+ def claim_attachment_from_bytes(bytes, file_name, file_type)
213
+ encoded_data = Base64.encode64(bytes)
214
+
215
+ {
216
+ file_base64: encoded_data,
217
+ file_name: file_name,
218
+ file_type: file_type || MimeMagic.by_magic(bytes).type
219
+ }
220
+ end
221
+
222
+ def claim_attachment_from_base46(base64, file_name, file_type)
223
+ {
224
+ file_base64: base64,
225
+ file_name: file_name,
226
+ file_type: file_type
227
+ }
228
+ end
111
229
 
112
- # Link a claim and a policy
113
- #
114
- # @param [String] claim_id The unique identifier of the claim.
115
- # @param [String] policy_id The unique identifier of the policy.
116
- # @return [Hash]
117
- #
118
- # @example
119
- # client.link_policy_to_claim(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225", policy_id: "8349345c-a6c5-4bf9-8ebb-6bbfc1628715")
120
- #
121
- def link_policy_to_claim(claim_id:, policy_id:)
122
- data = {policy_id: policy_id}
123
-
124
- post("claims/#{claim_id}/policy", data)
125
230
  end
126
-
127
-
128
- # Link a claim and a policy holder
129
- #
130
- # @param [String] claim_id The unique identifier of the claim.
131
- # @param [String] policyholder_id The unique identifier of the policy holder.
132
- # @return [Hash]
133
- #
134
- # @example
135
- # client.link_policyholder_to_claim(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225", policyholder_id: "808f75dc-cb8a-4808-93e9-e13f8eea84de")
136
- #
137
- def link_policyholder_to_claim(claim_id:, policyholder_id:)
138
- data = {policyholder_id: policyholder_id}
139
-
140
- post("claims/#{claim_id}/policyholder", data)
141
- end
142
-
143
- # List all claim events
144
- #
145
- # @param [String] claim_id The unique identifier of the claim.
146
- # @return [Array<Hash>]
147
- #
148
- # @example
149
- # client.list_claim_events(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225")
150
- #
151
- def list_claim_events(id: nil, claim_id: nil)
152
- claim_id = claim_id || id
153
- get("claims/#{claim_id}/events")
154
- end
155
-
156
- # Create a claim attachment
157
- #
158
- # The file data can be passed using either +path+, +file+, +bytes+ or +base64+.
159
- #
160
- # @param [String] claim_id The unique identifier of the claim
161
- # @param [String] path The full path to the file's location
162
- # @param [File] file instance of a File object
163
- # @param [String] bytes The raw butes of the file
164
- # @param [String] base64 The base64 encoded file
165
- # @param [String] file_name The file's name (only required when not using +path+ or +file+)
166
- # @param [String] file_type The file's mime type (only required when using +base64+)
167
- # @param [String] description A description of the file
168
- # @return [Hash]
169
- #
170
- def create_claim_attachment(claim_id:, path: nil, file: nil, bytes: nil, base64: nil, file_name: nil, file_type: nil, description: '')
171
- data = if path
172
- claim_attachment_from_path(path)
173
- elsif file
174
- claim_attachment_from_file(file)
175
- elsif bytes
176
- raise ArgumentError.new("file_name is required when supplying bytes") unless file_name
177
- claim_attachment_from_bytes(bytes, file_name, file_type)
178
- elsif base64
179
- raise ArgumentError.new("file_name is required when supplying base64") unless file_name
180
- raise ArgumentError.new("file_type is required when supplying base64") unless file_type
181
- claim_attachment_from_base46(base64, file_name, file_type)
182
- else
183
- {}
184
- end.merge({description: description})
185
-
186
- post("claims/#{claim_id}/attachments", data)
187
- end
188
-
189
- private
190
- def claim_attachment_from_path(path)
191
- encoded_data = Base64.encode64(File.binread(path))
192
- file_name = File.basename(path)
193
-
194
- {
195
- file_base64: encoded_data,
196
- file_name: file_name,
197
- file_type: MimeMagic.by_magic(File.open(path)).type
198
- }
199
- end
200
-
201
- def claim_attachment_from_file(file)
202
- encoded_data = Base64.encode64(file.read)
203
-
204
- {
205
- file_base64: encoded_data,
206
- file_name: File.basename(file.path),
207
- file_type: MimeMagic.by_magic(file).type
208
- }
209
- end
210
-
211
- def claim_attachment_from_bytes(bytes, file_name, file_type)
212
- encoded_data = Base64.encode64(bytes)
213
-
214
- {
215
- file_base64: encoded_data,
216
- file_name: file_name,
217
- file_type: file_type || MimeMagic.by_magic(bytes).type
218
- }
219
- end
220
-
221
- def claim_attachment_from_base46(base64, file_name, file_type)
222
- {
223
- file_base64: base64,
224
- file_name: file_name,
225
- file_type: file_type
226
- }
227
- end
228
-
229
231
  end
230
- end
232
+ end