Module: RootInsurance::Api::Claim

Included in:
Client
Defined in:
lib/root_insurance/api/claim.rb

Instance Method Summary collapse

Instance Method Details

#create_claim_attachment(claim_id:, path: nil, file: nil, bytes: nil, base64: nil, file_name: nil, file_type: nil, description: '') ⇒ Hash

Create a claim attachment

The file data can be passed using either path, file, bytes or base64.

Parameters:

  • claim_id (String)

    The unique identifier of the claim

  • path (String) (defaults to: nil)

    The full path to the file’s location

  • file (File) (defaults to: nil)

    instance of a File object

  • bytes (String) (defaults to: nil)

    The raw butes of the file

  • base64 (String) (defaults to: nil)

    The base64 encoded file

  • file_name (String) (defaults to: nil)

    The file’s name (only required when not using path or file)

  • file_type (String) (defaults to: nil)

    The file’s mime type (only required when using base64)

  • description (String) (defaults to: '')

    A description of the file

Returns:

  • (Hash)


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/root_insurance/api/claim.rb', line 171

def create_claim_attachment(claim_id:, path: nil, file: nil, bytes: nil, base64: nil, file_name: nil, file_type: nil, description: '')
  data = if path
    claim_attachment_from_path(path)
  elsif file
    claim_attachment_from_file(file)
  elsif bytes
    raise ArgumentError.new("file_name is required when supplying bytes") unless file_name
    claim_attachment_from_bytes(bytes, file_name, file_type)
  elsif base64
    raise ArgumentError.new("file_name is required when supplying base64") unless file_name
    raise ArgumentError.new("file_type is required when supplying base64") unless file_type
    claim_attachment_from_base46(base64, file_name, file_type)
  else
    {}
  end.merge({description: description})

  post("claims/#{claim_id}/attachments", data)
end

#get_claim(id:) ⇒ Hash

Get a specific claim

Examples:

client.get_claim(id: 'd3d13c48-4dc3-4816-8d01-de3215878225')

Parameters:

  • id (String)

    The claim’s id

Returns:

  • (Hash)


32
33
34
# File 'lib/root_insurance/api/claim.rb', line 32

def get_claim(id:)
  get("claims/#{id}")
end

Link a claim and a policy

Examples:

