barkibu-kb 0.22.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60c13170a8bc9ef25645fcdef01fc91f75210c4c37b91a6625c6556f836b85b8
4
- data.tar.gz: cff3103e0dd410df52443d5133899a7d0af5208e7122b2c55dd75526c464f842
3
+ metadata.gz: 29792b50e3dad51825c1fb0237155a3a6983a893173d00fafe3722e406f5f771
4
+ data.tar.gz: 3390ea2cc76d6d6ac5489fda5e4dbacd4b1cc556ba773a1e12f3ca21645ef9ed
5
5
  SHA512:
6
- metadata.gz: fc81ede8d03708a18439bf9ff7c154e274cd61d37136788ad10a3361b089a8b6eb64d6b852e2e76778560133ef4f3e15c646779c9cf8cb15903521e4163abf19
7
- data.tar.gz: 03dca28d0b6b9fab0c1c7b3d66e53746dd6368db4baf7f183a1e394072d3c7b31cdd949096c05c4019f2caac67a11b3ac1b9a8e2a5ced5c573635787529c96f5
6
+ metadata.gz: d76b73f6fcc48fad7f3242f3278e340d258f902b9bf999a61c7fe482c50fe734f28edf2aa28a88bbe37e61dcc6b56862e4f2ef31666fe8a2398609a1a5504d56
7
+ data.tar.gz: 3e83ee7c1e7c357661293f2bfa750ca29a9358afa7dc4dbf94216f7fd947b7a23616c964e87e31ab0dcd6c06dba04727881d4301d68ea6bd91482d8ed59a883e
@@ -0,0 +1,15 @@
1
+ # Human understandable Feature/Bugfix Title
2
+
3
+ ## Why?
4
+
5
+ --
6
+
7
+ ## Changes
8
+
9
+ --
10
+
11
+ ## Checklist
12
+ - [ ] Tests added/updated
13
+ - [ ] README file updated
14
+ - [ ] Changelog updated
15
+ - [ ] Version file `lib/kb/version.rb` updated
data/CHANGELOG.md CHANGED
@@ -6,7 +6,13 @@ 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.22.0...HEAD
9
+ - See diff: https://github.com/barkibu/kb-ruby/compare/v0.24.0...HEAD
10
+
11
+ # [0.24.0]
12
+ - Add support for `.referrers` method on `PetParent`
13
+
14
+ # [0.23.0]
15
+ - Add support for `.search` method on `PetContract`
10
16
 
11
17
  # [0.22.0]
12
18
  - Fix error parsing if HTTP client returns no response
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barkibu-kb (0.22.0)
4
+ barkibu-kb (0.24.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.22.0)
14
- barkibu-kb (= 0.22.0)
13
+ barkibu-kb-fake (0.24.0)
14
+ barkibu-kb (= 0.24.0)
15
15
  countries
16
16
  sinatra
17
17
  webmock
@@ -19,29 +19,38 @@ PATH
19
19
  GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
- activemodel (7.0.4.2)
23
- activesupport (= 7.0.4.2)
24
- activerecord (7.0.4.2)
25
- activemodel (= 7.0.4.2)
26
- activesupport (= 7.0.4.2)
27
- activesupport (7.0.4.2)
22
+ activemodel (7.1.3.2)
23
+ activesupport (= 7.1.3.2)
24
+ activerecord (7.1.3.2)
25
+ activemodel (= 7.1.3.2)
26
+ activesupport (= 7.1.3.2)
27
+ timeout (>= 0.4.0)
28
+ activesupport (7.1.3.2)
29
+ base64
30
+ bigdecimal
28
31
  concurrent-ruby (~> 1.0, >= 1.0.2)
32
+ connection_pool (>= 2.2.5)
33
+ drb
29
34
  i18n (>= 1.6, < 2)
30
35
  minitest (>= 5.1)
36
+ mutex_m
31
37
  tzinfo (~> 2.0)
32
38
  addressable (2.8.0)
33
39
  public_suffix (>= 2.0.2, < 5.0)
34
40
  ast (2.4.2)
41
+ base64 (0.2.0)
42
+ bigdecimal (3.1.6)
35
43
  byebug (11.1.3)
36
- concurrent-ruby (1.2.2)
37
- countries (5.3.1)
44
+ concurrent-ruby (1.2.3)
45
+ connection_pool (2.4.1)
46
+ countries (5.7.2)
38
47
  unaccent (~> 0.3)
39
48
  crack (0.4.5)
40
49
  rexml
