Module: RootInsurance::Api::Policyholder

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

Instance Method Summary collapse

Instance Method Details

#create_policyholder(id:, first_name:, last_name:, email: nil, date_of_birth: nil, cellphone: nil, app_data: nil) ⇒ Hash

Create a policy holder

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.create_policy_holder(
  id:         {type: :id, number: "6801015800084", country: "ZA"},
  first_name: 'Erlich',
  last_name:  'Bachman',
  email:      '[email protected]',
  app_data:   {company: 'Aviato'})

Parameters:

  • id (Hash)

    Hash containing policyholder’s identification number, type and country. See below for details.

  • first_name (String)

    Policyholder’s legal first name.

  • last_name (String)

    Policyholder’s legal last name.

  • email (String) (defaults to: nil)

    Policyholder’s contact email address. (Optional)

  • date_of_birth (String) (defaults to: nil)

    The policyholder’s date of birth in the format YYYYMMDD. This field may be omitted if the policyholder’s id type is id.

  • cellphone (Hash) (defaults to: nil)

    Hash containing policyholder’s cellphone number and country. See below for details. (Optional)

  • app_data (Hash) (defaults to: nil)

    A hash containing additional custom data for the policy holder.

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/root_insurance/api/policyholder.rb', line 32

def create_policyholder(id:, first_name:, last_name:, email: nil, date_of_birth: nil, cellphone: nil, app_data: 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,
    date_of_birth: date_of_birth,
    email:         email,
    cellphone:     cellphone,
    app_data:      app_data
  }.reject { |key, value| value.nil? }

  post(:policyholders, data)
end

#get_policyholder(id:, included_objects: nil) ⇒ Hash

Get a policy holder

Examples:

client.get_policyholder(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", included_objects: :policies)

Parameters:

  • id (String)

    The unique identifier of the policy holder

  • included_objects (Array<String, Symbol>, String, Symbol) (defaults to: nil)

    An optional list, or single item, of underlying objects to include, e.g. ?include=policies. Currently, only policies is supported, which will include all policies owned by the policyholder.

Returns:

  • (Hash)


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

def get_policyholder(id:, included_objects: nil)
  query = {
    include:   format_included_objects(included_objects),
  }.reject { |_, v| v.nil? }

  get("policyholders/#{id}", query)
end

#list_policyholder_events(id:) ⇒ Array<Hash>

List all the events which are applicable to this policy holder.

Examples:

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

Parameters:

  • id (String)

    The unique identifier of the policy holder

Returns:

  • (Array<Hash>)


118
119
120
# File 'lib/root_insurance/api/policyholder.rb', line 118

def list_policyholder_events(id:)
  get("policyholders/#{id}/events")
end

#list_policyholders(id_number: nil, included_objects: nil) ⇒ Array<Hash>

List policy holders

Examples:

client.list_policyholders(id_number: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", included_objects: :policies)

Parameters:

  • id_number (Hash) (defaults to: nil)

    An optional ID or passport number to filter by.

  • included_objects (Array<String, Symbol>, String, Symbol) (defaults to: nil)

    An optional list, or single item, of underlying objects to include, e.g. ?include=policies. Currently, only policies is supported, which will include all policies owned by the policyholder.

Returns:

  • (Array<Hash>)


56
57
58
59
60
61
62
63
# File 'lib/root_insurance/api/policyholder.rb', line 56

def list_policyholders(id_number: nil, included_objects: nil)
  query = {
    include:   format_included_objects(included_objects),
    id_number: id_number
  }.reject { |_, v| v.nil? }

  get(:policyholders, query)
end

#update_policyholder(id:, email: nil, cellphone: nil, app_data: nil) ⇒ Hash

Update a policy holder

Cellphone

number (string)

The cellphone number

country (string)

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

Examples:

client.update_policyholders(
  id: 'bf1ada91-eecb-4f47-9bfa-1258bb1e0055',
  cellphone: {number: '07741011337', country: 'ZA'},
  app_data:  {company: 'Pied Piper'})

Parameters:

  • id (String)

    The unique identifier of the policy holder

  • email (String) (defaults to: nil)

    Policyholder’s contact email address. (Optional)

  • cellphone (Hash) (defaults to: nil)

    Hash containing policyholder’s cellphone number and country. See below for details. (Optional)

  • app_data (Hash) (defaults to: nil)

    A hash containing additional custom data for the policy holder.

Returns:

  • (Hash)


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

def update_policyholder(id:, email: nil, cellphone: nil, app_data: nil)
  data = {
    email:     email,
    cellphone: cellphone,
    app_data:  app_data
  }.reject { |key, value| value.nil? }

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