barkibu-kb 0.16.2 → 0.17.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: fb67cd61d20540319a057c991e8d3057f7de137f34b766cd083a00f503587168
4
- data.tar.gz: a8a9eede090992a9aa54b3f7eacb6e4e3840b6f3932d809a4bfa8315f38dde61
3
+ metadata.gz: a893e849049eb479e171c341b8cf56d22a2ade1c248083ee5a9cd66f251c7cc4
4
+ data.tar.gz: 2008d1d02b6ecc392c5db59d579a07659de53ad4302c97b55d08cd24b0030f0c
5
5
  SHA512:
6
- metadata.gz: 9139e56115d588e201d0247761a429fab0c01fc3ea9676eb05cc211915a72ad45077ca4996c39f9b080413f81d6263636ba2a6a5fefbb815907bb47e7b8f2015
7
- data.tar.gz: 6e78fed61516a203cf2e07db8c6e088fa242a4fbe083cf7380f8e6e3d8e55b660a9a5fe7395ff52197be90b5cd21002e5b32d29e886cddd5e7a90b8ea46c3826
6
+ metadata.gz: 904e31438bad89e6762e43031a6ae3914dd8d7d5095faed0787ee44a4cc2d945cfbbf6ebae92680db63ab3fce64553715cd496963fd365f33e87fa80dfcaacce
7
+ data.tar.gz: 6f84cc1cef486ecc571c22ad4e0a08db129b6d456f5b722a389679af84a34e291e4ae7ee0f63b5f3db4b68bdb93802a146dd68a5c8ac74870f41c01a41fb312f
@@ -8,7 +8,7 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  steps:
11
- - uses: actions/checkout@v1
11
+ - uses: actions/checkout@v3
12
12
 
13
13
  - name: Github whoami
14
14
  run: |
@@ -19,4 +19,4 @@ jobs:
19
19
  env:
20
20
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21
21
  RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
- RELEASE_COMMAND: rake release
22
+ RELEASE_COMMAND: rake release
data/.gitignore CHANGED
@@ -17,4 +17,5 @@
17
17
  .byebug_history
18
18
 
19
19
  # intellij
20
- /.idea
20
+ /.idea
21
+ .env
data/.rubocop.yml CHANGED
@@ -21,13 +21,13 @@ RSpec/FilePath:
21
21
  Metrics/BlockLength:
22
22
  Max: 15
23
23
  Exclude:
24
- - 'spec/**/*.rb'
25
- - 'barkibu-kb.gemspec'
26
- - 'barkibu-kb-*.gemspec'
24
+ - "spec/**/*.rb"
25
+ - "barkibu-kb.gemspec"
26
+ - "barkibu-kb-*.gemspec"
27
27
 
28
28
  Naming/FileName:
29
29
  Exclude:
30
- - 'lib/barkibu-kb*.rb'
30
+ - "lib/barkibu-kb*.rb"
31
31
 
32
32
  Style/FrozenStringLiteralComment:
33
33
  Enabled: false
@@ -43,3 +43,6 @@ Metrics/MethodLength:
43
43
 
44
44
  Metrics/ModuleLength:
45
45
  Max: 110
46
+
47
+ RSpec/ExampleLength:
48
+ CountAsOne: ["array", "heredoc", "hash"]
data/CHANGELOG.md CHANGED
@@ -1,146 +1,196 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
7
 
8
+ ## [0.17.0]
9
+
10
+ - add `KB::Referral` model to create a referral on a PetParent
11
+ - add `PetParent#referrals` to get a list of referrals
12
+
7
13
  ## [0.16.2]
14
+
8
15
  - Rename gems to barkibu-kb / barkibu-kb-fake
9
16
 
10
17
  ## [0.16.0]