41
50
  diff-lcs (1.4.4)
42
51
  docile (1.4.0)
43
- domain_name (0.5.20190701)
44
- unf (>= 0.0.5, < 1.0.0)
52
+ domain_name (0.6.20240107)
53
+ drb (2.2.1)
45
54
  dry-configurable (0.16.1)
46
55
  dry-core (~> 0.6)
47
56
  zeitwerk (~> 2.6)
@@ -76,35 +85,40 @@ GEM
76
85
  faraday-retry (1.0.3)
77
86
  faraday_middleware (1.2.0)
78
87
  faraday (~> 1.0)
79
- ffi (1.15.5)
88
+ ffi (1.16.3)
80
89
  ffi-compiler (1.0.1)
81
90
  ffi (>= 1.0.0)
82
91
  rake
83
92
  hashdiff (1.0.1)
84
- http (5.1.1)
93
+ http (5.2.0)
85
94
  addressable (~> 2.8)
95
+ base64 (~> 0.1)
86
96
  http-cookie (~> 1.0)
87
97
  http-form_data (~> 2.2)
88
- llhttp-ffi (~> 0.4.0)
98
+ llhttp-ffi (~> 0.5.0)
89
99
  http-cookie (1.0.5)
90
100
  domain_name (~> 0.5)
91
101
  http-form_data (2.3.0)
92
- i18n (1.12.0)
102
+ i18n (1.14.1)
93
103
  concurrent-ruby (~> 1.0)
94
- llhttp-ffi (0.4.0)
104
+ llhttp-ffi (0.5.0)
95
105
  ffi-compiler (~> 1.0)
96
106
  rake (~> 13.0)
97
- minitest (5.18.0)
98
- multipart-post (2.3.0)
107
+ minitest (5.22.2)
108
+ multipart-post (2.4.0)
99
109
  mustermann (3.0.0)
100
110
  ruby2_keywords (~> 0.0.1)
111
+ mutex_m (0.2.0)
101
112
  parallel (1.21.0)
102
113
  parser (3.0.2.0)
103
114
  ast (~> 2.4.1)
104
115
  public_suffix (4.0.7)
105
- rack (2.2.6.3)
106
- rack-protection (3.0.5)
107
- rack
116
+ rack (3.0.9.1)
117
+ rack-protection (4.0.0)
118
+ base64 (>= 0.1.0)
119
+ rack (>= 3.0.0, < 4)
120
+ rack-session (2.0.0)
121
+ rack (>= 3.0.0)
108
122
  rainbow (3.0.0)
109
123
  rake (13.0.6)
110
124
  regexp_parser (2.1.1)
@@ -143,24 +157,23 @@ GEM
143
157
  simplecov_json_formatter (~> 0.1)
144
158
  simplecov-html (0.12.3)
145
159
  simplecov_json_formatter (0.1.3)
146
- sinatra (3.0.5)
160
+ sinatra (4.0.0)
147
161
  mustermann (~> 3.0)
148
- rack (~> 2.2, >= 2.2.4)
149
- rack-protection (= 3.0.5)
162
+ rack (>= 3.0.0, < 4)
163
+ rack-protection (= 4.0.0)
164
+ rack-session (>= 2.0.0, < 3)
150
165
  tilt (~> 2.0)
151
- tilt (2.1.0)
166
+ tilt (2.3.0)
167
+ timeout (0.4.1)
152
168
  tzinfo (2.0.6)
153
169
  concurrent-ruby (~> 1.0)
154
170
  unaccent (0.4.0)
155
- unf (0.1.4)
156
- unf_ext
157
- unf_ext (0.0.8.2)
158
171
  unicode-display_width (2.1.0)
159
172
  webmock (3.14.0)
160
173
  addressable (>= 2.8.0)
161
174
  crack (>= 0.3.2)
162
175
  hashdiff (>= 0.4.0, < 2.0.0)
163
- zeitwerk (2.6.7)
176
+ zeitwerk (2.6.13)
164
177
 
165
178
  PLATFORMS
166
179
  ruby
@@ -168,7 +181,7 @@ PLATFORMS
168
181
  DEPENDENCIES
169
182
  barkibu-kb!
170
183
  barkibu-kb-fake!
171
- bundler (~> 2.4.12)
184
+ bundler
172
185
  byebug
173
186
  rake (>= 12.3.3)
174
187
  rspec (~> 3.0)
@@ -178,4 +191,4 @@ DEPENDENCIES
178
191
  webmock
