Module: RootInsurance::Api::Policy

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

Instance Method Summary collapse

Instance Method Details

#add_policy_beneficiary(policy_id:, id:, first_name:, last_name:, percentage:, cellphone: nil) ⇒ Hash

Add a benificiary to a policy

ID

type (string or symbol)

Either :id or :passport

number (string)

The id or passport number

country (string)

The ISO Alpha-2 country code of the country of the id/passport number.

Cellphone

number (string)

The cellphone number

country (string)

The ISO Alpha-2 country code of the country of the cellphone number.

Examples:

client.add_policy_beneficiary(
  policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
  first_name: "Jared"
  last_name:  "Dunn",
  id:         {type: :id, number: "8704094800082", country: "ZA"},
  percentage: 100)

Parameters:

  • policy_id (String)

    The unique identifier of the policy.

  • first_name (String)

    The beneficiary’s first name

  • last_name (String)

    The beneficiary’s last name

  • id (Hash)

    An hash containing the beneficiary’s identification number, type and country. See below.

  • percentage (Integer)

    An integer representing the percentage of a claim payout that the beneficiary should receive.

  • cellphone (String) (defaults to: nil)

    Hash containing beneficiary’s cellphone number and country. See below for details. (optional)

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/root_insurance/api/policy.rb', line 53

def add_policy_beneficiary(policy_id:, id:, first_name:, last_name:, percentage:, cellphone: nil)
  raise ArgumentError.new('id needs to be a hash') unless id.is_a? Hash

  data = {
    id:         id,
    first_name: first_name,
    last_name:  last_name,
    percentage: percentage,
    cellphone:  cellphone
  }.reject { |k, v| v.nil? }

  put("policies/#{policy_id}/beneficiaries", data)
end

#cancel_policy(id:, reason:) ⇒ Hash

Cancel a policy

Examples:

client.cancel_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", reason: "Not needed anymore")

Parameters:

  • id (String)

    The unique identifier of the policy

  • reason (String)

    A reason for why this policy is being cancelled.

Returns:

  • (Hash)


102
103
104
105
106
# File 'lib/root_insurance/api/policy.rb', line 102

def cancel_policy(id:, reason:)
  data = {reason: reason}

  post("policies/#{id}/cancel", data)
end

#get_policy(id:) ⇒ Hash

Get a policy

Examples:

client.get_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")

Parameters:

  • id (String)

    The unique identifier of the policy

Returns:

  • (Hash)


89
90
91
# File 'lib/root_insurance/api/policy.rb', line 89

def get_policy(id:)
  get("policies/#{id}")
end

#issue_policy(application_id:, app_data: nil) ⇒ Hash

Issue a policy

Examples:

client.issue_policy(
  application_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
  app_data:       {gadget_colour: "Space Grey"})

Parameters:

  • application_id (String)

    The unique identifier of the application.

  • app_data (Hash, nil) (defaults to: nil)

    An object containing additional custom data for the policy.

Returns:

  • (Hash)


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

def issue_policy(application_id:, app_data: nil)
  data = {
    application_id: application_id,
  }

  data.merge!(app_data: app_data) if app_data

  post(:policies, data)
end

#list_policies(id_number: nil) ⇒ Array<Hash>

List policies

Examples:

client.list_policies(id_number: "8704094800082")

Parameters:

  • id_number (String) (defaults to: nil)

    The National ID Number of the policyholder (optional)

Returns:

  • (Array<Hash>)


75
76
77
78
79
# File 'lib/root_insurance/api/policy.rb', line 75

def list_policies(id_number: nil)
  query = id_number ? {id_number: id_number} : nil

  get(:policies, query)
end

#list_policy_beneficiaries(id:) ⇒ Array<Hash>

List a policy’s bebeficiaries

Examples:

client.list_policy_beneficiaries(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")

Parameters:

  • id (String)

    The unique identifier of the policy

Returns:

  • (Array<Hash>)


148
149
150
# File 'lib/root_insurance/api/policy.rb', line 148

def list_policy_beneficiaries(id:)
  get("policies/#{id}/beneficiaries")
end

#list_policy_events(id:) ⇒ Array<Hash>

List all the events which are applicable to this policy.

Examples:

client.list_policy_events(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")

Parameters:

  • id (String)

    The unique identifier of the policy

Returns:

  • (Array<Hash>)


160
161
162
# File 'lib/root_insurance/api/policy.rb', line 160

def list_policy_events(id:)
  get("policies/#{id}/events")
end

#update_policy(id:, app_data:) ⇒ Hash

Update a policy. Currently, only updating the app_data object is supported

Examples:

app_data = {gadget_color: "Space Grey", has_screen_cover: true}
client.update_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", app_data: app_data)

Parameters:

  • id (String)

    The unique identifier of the policy

  • app_data (Hash)

    An object containing additional custom data for the policy.

Returns:

  • (Hash)


119
120
121
122
123
# File 'lib/root_insurance/api/policy.rb', line 119

def update_policy(id:, app_data:)
  data = {app_data: app_data}

  patch("policies/#{id}", data)
end

#update_policy_billing_amount(id:, billing_amount:) ⇒ Hash

Update a policy’s billing amount.

Examples:

client.update_policy_billing_amount(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", billing_amount: 45000)

Parameters:

  • id (String)

    The unique identifier of the policy

  • billing_amount (Integer)

    The billing amount to be set on the policy in cents.

Returns:

  • (Hash)


134
135
136
137
138
# File 'lib/root_insurance/api/policy.rb', line 134

def update_policy_billing_amount(id:, billing_amount:)
  data = {billing_amount: billing_amount}

  post("policies/#{id}/billing_amount", data)
end