barkibu-kb 0.25.0 → 0.26.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 514a4fe3fe5b5e3bdaa67b8b427034c9151631663810bf0612cddeb7840bbac6
4
- data.tar.gz: c10122e8070297cda87ed8cef03867f054e588ba11adacfbead7a704f173a588
3
+ metadata.gz: 764bc253dcc5b70bd9e72c7daf6f740813b82e4ab1c479e189c179ca247cb860
4
+ data.tar.gz: addb4558e1b7e624f1c82c79818b26978814e4df605eeef54fa81f486b69df11
5
5
  SHA512:
6
- metadata.gz: ed95e271a8d9404ad6b418751df66d0e4e7a53cb59d77485c946b0b0fb6fc0032606594ed44c6778b4dcd8d35d3b5e3eaf99c20571a1e4d31f5bb2594de8268b
7
- data.tar.gz: a5c92333e028bae2ed1cd7a59b73eb89623731bb6c3e3b8c8b4df50e75fd2a8479c5fd78ac24c90cac362cebda191857abb4057e2a3d61ea34e416126279fb9f
6
+ metadata.gz: db382311f048cfedc62265241b487c05c40a977b0e906248426383d471db931f5b5fd169b6d69b51dcbef219d8d429e652d971a013ce1e101d22021161abf531
7
+ data.tar.gz: 5d0e713464fc4eee1f8c1a6c4ca537caee773085a2a1f3178eba80f65abf16dafab7df10185483bfeab538656a207ec9bd8c4b7720336ccc80e1119e0c194ae4
data/CHANGELOG.md CHANGED
@@ -6,7 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [unreleased]
9
- - See diff: https://github.com/barkibu/kb-ruby/compare/v0.25...HEAD
9
+ - See diff: https://github.com/barkibu/kb-ruby/compare/v0.26...HEAD
10
+
11
+ # [0.26.0]
12
+ - Add `#iban` and `#update_iban` to `PetParent`
13
+ - Add /iban endpoints in fake API
10
14
 
11
15
  # [0.25.0]
12
16
  - Add support for Ruby 3.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barkibu-kb (0.25.0)
4
+ barkibu-kb (0.26.0)
5
5
  activemodel (>= 4.0.2)
6
6
  activerecord
7
7
  activesupport (>= 3.0.0)
@@ -10,8 +10,8 @@ PATH
10
10
  faraday-http
11
11
  faraday_middleware
12
12
  i18n
13
- barkibu-kb-fake (0.25.0)
14
- barkibu-kb (= 0.25.0)
13
+ barkibu-kb-fake (0.26.0)
14
+ barkibu-kb (= 0.26.0)
15
15
  countries
16
16
  sinatra
17
17
  webmock
data/README.md CHANGED
@@ -74,6 +74,11 @@ KB.config.log_level = :debugger # :info by default
74
74
  - returns all the KB::Referral associated with this pet parent
75
75
  - `referrers`
76
76
  - returns all the KB::Referral associated with any of the pet parent's pets
77
+ - `iban`
78
+ - returns the IBAN of the pet parent
79
+ - `update_iban`
80
+ - arg: `iban` string
81
+ - updates the IBAN of the pet parent and reloads the entity
77
82
 
78
83
  #### Assessment 📄
79
84
 
@@ -15,6 +15,15 @@ module BoundedContext
15
15
  KB::PetParent::FIELDS.map { |k| k.to_s.camelize(:lower) }
16
16
  end
17
17
 
18
+ def on_petparents_show(_version)
19
+ pet_parent = pet_parent_by_key(params).dup
20
+ return json_response 404, {} if pet_parent.nil?
21
+
22
+ pet_parent['iban_last4'] = pet_parent.delete('iban')&.chars&.last(4)&.join
23
+
24
+ json_response 200, pet_parent
25
+ end
26
+
18
27
  get '/v1/petparents/:key/pets' do
19
28
  json_response 200, pets_by_pet_parent_key(params['key'])
20
29
  end
@@ -70,6 +79,25 @@ module BoundedContext
70
79
  json_response 200, resource
71
80
  end
72
81
 
82
+ get '/v1/petparents/:key/iban' do
83
+ pet_parent = pet_parent_by_key(params)
84
+ return json_response 404, {} if pet_parent.blank?
85
+
86
+ json_response 200, { iban: pet_parent['iban'] }
87
+ end
88
+
89
+ put '/v1/petparents/:key/iban' do
90
+ pet_parent = pet_parent_by_key(params)
91
+ return json_response 404, {} if pet_parent.blank?
92
+
93
+ body = JSON.parse(request.body.read)
94
+
95
+ updated_pet_parent = pet_parent.merge body.slice('iban')
96
+ update_resource_state(:petparents, updated_pet_parent)
97
+
98
+ json_response 200, { iban: updated_pet_parent['iban'] }
99
+ end
100
+
73
101
  private