179
192
 
180
193
  BUNDLED WITH
181
- 2.4.12
194
+ 2.4.19
data/README.md CHANGED
@@ -72,6 +72,8 @@ KB.config.log_level = :debugger # :info by default
72
72
  - returns all the KB::PetContract associated with this pet parent
73
73
  - `referrals`
74
74
  - returns all the KB::Referral associated with this pet parent
75
+ - `referrers`
76
+ - returns all the KB::Referral associated with any of the pet parent's pets
75
77
 
76
78
  #### Assessment 📄
77
79
 
@@ -117,7 +119,7 @@ KB.config.log_level = :debugger # :info by default
117
119
  - returns all the KB::PetContract associated with this pet
118
120
  - `upsert`
119
121
  - updates KB:Pet if exists a Pet with same name for its PetParent
120
- - creates a new KB:Pet if not exists a Pet with same name for its PetParent
122
+ - creates a new KB:Pet if not exists a Pet with same name for its PetParent
121
123
 
122
124
  #### PetContract 📝
123
125
 
@@ -138,6 +140,15 @@ KB.config.log_level = :debugger # :info by default
138
140
  - `save!`
139
141
  - persists (create or update) the entity to the Knowledge Base
140
142
  - throws an `KB::Error` exception if something went wrong
143
+ - `search`
144
+ - arg: `filters` hash. Currently, KB API supports these keys:
145
+ - `page`: results page number. Default 0.
146
+ - `size`: amount of results per page. Default 10.
147
+ - `chip`: searches contracts by insured pet chip
148
+ - returns: a hash including:
149
+ - `total`: total amount of contracts found
150
+ - `page`: current page number
151
+ - `elements`: array of PetContract instances matching the filters
141
152
 
142
153
  #### Plan 🗺
143
154
 
@@ -234,12 +245,18 @@ You should be able to use the API seemlessly and the calls to the API will be in
234
245
  ## Development & Testing
235
246
 
236
247
  ```bash
237
- docker run -it --rm -v $(pwd):/app --workdir=/app ruby:2.6.5 bash
238
-
239
- > bundle install
240
- > rspec
248
+ docker run -it --rm -v $(pwd):/app --workdir=/app ruby:2.7.2 bash
249
+ > bundle install
250
+ > rspec
241
251
  ```
242
252
 
253
+ You can also start an interactive console if needed:
254
+ ```bash
255
+ KB_API_URL_TEMPLATE=https://example.com/%{version}/%{entity} \
256
+ KB_API_KEY=YourKbApiKey \
257
+ KB_PARTNER_KEY=YourKbPartnerKey \
258
+ bin/console
259
+ ```
243
260
  ## Contributing
244
261
 
245
262
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/barkibu-kb.gemspec CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.required_ruby_version = '>= 2.6'
38
38
 
39
39
  spec.add_dependency 'dry-configurable', '~> 0.9'
40
- spec.add_development_dependency 'bundler', '~> 2.4.12'
40
+ spec.add_development_dependency 'bundler'
41
41
  spec.add_development_dependency 'byebug'
42
42
  spec.add_development_dependency 'rake', '>= 12.3.3'
43
43
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -0,0 +1,18 @@
1
+ module BoundedContext
2
+ module Paginable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def paginate(list)
7
+ list = list.to_a
8
+ page = params.fetch('page', 1).to_i
9
+ page_size = params.fetch('size', 10).to_i
10
+ offset = (page - 1) * page_size
11
+
12
+ { total: list.size,
13
+ page: page,
14
+ elements: list[offset, page_size] }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,12 +1,15 @@
1
1
  require 'kb/fake/bounded_context/rest_resource'
2
+ require 'kb/fake/bounded_context/paginable'
2
3
 
3
4
  module BoundedContext
4
5
  module PetFamily
5
6
  module PetContracts
6
7
  extend ActiveSupport::Concern
7
8
 
9
+ # rubocop:disable Metrics/BlockLength
8
10
  included do
9
11
  include RestResource
12
+ include Paginable
10
13
 
11
14
  get '/v1/petcontracts/contractnumber/:contract_number' do
12
15
  resource = resource_state(:petcontracts).detect do |contract|
@@ -17,8 +20,24 @@ module BoundedContext
17
20
  json_response 200, resource
18
21
  end
19
22
 
