mints 0.0.26 → 0.0.27
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/lib/client.rb +72 -34
- data/lib/contact.rb +46 -46
- data/lib/errors.rb +98 -0
- data/lib/mints/controllers/admin_base_controller.rb +8 -66
- data/lib/mints/controllers/base_api_controller.rb +16 -134
- data/lib/mints/controllers/base_controller.rb +20 -106
- data/lib/mints/controllers/concerns/mints_clients.rb +74 -0
- data/lib/mints/controllers/concerns/read_config_file.rb +28 -0
- data/lib/mints/controllers/contact_api_controller.rb +6 -85
- data/lib/mints/controllers/public_api_controller.rb +6 -79
- data/lib/mints/controllers/user_api_controller.rb +7 -82
- data/lib/mints/helpers/contact_auth_helper.rb +67 -0
- data/lib/{mints_helper.rb → mints/helpers/mints_helper.rb} +7 -5
- data/lib/mints/helpers/proxy_controllers_methods.rb +126 -0
- data/lib/mints/helpers/user_auth_helper.rb +53 -0
- data/lib/mints.rb +2 -0
- data/lib/pub.rb +21 -21
- data/lib/user/config/api_keys.rb +4 -4
- data/lib/user/config/appointments.rb +13 -13
- data/lib/user/config/attribute_groups.rb +5 -5
- data/lib/user/config/attributes.rb +6 -6
- data/lib/user/config/calendars.rb +5 -5
- data/lib/user/config/config.rb +7 -7
- data/lib/user/config/importers.rb +13 -13
- data/lib/user/config/public_folders.rb +7 -7
- data/lib/user/config/relationships.rb +9 -9
- data/lib/user/config/roles.rb +6 -6
- data/lib/user/config/seeds.rb +3 -3
- data/lib/user/config/system_settings.rb +4 -4
- data/lib/user/config/tags.rb +4 -4
- data/lib/user/config/taxonomies.rb +7 -7
- data/lib/user/config/teams.rb +5 -5
- data/lib/user/config/users.rb +5 -5
- data/lib/user/contacts/contacts.rb +1 -1
- data/lib/user/content/assets.rb +17 -17
- data/lib/user/content/content.rb +13 -13
- data/lib/user/content/content_instances.rb +9 -9
- data/lib/user/content/content_templates.rb +7 -7
- data/lib/user/content/conversations.rb +13 -13
- data/lib/user/content/dam.rb +8 -8
- data/lib/user/content/forms.rb +16 -16
- data/lib/user/content/message_templates.rb +11 -11
- data/lib/user/content/messages.rb +5 -5
- data/lib/user/content/pages.rb +7 -7
- data/lib/user/content/stories.rb +6 -6
- data/lib/user/content/story_templates.rb +6 -6
- data/lib/user/content/story_versions.rb +6 -6
- data/lib/user/crm/companies.rb +5 -5
- data/lib/user/crm/contacts.rb +18 -18
- data/lib/user/crm/deals.rb +6 -6
- data/lib/user/crm/favorites.rb +3 -3
- data/lib/user/crm/segments.rb +9 -9
- data/lib/user/crm/users.rb +1 -1
- data/lib/user/crm/workflow_step_objects.rb +5 -5
- data/lib/user/crm/workflow_steps.rb +3 -3
- data/lib/user/crm/workflows.rb +4 -4
- data/lib/user/ecommerce/item_prices.rb +5 -5
- data/lib/user/ecommerce/locations.rb +10 -10
- data/lib/user/ecommerce/order_items_groups.rb +15 -14
- data/lib/user/ecommerce/order_statuses.rb +2 -2
- data/lib/user/ecommerce/orders.rb +16 -16
- data/lib/user/ecommerce/price_lists.rb +3 -3
- data/lib/user/ecommerce/product_templates.rb +7 -7
- data/lib/user/ecommerce/product_variations.rb +8 -8
- data/lib/user/ecommerce/products.rb +10 -10
- data/lib/user/ecommerce/skus.rb +5 -5
- data/lib/user/ecommerce/taxes.rb +5 -5
- data/lib/user/ecommerce/variant_options.rb +4 -4
- data/lib/user/ecommerce/variant_values.rb +4 -4
- data/lib/user/helpers/helpers.rb +8 -8
- data/lib/user/helpers/object_activities.rb +5 -5
- data/lib/user/helpers/object_folders.rb +5 -5
- data/lib/user/helpers/user_folders.rb +5 -5
- data/lib/user/marketing/marketing.rb +8 -8
- data/lib/user/profile/profile.rb +8 -8
- data/lib/user.rb +1 -1
- metadata +10 -4
data/lib/errors.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Mints
|
2
|
+
|
3
|
+
module Errors
|
4
|
+
|
5
|
+
class NonSupportedRubyVersionError < RuntimeError; end
|
6
|
+
|
7
|
+
class DynamicError < RuntimeError
|
8
|
+
ERRORS = {
|
9
|
+
'401' => 'AccessDeniedException',
|
10
|
+
'404' => 'ResourceNotFoundException',
|
11
|
+
'422' => 'ValidationException',
|
12
|
+
'405' => 'MethodNotAllowed',
|
13
|
+
'default' => 'InternalServerException',
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(client, title, detail, http_status, response)
|
17
|
+
@http_status = http_status
|
18
|
+
@error = error_class.constantize&.new(client, title, detail, http_status, response)
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :error, :http_status
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
error_class
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def error_class
|
30
|
+
"Mints::Errors::#{ERRORS[http_status.to_s] || ERRORS['default']}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ServiceError < RuntimeError
|
35
|
+
# @param [Client] client
|
36
|
+
# @param [String] title
|
37
|
+
# @param [String] detail
|
38
|
+
# @param [Integer] http_status
|
39
|
+
# @param [String Object Array] response
|
40
|
+
def initialize(client, title, detail, http_status, response)
|
41
|
+
@title = title
|
42
|
+
@client = client
|
43
|
+
@response = response
|
44
|
+
@http_status = http_status
|
45
|
+
@detail = detail && !detail.empty? ? detail : self.class.to_s
|
46
|
+
|
47
|
+
super(@detail)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String]
|
51
|
+
def detail
|
52
|
+
@detail
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_h(extra_fields = {})
|
56
|
+
default_fields = {
|
57
|
+
client: client,
|
58
|
+
title: title,
|
59
|
+
detail: detail,
|
60
|
+
http_status: http_status,
|
61
|
+
response: response
|
62
|
+
}
|
63
|
+
|
64
|
+
default_fields.merge(extra_fields)
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
to_h.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :client, :detail, :title, :http_status, :response
|
72
|
+
end
|
73
|
+
|
74
|
+
class AccessDeniedException < ServiceError; end
|
75
|
+
|
76
|
+
class ResourceNotFoundException < ServiceError; end
|
77
|
+
|
78
|
+
class MethodNotAllowed < ServiceError; end
|
79
|
+
|
80
|
+
class ValidationException < ServiceError
|
81
|
+
|
82
|
+
def to_h
|
83
|
+
super(errors_hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
def errors_hash
|
87
|
+
{
|
88
|
+
errors: response.keys.reduce([]) {|carry, error_key| carry + response[error_key]}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
attr_reader :failed_validations
|
93
|
+
end
|
94
|
+
|
95
|
+
class InternalServerException < ServiceError; end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -1,73 +1,15 @@
|
|
1
|
+
require_relative "./concerns/mints_clients.rb"
|
2
|
+
require_relative "../helpers/user_auth_helper.rb"
|
3
|
+
|
1
4
|
module Mints
|
2
5
|
class AdminBaseController < ActionController::Base
|
3
|
-
before_action :set_mints_user_client
|
4
|
-
|
5
|
-
def mints_user_signed_in?
|
6
|
-
# Check status in mints
|
7
|
-
response = @mints_user.me
|
8
|
-
status = response['data'] ? true : false
|
9
|
-
unless status
|
10
|
-
# if mints response is negative delete the session cookie
|
11
|
-
#cookies.delete(:mints_user_session_token)
|
12
|
-
end
|
13
|
-
return status
|
14
|
-
end
|
15
|
-
|
16
|
-
##
|
17
|
-
# === Mints user Login.
|
18
|
-
# Starts a user session in mints.cloud and set a session cookie
|
19
|
-
def mints_user_login(email, password)
|
20
|
-
# Login in mints
|
21
|
-
response = @mints_user.login(email, password)
|
22
|
-
# Get session token from response
|
23
|
-
session_token = response['api_token']
|
24
|
-
# Set a permanent cookie with the session token
|
25
|
-
cookies[:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day }
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# === Mints user Login.
|
30
|
-
# Starts a user session in mints.cloud and set a session cookie
|
31
|
-
def mints_user_magic_link_login(hash)
|
32
|
-
# Login in mints
|
33
|
-
response = @mints_user.magic_link_login(hash)
|
34
|
-
if response['data'] && response['data']['redirect_url']
|
35
|
-
# Set a cookie with the session token
|
36
|
-
cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day, secure: true, httponly: true }
|
37
|
-
redirect_to response['data']['redirect_url']
|
38
|
-
else
|
39
|
-
redirect_to '/'
|
40
|
-
end
|
41
|
-
end
|
42
6
|
|
43
|
-
|
44
|
-
|
45
|
-
# Destroy session from mints.cloud and delete local session cookie
|
46
|
-
def mints_user_logout
|
47
|
-
# Logout from mints
|
48
|
-
# @mints_user.logout
|
49
|
-
# Delete local cookie
|
50
|
-
cookies.delete(:mints_user_session_token)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
7
|
+
include MintsClients
|
8
|
+
include UserAuthHelper
|
54
9
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def set_mints_user_client
|
59
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
60
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
61
|
-
config = YAML.load template.result(binding)
|
62
|
-
@host = config["mints"]["host"]
|
63
|
-
@api_key = config["mints"]["api_key"]
|
64
|
-
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
65
|
-
else
|
66
|
-
raise 'MintsBadCredentialsError'
|
67
|
-
end
|
68
|
-
# Initialize mints user client
|
69
|
-
session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
|
70
|
-
@mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
|
10
|
+
# Override default values for mints clients concern
|
11
|
+
def define_mints_clients
|
12
|
+
%w[ user service_account ]
|
71
13
|
end
|
72
14
|
end
|
73
15
|
end
|
@@ -1,144 +1,26 @@
|
|
1
|
+
require_relative "./concerns/mints_clients.rb"
|
2
|
+
require_relative "../helpers/user_auth_helper.rb"
|
3
|
+
require_relative "../helpers/contact_auth_helper.rb"
|
4
|
+
|
1
5
|
module Mints
|
2
6
|
class BaseApiController < ActionController::Base
|
3
|
-
|
4
|
-
|
5
|
-
##
|
6
|
-
# === Mints Contact Login.
|
7
|
-
# Starts a contact session in mints.cloud and set a session cookie
|
8
|
-
def mints_contact_login(email, password)
|
9
|
-
# Login in mints
|
10
|
-
response = @mints_contact.login(email, password)
|
11
|
-
# Get session token from response
|
12
|
-
session_token = response['session_token']
|
13
|
-
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
14
|
-
# Set a permanent cookie with the session token
|
15
|
-
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
16
|
-
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
17
|
-
@contact_token = id_token
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# === Mints contact Login.
|
22
|
-
# Starts a contact session in mints.cloud and set a session cookie
|
23
|
-
def mints_contact_magic_link_login(hash)
|
24
|
-
# Login in mints
|
25
|
-
response = @mints_contact.magic_link_login(hash)
|
26
|
-
if response['data']
|
27
|
-
# Get session token from response
|
28
|
-
session_token = response['data']['session_token']
|
29
|
-
id_token = response['data']['contact']['contact_token'] ? response['data']['contact']['contact_token'] : response['data']['contact']['id_token']
|
30
|
-
# Set a permanent cookie with the session token
|
31
|
-
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
32
|
-
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
33
|
-
@contact_token = id_token
|
34
|
-
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
35
|
-
else
|
36
|
-
redirect_to '/'
|
37
|
-
end
|
38
|
-
end
|
7
|
+
# Concerns
|
8
|
+
include MintsClients
|
39
9
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def mints_contact_logout
|
44
|
-
# Logout from mints
|
45
|
-
@mints_contact.logout
|
46
|
-
# Delete local cookie
|
47
|
-
cookies.delete(:mints_contact_session_token)
|
48
|
-
cookies.delete(:mints_contact_id)
|
49
|
-
@contact_token = nil
|
50
|
-
end
|
10
|
+
# Helpers
|
11
|
+
include ContactAuthHelper
|
12
|
+
include UserAuthHelper
|
51
13
|
|
52
|
-
|
53
|
-
|
54
|
-
# Starts a user session in mints.cloud and set a session cookie
|
55
|
-
def mints_user_login(email, password)
|
56
|
-
# Login in mints
|
57
|
-
response = @mints_user.login(email, password)
|
58
|
-
# Get session token from response
|
59
|
-
session_token = response['api_token']
|
60
|
-
# Set a permanent cookie with the session token
|
61
|
-
cookies[:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day }
|
14
|
+
def define_mints_clients
|
15
|
+
%w[ contact pub ]
|
62
16
|
end
|
63
17
|
|
64
18
|
##
|
65
|
-
# === Mints
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
if response['data']
|
71
|
-
# Set a cookie with the session token
|
72
|
-
cookies[:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day }
|
73
|
-
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
74
|
-
else
|
75
|
-
redirect_to '/'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# === Mints user Logout.
|
81
|
-
# Destroy session from mints.cloud and delete local session cookie
|
82
|
-
def mints_user_logout
|
83
|
-
# Logout from mints
|
84
|
-
# @mints_user.logout
|
85
|
-
# Delete local cookie
|
86
|
-
cookies.delete(:mints_user_session_token)
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
##
|
92
|
-
# === Set mints clients (pub, user and contact)
|
93
|
-
# Initialize all clients from mitns
|
94
|
-
def set_mints_clients
|
95
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
96
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
97
|
-
config = YAML.load template.result(binding)
|
98
|
-
@host = config["mints"]["host"]
|
99
|
-
@api_key = config["mints"]["api_key"]
|
100
|
-
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
101
|
-
|
102
|
-
#public client
|
103
|
-
set_mints_pub_client
|
104
|
-
#contact client
|
105
|
-
set_mints_contact_client
|
106
|
-
#user client
|
107
|
-
set_mints_user_client
|
108
|
-
else
|
109
|
-
raise 'MintsBadCredentialsError'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
##
|
114
|
-
# === Set mints pub.
|
115
|
-
# Initialize the public client and set the contact token
|
116
|
-
def set_mints_pub_client
|
117
|
-
|
118
|
-
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
119
|
-
@visit_id = cookies[:mints_visit_id] ? cookies[:mints_visit_id] : nil
|
120
|
-
@mints_pub = Mints::Pub.new(@host, @api_key, nil, @visit_id, @debug)
|
121
|
-
# Set contact token from cookie
|
122
|
-
@mints_pub.client.session_token = @contact_token
|
123
|
-
end
|
124
|
-
|
125
|
-
##
|
126
|
-
# === Set mints contact client.
|
127
|
-
# Initialize the public client and set the contact token
|
128
|
-
def set_mints_contact_client
|
129
|
-
# Initialize mints clontact client
|
130
|
-
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
131
|
-
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
132
|
-
@mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
|
133
|
-
end
|
134
|
-
|
135
|
-
##
|
136
|
-
# === Set Mints user client.
|
137
|
-
# Initialize the public client and set the user token
|
138
|
-
def set_mints_user_client
|
139
|
-
# Initialize mints user client
|
140
|
-
session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
|
141
|
-
@mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
|
19
|
+
# === Mints contact Login.
|
20
|
+
# This method works to override the base to add the redirect parameter
|
21
|
+
# The main method is located in contact_auth_helper.rb
|
22
|
+
def mints_contact_magic_link_login(hash)
|
23
|
+
super(hash, true)
|
142
24
|
end
|
143
25
|
end
|
144
26
|
end
|
@@ -1,63 +1,21 @@
|
|
1
|
+
require_relative "./concerns/mints_clients.rb"
|
2
|
+
require_relative "../helpers/contact_auth_helper.rb"
|
3
|
+
|
1
4
|
module Mints
|
2
5
|
class BaseController < ActionController::Base
|
3
|
-
|
4
|
-
|
5
|
-
before_action :register_visit
|
6
|
-
before_action :set_mints_contact_client
|
7
|
-
|
8
|
-
def mints_contact_signed_in?
|
9
|
-
# Check status in mints
|
10
|
-
response = @mints_contact.status
|
11
|
-
status = response['success'] ? response['success'] : false
|
12
|
-
unless status
|
13
|
-
# if mints response is negative delete the session cookie
|
14
|
-
cookies.delete(:mints_contact_session_token)
|
15
|
-
end
|
16
|
-
return status
|
17
|
-
end
|
6
|
+
# Concerns
|
7
|
+
include MintsClients
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
# Starts a contact session in mints.cloud and set a session cookie
|
22
|
-
def mints_contact_login(email, password)
|
23
|
-
# Login in mints
|
24
|
-
response = @mints_contact.login(email, password)
|
25
|
-
# Get session token from response
|
26
|
-
session_token = response['session_token']
|
27
|
-
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
28
|
-
# Set a permanent cookie with the session token
|
29
|
-
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
30
|
-
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
31
|
-
@contact_token = id_token
|
32
|
-
end
|
9
|
+
# Helpers
|
10
|
+
include ContactAuthHelper
|
33
11
|
|
34
|
-
|
35
|
-
# === Mints Contact Magic Link Login.
|
36
|
-
# Starts a contact session in mints.cloud and set a session cookie
|
37
|
-
def mints_contact_magic_link_login(token)
|
38
|
-
# Login in mints
|
39
|
-
response = @mints_contact.login(email, password)
|
40
|
-
# Get session token from response
|
41
|
-
session_token = response['session_token']
|
42
|
-
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
43
|
-
# Set a permanent cookie with the session token
|
44
|
-
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
45
|
-
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
46
|
-
@contact_token = id_token
|
47
|
-
end
|
12
|
+
before_action :register_visit
|
48
13
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def mints_contact_logout
|
53
|
-
# Logout from mints
|
54
|
-
@mints_contact.logout
|
55
|
-
# Delete local cookie
|
56
|
-
cookies.delete(:mints_contact_session_token)
|
57
|
-
cookies.delete(:mints_contact_id)
|
58
|
-
@contact_token = nil
|
14
|
+
# Override default values for mints clients concern
|
15
|
+
def define_mints_clients
|
16
|
+
%w[ contact pub ]
|
59
17
|
end
|
60
|
-
|
18
|
+
|
61
19
|
private
|
62
20
|
|
63
21
|
##
|
@@ -76,63 +34,19 @@ module Mints
|
|
76
34
|
puts "REQUEST IP ADDRESS: #{request['ip_address']}"
|
77
35
|
puts "REQUEST REMOTE IP: #{request['remote_ip']}"
|
78
36
|
end
|
37
|
+
|
79
38
|
response = @mints_pub.register_visit(request)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
@contact_token = response['contact_token']
|
39
|
+
|
40
|
+
puts "RESPONSE IN REGISTER VISIT: #{response}" if @debug
|
41
|
+
|
42
|
+
@contact_token = response['contact_token'] || response['user_token']
|
84
43
|
@visit_id = response['visit_id']
|
85
|
-
if @debug
|
86
|
-
puts "VISIT ID: #{@visit_id}"
|
87
|
-
end
|
88
|
-
cookies.permanent[:mints_contact_id] = { value: @contact_token, secure: true, httponly: true }
|
89
|
-
cookies.permanent[:mints_visit_id] = { value: @visit_id, secure: true, httponly: true }
|
90
|
-
end
|
91
44
|
|
92
|
-
|
93
|
-
# === Set mints pub.
|
94
|
-
# Initialize the public client and set the contact token
|
95
|
-
def set_mints_pub_client
|
96
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
97
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
98
|
-
config = YAML.load template.result(binding)
|
99
|
-
@host = config["mints"]["host"]
|
100
|
-
@api_key = config["mints"]["api_key"]
|
101
|
-
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
102
|
-
else
|
103
|
-
raise 'MintsBadCredentialsError'
|
104
|
-
end
|
105
|
-
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
106
|
-
@visit_id = cookies[:mints_visit_id] ? cookies[:mints_visit_id] : nil
|
107
|
-
@mints_pub = Mints::Pub.new(@host, @api_key, @contact_token, @visit_id, @debug)
|
108
|
-
# Set contact token from cookie
|
109
|
-
@mints_pub.client.session_token = @contact_token
|
110
|
-
end
|
45
|
+
puts "VISIT ID: #{@visit_id}" if @debug
|
111
46
|
|
112
|
-
|
113
|
-
|
114
|
-
# Set contact token variable from the mints_contact_id cookie value
|
115
|
-
def set_contact_token
|
116
|
-
@contact_token = cookies[:mints_contact_id]
|
47
|
+
cookies.permanent[:mints_contact_id] = { value: @contact_token, secure: true, httponly: true }
|
48
|
+
cookies.permanent[:mints_visit_id] = { value: @visit_id, secure: true, httponly: true }
|
117
49
|
end
|
118
50
|
|
119
|
-
##
|
120
|
-
# === Set mints contact client.
|
121
|
-
# Initialize the public client and set the contact token
|
122
|
-
def set_mints_contact_client
|
123
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
124
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
125
|
-
config = YAML.load template.result(binding)
|
126
|
-
@host = config["mints"]["host"]
|
127
|
-
@api_key = config["mints"]["api_key"]
|
128
|
-
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
129
|
-
else
|
130
|
-
raise 'MintsBadCredentialsError'
|
131
|
-
end
|
132
|
-
# Initialize mints clontact client
|
133
|
-
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
134
|
-
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
135
|
-
@mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
|
136
|
-
end
|
137
51
|
end
|
138
52
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative "./read_config_file.rb"
|
2
|
+
|
3
|
+
module MintsClients
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include ReadConfigFile
|
8
|
+
before_action :set_mints_clients
|
9
|
+
end
|
10
|
+
|
11
|
+
# Define the clients that will have
|
12
|
+
# Override in the controller if you dont wanna all clients
|
13
|
+
def define_mints_clients
|
14
|
+
%w[ contact user pub service_account ]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
##
|
20
|
+
# === Set mints clients (pub, user and contact)
|
21
|
+
# Initialize all clients from mints
|
22
|
+
def set_mints_clients
|
23
|
+
clients = define_mints_clients
|
24
|
+
|
25
|
+
if @debug
|
26
|
+
puts "Clients to initialize:", clients
|
27
|
+
puts "Host:", @host
|
28
|
+
end
|
29
|
+
|
30
|
+
if clients.kind_of?(Array) and @host
|
31
|
+
clients.each do |client|
|
32
|
+
send("set_mints_#{client}_client")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# === Set mints pub.
|
39
|
+
# Initialize the public client and set the contact token
|
40
|
+
def set_mints_pub_client
|
41
|
+
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
42
|
+
visit_id = cookies[:mints_visit_id]
|
43
|
+
contact_token_id = cookies[:mints_contact_id]
|
44
|
+
|
45
|
+
@mints_pub = Mints::Pub.new(@host, @api_key, contact_token_id, visit_id, @debug)
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# === Set mints contact client.
|
50
|
+
# Initialize the contact client and set the contact token
|
51
|
+
def set_mints_contact_client
|
52
|
+
# Initialize mints contact client
|
53
|
+
contact_session_token = cookies[:mints_contact_session_token]
|
54
|
+
contact_token_id = cookies[:mints_contact_id]
|
55
|
+
@mints_contact = Mints::Contact.new(@host, @api_key, contact_session_token, contact_token_id, @debug)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# === Set Mints user client.
|
60
|
+
# Initialize the user client
|
61
|
+
def set_mints_user_client
|
62
|
+
# Initialize mints user client
|
63
|
+
user_session_token = cookies[:mints_user_session_token]
|
64
|
+
@mints_user = Mints::User.new(@host, @api_key, user_session_token, @debug)
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# === Set Mints service account
|
69
|
+
# Initialize the service account client
|
70
|
+
def set_mints_service_account_client
|
71
|
+
# Initialize service account client
|
72
|
+
@mints_service_account = Mints::User.new(@host, @api_key, @api_key, @debug)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ReadConfigFile
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
before_action :set_config_variables
|
6
|
+
end
|
7
|
+
|
8
|
+
def set_config_variables
|
9
|
+
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
10
|
+
|
11
|
+
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
12
|
+
config = YAML.safe_load template.result(binding)
|
13
|
+
@host = config["mints"]["host"]
|
14
|
+
@api_key = config["mints"]["api_key"]
|
15
|
+
@debug = !!config["sdk"]["debug"]
|
16
|
+
@redis_config = config['redis_cache']
|
17
|
+
@use_cache = config['redis_cache']['use_cache']
|
18
|
+
|
19
|
+
if config['redis_cache']['use_cache']
|
20
|
+
@redis_server = Redis.new(
|
21
|
+
host: config['redis_cache']['redis_host'],
|
22
|
+
port: config['redis_cache']['redis_port'] || 6379,
|
23
|
+
db: config['redis_cache']['redis_db'] || 1
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|