74
102
 
75
103
  def pet_parent_by_key(params)
@@ -30,6 +30,9 @@ module KB
30
30
  end
31
31
  end
32
32
 
33
+ STRING_FIELDS = %i[key pet_key urgency].freeze
34
+ FIELDS = [*STRING_FIELDS, :date, :should_stop, :finished, :conditions, :symptoms, :next_question].freeze
35
+
33
36
  # Legacy Field Name From Anamnesis
34
37
  alias_attribute :consultation_id, :key
35
38
  alias_attribute :should_stop, :finished
@@ -42,12 +45,7 @@ module KB
42
45
  attribute :date, :datetime
43
46
  attribute :finished, :boolean, default: false
44
47
 
45
- attribute :urgency, :string
46
- attribute :key, :string
47
- attribute :pet_key, :string
48
-
49
- STRING_FIELDS = %i[key pet_key urgency].freeze
50
- FIELDS = [*STRING_FIELDS, :date, :should_stop, :finished, :conditions, :symptoms, :next_question].freeze
48
+ define_attributes STRING_FIELDS, :string
51
49
 
52
50
  def urgent
53
51
  return false if urgency == 'low'
@@ -13,6 +13,23 @@ module KB
13
13
 
14
14
  class << self
15
15
  delegate :clear_cache_for, to: :kb_client
16
+
17
+ def define_attribute_methods(*fields)
18
+ super
19
+ fields.each do |field|
20
+ define_method :"#{field}=" do |value|
21
+ super(value).tap do
22
+ public_send "#{field}_will_change!" if public_send("#{field}_changed?")
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def define_attributes(attributes, cast_type = nil)
29
+ attributes.each do |attribute|
30
+ attribute attribute, cast_type&.to_sym
31
+ end
32
+ end
16
33
  end
17
34
 
18
35
  def initialize(attributes = {})
@@ -39,16 +56,5 @@ module KB
39
56
  other.key == key)
40
57
  end
41
58
  alias eql? ==
42
-
43
- def self.define_attribute_methods(*fields)
44
- super
45
- fields.each do |field|
46
- define_method :"#{field}=" do |value|
47
- super(value).tap do
48
- public_send "#{field}_will_change!" if public_send("#{field}_changed?")
49
- end
50
- end
51
- end
52
- end
53
59
  end
54
60
  end
@@ -32,8 +32,6 @@ module KB
32
32
 
33
33
  define_attribute_methods(*FIELDS)
34
34
 
35
- STRING_FIELDS.each do |field|
36
- attribute field, :string
37
- end
35
+ define_attributes STRING_FIELDS, :string
38
36
  end
39
37
  end
@@ -15,5 +15,11 @@ module KB
15
15
  raise KB::Error.from_faraday(e)
16
16
  end
17
17
  end
18
+
19
+ def reload
20
+ self.class.clear_cache_for(key)
21
+ self.attributes = self.class.find(key).attributes
22
+ self
23
+ end
18
24
  end
19
25
  end
@@ -16,13 +16,8 @@ module KB
16
16
 
17
17
  define_attribute_methods(*FIELDS)
18
18
 
19
- STRING_FIELDS.each do |field|
20
- attribute field, :string
21
- end
22
-
23
- DATE_FIELDS.each do |field|
24
- attribute field, :date
25
- end
19
+ define_attributes STRING_FIELDS, :string
20
+ define_attributes DATE_FIELDS, :date
26
21
 
27
22
  def self.find(model, model_key)
28
23
  response = kb_client.request("#{model}/#{model_key}/relationship")
data/lib/kb/models/pet.rb CHANGED
@@ -21,17 +21,9 @@ module KB
21
21
 
22
22
  define_attribute_methods(*FIELDS)
23
23
 
24
- STRING_FIELDS.each do |field|
25
- attribute field, :string
26
- end
27
-
28
- BOOLEAN_FIELDS.each do |field|
29
- attribute field, :boolean
30
- end
31
-
32
- DATE_FIELDS.each do |field|
33
- attribute field, :date
34
- end
24
+ define_attributes STRING_FIELDS, :string
25
+ define_attributes DATE_FIELDS, :date
26
+ define_attributes BOOLEAN_FIELDS, :boolean
35
27
 
36
28
  def save!
37
29
  return unless changed?
@@ -31,17 +31,9 @@ module KB
31
31
 
