hubrise_app 0.1.2 → 1.1.1
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 +4 -4
- data/LICENSE +21 -0
- data/README.md +78 -2
- data/app/controllers/hubrise_app/application_controller/app_instance_methods.rb +28 -0
- data/app/controllers/hubrise_app/application_controller/hubrise_gateway_methods.rb +25 -0
- data/app/controllers/hubrise_app/application_controller/session_methods.rb +33 -0
- data/app/controllers/hubrise_app/application_controller.rb +3 -66
- data/app/controllers/hubrise_app/callback_controller/action_disconnect.rb +5 -0
- data/app/controllers/hubrise_app/callback_controller/action_event.rb +5 -0
- data/app/controllers/hubrise_app/callback_controller.rb +19 -14
- data/app/controllers/hubrise_app/oauth_controller/action_authorize_callback.rb +13 -0
- data/app/controllers/hubrise_app/oauth_controller/action_connect_callback.rb +12 -0
- data/app/controllers/hubrise_app/oauth_controller/action_login_callback.rb +7 -0
- data/app/controllers/hubrise_app/oauth_controller.rb +8 -33
- data/app/controllers/hubrise_app/sessions_controller.rb +9 -0
- data/app/lib/hubrise_app/config_loader.rb +5 -0
- data/app/lib/hubrise_app/hubrise_gateway.rb +48 -24
- data/app/lib/hubrise_app/refresher/account.rb +15 -0
- data/app/lib/hubrise_app/refresher/app_instance.rb +24 -0
- data/app/lib/hubrise_app/refresher/base.rb +45 -0
- data/app/lib/hubrise_app/refresher/catalog.rb +13 -0
- data/app/lib/hubrise_app/refresher/customer_list.rb +13 -0
- data/app/lib/hubrise_app/refresher/location.rb +13 -0
- data/app/lib/hubrise_app/refresher/user.rb +16 -0
- data/app/lib/hubrise_app/services/assign_app_instance.rb +8 -0
- data/app/lib/hubrise_app/services/connect_app_instance.rb +3 -4
- data/app/lib/hubrise_app/services/resolve_app_instance.rb +5 -0
- data/app/models/account.rb +2 -0
- data/app/models/app_instance.rb +2 -0
- data/app/models/catalog.rb +2 -0
- data/app/models/customer_list.rb +2 -0
- data/app/models/hubrise_app/account_base.rb +7 -0
- data/app/models/hubrise_app/app_instance_base.rb +10 -0
- data/app/models/hubrise_app/catalog_base.rb +7 -0
- data/app/models/hubrise_app/customer_list_base.rb +7 -0
- data/app/models/hubrise_app/location_base.rb +11 -0
- data/app/models/hubrise_app/user_app_instance_base.rb +12 -0
- data/app/models/hubrise_app/user_base.rb +18 -0
- data/app/models/location.rb +2 -0
- data/app/models/user.rb +2 -0
- data/app/models/user_app_instance.rb +2 -0
- data/config/initializers/hubrise_app_config.rb +1 -1
- data/config/routes.rb +2 -0
- data/db/migrate/20190116155419_create_base_tables.rb +27 -23
- data/db/migrate/20200829091933_add_locations_timezone.rb +5 -0
- data/db/migrate/20210120142001_add_api_json_column.rb +6 -0
- data/db/migrate/20210121150253_remove_replaced_by_api_data_columns.rb +9 -0
- data/db/migrate/20210419120038_add_catalogs_and_customer_lists.rb +28 -0
- data/lib/hubrise_app/spec_support.rb +3 -0
- data/lib/hubrise_app/version.rb +1 -1
- metadata +46 -21
- data/MIT-LICENSE +0 -20
- data/app/lib/hubrise_app/services/disconnect_app_instance.rb +0 -6
- data/app/lib/hubrise_app/services/handle_event.rb +0 -22
- data/app/lib/hubrise_app/services/override/connect_app_instance.rb +0 -1
- data/app/lib/hubrise_app/services/override/disconnect_app_instance.rb +0 -1
- data/app/lib/hubrise_app/services/override/handle_event.rb +0 -1
- data/app/models/concerns/hubrise_app/hr_api_resource.rb +0 -29
- data/app/models/hubrise_app/hr_account.rb +0 -19
- data/app/models/hubrise_app/hr_app_instance.rb +0 -35
- data/app/models/hubrise_app/hr_location.rb +0 -11
- data/app/models/hubrise_app/hr_user.rb +0 -35
- data/app/models/hubrise_app/hr_user_app_instance.rb +0 -14
- data/app/models/hubrise_app/override/hr_user.rb +0 -1
@@ -0,0 +1,16 @@
|
|
1
|
+
module HubriseApp::Refresher
|
2
|
+
class User < Base
|
3
|
+
class << self
|
4
|
+
def fetch_attributes(resource, api_client)
|
5
|
+
api_data = api_client.get_user.data
|
6
|
+
{
|
7
|
+
access_token: api_client.access_token,
|
8
|
+
email: api_data["email"],
|
9
|
+
first_name: api_data["first_name"],
|
10
|
+
last_name: api_data["last_name"],
|
11
|
+
locales: api_data["locales"]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class HubriseApp::Services::ConnectAppInstance
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
def run(hr_app_instance, hubrise_callback_event_url:); end
|
2
|
+
def self.run(api_client, _ctx)
|
3
|
+
HubriseApp::Refresher::AppInstance.from_api_client(api_client)
|
4
|
+
end
|
6
5
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module HubriseApp
|
2
|
+
class AppInstanceBase < HubriseApp::ApplicationRecord
|
3
|
+
self.abstract_class = true
|
4
|
+
|
5
|
+
belongs_to :account, optional: true, primary_key: :hr_id, foreign_key: :hr_account_id
|
6
|
+
belongs_to :location, optional: true, primary_key: :hr_id, foreign_key: :hr_location_id
|
7
|
+
belongs_to :catalog, optional: true, primary_key: :hr_id, foreign_key: :hr_catalog_id
|
8
|
+
belongs_to :customer_list, optional: true, primary_key: :hr_id, foreign_key: :hr_customer_list_id
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module HubriseApp
|
2
|
+
class UserAppInstanceBase < HubriseApp::ApplicationRecord
|
3
|
+
self.abstract_class = true
|
4
|
+
|
5
|
+
belongs_to :app_instance, primary_key: :hr_id, foreign_key: :hr_app_instance_id
|
6
|
+
|
7
|
+
REFRESH_THRESHOLD = 1.day
|
8
|
+
def self.fresh(time: Time.now)
|
9
|
+
where("user_app_instances.refreshed_at > ?", time - REFRESH_THRESHOLD)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module HubriseApp
|
2
|
+
class UserBase < HubriseApp::ApplicationRecord
|
3
|
+
self.abstract_class = true
|
4
|
+
|
5
|
+
has_many :user_app_instances, -> { fresh }, primary_key: :hr_id, foreign_key: :hr_user_id
|
6
|
+
has_many :app_instances, through: :user_app_instances
|
7
|
+
|
8
|
+
serialize :locales
|
9
|
+
|
10
|
+
def primary_locale
|
11
|
+
locales.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def full_name
|
15
|
+
[first_name, last_name].join(" ")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/app/models/user.rb
ADDED
@@ -1 +1 @@
|
|
1
|
-
HubriseApp::CONFIG =
|
1
|
+
HubriseApp::CONFIG = HubriseApp::ConfigLoader.load
|
data/config/routes.rb
CHANGED
@@ -1,44 +1,48 @@
|
|
1
1
|
class CreateBaseTables < ActiveRecord::Migration[5.2]
|
2
2
|
def change
|
3
|
-
create_table :
|
4
|
-
t.string
|
5
|
-
t.
|
3
|
+
create_table :accounts do |t|
|
4
|
+
t.string :hr_id, null: false, index: { unique: true }
|
5
|
+
t.string :name, null: false
|
6
|
+
t.string :currency, null: false
|
6
7
|
t.datetime :refreshed_at, null: false
|
7
8
|
end
|
8
9
|
|
9
|
-
create_table :
|
10
|
-
t.string
|
11
|
-
t.
|
10
|
+
create_table :locations do |t|
|
11
|
+
t.string :hr_id, null: false, index: { unique: true }
|
12
|
+
t.string :name, null: false
|
12
13
|
t.datetime :refreshed_at, null: false
|
13
14
|
end
|
14
15
|
|
15
|
-
create_table :
|
16
|
+
create_table :app_instances do |t|
|
16
17
|
t.string :hr_id, null: false, index: { unique: true }
|
17
|
-
t.string :hr_account_id,
|
18
|
+
t.string :hr_account_id, index: true
|
18
19
|
t.string :hr_location_id, index: true
|
19
20
|
t.string :hr_catalog_id
|
20
21
|
t.string :hr_customer_list_id
|
21
|
-
t.string :
|
22
|
+
t.string :access_token, null: false
|
22
23
|
end
|
23
24
|
|
24
|
-
add_foreign_key :
|
25
|
-
add_foreign_key :
|
25
|
+
add_foreign_key :app_instances, :accounts, primary_key: :hr_id, column: :hr_account_id
|
26
|
+
add_foreign_key :app_instances, :locations, primary_key: :hr_id, column: :hr_location_id
|
26
27
|
|
27
|
-
create_table :
|
28
|
-
t.string
|
29
|
-
t.
|
30
|
-
t.string
|
31
|
-
t.
|
28
|
+
create_table :users do |t|
|
29
|
+
t.string :hr_id, null: false, index: { unique: true }
|
30
|
+
t.string :access_token, null: false
|
31
|
+
t.string :email
|
32
|
+
t.string :first_name
|
33
|
+
t.string :last_name
|
34
|
+
t.string :locales, array: true
|
35
|
+
t.datetime :refreshed_at, null: false
|
32
36
|
end
|
33
37
|
|
34
|
-
create_table :
|
35
|
-
t.string
|
36
|
-
t.string
|
37
|
-
t.datetime
|
38
|
+
create_table :user_app_instances do |t|
|
39
|
+
t.string :hr_user_id, index: true
|
40
|
+
t.string :hr_app_instance_id, index: true
|
41
|
+
t.datetime :refreshed_at, null: false
|
38
42
|
end
|
39
43
|
|
40
|
-
add_foreign_key :
|
41
|
-
add_foreign_key :
|
42
|
-
add_index :
|
44
|
+
add_foreign_key :user_app_instances, :users, primary_key: :hr_id, column: :hr_user_id
|
45
|
+
add_foreign_key :user_app_instances, :app_instances, primary_key: :hr_id, column: :hr_app_instance_id
|
46
|
+
add_index :user_app_instances, %i[hr_user_id hr_app_instance_id refreshed_at], name: :index_user_app_instances, using: :btree
|
43
47
|
end
|
44
48
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class AddCatalogsAndCustomerLists < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :catalogs do |t|
|
4
|
+
t.string :hr_id, null: false
|
5
|
+
t.json :api_data
|
6
|
+
t.datetime :refreshed_at, null: false
|
7
|
+
t.index :hr_id, unique: true
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table :customer_lists do |t|
|
11
|
+
t.string :hr_id, null: false
|
12
|
+
t.json :api_data
|
13
|
+
t.datetime :refreshed_at, null: false
|
14
|
+
t.index :hr_id, unique: true
|
15
|
+
end
|
16
|
+
|
17
|
+
AppInstance.distinct.pluck(:hr_catalog_id).each do |hr_catalog_id|
|
18
|
+
Catalog.create!(hr_id: hr_catalog_id, refreshed_at: Date.new(2000)) if hr_catalog_id.present?
|
19
|
+
end
|
20
|
+
|
21
|
+
AppInstance.distinct.pluck(:hr_customer_list_id).each do |hr_customer_list_id|
|
22
|
+
CustomerList.create!(hr_id: hr_customer_list_id, refreshed_at: Date.new(2000)) if hr_customer_list_id.present?
|
23
|
+
end
|
24
|
+
|
25
|
+
add_foreign_key :app_instances, :catalogs, primary_key: :hr_id, column: :hr_catalog_id
|
26
|
+
add_foreign_key :app_instances, :customer_lists, primary_key: :hr_id, column: :hr_customer_list_id
|
27
|
+
end
|
28
|
+
end
|
data/lib/hubrise_app/version.rb
CHANGED
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:
|
4
|
+
version: 1.1.1
|
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:
|
12
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hubrise_client
|
@@ -17,26 +17,26 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 2.0.
|
20
|
+
version: 2.0.6
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 2.0.
|
27
|
+
version: 2.0.6
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rails
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 5.2.2
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 5.2.2
|
42
42
|
description:
|
@@ -45,36 +45,62 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
48
|
+
- LICENSE
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- app/assets/config/hubrise_app_manifest.js
|
52
52
|
- app/assets/stylesheets/hubrise_app/application.css
|
53
53
|
- app/controllers/hubrise_app/application_controller.rb
|
54
|
+
- app/controllers/hubrise_app/application_controller/app_instance_methods.rb
|
55
|
+
- app/controllers/hubrise_app/application_controller/hubrise_gateway_methods.rb
|
56
|
+
- app/controllers/hubrise_app/application_controller/session_methods.rb
|
54
57
|
- app/controllers/hubrise_app/callback_controller.rb
|
58
|
+
- app/controllers/hubrise_app/callback_controller/action_disconnect.rb
|
59
|
+
- app/controllers/hubrise_app/callback_controller/action_event.rb
|
55
60
|
- app/controllers/hubrise_app/oauth_controller.rb
|
61
|
+
- app/controllers/hubrise_app/oauth_controller/action_authorize_callback.rb
|
62
|
+
- app/controllers/hubrise_app/oauth_controller/action_connect_callback.rb
|
63
|
+
- app/controllers/hubrise_app/oauth_controller/action_login_callback.rb
|
64
|
+
- app/controllers/hubrise_app/sessions_controller.rb
|
65
|
+
- app/lib/hubrise_app/config_loader.rb
|
56
66
|
- app/lib/hubrise_app/hubrise_gateway.rb
|
67
|
+
- app/lib/hubrise_app/refresher/account.rb
|
68
|
+
- app/lib/hubrise_app/refresher/app_instance.rb
|
69
|
+
- app/lib/hubrise_app/refresher/base.rb
|
70
|
+
- app/lib/hubrise_app/refresher/catalog.rb
|
71
|
+
- app/lib/hubrise_app/refresher/customer_list.rb
|
72
|
+
- app/lib/hubrise_app/refresher/location.rb
|
73
|
+
- app/lib/hubrise_app/refresher/user.rb
|
74
|
+
- app/lib/hubrise_app/services/assign_app_instance.rb
|
57
75
|
- app/lib/hubrise_app/services/connect_app_instance.rb
|
58
|
-
- app/lib/hubrise_app/services/
|
59
|
-
- app/
|
60
|
-
- app/
|
61
|
-
- app/
|
62
|
-
- app/
|
63
|
-
- app/models/
|
76
|
+
- app/lib/hubrise_app/services/resolve_app_instance.rb
|
77
|
+
- app/models/account.rb
|
78
|
+
- app/models/app_instance.rb
|
79
|
+
- app/models/catalog.rb
|
80
|
+
- app/models/customer_list.rb
|
81
|
+
- app/models/hubrise_app/account_base.rb
|
82
|
+
- app/models/hubrise_app/app_instance_base.rb
|
64
83
|
- app/models/hubrise_app/application_record.rb
|
65
|
-
- app/models/hubrise_app/
|
66
|
-
- app/models/hubrise_app/
|
67
|
-
- app/models/hubrise_app/
|
68
|
-
- app/models/hubrise_app/
|
69
|
-
- app/models/hubrise_app/
|
70
|
-
- app/models/
|
84
|
+
- app/models/hubrise_app/catalog_base.rb
|
85
|
+
- app/models/hubrise_app/customer_list_base.rb
|
86
|
+
- app/models/hubrise_app/location_base.rb
|
87
|
+
- app/models/hubrise_app/user_app_instance_base.rb
|
88
|
+
- app/models/hubrise_app/user_base.rb
|
89
|
+
- app/models/location.rb
|
90
|
+
- app/models/user.rb
|
91
|
+
- app/models/user_app_instance.rb
|
71
92
|
- app/views/hubrise_app/application/root.html.haml
|
72
93
|
- app/views/layouts/hubrise_app/application.html.erb
|
73
94
|
- config/initializers/hubrise_app_config.rb
|
74
95
|
- config/routes.rb
|
75
96
|
- db/migrate/20190116155419_create_base_tables.rb
|
97
|
+
- db/migrate/20200829091933_add_locations_timezone.rb
|
98
|
+
- db/migrate/20210120142001_add_api_json_column.rb
|
99
|
+
- db/migrate/20210121150253_remove_replaced_by_api_data_columns.rb
|
100
|
+
- db/migrate/20210419120038_add_catalogs_and_customer_lists.rb
|
76
101
|
- lib/hubrise_app.rb
|
77
102
|
- lib/hubrise_app/engine.rb
|
103
|
+
- lib/hubrise_app/spec_support.rb
|
78
104
|
- lib/hubrise_app/version.rb
|
79
105
|
homepage: https://github.com/HubRise/ruby-app
|
80
106
|
licenses:
|
@@ -95,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
121
|
- !ruby/object:Gem::Version
|
96
122
|
version: '0'
|
97
123
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.7.6
|
124
|
+
rubygems_version: 3.1.2
|
100
125
|
signing_key:
|
101
126
|
specification_version: 4
|
102
127
|
summary: Rails engine to bootstrap a HubRise-based application
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright 2019 nsave
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,22 +0,0 @@
|
|
1
|
-
class HubriseApp::Services::HandleEvent
|
2
|
-
prepend HubriseApp::Services::Override::HandleEvent
|
3
|
-
|
4
|
-
class << self; delegate :run, to: :new; end
|
5
|
-
|
6
|
-
def run(hr_app_instance, params)
|
7
|
-
case params["resource_type"]
|
8
|
-
when "customer"
|
9
|
-
handle_customer_event(hr_app_instance, params)
|
10
|
-
when "order"
|
11
|
-
handle_order_event(hr_app_instance, params)
|
12
|
-
else
|
13
|
-
raise "Cannot handle hubrise event with type: " + params["resource_type"].to_s
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
def handle_customer_event(hr_app_instance, params); end
|
20
|
-
|
21
|
-
def handle_order_event(hr_app_instance, params); end
|
22
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
module HubriseApp::Services::Override::ConnectAppInstance; end
|
@@ -1 +0,0 @@
|
|
1
|
-
module HubriseApp::Services::Override::DisconnectAppInstance; end
|
@@ -1 +0,0 @@
|
|
1
|
-
module HubriseApp::Services::Override::HandleEvent; end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module HubriseApp::HrApiResource
|
2
|
-
REFRESH_THRESHOLD = 1.day
|
3
|
-
|
4
|
-
def stale?
|
5
|
-
refreshed_at.nil? || Time.now - refreshed_at > REFRESH_THRESHOLD
|
6
|
-
end
|
7
|
-
|
8
|
-
def refresh_via_api_client(api_client)
|
9
|
-
return unless stale?
|
10
|
-
|
11
|
-
refresh_with(self.class.fetch_hr_attrs(api_client, hr_id))
|
12
|
-
end
|
13
|
-
|
14
|
-
def refresh_with(attrs)
|
15
|
-
update!(attrs.merge(refreshed_at: Time.now))
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.included(base)
|
19
|
-
base.extend(ClassMethods)
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
def refresh_or_create_via_api_client(api_client, hr_id)
|
24
|
-
hr_record = find_or_initialize_by(hr_id: hr_id)
|
25
|
-
hr_record.refresh_via_api_client(api_client)
|
26
|
-
hr_record
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class HubriseApp::HrAccount < HubriseApp::ApplicationRecord
|
2
|
-
self.table_name = :hr_accounts
|
3
|
-
|
4
|
-
include HubriseApp::HrApiResource
|
5
|
-
class << self
|
6
|
-
def fetch_hr_attrs(api_client, hr_id)
|
7
|
-
raise if api_client.account_id != hr_id
|
8
|
-
|
9
|
-
{
|
10
|
-
hr_id: hr_id,
|
11
|
-
hr_api_data: if api_client.location_id
|
12
|
-
api_client.get_location(api_client.location_id).data["account"]
|
13
|
-
else
|
14
|
-
api_client.get_account(hr_id).data
|
15
|
-
end.except("id")
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module HubriseApp
|
2
|
-
class HrAppInstance < HubriseApp::ApplicationRecord
|
3
|
-
self.table_name = :hr_app_instances
|
4
|
-
|
5
|
-
belongs_to :hr_account, optional: true, primary_key: :hr_id
|
6
|
-
belongs_to :hr_location, optional: true, primary_key: :hr_id
|
7
|
-
|
8
|
-
def api_client
|
9
|
-
HubriseApp::HubriseGateway.build_api_client(
|
10
|
-
access_token: hr_access_token,
|
11
|
-
app_instance_id: hr_id,
|
12
|
-
account_id: hr_account_id,
|
13
|
-
location_id: hr_location_id,
|
14
|
-
catalog_id: hr_catalog_id,
|
15
|
-
customer_list_id: hr_customer_list_id
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.refresh_or_create_via_api_client(api_client)
|
20
|
-
hr_app_instance = find_or_initialize_by(hr_id: api_client.app_instance_id)
|
21
|
-
hr_account = api_client.account_id && HrAccount.refresh_or_create_via_api_client(api_client, api_client.account_id) # rubocop:disable Metrics/LineLength
|
22
|
-
hr_location = api_client.location_id && HrLocation.refresh_or_create_via_api_client(api_client, api_client.location_id) # rubocop:disable Metrics/LineLength
|
23
|
-
|
24
|
-
hr_app_instance.update!(
|
25
|
-
hr_account: hr_account,
|
26
|
-
hr_location: hr_location,
|
27
|
-
hr_access_token: api_client.access_token,
|
28
|
-
hr_catalog_id: api_client.catalog_id,
|
29
|
-
hr_customer_list_id: api_client.customer_list_id
|
30
|
-
)
|
31
|
-
|
32
|
-
hr_app_instance
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class HubriseApp::HrLocation < HubriseApp::ApplicationRecord
|
2
|
-
self.table_name = :hr_locations
|
3
|
-
|
4
|
-
include HubriseApp::HrApiResource
|
5
|
-
def self.fetch_hr_attrs(api_client, hr_id)
|
6
|
-
{
|
7
|
-
hr_id: hr_id,
|
8
|
-
hr_api_data: api_client.get_location(hr_id).data.except("id")
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module HubriseApp
|
2
|
-
class HrUser < HubriseApp::ApplicationRecord
|
3
|
-
include HubriseApp::Override::HrUser
|
4
|
-
|
5
|
-
self.table_name = :hr_users
|
6
|
-
|
7
|
-
has_many :hr_user_app_instances, -> { fresh }, primary_key: :hr_id
|
8
|
-
has_many :hr_app_instances, through: :hr_user_app_instances
|
9
|
-
|
10
|
-
include HubriseApp::HrApiResource
|
11
|
-
class << self
|
12
|
-
def fetch_hr_attrs(api_client)
|
13
|
-
data = api_client.get_user.data
|
14
|
-
{
|
15
|
-
hr_id: data.delete("id"),
|
16
|
-
hr_api_data: data,
|
17
|
-
hr_access_token: api_client.access_token
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def refresh_or_create_via_api_client(api_client)
|
22
|
-
hr_attrs = fetch_hr_attrs(api_client)
|
23
|
-
hr_user = find_or_initialize_by(hr_id: hr_attrs[:hr_id])
|
24
|
-
hr_user.refresh_with(hr_attrs)
|
25
|
-
hr_user
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def assign_hr_app_instance(hr_app_instance)
|
30
|
-
hr_user_app_instance = HrUserAppInstance.find_or_initialize_by(hr_app_instance_id: hr_app_instance.hr_id,
|
31
|
-
hr_user_id: hr_id)
|
32
|
-
hr_user_app_instance.refresh!
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|