hubrise_app 0.1.2
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +5 -0
- data/Rakefile +32 -0
- data/app/assets/config/hubrise_app_manifest.js +1 -0
- data/app/assets/stylesheets/hubrise_app/application.css +15 -0
- data/app/controllers/hubrise_app/application_controller.rb +70 -0
- data/app/controllers/hubrise_app/callback_controller.rb +26 -0
- data/app/controllers/hubrise_app/oauth_controller.rb +44 -0
- data/app/lib/hubrise_app/hubrise_gateway.rb +34 -0
- data/app/lib/hubrise_app/services/connect_app_instance.rb +6 -0
- data/app/lib/hubrise_app/services/disconnect_app_instance.rb +6 -0
- data/app/lib/hubrise_app/services/handle_event.rb +22 -0
- data/app/lib/hubrise_app/services/override/connect_app_instance.rb +1 -0
- data/app/lib/hubrise_app/services/override/disconnect_app_instance.rb +1 -0
- data/app/lib/hubrise_app/services/override/handle_event.rb +1 -0
- data/app/models/concerns/hubrise_app/hr_api_resource.rb +29 -0
- data/app/models/hubrise_app/application_record.rb +5 -0
- data/app/models/hubrise_app/hr_account.rb +19 -0
- data/app/models/hubrise_app/hr_app_instance.rb +35 -0
- data/app/models/hubrise_app/hr_location.rb +11 -0
- data/app/models/hubrise_app/hr_user.rb +35 -0
- data/app/models/hubrise_app/hr_user_app_instance.rb +14 -0
- data/app/models/hubrise_app/override/hr_user.rb +1 -0
- data/app/views/hubrise_app/application/root.html.haml +1 -0
- data/app/views/layouts/hubrise_app/application.html.erb +15 -0
- data/config/initializers/hubrise_app_config.rb +1 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20190116155419_create_base_tables.rb +44 -0
- data/lib/hubrise_app/engine.rb +5 -0
- data/lib/hubrise_app/version.rb +3 -0
- data/lib/hubrise_app.rb +5 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7967fa6921a0293b0bb9ba4dc2e34573fc34721bf62732c626d4e3ed7746cd1b
|
4
|
+
data.tar.gz: 0cfcc2aea23f782afcfd4b59019d63fbc38e9a77682df8130a3fe8273087bd35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 778100fedf85bc588497d93161813e2eabe8c18f83d565d1fa691a949e85917a37a549a3fb38a96d7a6193094dd44bdd5d6eb759edf113bd0758573a3375ddd5
|
7
|
+
data.tar.gz: 84994e316f35f455815dd0d8ad6d735b2d2a7d1b96d84ba568027820498fbf727a4d9fda81e85a165f479556827f0a8e4d61d056e7afdce61503583110a03551
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
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.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "rdoc/task"
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "HubriseApp"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.md")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
18
|
+
load "rails/tasks/engine.rake"
|
19
|
+
|
20
|
+
load "rails/tasks/statistics.rake"
|
21
|
+
|
22
|
+
require "bundler/gem_tasks"
|
23
|
+
|
24
|
+
require "rake/testtask"
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << "test"
|
28
|
+
t.pattern = "test/**/*_test.rb"
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../stylesheets/hubrise_app .css
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module HubriseApp
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
protect_from_forgery with: :reset_session
|
4
|
+
helper_method :current_hr_user, :current_hr_app_instance, :logged_in?
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
###########
|
9
|
+
# SESSION #
|
10
|
+
###########
|
11
|
+
|
12
|
+
def login(hr_user)
|
13
|
+
session[:user_id] = hr_user.id
|
14
|
+
@current_hr_user = hr_user
|
15
|
+
end
|
16
|
+
|
17
|
+
def logout
|
18
|
+
session[:user_id] = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_hr_user
|
22
|
+
@current_hr_user ||= HrUser.where(id: session[:user_id]).take
|
23
|
+
end
|
24
|
+
|
25
|
+
def logged_in?
|
26
|
+
!!current_hr_user
|
27
|
+
end
|
28
|
+
|
29
|
+
def ensure_authenticated!
|
30
|
+
redirect_to(build_hubrise_oauth_login_url) unless logged_in?
|
31
|
+
end
|
32
|
+
|
33
|
+
##############
|
34
|
+
# HR METHODS #
|
35
|
+
##############
|
36
|
+
|
37
|
+
def hr_app_instance_id
|
38
|
+
params[:app_instance_id]
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_url_options
|
42
|
+
super.merge(app_instance_id: hr_app_instance_id || current_hr_app_instance&.hr_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def current_hr_app_instance
|
46
|
+
@hr_app_instance ||= current_hr_user && begin
|
47
|
+
current_hr_user.hr_app_instances.where(hr_id: hr_app_instance_id).includes(:hr_account, :hr_location).take
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_hubrise_oauth_login_url
|
52
|
+
HubriseGateway.build_login_authorization_url(
|
53
|
+
hubrise_app.hubrise_oauth_login_callback_url
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_hubrise_oauth_authorize_url
|
58
|
+
HubriseGateway.build_app_authorization_url(hr_app_instance_id,
|
59
|
+
hubrise_app.hubrise_oauth_authorize_callback_url)
|
60
|
+
end
|
61
|
+
|
62
|
+
def ensure_hr_app_instance_found!
|
63
|
+
if hr_app_instance_id.blank?
|
64
|
+
render(plain: "Something went wrong. Please try to reopen from Hubrise Dashboard.")
|
65
|
+
elsif current_hr_app_instance.nil?
|
66
|
+
redirect_to(build_hubrise_oauth_authorize_url)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module HubriseApp
|
2
|
+
class CallbackController < ActionController::Base
|
3
|
+
skip_before_action :verify_authenticity_token
|
4
|
+
before_action :ensure_hr_app_instance_found!
|
5
|
+
|
6
|
+
def event
|
7
|
+
Services::HandleEvent.run(current_hr_app_instance, params.permit!.to_h)
|
8
|
+
head 200
|
9
|
+
end
|
10
|
+
|
11
|
+
def disconnect
|
12
|
+
Services::DisconnectAppInstance.run(current_hr_app_instance)
|
13
|
+
head 200
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def current_hr_app_instance
|
19
|
+
@hr_app_instance ||= HubriseApp::HrAppInstance.where(hr_id: params[:app_instance_id]).take
|
20
|
+
end
|
21
|
+
|
22
|
+
def ensure_hr_app_instance_found!
|
23
|
+
head(404) unless current_hr_app_instance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module HubriseApp
|
2
|
+
class OauthController < ApplicationController
|
3
|
+
before_action :ensure_authenticated!, only: :authorize_callback
|
4
|
+
|
5
|
+
def login_callback
|
6
|
+
hr_user = HrUser.refresh_or_create_via_api_client(api_client_from_oauth_code)
|
7
|
+
login(hr_user)
|
8
|
+
redirect_to(main_app.hubrise_open_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def connect_callback
|
12
|
+
@hr_app_instance = HrAppInstance.refresh_or_create_via_api_client(api_client_from_oauth_code)
|
13
|
+
|
14
|
+
Services::ConnectAppInstance.run(current_hr_app_instance, hubrise_callback_event_url: hubrise_callback_event_url)
|
15
|
+
|
16
|
+
if logged_in?
|
17
|
+
current_hr_user.assign_hr_app_instance(current_hr_app_instance)
|
18
|
+
redirect_to(main_app.hubrise_open_path)
|
19
|
+
else
|
20
|
+
redirect_to(build_hubrise_oauth_login_url)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# authorize access to specific app_instance (expirable)
|
25
|
+
def authorize_callback
|
26
|
+
if current_hr_app_instance
|
27
|
+
current_hr_user.assign_hr_app_instance(current_hr_app_instance)
|
28
|
+
redirect_to(main_app.hubrise_open_path)
|
29
|
+
else
|
30
|
+
render(plain: "Something went wrong. Please try to reinstall the app")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def current_hr_app_instance
|
37
|
+
@hr_app_instance ||= HrAppInstance.where(hr_id: api_client_from_oauth_code.app_instance_id).take
|
38
|
+
end
|
39
|
+
|
40
|
+
def api_client_from_oauth_code
|
41
|
+
@api_client_from_oauth_code ||= HubriseGateway.build_api_client_from_authorization_code(params[:code])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class HubriseApp::HubriseGateway
|
2
|
+
HUBRISE_LOGIN_SCOPE = "profile_with_email".freeze
|
3
|
+
HUBRISE_API_VERSION = :v1
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def build_api_client(params = {})
|
7
|
+
HubriseClient::V1.new(
|
8
|
+
HubriseApp::CONFIG[:hubrise_client_id],
|
9
|
+
HubriseApp::CONFIG[:hubrise_client_secret],
|
10
|
+
params.merge(
|
11
|
+
oauth_host: HubriseApp::CONFIG[:hubrise_oauth_host],
|
12
|
+
oauth_port: HubriseApp::CONFIG[:hubrise_oauth_port],
|
13
|
+
api_host: HubriseApp::CONFIG[:hubrise_api_host],
|
14
|
+
api_port: HubriseApp::CONFIG[:hubrise_api_port],
|
15
|
+
use_https: HubriseApp::CONFIG[:hubrise_use_https]
|
16
|
+
)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_api_client_from_authorization_code(authorization_code)
|
21
|
+
build_api_client.tap do |api_client|
|
22
|
+
api_client.authorize!(authorization_code)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_login_authorization_url(redirect_uri)
|
27
|
+
build_api_client.build_authorization_url(redirect_uri, HUBRISE_LOGIN_SCOPE)
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_app_authorization_url(hr_app_instance_id, redirect_uri)
|
31
|
+
build_api_client.build_authorization_url(redirect_uri, nil, app_instance_id: hr_app_instance_id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
module HubriseApp::Services::Override::ConnectAppInstance; end
|
@@ -0,0 +1 @@
|
|
1
|
+
module HubriseApp::Services::Override::DisconnectAppInstance; end
|
@@ -0,0 +1 @@
|
|
1
|
+
module HubriseApp::Services::Override::HandleEvent; end
|
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,11 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class HubriseApp::HrUserAppInstance < HubriseApp::ApplicationRecord
|
2
|
+
self.table_name = :hr_user_app_instances
|
3
|
+
|
4
|
+
belongs_to :hr_app_instance, primary_key: :hr_id
|
5
|
+
|
6
|
+
REFRESH_THRESHOLD = 1.day
|
7
|
+
def self.fresh(time: Time.now)
|
8
|
+
where("hr_user_app_instances.refreshed_at > ?", time - REFRESH_THRESHOLD)
|
9
|
+
end
|
10
|
+
|
11
|
+
def refresh!(time: Time.now)
|
12
|
+
update!(refreshed_at: time)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module HubriseApp::Override::HrUser; end
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 Hubrise app root
|
@@ -0,0 +1 @@
|
|
1
|
+
HubriseApp::CONFIG = Rails.application.config_for("hubrise_app/config").deep_symbolize_keys
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
HubriseApp::Engine.routes.draw do
|
2
|
+
namespace :hubrise_oauth, controller: "/hubrise_app/oauth" do
|
3
|
+
get :connect_callback
|
4
|
+
get :login_callback
|
5
|
+
get :authorize_callback
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :hubrise_callback, controller: "/hubrise_app/callback" do
|
9
|
+
post :event
|
10
|
+
get :disconnect
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class CreateBaseTables < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :hr_accounts do |t|
|
4
|
+
t.string :hr_id, null: false, index: { unique: true }
|
5
|
+
t.json :hr_api_data, null: false
|
6
|
+
t.datetime :refreshed_at, null: false
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :hr_locations do |t|
|
10
|
+
t.string :hr_id, null: false, index: { unique: true }
|
11
|
+
t.json :hr_api_data, null: false
|
12
|
+
t.datetime :refreshed_at, null: false
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :hr_app_instances do |t|
|
16
|
+
t.string :hr_id, null: false, index: { unique: true }
|
17
|
+
t.string :hr_account_id, index: true
|
18
|
+
t.string :hr_location_id, index: true
|
19
|
+
t.string :hr_catalog_id
|
20
|
+
t.string :hr_customer_list_id
|
21
|
+
t.string :hr_access_token, null: false
|
22
|
+
end
|
23
|
+
|
24
|
+
add_foreign_key :hr_app_instances, :hr_accounts, primary_key: :hr_id
|
25
|
+
add_foreign_key :hr_app_instances, :hr_locations, primary_key: :hr_id
|
26
|
+
|
27
|
+
create_table :hr_users do |t|
|
28
|
+
t.string :hr_id, null: false, index: { unique: true }
|
29
|
+
t.json :hr_api_data, null: false
|
30
|
+
t.string :hr_access_token, null: false
|
31
|
+
t.datetime :refreshed_at, null: false
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :hr_user_app_instances do |t|
|
35
|
+
t.string :hr_user_id, index: true
|
36
|
+
t.string :hr_app_instance_id, index: true
|
37
|
+
t.datetime :refreshed_at, null: false
|
38
|
+
end
|
39
|
+
|
40
|
+
add_foreign_key :hr_user_app_instances, :hr_users, primary_key: :hr_id
|
41
|
+
add_foreign_key :hr_user_app_instances, :hr_app_instances, primary_key: :hr_id
|
42
|
+
add_index :hr_user_app_instances, %i[hr_user_id hr_app_instance_id refreshed_at], name: :index_user_app_instances, using: :btree
|
43
|
+
end
|
44
|
+
end
|
data/lib/hubrise_app.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubrise_app
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Antoine Monnier
|
8
|
+
- Nick Save
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hubrise_client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.0.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 5.2.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 5.2.2
|
42
|
+
description:
|
43
|
+
email:
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/assets/config/hubrise_app_manifest.js
|
52
|
+
- app/assets/stylesheets/hubrise_app/application.css
|
53
|
+
- app/controllers/hubrise_app/application_controller.rb
|
54
|
+
- app/controllers/hubrise_app/callback_controller.rb
|
55
|
+
- app/controllers/hubrise_app/oauth_controller.rb
|
56
|
+
- app/lib/hubrise_app/hubrise_gateway.rb
|
57
|
+
- app/lib/hubrise_app/services/connect_app_instance.rb
|
58
|
+
- app/lib/hubrise_app/services/disconnect_app_instance.rb
|
59
|
+
- app/lib/hubrise_app/services/handle_event.rb
|
60
|
+
- app/lib/hubrise_app/services/override/connect_app_instance.rb
|
61
|
+
- app/lib/hubrise_app/services/override/disconnect_app_instance.rb
|
62
|
+
- app/lib/hubrise_app/services/override/handle_event.rb
|
63
|
+
- app/models/concerns/hubrise_app/hr_api_resource.rb
|
64
|
+
- app/models/hubrise_app/application_record.rb
|
65
|
+
- app/models/hubrise_app/hr_account.rb
|
66
|
+
- app/models/hubrise_app/hr_app_instance.rb
|
67
|
+
- app/models/hubrise_app/hr_location.rb
|
68
|
+
- app/models/hubrise_app/hr_user.rb
|
69
|
+
- app/models/hubrise_app/hr_user_app_instance.rb
|
70
|
+
- app/models/hubrise_app/override/hr_user.rb
|
71
|
+
- app/views/hubrise_app/application/root.html.haml
|
72
|
+
- app/views/layouts/hubrise_app/application.html.erb
|
73
|
+
- config/initializers/hubrise_app_config.rb
|
74
|
+
- config/routes.rb
|
75
|
+
- db/migrate/20190116155419_create_base_tables.rb
|
76
|
+
- lib/hubrise_app.rb
|
77
|
+
- lib/hubrise_app/engine.rb
|
78
|
+
- lib/hubrise_app/version.rb
|
79
|
+
homepage: https://github.com/HubRise/ruby-app
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.7.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Rails engine to bootstrap a HubRise-based application
|
103
|
+
test_files: []
|