alfa_insurance 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/alfa_insurance.gemspec +1 -0
- data/lib/alfa_insurance/calculate_response.rb +17 -4
- data/lib/alfa_insurance/create_response.rb +0 -18
- data/lib/alfa_insurance/find_response.rb +20 -11
- data/lib/alfa_insurance/response.rb +17 -0
- data/lib/alfa_insurance/version.rb +1 -1
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 036ece7ad59c8afea309a75ed9c109c27c666963290b6b10c2e47de8609a38d1
|
4
|
+
data.tar.gz: c21cc073ff5ab7b9c1548f632c006f8c977f48d528a41623db3563916bf7906f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb1aa7b122b8932bb1e37fdaabeb8f086419cc86e992739d37cc1503d1483e61ae882dfe558a34aca3ca28abfab65065fcadca115f2a1d29d0e135507d7978b
|
7
|
+
data.tar.gz: 92bc427be8abc379c298bf56b8a0f2ced301545528cab85cb3fcbdb01a569475549c0cfedba670d6d3ff6a33f523c7086d71e7889535984c634b3917344cec03
|
data/README.md
CHANGED
@@ -29,12 +29,12 @@ Or install it yourself as:
|
|
29
29
|
response.risk_value
|
30
30
|
```
|
31
31
|
|
32
|
-
Все ответы сервера поддерживают метод success? и если он возвращает false, содержат код и описание ошибки в полях error_code и error_description.
|
32
|
+
Все ответы сервера поддерживают метод success? и если он возвращает false, содержат код и описание ошибки в полях error_code и error_description.
|
33
33
|
|
34
34
|
Описание методов:
|
35
35
|
### calculate
|
36
36
|
|
37
|
-
Принимает на вход стоимость билета (тип Money, или Float), возвращает структуру CalculateResponse с полями cost, risk_value (денежные) и
|
37
|
+
Принимает на вход стоимость билета (тип Money, или Float), возвращает структуру CalculateResponse с полями cost, risk_value (денежные) и массивом строк risk_types, где содержатся коды покрываемых рисков. Расчет осуществляется без учета валюты - она настраивается на уровне выбора страхового продукта.
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
response = client.calculate(480)
|
@@ -94,7 +94,7 @@ Or install it yourself as:
|
|
94
94
|
|
95
95
|
### find
|
96
96
|
|
97
|
-
Принимает на вход числовой идентификатор страховки, возвращает FindReponse с полями insurance_id, cost, risk_value,
|
97
|
+
Принимает на вход числовой идентификатор страховки, возвращает FindReponse с полями insurance_id, cost, risk_value, risk_types (см. выше) и state, где содержится текстовый статус страховки (например ISSUING, CONFIRMED, CANCELLED)
|
98
98
|
|
99
99
|
```ruby
|
100
100
|
response = client.find(insurance_id)
|
data/alfa_insurance.gemspec
CHANGED
@@ -1,21 +1,34 @@
|
|
1
1
|
module AlfaInsurance
|
2
2
|
class CalculateResponse < Response
|
3
3
|
def cost
|
4
|
-
|
4
|
+
@cost ||= to_money(result[:premium], currency)
|
5
5
|
end
|
6
6
|
|
7
7
|
def risk_value
|
8
|
-
|
8
|
+
@risk_value ||= to_money(result[:risk_value_sum], currency)
|
9
9
|
end
|
10
10
|
|
11
11
|
def risk_type
|
12
|
-
|
12
|
+
warn "[DEPRECATION] `risk_type` is deprecated. Please use `risk_types` instead."
|
13
|
+
risk_types.first
|
14
|
+
end
|
15
|
+
|
16
|
+
def risk_types
|
17
|
+
risk_values.keys
|
18
|
+
end
|
19
|
+
|
20
|
+
def risk_values
|
21
|
+
@risk_values ||= risk_values_from(result, currency: currency)
|
13
22
|
end
|
14
23
|
|
15
24
|
private
|
16
25
|
|
17
26
|
def currency
|
18
|
-
|
27
|
+
result[:currency]
|
28
|
+
end
|
29
|
+
|
30
|
+
def result
|
31
|
+
@result ||= body[:calculation_result] || {}
|
19
32
|
end
|
20
33
|
end
|
21
34
|
end
|
@@ -3,23 +3,5 @@ module AlfaInsurance
|
|
3
3
|
def insurance_id
|
4
4
|
body[:policy_id].to_i
|
5
5
|
end
|
6
|
-
|
7
|
-
def cost
|
8
|
-
Money.from_amount(body.dig(:calculation_result, :premium).to_f, currency)
|
9
|
-
end
|
10
|
-
|
11
|
-
def risk_value
|
12
|
-
Money.from_amount(body.dig(:calculation_result, :risk_value_sum).to_f, currency)
|
13
|
-
end
|
14
|
-
|
15
|
-
def risk_type
|
16
|
-
body.dig(:calculation_result, :risk_value, :@risk_type)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def currency
|
22
|
-
@currency ||= body.dig(:calculation_result, :currency)
|
23
|
-
end
|
24
6
|
end
|
25
7
|
end
|
@@ -1,33 +1,42 @@
|
|
1
1
|
module AlfaInsurance
|
2
2
|
class FindResponse < CalculateResponse
|
3
3
|
def insurance_id
|
4
|
-
|
4
|
+
policy[:policy_id].to_i
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def state
|
8
|
+
policy[:policy_status]
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def cost
|
12
|
+
@cost ||= to_money(policy[:rate], policy[:currency])
|
13
13
|
end
|
14
14
|
|
15
15
|
def risk_type
|
16
|
-
|
16
|
+
warn "[DEPRECATION] `risk_type` is deprecated. Please use `risk_types` instead."
|
17
|
+
risk_types.first
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
20
|
+
def risk_types
|
21
|
+
risk_values.keys
|
22
|
+
end
|
23
|
+
|
24
|
+
def risk_value
|
25
|
+
@risk_value ||= risk_values.values.inject(&:+)
|
26
|
+
end
|
27
|
+
|
28
|
+
def risk_values
|
29
|
+
@risk_values ||= risk_values_from(policy, currency: risk_currency)
|
21
30
|
end
|
22
31
|
|
23
32
|
private
|
24
33
|
|
25
34
|
def risk_currency
|
26
|
-
|
35
|
+
policy.dig(:risk_currency, :@value)
|
27
36
|
end
|
28
37
|
|
29
|
-
def
|
30
|
-
@
|
38
|
+
def policy
|
39
|
+
@policy ||= body[:policy_information] || {}
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
@@ -19,5 +19,22 @@ module AlfaInsurance
|
|
19
19
|
def body
|
20
20
|
@body ||= @raw_response.body.values.first
|
21
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def risk_values_from(data, currency:)
|
26
|
+
raw_values = data[:risk_value]
|
27
|
+
raw_values = [raw_values] unless raw_values.is_a?(Array)
|
28
|
+
|
29
|
+
raw_values.each_with_object({}) do |item, result|
|
30
|
+
risk_type = item[:@risk_type]
|
31
|
+
risk_value = item[:@value]
|
32
|
+
result[risk_type] = to_money(risk_value, currency)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_money(amount, currency)
|
37
|
+
Money.from_amount(amount.to_f, currency)
|
38
|
+
end
|
22
39
|
end
|
23
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alfa_insurance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Sviridov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description:
|
126
140
|
email:
|
127
141
|
- alexander.sviridov@gmail.com
|
@@ -167,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
181
|
- !ruby/object:Gem::Version
|
168
182
|
version: '0'
|
169
183
|
requirements: []
|
170
|
-
|
171
|
-
rubygems_version: 2.7.6
|
184
|
+
rubygems_version: 3.0.3
|
172
185
|
signing_key:
|
173
186
|
specification_version: 4
|
174
187
|
summary: Ruby wrapper for ALfaInsurance SOAP API
|