23
+ get '/v1/petcontracts/search' do
24
+ return json_response 400, {} unless params['chip']
25
+
26
+ pet_by_chip = resource_state(:pets).detect do |pet|
27
+ pet['chip'] == params['chip']
28
+ end
29
+ return json_response 200, paginate([]) if pet_by_chip.nil?
30
+
31
+ contracts = resource_state(:petcontracts).select do |contract|
32
+ contract['petKey'] == pet_by_chip['key']
33
+ end
34
+
35
+ json_response 200, paginate(contracts)
36
+ end
37
+
20
38
  resource :petcontracts, except: %i[index destroy]
21
39
  end
40
+ # rubocop:enable Metrics/BlockLength
22
41
  end
23
42
  end
24
43
  end
@@ -0,0 +1,19 @@
1
+ module KB
2
+ module Searchable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Queryable
7
+ end
8
+
9
+ module ClassMethods
10
+ def search(filters)
11
+ response = kb_client.request('search', filters: filters).symbolize_keys
12
+ elements = response[:elements].map { |contract| from_api(contract) }
13
+ KB::SearchResult.new(**response.merge(elements: elements))
14
+ rescue Faraday::Error => e
15
+ raise KB::Error.from_faraday(e)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,3 +8,4 @@ require 'kb/models/concerns/upsertable'
8
8
  require 'kb/models/concerns/updatable'
9
9
  require 'kb/models/concerns/listable'
10
10
  require 'kb/models/concerns/destroyable'
11
+ require 'kb/models/concerns/searchable'
@@ -3,6 +3,7 @@ module KB
3
3
  include Findable
4
4
  include Creatable
5
5
  include Updatable
6
+ include Searchable
6
7
 
7
8
  kb_api :pet_contract
8
9
 
@@ -113,5 +113,11 @@ module KB
113
113
  Referral.from_api(referral)
114
114
  end
115
115
  end
116
+
117
+ def referrers
118
+ self.class.kb_client.request("#{key}/referrers").map do |referral|
119
+ Referral.from_api(referral)
120
+ end
121
+ end
116
122
  end
117
123
  end
@@ -0,0 +1,11 @@
1
+ module KB
2
+ class SearchResult
3
+ attr_reader :elements, :total, :page
4
+
5
+ def initialize(elements:, total:, page:)
6
+ @elements = elements
7
+ @total = total
8
+ @page = page
9
+ end
10
+ end
11
+ end
data/lib/kb/models.rb CHANGED
@@ -14,3 +14,4 @@ require 'kb/models/breed'
14
14
 
15
15
  require 'kb/models/hubspot_relationship'
16
16
  require 'kb/models/referral'
17
+ require 'kb/models/search_result'
data/lib/kb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KB
2
- VERSION = '0.22.0'.freeze
2
+ VERSION = '0.24.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.22.0
4
+ version: 0.24.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: 2023-05-09 00:00:00.000000000 Z
11
+ date: 2024-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.4.12
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.4.12
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +243,7 @@ extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
245
  - ".env.example"
246
+ - ".github/pull_request_template.md"
246
247
  - ".github/workflows/release.yaml"
247
248
  - ".gitignore"
248
249
  - ".rspec"
@@ -276,6 +277,7 @@ files:
276
277
  - lib/kb/errors/unprocessable_entity_error.rb
277
278
  - lib/kb/fake.rb
278
279
  - lib/kb/fake/api.rb
280
+ - lib/kb/fake/bounded_context/paginable.rb
279
281
  - lib/kb/fake/bounded_context/pet_family/breeds.rb
280
282
  - lib/kb/fake/bounded_context/pet_family/hubspot_relationship.rb
281
283
  - lib/kb/fake/bounded_context/pet_family/pet_contracts.rb
@@ -296,6 +298,7 @@ files:
296
298
  - lib/kb/models/concerns/inspectionable.rb
297
299
  - lib/kb/models/concerns/listable.rb
298
300
  - lib/kb/models/concerns/queryable.rb
301
+ - lib/kb/models/concerns/searchable.rb
299
302
  - lib/kb/models/concerns/updatable.rb
300
303
  - lib/kb/models/concerns/upsertable.rb
301
304
  - lib/kb/models/condition.rb
@@ -306,6 +309,7 @@ files:
306
309
  - lib/kb/models/plan.rb
307
310
  - lib/kb/models/product.rb
308
311
  - lib/kb/models/referral.rb
312
+ - lib/kb/models/search_result.rb
309
313
  - lib/kb/models/symptom.rb
310
314
  - lib/kb/type/array_of_conditions_type.rb
311
315
  - lib/kb/type/array_of_strings_type.rb