32
32
  define_attribute_methods(*FIELDS)
33
33
 
34
- STRING_FIELDS.each do |field|
35
- attribute field, :string
36
- end
37
-
38
- DATE_FIELDS.each do |field|
39
- attribute field, :date
40
- end
41
-
42
- INTEGER_FIELDS.each do |field|
43
- attribute field, :integer
44
- end
34
+ define_attributes STRING_FIELDS, :string
35
+ define_attributes DATE_FIELDS, :date
36
+ define_attributes INTEGER_FIELDS, :integer
45
37
 
46
38
  def save!
47
39
  return unless changed?
@@ -41,8 +41,8 @@ module KB
41
41
 
42
42
  private_class_method :attributes_from_response
43
43
 
44
- STRING_FIELDS = %i[key partner_name first_name last_name prefix_phone_number
45
- phone_number email country address zip_code nif affiliate_code city].freeze
44
+ STRING_FIELDS = %i[key partner_name first_name last_name prefix_phone_number phone_number email country address
45
+ zip_code nif affiliate_code city iban_last4].freeze
46
46
  DATE_FIELDS = %i[birth_date deleted_at].freeze
47
47
  BOOLEAN_FIELDS = %i[phone_number_verified email_verified].freeze
48
48
  FIELDS = [*STRING_FIELDS, *DATE_FIELDS, *BOOLEAN_FIELDS].freeze
@@ -52,18 +52,9 @@ module KB
52
52
  alias phone_number_prefix prefix_phone_number
53
53
  alias phone_number_prefix= prefix_phone_number=
54
54
 
55
- STRING_FIELDS.each do |field|
56
- attribute field, :string
57
- end
58
-
59
- DATE_FIELDS.each do |field|
60
- attribute field, :date
61
- end
62
-
63
- BOOLEAN_FIELDS.each do |field|
64
- attribute field, :boolean
65
- end
66
-
55
+ define_attributes STRING_FIELDS, :string
56
+ define_attributes DATE_FIELDS, :date
57
+ define_attributes BOOLEAN_FIELDS, :boolean
67
58
  attribute :first_name, :string, default: ''
68
59
 
69
60
  def save!
@@ -119,5 +110,18 @@ module KB
119
110
  Referral.from_api(referral)
120
111
  end
121
112
  end
113
+
114
+ def iban
115
+ @iban ||= self.class.kb_client.request("#{key}/iban")['iban']
116
+ rescue Faraday::Error => e
117
+ raise KB::Error.from_faraday(e)
118
+ end
119
+
120
+ def update_iban(iban)
121
+ self.class.kb_client.request("#{key}/iban", filters: { iban: iban }, method: :put)
122
+ reload
123
+ rescue Faraday::Error => e
124
+ raise KB::Error.from_faraday(e)
125
+ end
122
126
  end
123
127
  end
@@ -19,13 +19,8 @@ module KB
19
19
  attribute :plan_life_in_months, :integer
20
20
  attribute :buyable, :boolean
21
21
 
22
- STRING_FIELDS.each do |field|
23
- attribute field, :string
24
- end
25
-
26
- HASH_FIELDS.each do |field|
27
- attribute field
28
- end
22
+ define_attributes STRING_FIELDS, :string
23
+ define_attributes HASH_FIELDS
29
24
 
30
25
  def save!
31
26
  return unless changed?
@@ -23,12 +23,7 @@ module KB
23
23
 
24
24
  attribute :purchasable, :boolean
25
25
 
26
- STRING_FIELDS.each do |field|
27
- attribute field, :string
28
- end
29
-
30
- STRING_ARRAY_FIELDS.each do |field|
31
- attribute field, :array_of_strings
32
- end
26
+ define_attributes STRING_FIELDS, :string
27
+ define_attributes STRING_ARRAY_FIELDS, :array_of_strings
33
28
  end
34
29
  end
@@ -16,13 +16,8 @@ module KB
16
16
 
17
17
  define_attribute_methods(*FIELDS)
18
18
 
19
- STRING_FIELDS.each do |field|
20
- attribute field, :string
21
- end
22
-
23
- DATE_FIELDS.each do |field|
24
- attribute field, :date
25
- end
19
+ define_attributes STRING_FIELDS, :string
20
+ define_attributes DATE_FIELDS, :date
26
21
 
27
22
  def self.create(pet_parent_key, attributes)
28
23
  response = kb_client.request("#{pet_parent_key}/referrals", filters: attributes, method: :post)
data/lib/kb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KB
2
- VERSION = '0.25.0'.freeze
2
+ VERSION = '0.26.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barkibu-kb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LĂ©o Figea
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-21 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable