hubrise_app 1.2.7 → 1.2.8

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: 6ea0aa426efee9b8bc01b864746d60b6cf7d5d6d79dc49c539dd45dd66c5b50e
4
- data.tar.gz: ec16b42560772c4667561fbbecb377f324e9c3b695737263d022db613d1f7dcd
3
+ metadata.gz: 507fec5ef715afdd2d0db010143e59becb723fc2c6fc64c87fdb95fdaa42a500
4
+ data.tar.gz: 1090c5f41835de5c32fcbfa94b348c1040d24c147288844ae5130a2025f62570
5
5
  SHA512:
6
- metadata.gz: 5e722632eb9cc0170ea4207f0b711dc8a77d8a414fce825cbf7e178cfab60451532d0594da318ba562a92a89cc7c70b682e820971f03ca3227b2ad92d88673d5
7
- data.tar.gz: 8d0750d4b9a58be3713b95e3d22db8a0b7354279a58b08c4fe84dffbe55ced2d47b66d5ce5c1c5bb47143b89623e590e1fbcd5c6212daf748a6cfe74a24803d1
6
+ metadata.gz: c858a6cb42b8e9d3374388d6d1ee537f3e4f4c91f209a3201430360eece8c2db9ecd521782c0d7c0c696aa754e8b5955d4a0940856474c6108d71ce5c570bd05
7
+ data.tar.gz: 9bfffefb6d02730073d0ba36884456ca89f87b8a5fc130f759d7a0ab343d9f10dc63b84ed231975b8b5f073e85c2bce91e392372c1437aa3d62a7bd0e268e571
data/README.md CHANGED
@@ -79,6 +79,17 @@ A use case:
79
79
 
80
80
  TODO
81
81
 
82
+ ## Run specs
83
+
84
+ This repository contains a dummy rails app in `spec/dummy` folder, that uses SQLite as DB.
85
+
86
+ To run specs:
87
+ ```bash
88
+ bundle install
89
+ bin/rails db:schema:load
90
+ bundle exec rspec
91
+ ```
92
+
82
93
  ## Publish changes to this gem
83
94
 
84
95
  1. Make sure all local changes are committed.
@@ -88,7 +99,7 @@ TODO
88
99
  3. Tag the repository:
89
100
 
90
101
  ```bash
91
- VERSION=1.2.7
102
+ VERSION=1.2.8
92
103
  bundle install
93
104
  git add Gemfile.lock
94
105
  git add lib/hubrise_app/version.rb
@@ -3,15 +3,35 @@ module HubriseApp
3
3
  module Refresher
4
4
  class Account < Base
5
5
  class << self
6
- def fetch_attributes(resource, api_client)
6
+ def attributes_from_api_call(resource, api_client)
7
7
  {
8
- api_data: if api_client.location_id
9
- api_client.get_location(api_client.location_id).data["account"]
10
- else
11
- api_client.get_account(resource.hr_id).data
12
- end.except("id"),
8
+ api_data: cleanup_api_data(
9
+ if api_client.location_id
10
+ api_client.get_location(api_client.location_id).data["account"]
11
+ else
12
+ api_client.get_account(resource.hr_id).data
13
+ end
14
+ ),
13
15
  }
14
16
  end
17
+
18
+ def attributes_from_event(event_params)
19
+ {
20
+ api_data: cleanup_api_data(
21
+ if event_params["resource_type"] == "location"
22
+ event_params["new_state"]["account"]
23
+ else
24
+ event_params["new_state"]
25
+ end
26
+ ),
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def cleanup_api_data(api_data)
33
+ api_data.except("id")
34
+ end
15
35
  end
16
36
  end
17
37
  end
@@ -21,6 +21,38 @@ module HubriseApp
21
21
  )
22
22
  resource
23
23
  end
24
+
25
+ def from_event(resource, event_params)
26
+ case event_params["resource_type"]
27
+ when "account"
28
+ HubriseApp::Refresher::Account.from_event(resource.account, event_params)
29
+ when "location"
30
+ HubriseApp::Refresher::Location.from_event(resource.location, event_params)
31
+ HubriseApp::Refresher::Account.from_event(resource.account, event_params)
32
+ when "catalog"
33
+ HubriseApp::Refresher::Catalog.from_event(resource.catalog, event_params)
34
+ when "customer_list"
35
+ HubriseApp::Refresher::CustomerList.from_event(resource.customer_list, event_params)
36
+ end
37
+ end
38
+
39
+ def default_callback_events(app_instance)
40
+ events = {}
41
+
42
+ if app_instance.location
43
+ events[:location] = [:update]
44
+ end
45
+
46
+ if app_instance.catalog
47
+ events[:catalog] = [:update]
48
+ end
49
+
50
+ if app_instance.customer_list
51
+ events[:customer_list] = [:update]
52
+ end
53
+
54
+ events
55
+ end
24
56
  end
25
57
  end
26
58
  end
@@ -16,11 +16,22 @@ module HubriseApp
16
16
  end
17
17
  end
18
18
 
19
+ def from_event(resource, event_params)
20
+ return if resource.nil?
21
+
22
+ resource.update!(
23
+ attributes_from_event(event_params).merge(
24
+ refreshed_at: Time.now,
25
+ )
26
+ )
27
+ resource
28
+ end
29
+
19
30
  def run(resource, api_client, force: false)
20
31
  return resource if !stale?(resource) && !force
21
32
 
22
33
  resource.update!(
23
- fetch_attributes(resource, api_client).merge(
34
+ attributes_from_api_call(resource, api_client).merge(
24
35
  refreshed_at: Time.now,
25
36
  )
26
37
  )
@@ -29,10 +40,14 @@ module HubriseApp
29
40
 
30
41
  protected
31
42
 
32
- def fetch_attributes(_resource, _api_client)
43
+ def attributes_from_api_call(_resource, _api_client)
33
44
  {}
34
45
  end
35
46
 
47
+ def attributes_from_event(event_params)
48
+ event_params
49
+ end
50
+
36
51
  def stale?(resource)
37
52
  resource.refreshed_at.nil? || Time.now - resource.refreshed_at > REFRESH_THRESHOLD
38
53
  end
@@ -3,13 +3,25 @@ module HubriseApp
3
3
  module Refresher
4
4
  class Catalog < Base
5
5
  class << self
6
- def fetch_attributes(resource, api_client)
6
+ def attributes_from_api_call(resource, api_client)
7
7
  {
8
- api_data: api_client.get_catalog(resource.hr_id, hide_data: true)
9
- .data
10
- .except("id"),
8
+ api_data: cleanup_api_data(
9
+ api_client.get_catalog(resource.hr_id, hide_data: true).data
10
+ ),
11
11
  }
12
12
  end
13
+
14
+ def attributes_from_event(event_params)
15
+ {
16
+ api_data: cleanup_api_data(event_params["new_state"]),
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def cleanup_api_data(api_data)
23
+ api_data.except("id")
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -3,13 +3,25 @@ module HubriseApp
3
3
  module Refresher
4
4
  class CustomerList < Base
5
5
  class << self
6
- def fetch_attributes(resource, api_client)
6
+ def attributes_from_api_call(resource, api_client)
7
7
  {
8
- api_data: api_client.get_customer_list(resource.hr_id)
9
- .data
10
- .except("id"),
8
+ api_data: cleanup_api_data(
9
+ api_client.get_customer_list(resource.hr_id).data
10
+ ),
11
11
  }
12
12
  end
13
+
14
+ def attributes_from_event(event_params)
15
+ {
16
+ api_data: cleanup_api_data(event_params["new_state"]),
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def cleanup_api_data(api_data)
23
+ api_data.except("id")
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -3,13 +3,23 @@ module HubriseApp
3
3
  module Refresher
4
4
  class Location < Base
5
5
  class << self
6
- def fetch_attributes(resource, api_client)
6
+ def attributes_from_api_call(resource, api_client)
7
7
  {
8
- api_data: api_client.get_location(resource.hr_id)
9
- .data
10
- .except("id", "account"),
8
+ api_data: cleanup_api_data(api_client.get_location(resource.hr_id).data),
11
9
  }
12
10
  end
11
+
12
+ def attributes_from_event(event_params)
13
+ {
14
+ api_data: cleanup_api_data(event_params["new_state"]),
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def cleanup_api_data(api_data)
21
+ api_data.except("id", "account")
22
+ end
13
23
  end
14
24
  end
15
25
  end
@@ -3,7 +3,7 @@ module HubriseApp
3
3
  module Refresher
4
4
  class User < Base
5
5
  class << self
6
- def fetch_attributes(_resource, api_client)
6
+ def attributes_from_api_call(_resource, api_client)
7
7
  api_data = api_client.get_user.data
8
8
  {
9
9
  access_token: api_client.access_token,
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module HubriseApp
3
- VERSION = "1.2.7"
3
+ VERSION = "1.2.8"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubrise_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Monnier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-09-01 00:00:00.000000000 Z
12
+ date: 2026-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hubrise_client