client.link_policy_to_claim(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225", policy_id: "8349345c-a6c5-4bf9-8ebb-6bbfc1628715")

Parameters:

  • claim_id (String)

    The unique identifier of the claim.

  • policy_id (String)

    The unique identifier of the policy.

Returns:

  • (Hash)


122
123
124
125
126
# File 'lib/root_insurance/api/claim.rb', line 122

def link_policy_to_claim(claim_id:, policy_id:)
  data = {policy_id: policy_id}

  post("claims/#{claim_id}/policy", data)
end

Link a claim and a policy holder

Examples:

client.link_policyholder_to_claim(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225", policyholder_id: "808f75dc-cb8a-4808-93e9-e13f8eea84de")

Parameters:

  • claim_id (String)

    The unique identifier of the claim.

  • policyholder_id (String)

    The unique identifier of the policy holder.

Returns:

  • (Hash)


138
139
140
141
142
# File 'lib/root_insurance/api/claim.rb', line 138

def link_policyholder_to_claim(claim_id:, policyholder_id:)
  data = {policyholder_id: policyholder_id}

  post("claims/#{claim_id}/policyholder", data)
end

#list_claim_events(id: nil, claim_id: nil) ⇒ Array<Hash>

List all claim events

Examples:

client.list_claim_events(claim_id: "d3d13c48-4dc3-4816-8d01-de3215878225")

Parameters:

  • claim_id (String) (defaults to: nil)

    The unique identifier of the claim.

Returns:

  • (Array<Hash>)


152
153
154
155
# File 'lib/root_insurance/api/claim.rb', line 152

def list_claim_events(id: nil, claim_id: nil)
  claim_id = claim_id || id
  get("claims/#{claim_id}/events")
end

#list_claims(status: nil, approval: nil) ⇒ Array<Hash>

List all claims

Examples:

client.list_claims(status: :open)

Parameters:

  • status (String, Symbol) (defaults to: nil)

    Either :open, :closed, :finalized, :acknowledged or :all. If omitted defaults to :all

  • approval (String, Symbol) (defaults to: nil)

    Either :approved, :repudiated, :‘ex-gratia’, :‘no-claim’, :pending or :all. If omitted defaults to :all

Returns:

  • (Array<Hash>)


16
17
18
19
20
21
22
23
# File 'lib/root_insurance/api/claim.rb', line 16

def list_claims(status: nil, approval: nil)
  query = {
    claim_status:    status,
    approval_status: approval
  }.reject { |key, value| value.nil? }

  get(:claims, query)
end

#open_claim(policy_id: nil, policyholder_id: nil, incident_type: nil, incident_cause: nil, incident_date: nil, app_data: nil, claimant: nil, requested_amount: nil) ⇒ Hash

Open a claim

Claimant

first_name (string)

The name of the claimant

last_name (string)

The last name of the claimant

email (string)

The claimant’s email address

cellphone (string)

The claimant’s cellphone number

Examples:

client.open_claim(
  policy_id: "8349345c-a6c5-4bf9-8ebb-6bbfc1628715",
  incident_type: "Theft",
  incident_cause: "Device stolen during burglary",
  incident_date: "2017-10-16T10:12:02.872Z",
  requested_amount: 13000000,
  app_data: {
    key1: "value 1"
    key2: "value 2"})

Parameters:

  • policy_id (String) (defaults to: nil)

    The ID of the policy under which the claim is being made. (optional)

  • policyholder_id (String) (defaults to: nil)

    The ID of the policyholder for whom the claim is being made. (optional)

  • incident_type (String) (defaults to: nil)

    A description of the incident type. (optional)

  • incident_cause (String) (defaults to: nil)

    A description of the cause of the incident. (optional)

  • incident_date (String) (defaults to: nil)

    The date on the which the incident occured. (optional)

  • app_data (String) (defaults to: nil)

    An object containing additional custom data for the claim. (optional)

  • claimant (String) (defaults to: nil)

    Object containing claimants’s first name, last name, email and/or cellphone. See below for details. (optional)

  • requested_amount (String) (defaults to: nil)

    The requested payout amount (in cents) for the claim. (optional)

Returns:

  • (Hash)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/root_insurance/api/claim.rb', line 65

def open_claim(policy_id: nil, policyholder_id: nil, incident_type: nil, incident_cause: nil,
              incident_date: nil, app_data: nil, claimant: nil, requested_amount: nil)
  data = {
    policy_id:        policy_id,
    policyholder_id:  policyholder_id,
    incident_type:    incident_type,
    incident_cause:   incident_cause,
    incident_date:    incident_date,
    app_data:         app_data,
    claimant:         claimant,
    requested_amount: requested_amount
  }.reject { |key, value| value.nil? }

  post(:claims, data)
end

#update_claim(claim_id:, incident_type: nil, incident_cause: nil, incident_date: nil, app_data: nil, requested_amount: nil) ⇒ Hash

Update a claim

Examples:

client.update_claim(
  claim_id:         "d3d13c48-4dc3-4816-8d01-de3215878225",
  incident_type:    "Theft",
  incident_cause:   "Device stolen during burglary",
  incident_date:    "2017-10-16T10:12:02.872Z",
  app_data:         {key3: "value 3"},
  requested_amount: 13000000)

Parameters:

  • claim_id (String)

    The unique identifier of the claim.

  • incident_type (String) (defaults to: nil)

    A description of the incident type. (optional)

  • incident_cause (String) (defaults to: nil)

    A description of the cause of the incident. (optional)

  • incident_date (String) (defaults to: nil)

    The date on the which the incident occured. (optional)

  • app_data (String) (defaults to: nil)

    An object containing additional custom data for the claim. (optional)

  • requested_amount (String) (defaults to: nil)

    The requested payout amount (in cents) for the claim. (optional)

Returns:

  • (Hash)


100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/root_insurance/api/claim.rb', line 100

def update_claim(claim_id:, incident_type: nil, incident_cause: nil, incident_date: nil,
                app_data: nil, requested_amount: nil)
  data = {
    incident_type:    incident_type,
    incident_cause:   incident_cause,
    incident_date:    incident_date,
    app_data:         app_data,
    requested_amount: requested_amount
  }.reject { |key, value| value.nil? }

  patch("claims/#{claim_id}", data)
end