18
+
11
19
  - Add `Hubspot` model to retrieve information from [Hubspot Relationship endpoint](https://knowledge-base-staging.herokuapp.com/swagger-ui/index.html#/Hubspot)
12
20
  - Change `husbpot_id` attribute on PetContract, now it comes from the Hubspot Relationship
13
21
 
14
22
  ## [0.15.1]
23
+
15
24
  - Fix Cache invalidation deleting wrong key
16
25
 
17
26
  ## [0.15.0]
27
+
18
28
  - Add `husbpot_id` attribute on PetContract
19
29
 
20
30
  ## [0.14.2]
31
+
21
32
  - Fix Merged Pet Parent instanciation
22
33
 
23
34
  ## [0.14.1]
35
+
24
36
  - Convert API exception into KB::Error for admin `merge!` endpoint
25
37
 
26
38
  ## [0.14.0]
39
+
27
40
  - Add admin `merge!` method on PetParent
28
41
 
29
42
  ## [0.13.0]
30
- - Add `affiliate_code` attribute on PetParent
43
+
44
+ - Add `affiliate_code` attribute on PetParent
31
45
 
32
46
  ## [0.12.0]
47
+
33
48
  - Add `phone_number_verified` and `email_verified` attributes on PetParent
34
49
 
35
50
  ## [0.11.0]
51
+
36
52
  - Expose product_key on PetContract
37
53
 
38
54
  ## [0.10.0]
55
+
39
56
  - Add KB::Product Entity
40
57
 
41
58
  ## [0.9.0]
59
+
42
60
  - Add conversion_utm_adgroup_id and conversion_utm_campaign_id to PetContract
43
61
 
44
62
  ## [0.8.0]
45
- - Add conversion_utm_\* attributes to PetContract
63
+
64
+ - Add conversion*utm*\* attributes to PetContract
46
65
 
47
66
  ## [0.7.2]
67
+
48
68
  - Fix kb-fake pet parent upsert with partial identification
49
69
 
50
70
  ## [0.7.1]
71
+
51
72
  - Fix dsl-configurable positional arg deprecated warning
52
73
 
53
74
  ## [0.7.0]
75
+
54
76
  - Add new Error classes
55
77
  - Emulate the same behavior on Pet Parent Upsert
56
78
 
57
79
  ## [0.6.0]
80
+
58
81
  - Add price_discount_yearly PetContract attribute
59
82
 
60
83
  ## [0.5.0]
84
+
61
85
  - Switch to consume petfamily based consultation endpoint
62
86
 
63
87
  ## [0.4.10]
88
+
64
89
  - Add affiliate PetContract attributes
65
90
 
66
91
  ## [0.4.9]
92
+
67
93
  - Fix ActiveModel dirty implementation
68
94
 
69
95
  ## [0.4.8]
96
+
70
97
  - Fix KB::Error not accepting nil body
71
98
 
72
99
  ## [0.4.7]
100
+
73
101
  - Breed - Add external_id field
74
102
 
75
103
  ## [0.4.6]
104
+
76
105
  - PetParent - Add more KB fields
77
106
 
78
107
  ## [0.4.5]
108
+
79
109
  - Breeds - Add server endpoint for tests on fake gem
80
110
 
81
111
  ## [0.4.4]
112
+
82
113
  - Breeds - Adjust fields definition to petfamily domain ones
83
114
 
84
115
  ## [0.4.3]
116
+
85
117
  - Breeds - Change client resolver template to use petfamily domain
86
118
 
87
119
  ## [0.4.2]
120
+
88
121
  - Assessment - Parse time from date
89
122
 
90
123
  ## [0.4.1]
124
+
91
125
  - Add Pet Upsert method
92
126
 
93
127
  ## [0.4.0]
128
+
94
129
  - Add Upsert Endpoint
95
130
 
96
131
  ## [0.3.6]
132
+
97
133
  - Add cache to client request method
98
134
 
99
135
  ## [0.3.5]
136
+
100
137
  - Add Dry gem and setup config
101
138
  - Add cache as gem config settings
102
139
  - Add log level as gem config settings
103
140
  - Improve KB Exceptions definitions
104
141
 
105
142
  ## [0.3.4]
143
+
106
144
  - Fix planName attributes wrongly named on Plan
107
145
 
108
146
  ## [0.3.3]
147
+
109
148
  - Fix buyable and planLifeInMonths attributes wrongly named on Plan
110
149
 
111
150
  ## [0.3.2]
151
+
112
152
  - Exposes `KB::PetContract` entity
113
153
  - Add `contracts` method to `KB::Pet` and `KB::PetParent`
114
154
 
115
155
  ## [0.3.1]
156
+
116
157
  - Fix Fake Consultation wrong endpoint version
117
158
 
118
159
  ## [0.3.0]
160
+
119
161
  - Extracted `kb-fake` gem for client test purposes
120
162
 
121
163
  ## [0.2.7]
164
+
122
165
  - Fix missing deleted_at accessors on PetParent and Pet entities
123
166
 
124
167
  ## [0.2.6]
168
+
125
169
  - Exposes `Destroyable` concerns on PetParent and Pet entities
126
170
 
127
171
  ## [0.2.5]
172
+
128
173
  - Exposes `FindOrCreatable` concerns on PetParent and Pet entities
129
174
 
130
175
  ## [0.2.4]
176
+
131
177
  - Fix Assessment not properly localized
132
178
 
133
179
  ## [0.2.3]
180
+
134
181
  - Fix missing ActiveSupport dependency loading
135
182
 
136
183
  ## [0.2.2]
184
+
137
185
  - Fix custom array types returning single element
138
186
  - Test dependency extracted
139
187
 
140
188
  ## [0.2.1]
189
+
141
190
  - Fix gem loading order for tests
142
191
 
143
192
  ## [0.2.0]
193
+
144
194
  - Provide FakeApi for client implementation testing
145
195
  - Add Pet entity
146
196
  - Add `AsKBWrapper` concern for easy activerecord wrapping
@@ -148,9 +198,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
148
198
  - `AsKBWrapper` - add `skip_callback` option
149
199
 
150
200
  ## [0.1.1] - 2020-01-12
201
+
151
202
  - Init Version: Breeds and limited PetParents/Consultations
152
203
 
153
- [Unreleased]: https://github.com/barkibu/kb-ruby/compare/v0.10.0...HEAD
204
+ [unreleased]: https://github.com/barkibu/kb-ruby/compare/v0.10.0...HEAD
154
205
  [0.10.0]: https://github.com/barkibu/kb-ruby/compare/v0.9.0...0.10.0
155
206
  [0.9.0]: https://github.com/barkibu/kb-ruby/compare/v0.8.0...0.9.0
156
207
  [0.8.0]: https://github.com/barkibu/kb-ruby/compare/v0.7.2...0.8.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barkibu-kb (0.16.2)
4
+ barkibu-kb (0.17.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.16.2)
14
- barkibu-kb (= 0.16.2)
13
+ barkibu-kb-fake (0.17.0)
14
+ barkibu-kb (= 0.17.0)
15
15
  countries
16
16
  sinatra
17
17
  webmock
@@ -81,7 +81,7 @@ GEM
81
81
  ffi (>= 1.0.0)
82
82
  rake
83
83
  hashdiff (1.0.1)
84
- http (5.0.4)
84
+ http (5.1.0)
85
85
  addressable (~> 2.8)
86
86
  http-cookie (~> 1.0)
87
87
  http-form_data (~> 2.2)
@@ -96,7 +96,7 @@ GEM
96
96
  llhttp-ffi (0.4.0)
97
97
  ffi-compiler (~> 1.0)
98
98
  rake (~> 13.0)
99
- minitest (5.15.0)
99
+ minitest (5.16.1)
100
100
  multipart-post (2.2.3)
101
101
  mustermann (1.1.1)
102
102
  ruby2_keywords (~> 0.0.1)
@@ -177,6 +177,7 @@ DEPENDENCIES
177
177
  rubocop
178
178
  rubocop-rspec
179
179
  simplecov
180
+ webmock
180
181
 
181
182
  BUNDLED WITH
182
183
  1.17.3
data/README.md CHANGED
@@ -70,6 +70,8 @@ KB.config.log_level = :debugger # :info by default
70
70
  - throws a `KB::Error` exception if something went wrong
71
71
  - `contracts`
72
72
  - returns all the KB::PetContract associated with this pet parent
73
+ - `referrals`
74
+ - returns all the KB::Referral associated with this pet parent
73
75
 
74
76
  #### Assessment 📄
75
77
 
@@ -162,6 +164,14 @@ KB.config.log_level = :debugger # :info by default
162
164
  - arg: `filters` hash of filters
163
165
  - returns: and array of Cat Breed instances matching the filters
164
166
 
167
+ #### Referral
168
+ `KB::Referral` represets a referral resource
169
+
170
+ - `create`
171
+ - arg: `pet_parent_key`, `attributes` to initialize the entity
172
+ - returns: the raw attributes of the Referral instance
173
+ - throws an `KB::Error` exception if something went wrong
174
+
165
175
  ### Make an ActiveRecord wrap a KB entity
166
176
 
167
177
  The `KB::Concerns::AsKBWrapper` concern has been created in order to easily make an ActiveRecord model wrap a KB model.
data/barkibu-kb.gemspec CHANGED
@@ -44,6 +44,7 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency 'rubocop'
45
45
  spec.add_development_dependency 'rubocop-rspec'
46
46
  spec.add_development_dependency 'simplecov'
47
+ spec.add_development_dependency 'webmock'
47
48
  spec.add_runtime_dependency 'activemodel', '>= 4.0.2'
48
49
  spec.add_runtime_dependency 'activerecord'
49
50
  spec.add_runtime_dependency 'activesupport', '>= 3.0.0'
data/lib/kb/client.rb CHANGED
@@ -8,7 +8,7 @@ module KB
8
8
  end
9
9
 
10
10
  def request(sub_path, filters: nil, method: :get)
11
- return connection.public_send(method, sub_path, filters).body if method != :get
11
+ return connection.public_send(method, sub_path, attributes_to_json(filters)).body if method != :get
12
12
 
13
13
  cache_key = "#{@base_url}/#{sub_path}/#{(filters || {}).sort.to_h}"
14
14
  KB::Cache.fetch(cache_key) do
data/lib/kb/fake/api.rb CHANGED
@@ -8,11 +8,12 @@ require 'kb/fake/bounded_context/pet_family/hubspot_relationship'
8
8
  module KB
9
9
  module Fake
10
10
  class ApiState
11
- attr_accessor :petparents, :pets, :consultations, :petcontracts, :plans, :breeds, :products, :hubspot_relationship
11
+ attr_accessor :petparents, :pets, :consultations, :petcontracts, :plans, :breeds, :products,
12
+ :hubspot_relationship, :referrals
12
13
 
13
14
  # rubocop:disable Metrics/ParameterLists
14
15
  def initialize(petparents: [], pets: [], consultations: [], petcontracts: [], plans: [], breeds: [],
15
- products: [], hubspot_relationship: [])
16
+ products: [], hubspot_relationship: [], referrals: [])
16
17
  @petparents = petparents
