Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@ Root’s developers and our community are expected to abide by the [Contributor
```
pip install rootsdk
```
or
or for active development
```
git clone git@github.com:root-community/root-insurance-python.git
pip install -e root-insurance-python
```

## Environment Variables
```
ROOT_APP_ID
ROOT_APP_SECRET
ROOT_API_KEY
```

## Code

```python
from root import insurance
from root.insurance import InsuranceClient,GadgetCover

client = insurance.Client()
client = InsuranceClient(cover=GadgetCover)
phone_brands = client.gadgets.list_phone_brands()

```
Expand Down
3 changes: 1 addition & 2 deletions env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# ENV variables for app
export ROOT_APP_SECRET="__replace__";
export ROOT_APP_ID="__replace__";
export ROOT_API_KEY="__replace__";
45 changes: 45 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from pprint import pprint
from root.insurance import InsuranceClient, GadgetCover, Policyholder, Beneficiary


def main():
# 0. Create an insurance client
client = InsuranceClient(cover=GadgetCover)
phone = "iPhone 6 Plus 128GB LTE"
phone_value = client.quotes.get_phone_value(phone)
print("The value of a {} is R{}".format(phone, phone_value))
# 1. Issue a quote for the thing to be insured.
quotes_data = client.quotes.generate(model_name=phone)
print("The quotes for {} are".format(phone))
pprint(quotes_data)

# 2. Create a policy holder
policyholder = Policyholder(Policyholder.identification("id", "6801015800084", "ZA"), "Erlich", "Bachman")
policyholder_data = client.policyholders.create(policyholder=policyholder)
print("Person holding policy is")
pprint(policyholder_data)
# 3. Create an application. For this, a generated quote is required.
chosen_quote = quotes_data[0]
chosen_quote_id = chosen_quote['quote_package_id']
policyholder_id = policyholder_data['policyholder_id']
application_data = client.applications.create(policyholder_id=policyholder_id,
quote_package_id=chosen_quote_id,
monthly_premium=chosen_quote['suggested_premium'],
serial_number='random_serial')
print("Application data to insure {} is ".format(phone))
pprint(application_data)
# 4. Issue policy, if application is approved (this check is not done here)
policy_data = client.policies.issue(application_id=application_data['application_id'])
print("Congratulations, your policy looks as follows:")
pprint(policy_data)
# 5. Add beneficiaries (if supported, which root_gadgets do not)
# updated_policy_data = client.policies.add_beneficiary(policy_data['policy_id'],
# [Beneficiary(
# Policyholder.identification("id", "6801015800084", "ZA"),
# "Erlich", "Bachman", percentage=100.0)])
# 6. Link credit card
# See API docs https://app.root.co.za/docs/insurance/api#linking-credit-card


if __name__ == "__main__":
main()
12 changes: 0 additions & 12 deletions root/exceptions.py

This file was deleted.

240 changes: 0 additions & 240 deletions root/insurance.py

This file was deleted.

3 changes: 3 additions & 0 deletions root/insurance/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from root.insurance.insurance import InsuranceClient
from root.insurance.policyholder import Policyholder, Beneficiary
from root.insurance.resources import GadgetCover, TermCover, FuneralCover
34 changes: 34 additions & 0 deletions root/insurance/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class RootException(Exception):
"""Base class for exceptions in this module."""
pass


class RootCredentialsException(RootException):
"""Raised when library/wrapper is used without credentials set in the env variables.

Attributes:
message -- explanation of why the specific transition is not allowed
"""

def __init__(self, message="No ROOT_API_KEY set in environment variables"):
print(message)


class RootIdentificationException(RootException):
"""Raised when given identification is not syntactically correct
Attributes:
message -- explanation of why syntax was wrong
"""

def __init__(self, message="identification provided was ill-formed"):
print(message)


class RootInsufficientDataException(RootException):
"""Raised when not enough data is given to a function/method/api call
Attributes:
message -- explanation of why the data was not fully-formed
"""

def __init__(self, message="not all data fields present"):
print(message)
Loading