root_insurance 1.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +48 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +34 -0
- data/Rakefile +8 -0
- data/lib/root_insurance/api/application.rb +14 -0
- data/lib/root_insurance/api/call.rb +15 -0
- data/lib/root_insurance/api/claim.rb +103 -0
- data/lib/root_insurance/api/payment.rb +35 -0
- data/lib/root_insurance/api/policy.rb +60 -0
- data/lib/root_insurance/api/policy_holder.rb +39 -0
- data/lib/root_insurance/api/quote.rb +59 -0
- data/lib/root_insurance/client.rb +89 -0
- data/lib/root_insurance/exceptions.rb +4 -0
- data/lib/root_insurance/version.rb +3 -0
- data/lib/root_insurance.rb +8 -0
- data/root_insurance.gemspec +31 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ece43ed608f56cabd17c84d89b7c5257f1967026
|
4
|
+
data.tar.gz: 8950e5c2fa3e06fc78e28df32cd3ed893bb9b16c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e055d002cc24644191412373245c70c2b96d32ab09e505775eff9b2f5d49608918e54b3eafc073ebf1a51592a25474d52a82bb7a13aa045fd7590570039fa64
|
7
|
+
data.tar.gz: 2a09007593a4136246771c9d615c7b234fcbe308ba4c8ae08831865cd989c11e1295ab5f08bcfb727e4fe277c2becb10fd624efc2312eab4c1678a08f4f32e7c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
# 1.1.1 - Release date: 2018-11-05
|
4
|
+
* Fix gemspec to allow publishing to rubygems.org
|
5
|
+
|
6
|
+
|
7
|
+
# 1.1.0 - Release date: 2018-11-05
|
8
|
+
* Added support for claim attachments
|
9
|
+
* Added support to get calls
|
10
|
+
* Added support to add and attach payment methods
|
11
|
+
* When issuing a polidy app data can be attached
|
12
|
+
|
13
|
+
|
14
|
+
# 1.0.0 - Release date: 2018-09-05
|
15
|
+
* Renamed gem to root_insurance
|
16
|
+
* Removed unnecessarily complicated module nesting (it's now just RootInsurance)
|
17
|
+
* Removed dependency on 'root' gem
|
18
|
+
|
19
|
+
|
20
|
+
# 0.2.1 - Release date: 2018-24-01
|
21
|
+
* Spec cleanups
|
22
|
+
|
23
|
+
|
24
|
+
# 0.2.0 - Release date: 2017-14-12
|
25
|
+
* Quote api also works for term and funeral insurance
|
26
|
+
|
27
|
+
|
28
|
+
# 0.1.0 - Release date: 2017-13-12
|
29
|
+
* Added events endpoints for policy holders, policies and claims
|
30
|
+
* Fixed method naming inconsistency (it's actually a breaking change, but yolo)
|
31
|
+
* DRYed up some specs
|
32
|
+
|
33
|
+
|
34
|
+
# 0.0.4 - Release date: 2017-13-12
|
35
|
+
* Fixed claim list filtering
|
36
|
+
|
37
|
+
|
38
|
+
# 0.0.3 - Release date: 2017-13-12
|
39
|
+
* Fix dependency ordering
|
40
|
+
|
41
|
+
|
42
|
+
# 0.0.2 - Release date: 2017-13-12
|
43
|
+
* Fix broken version require
|
44
|
+
|
45
|
+
|
46
|
+
# 0.0.1 - Release date: 2017-13-12
|
47
|
+
* Initial release
|
48
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@root.co.za. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Root Community
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Root Insurance Ruby
|
2
|
+
|
3
|
+
[](https://travis-ci.org/root-community/root-insurance-ruby)
|
4
|
+
|
5
|
+
Root is a company built by developers for developers. Open Source Software is part of our culture. We open-source as much of our codebase as we can.
|
6
|
+
|
7
|
+
Our SDKs are community maintained. (because we’re not experts in go, or lolcode, or ruby, or swift or rust or any of the plethora of wonderful languages living out in the wild).
|
8
|
+
|
9
|
+
This repo for the Ruby Insurance SDK is currently a simple wrapper around Root's Insurance API. The full API documentation can be found [here](https://app.root.co.za/docs/insurance/api).
|
10
|
+
|
11
|
+
For help and support, please reach out to us on the Root Club Slack.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'root_insurance'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
See the [wiki](https://github.com/root-community/root-insurance-ruby/wiki).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
If you wish to contribute to this repository, please fork it and send a PR our way.
|
31
|
+
|
32
|
+
## Code of Conduct
|
33
|
+
Root’s developers and our community are expected to abide by the [Contributor Covenant Code of Conduct](https://github.com/root-community/root-insurance-ruby/tree/master/CODE_OF_CONDUCT.md).
|
34
|
+
Play nice.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module RootInsurance::Api
|
2
|
+
module Application
|
3
|
+
def create_application(policyholder_id:, quote_package_id:, monthly_premium:, serial_number: nil)
|
4
|
+
data = {
|
5
|
+
policyholder_id: policyholder_id,
|
6
|
+
quote_package_id: quote_package_id,
|
7
|
+
monthly_premium: monthly_premium,
|
8
|
+
serial_number: serial_number
|
9
|
+
}
|
10
|
+
|
11
|
+
post(:applications, data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'mimemagic'
|
2
|
+
|
3
|
+
module RootInsurance::Api
|
4
|
+
module Claim
|
5
|
+
def list_claims(status: nil, approval: nil)
|
6
|
+
query = {
|
7
|
+
claim_status: status,
|
8
|
+
approval_status: approval
|
9
|
+
}.reject { |key, value| value.nil? }
|
10
|
+
|
11
|
+
get(:claims, query)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_claim(id:)
|
15
|
+
get("claims/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def open_claim(policy_id: nil, policy_holder_id: nil)
|
19
|
+
data = {
|
20
|
+
policy_id: policy_id,
|
21
|
+
policy_holder_id: policy_holder_id
|
22
|
+
}.reject { |key, value| value.nil? }
|
23
|
+
|
24
|
+
post(:claims, data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def link_policy_to_claim(claim_id:, policy_id:)
|
28
|
+
data = {policy_id: policy_id}
|
29
|
+
|
30
|
+
post("claims/#{claim_id}/policy", data)
|
31
|
+
end
|
32
|
+
|
33
|
+
def link_policyholder_to_claim(claim_id:, policyholder_id:)
|
34
|
+
data = {policyholder_id: policyholder_id}
|
35
|
+
|
36
|
+
post("claims/#{claim_id}/policyholder", data)
|
37
|
+
end
|
38
|
+
|
39
|
+
def list_claim_events(id:)
|
40
|
+
get("claims/#{id}/events")
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_claim_attachment(claim_id:, path: nil, file: nil, bytes: nil, base64: nil, file_name: nil, file_type: nil, description: '')
|
44
|
+
data = if path
|
45
|
+
claim_attachment_from_path(path)
|
46
|
+
elsif file
|
47
|
+
claim_attachment_from_file(file)
|
48
|
+
elsif bytes
|
49
|
+
raise ArgumentError.new("file_name is required when supplying bytes") unless file_name
|
50
|
+
claim_attachment_from_bytes(bytes, file_name, file_type)
|
51
|
+
elsif base64
|
52
|
+
raise ArgumentError.new("file_name is required when supplying base64") unless file_name
|
53
|
+
raise ArgumentError.new("file_type is required when supplying base64") unless file_type
|
54
|
+
claim_attachment_from_base46(base64, file_name, file_type)
|
55
|
+
else
|
56
|
+
{}
|
57
|
+
end.merge({description: description})
|
58
|
+
|
59
|
+
post("claims/#{claim_id}/attachments", data)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def claim_attachment_from_path(path)
|
64
|
+
encoded_data = Base64.encode64(File.binread(path))
|
65
|
+
file_name = File.basename(path)
|
66
|
+
|
67
|
+
{
|
68
|
+
file_base64: encoded_data,
|
69
|
+
file_name: file_name,
|
70
|
+
file_type: MimeMagic.by_magic(File.open(path)).type
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def claim_attachment_from_file(file)
|
75
|
+
encoded_data = Base64.encode64(file.read)
|
76
|
+
|
77
|
+
{
|
78
|
+
file_base64: encoded_data,
|
79
|
+
file_name: File.basename(file.path),
|
80
|
+
file_type: MimeMagic.by_magic(file).type
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def claim_attachment_from_bytes(bytes, file_name, file_type)
|
85
|
+
encoded_data = Base64.encode64(bytes)
|
86
|
+
|
87
|
+
{
|
88
|
+
file_base64: encoded_data,
|
89
|
+
file_name: file_name,
|
90
|
+
file_type: file_type || MimeMagic.by_magic(bytes).type
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def claim_attachment_from_base46(base64, file_name, file_type)
|
95
|
+
{
|
96
|
+
file_base64: base64,
|
97
|
+
file_name: file_name,
|
98
|
+
file_type: file_type
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RootInsurance::Api
|
2
|
+
module Payment
|
3
|
+
def create_payment_method(policy_holder_id:, type: 'debit_order', bank_details: {}, policy_ids: nil)
|
4
|
+
validate_bank_details(bank_details)
|
5
|
+
|
6
|
+
data = {
|
7
|
+
type: type,
|
8
|
+
bank_details: bank_details
|
9
|
+
}
|
10
|
+
|
11
|
+
if policy_ids && policy_ids.is_a?(Array)
|
12
|
+
data.merge!(policy_ids: policy_ids)
|
13
|
+
elsif policy_ids && policy_ids.is_a?(String)
|
14
|
+
data.merge!(policy_ids: [policy_ids])
|
15
|
+
end
|
16
|
+
|
17
|
+
post("policyholders/#{policy_holder_id}/payment-methods", data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def link_payment_method(policy_id:, payment_method_id:)
|
21
|
+
data = {payment_method_id: payment_method_id}
|
22
|
+
|
23
|
+
put("policies/#{policy_id}/payment-method", data)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def validate_bank_details(bank_details)
|
28
|
+
[:first_name, :last_name, :bank, :branch_code, :account_number].each do |key|
|
29
|
+
if !(bank_details[key] || bank_details[key.to_sym])
|
30
|
+
raise ArgumentError.new("Bank details need to include #{key}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RootInsurance::Api
|
2
|
+
module Policy
|
3
|
+
def issue_policy(application_id:, app_data: nil)
|
4
|
+
data = {
|
5
|
+
application_id: application_id,
|
6
|
+
}
|
7
|
+
|
8
|
+
data.merge!(app_data: app_data) if app_data
|
9
|
+
|
10
|
+
post(:policies, data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_policy_beneficiary(policy_id:, id:, first_name:, last_name:, percentage:)
|
14
|
+
raise ArgumentError.new('id needs to be a hash') unless id.is_a? Hash
|
15
|
+
|
16
|
+
data = {
|
17
|
+
id: id,
|
18
|
+
first_name: first_name,
|
19
|
+
last_name: last_name,
|
20
|
+
percentage: percentage
|
21
|
+
}
|
22
|
+
|
23
|
+
put("policies/#{policy_id}/beneficiaries", data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def list_policies
|
27
|
+
get(:policies)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_policy(id:)
|
31
|
+
get("policies/#{id}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def cancel_policy(id:, reason:)
|
35
|
+
data = {reason: reason}
|
36
|
+
|
37
|
+
post("policies/#{id}/cancel", data)
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_policy(id:, quote_package_id:)
|
41
|
+
data = {quote_package_id: quote_package_id}
|
42
|
+
|
43
|
+
post("policies/#{id}/replace", data)
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_policy_billing_amount(id:, billing_amount:)
|
47
|
+
data = {billing_amount: billing_amount}
|
48
|
+
|
49
|
+
post("policies/#{id}/billing_amount", data)
|
50
|
+
end
|
51
|
+
|
52
|
+
def list_policy_beneficiaries(id:)
|
53
|
+
get("policies/#{id}/beneficiaries")
|
54
|
+
end
|
55
|
+
|
56
|
+
def list_policy_events(id:)
|
57
|
+
get("policies/#{id}/events")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RootInsurance::Api
|
2
|
+
module PolicyHolder
|
3
|
+
def create_policy_holder(id:, first_name:, last_name:, email: nil, date_of_birth: nil, cellphone: nil)
|
4
|
+
raise ArgumentError.new('id needs to be a hash') unless id.is_a? Hash
|
5
|
+
|
6
|
+
data = {
|
7
|
+
id: id,
|
8
|
+
first_name: first_name,
|
9
|
+
last_name: last_name,
|
10
|
+
date_of_birth: date_of_birth,
|
11
|
+
email: email,
|
12
|
+
cellphone: cellphone
|
13
|
+
}.reject { |key, value| value.nil? }
|
14
|
+
|
15
|
+
post(:policyholders, data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def list_policy_holders
|
19
|
+
get(:policyholders)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_policy_holder(id:)
|
23
|
+
get("policyholders/#{id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_policy_holder(id:, email: nil, cellphone: nil)
|
27
|
+
data = {
|
28
|
+
email: email,
|
29
|
+
cellphone: cellphone
|
30
|
+
}.reject { |key, value| value.nil? }
|
31
|
+
|
32
|
+
patch("policyholders/#{id}", data)
|
33
|
+
end
|
34
|
+
|
35
|
+
def list_policy_holder_events(id:)
|
36
|
+
get("policyholders/#{id}/events")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module RootInsurance::Api
|
2
|
+
module Quote
|
3
|
+
def create_quote(opts={})
|
4
|
+
type = opts[:type]
|
5
|
+
|
6
|
+
case type.to_sym
|
7
|
+
when :root_gadgets
|
8
|
+
create_gadget_quote(opts)
|
9
|
+
when :root_term
|
10
|
+
create_term_quote(opts)
|
11
|
+
when :root_funeral
|
12
|
+
create_funeral_quote(opts)
|
13
|
+
else
|
14
|
+
raise ArgumentError("Unknown quote type: #{type}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def list_gadget_models
|
19
|
+
get('gadgets/models')
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def create_gadget_quote(opts)
|
24
|
+
data = {
|
25
|
+
type: :root_gadgets,
|
26
|
+
model_name: opts[:model_name]
|
27
|
+
}
|
28
|
+
|
29
|
+
post(:quotes, data)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_term_quote(opts)
|
33
|
+
data = {
|
34
|
+
type: :root_term,
|
35
|
+
cover_amount: opts[:cover_amount],
|
36
|
+
cover_period: opts[:cover_period],
|
37
|
+
education_status: opts[:education_status],
|
38
|
+
smoker: opts[:smoker],
|
39
|
+
gender: opts[:gender],
|
40
|
+
age: opts[:age],
|
41
|
+
basic_income_per_month: opts[:basic_income_per_month],
|
42
|
+
}
|
43
|
+
|
44
|
+
post(:quotes, data)
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_funeral_quote(opts)
|
48
|
+
data = {
|
49
|
+
type: :root_funeral,
|
50
|
+
cover_amount: opts[:cover_amount],
|
51
|
+
has_spouse: opts[:has_spouse],
|
52
|
+
number_of_children: opts[:number_of_children],
|
53
|
+
extended_family_ages: opts[:extended_family_ages]
|
54
|
+
}
|
55
|
+
|
56
|
+
post(:quotes, data)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
require 'root_insurance/api/quote'
|
4
|
+
require 'root_insurance/api/policy_holder'
|
5
|
+
require 'root_insurance/api/application'
|
6
|
+
require 'root_insurance/api/policy'
|
7
|
+
require 'root_insurance/api/claim'
|
8
|
+
require 'root_insurance/api/call'
|
9
|
+
require 'root_insurance/api/payment'
|
10
|
+
|
11
|
+
class RootInsurance::Client
|
12
|
+
include RootInsurance::Api::Quote
|
13
|
+
include RootInsurance::Api::PolicyHolder
|
14
|
+
include RootInsurance::Api::Application
|
15
|
+
include RootInsurance::Api::Policy
|
16
|
+
include RootInsurance::Api::Claim
|
17
|
+
include RootInsurance::Api::Call
|
18
|
+
include RootInsurance::Api::Payment
|
19
|
+
|
20
|
+
def initialize(app_id, app_secret, env=nil)
|
21
|
+
@app_id = app_id
|
22
|
+
@app_secret = app_secret
|
23
|
+
@env = env || :sandbox
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def get(entity, query=nil)
|
28
|
+
response = HTTParty.get("#{api_root}/#{entity}",
|
29
|
+
query: query || {},
|
30
|
+
basic_auth: auth)
|
31
|
+
|
32
|
+
parse_response(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def post(entity, data)
|
36
|
+
response = HTTParty.post("#{api_root}/#{entity}",
|
37
|
+
body: data.to_json,
|
38
|
+
basic_auth: auth,
|
39
|
+
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
40
|
+
|
41
|
+
parse_response(response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def put(entity, data)
|
45
|
+
response = HTTParty.put("#{api_root}/#{entity}",
|
46
|
+
body: data.to_json,
|
47
|
+
basic_auth: auth,
|
48
|
+
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
49
|
+
|
50
|
+
parse_response(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
def patch(entity, data)
|
54
|
+
response = HTTParty.patch("#{api_root}/#{entity}",
|
55
|
+
body: data.to_json,
|
56
|
+
basic_auth: auth,
|
57
|
+
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
58
|
+
|
59
|
+
parse_response(response)
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_response(response)
|
63
|
+
parsed = JSON.parse(response.body)
|
64
|
+
|
65
|
+
case response.code
|
66
|
+
when 200
|
67
|
+
parsed
|
68
|
+
when 400
|
69
|
+
raise RootInsurance::InputError.new(error_message(parsed))
|
70
|
+
when 401, 403
|
71
|
+
raise RootInsurance::AuthenticationError.new(error_message(parsed))
|
72
|
+
else
|
73
|
+
raise error_message(parsed)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def auth
|
78
|
+
{username: @app_id, password: @app_secret}
|
79
|
+
end
|
80
|
+
|
81
|
+
def api_root
|
82
|
+
@env == :production ? "https://api.root.co.za/v1/insurance" : "https://sandbox.root.co.za/v1/insurance"
|
83
|
+
end
|
84
|
+
|
85
|
+
def error_message(response_body)
|
86
|
+
response_body["error"] || response_body["message"]
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "root_insurance/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "root_insurance"
|
8
|
+
spec.version = RootInsurance::VERSION
|
9
|
+
spec.authors = ["Root Wealth"]
|
10
|
+
spec.email = ["hello@root.co.za"]
|
11
|
+
|
12
|
+
spec.summary = "Root Insurance API client"
|
13
|
+
spec.description = "Root Insurance API client"
|
14
|
+
spec.homepage = "https://github.com/root-community/root-insurance-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'httparty'
|
25
|
+
spec.add_dependency 'mimemagic'
|
26
|
+
spec.add_development_dependency "semvergen", "~> 1.9"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "webmock", "~> 3.1.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: root_insurance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Root Wealth
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mimemagic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: semvergen
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.15'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.15'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.1.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.1.0
|
111
|
+
description: Root Insurance API client
|
112
|
+
email:
|
113
|
+
- hello@root.co.za
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CHANGELOG.md
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- lib/root_insurance.rb
|
128
|
+
- lib/root_insurance/api/application.rb
|
129
|
+
- lib/root_insurance/api/call.rb
|
130
|
+
- lib/root_insurance/api/claim.rb
|
131
|
+
- lib/root_insurance/api/payment.rb
|
132
|
+
- lib/root_insurance/api/policy.rb
|
133
|
+
- lib/root_insurance/api/policy_holder.rb
|
134
|
+
- lib/root_insurance/api/quote.rb
|
135
|
+
- lib/root_insurance/client.rb
|
136
|
+
- lib/root_insurance/exceptions.rb
|
137
|
+
- lib/root_insurance/version.rb
|
138
|
+
- root_insurance.gemspec
|
139
|
+
homepage: https://github.com/root-community/root-insurance-ruby
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.4.8
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Root Insurance API client
|
163
|
+
test_files: []
|