17
18
  @pets = pets
18
19
  @consultations = consultations
@@ -21,6 +22,7 @@ module KB
21
22
  @breeds = breeds
22
23
  @products = products
23
24
  @hubspot_relationship = hubspot_relationship
25
+ @referrals = referrals
24
26
  end
25
27
  # rubocop:enable Metrics/ParameterLists
26
28
 
@@ -33,7 +35,8 @@ module KB
33
35
  plans: @plans.clone,
34
36
  breeds: @breeds.clone,
35
37
  products: @products.clone,
36
- hubspot_relationship: @hubspot_relationship.clone
38
+ hubspot_relationship: @hubspot_relationship.clone,
39
+ referrals: @referrals.clone
37
40
  }
38
41
  end
39
42
  end
@@ -26,6 +26,18 @@ module BoundedContext
26
26
  json_response 200, contracts
27
27
  end
28
28
 
29
+ get '/v1/petparents/:key/referrals' do
30
+ json_response 200, referrals_by_pet_parent_key(params['key'])
31
+ end
32
+
33
+ post '/v1/petparents/:key/referrals' do
34
+ resource = JSON.parse(request.body.read)
35
+ resource = resource.merge 'key' => SecureRandom.uuid
36
+ resource = resource.merge 'referralKey' => params['key']
37
+ resource_state(:referrals) << resource
38
+ json_response 201, resource
39
+ end
40
+
29
41
  put '/v1/petparents' do
30
42
  params = JSON.parse(request.body.read)
31
43
  existing_pet_parent = pet_parent_by_key(params) || pet_parent_by_email(params) || pet_parent_by_phone(params)
@@ -78,6 +90,10 @@ module BoundedContext
78
90
  resource_state(:pets).select { |pet| pet['petParentKey'] == key }
79
91
  end
80
92
 
93
+ def referrals_by_pet_parent_key(key)
94
+ resource_state(:referrals).select { |resource| resource['referralKey'] == key }
95
+ end
96
+
81
97
  def same_email_but_different_phone_number?(previous, new)
82
98
  (previous['email'] == new['email']) &&
83
99
  ((previous['phoneNumber'] != new['phoneNumber']) ||
@@ -107,5 +107,11 @@ module KB
107
107
  PetContract.from_api(contract)
108
108
  end
109
109
  end
110
+
111
+ def referrals
112
+ self.class.kb_client.request("#{key}/referrals").map do |referral|
113
+ Referral.from_api(referral)
114
+ end
115
+ end
110
116
  end
111
117
  end
@@ -0,0 +1,34 @@
1
+ module KB
2
+ class Referral < BaseModel
3
+ include Queryable
4
+
5
+ kb_api :pet_parent
6
+
7
+ def self.attributes_from_response(response)
8
+ response.transform_keys(&:underscore).transform_keys(&:to_sym).slice(*FIELDS)
9
+ end
10
+
11
+ private_class_method :attributes_from_response
12
+
13
+ STRING_FIELDS = %i[key referral_key referred_key type].freeze
14
+ DATE_FIELDS = %i[joined_at].freeze
15
+ FIELDS = [*STRING_FIELDS, *DATE_FIELDS].freeze
16
+
17
+ define_attribute_methods(*FIELDS)
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
26
+
27
+ def self.create(pet_parent_key, attributes)
28
+ response = kb_client.request("#{pet_parent_key}/referrals", filters: attributes, method: :post)
29
+ attributes_from_response(response)
30
+ rescue Faraday::Error => e
31
+ raise KB::Error.from_faraday(e)
32
+ end
33
+ end
34
+ end
data/lib/kb/models.rb CHANGED
@@ -13,3 +13,4 @@ require 'kb/models/plan'
13
13
  require 'kb/models/breed'
14
14
 
15
15
  require 'kb/models/hubspot_relationship'
16
+ require 'kb/models/referral'
data/lib/kb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KB
2
- VERSION = '0.16.2'.freeze
2
+ VERSION = '0.17.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.16.2
4
+ version: 0.17.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: 2022-06-13 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
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
  - !ruby/object:Gem::Dependency
126
140
  name: activemodel
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -291,6 +305,7 @@ files:
291
305
  - lib/kb/models/pet_parent.rb
292
306
  - lib/kb/models/plan.rb
293
307
  - lib/kb/models/product.rb
308
+ - lib/kb/models/referral.rb
294
309
  - lib/kb/models/symptom.rb
295
310
  - lib/kb/type/array_of_conditions_type.rb
296
311
  - lib/kb/type/array_of_strings_type.rb
@@ -319,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
334
  - !ruby/object:Gem::Version
320
335
  version: '0'
321
336
  requirements: []
322
- rubygems_version: 3.1.2
337
+ rubygems_version: 3.3.7
323
338
  signing_key:
324
339
  specification_version: 4
325
340
  summary: Barkibu's Knowledge Base API sdk