mints 0.0.26 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/lib/client.rb +75 -37
- data/lib/contact.rb +61 -62
- data/lib/errors.rb +98 -0
- data/lib/generators/mints_config.yml.erb +0 -2
- data/lib/generators/mints_link.rb +3 -3
- 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 +56 -56
- data/lib/user/config/api_keys.rb +7 -7
- data/lib/user/config/appointments.rb +16 -16
- data/lib/user/config/attribute_groups.rb +10 -10
- data/lib/user/config/attributes.rb +10 -10
- data/lib/user/config/calendars.rb +9 -9
- data/lib/user/config/config.rb +7 -7
- data/lib/user/config/importers.rb +15 -15
- data/lib/user/config/public_folders.rb +11 -11
- data/lib/user/config/relationships.rb +11 -11
- data/lib/user/config/roles.rb +9 -9
- data/lib/user/config/seeds.rb +5 -5
- data/lib/user/config/system_settings.rb +5 -5
- data/lib/user/config/tags.rb +5 -5
- data/lib/user/config/taxonomies.rb +15 -15
- data/lib/user/config/teams.rb +67 -68
- data/lib/user/config/users.rb +70 -71
- data/lib/user/contacts/contacts.rb +19 -20
- data/lib/user/content/assets.rb +273 -278
- data/lib/user/content/content.rb +48 -48
- data/lib/user/content/content_instances.rb +136 -138
- data/lib/user/content/content_templates.rb +103 -103
- data/lib/user/content/conversations.rb +193 -193
- data/lib/user/content/dam.rb +83 -80
- data/lib/user/content/forms.rb +229 -233
- data/lib/user/content/message_templates.rb +152 -151
- data/lib/user/content/messages.rb +87 -87
- data/lib/user/content/pages.rb +82 -82
- data/lib/user/content/stories.rb +101 -101
- data/lib/user/content/story_templates.rb +88 -88
- data/lib/user/content/story_versions.rb +115 -117
- data/lib/user/crm/companies.rb +103 -105
- data/lib/user/crm/contacts.rb +285 -292
- data/lib/user/crm/crm.rb +19 -19
- data/lib/user/crm/deals.rb +103 -103
- data/lib/user/crm/favorites.rb +14 -13
- data/lib/user/crm/segments.rb +121 -123
- data/lib/user/crm/users.rb +20 -20
- data/lib/user/crm/workflow_step_objects.rb +84 -84
- data/lib/user/crm/workflow_steps.rb +45 -45
- data/lib/user/crm/workflows.rb +65 -65
- data/lib/user/ecommerce/ecommerce.rb +27 -27
- data/lib/user/ecommerce/item_prices.rb +82 -81
- data/lib/user/ecommerce/locations.rb +160 -160
- data/lib/user/ecommerce/order_items_groups.rb +107 -105
- data/lib/user/ecommerce/order_statuses.rb +24 -24
- data/lib/user/ecommerce/orders.rb +250 -246
- data/lib/user/ecommerce/price_lists.rb +68 -68
- data/lib/user/ecommerce/product_templates.rb +99 -99
- data/lib/user/ecommerce/product_variations.rb +122 -120
- data/lib/user/ecommerce/products.rb +160 -159
- data/lib/user/ecommerce/skus.rb +85 -85
- data/lib/user/ecommerce/taxes.rb +79 -79
- data/lib/user/ecommerce/variant_options.rb +66 -66
- data/lib/user/ecommerce/variant_values.rb +69 -69
- data/lib/user/helpers/helpers.rb +102 -101
- data/lib/user/helpers/object_activities.rb +78 -78
- data/lib/user/helpers/object_folders.rb +76 -76
- data/lib/user/helpers/user_folders.rb +77 -77
- data/lib/user/marketing/marketing.rb +114 -113
- data/lib/user/profile/profile.rb +94 -103
- data/lib/user.rb +4 -4
- metadata +41 -35
@@ -1,89 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "./concerns/read_config_file.rb"
|
2
|
+
require_relative "../helpers/proxy_controllers_methods.rb"
|
3
|
+
|
3
4
|
module Mints
|
4
5
|
class UserAPIController < ActionController::API
|
5
6
|
include AbstractController::Helpers
|
6
|
-
include
|
7
|
-
include
|
8
|
-
before_action :set_config_variables
|
9
|
-
|
10
|
-
def index
|
11
|
-
headers = {
|
12
|
-
'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
|
13
|
-
'ApiKey' => "#{@api_key}",
|
14
|
-
'Content-Type'=> 'application/json',
|
15
|
-
'Accept'=> 'application/json'
|
16
|
-
}
|
17
|
-
if cookies[:mints_user_session_token]
|
18
|
-
session_token = cookies[:mints_user_session_token]
|
19
|
-
headers["Authorization"] = "Bearer #{session_token}"
|
20
|
-
end
|
21
|
-
|
22
|
-
url_need_cache = false
|
23
|
-
result_from_cache = false
|
24
|
-
time = 0
|
25
|
-
full_url = request.original_url
|
26
|
-
|
27
|
-
if request.method == "GET"
|
28
|
-
if url_need_cache
|
29
|
-
@redis_config['groups'].each do |group|
|
30
|
-
group['urls'].each do |url|
|
31
|
-
if full_url.match url
|
32
|
-
time = group['time']
|
33
|
-
url_need_cache = true
|
34
|
-
break
|
35
|
-
end
|
36
|
-
end
|
37
|
-
break if url_need_cache
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
7
|
+
include ReadConfigFile
|
8
|
+
include ProxyControllersMethods
|
41
9
|
|
42
|
-
|
43
|
-
|
44
|
-
response = @redis_server.get(full_url)
|
45
|
-
result_from_cache = true
|
46
|
-
render json: response
|
47
|
-
else
|
48
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
49
|
-
# Request succeded!
|
50
|
-
config.on_response do |code, response|
|
51
|
-
@redis_server.setex(full_url,time,response.body)
|
52
|
-
end
|
53
|
-
# Request failed!
|
54
|
-
config.on_missing do |code, response|
|
55
|
-
# We got a 404!
|
56
|
-
if code == 404
|
57
|
-
raise ActionController::RoutingError.new('Not Found')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
else
|
63
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
64
|
-
# Request failed!
|
65
|
-
config.on_missing do |code, response|
|
66
|
-
# We got a 404!
|
67
|
-
if code == 404
|
68
|
-
raise ActionController::RoutingError.new('Not Found')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def set_config_variables
|
78
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
79
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
80
|
-
config = YAML.load template.result(binding)
|
81
|
-
@host = config["mints"]["host"]
|
82
|
-
@api_key = config["mints"]["api_key"]
|
83
|
-
@redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
|
84
|
-
@redis_config = config['redis_cache']
|
85
|
-
@use_cache = config['redis_cache']['use_cache'] if config['redis_cache']['use_cache']
|
86
|
-
end
|
10
|
+
def index
|
11
|
+
super('user')
|
87
12
|
end
|
88
13
|
end
|
89
14
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ContactAuthHelper
|
2
|
+
##
|
3
|
+
# === Mints Contact Login.
|
4
|
+
# Starts a contact session in mints.cloud and set a session cookie
|
5
|
+
def mints_contact_login(email, password)
|
6
|
+
# Login in mints
|
7
|
+
response = @mints_contact.login(email, password)
|
8
|
+
# Get session token from response
|
9
|
+
session_token = response['session_token']
|
10
|
+
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
11
|
+
# Set a permanent cookie with the session token
|
12
|
+
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
13
|
+
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
14
|
+
@contact_token = id_token
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# === Mints contact Login.
|
19
|
+
# Starts a contact session in mints.cloud and set a session cookie
|
20
|
+
def mints_contact_magic_link_login(hash, redirect_in_error = false)
|
21
|
+
# Login in mints
|
22
|
+
response = @mints_contact.magic_link_login(hash)
|
23
|
+
|
24
|
+
if response['data']
|
25
|
+
# Get session token from response
|
26
|
+
session_token = response['data']['session_token']
|
27
|
+
id_token = response['data']['contact']['contact_token'] ? response['data']['contact']['contact_token'] : response['data']['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
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/' if redirect_in_error
|
33
|
+
else
|
34
|
+
redirect_to '/' if redirect_in_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# === Mints Contact Logout.
|
40
|
+
# Destroy session from mints.cloud and delete local session cookie
|
41
|
+
def mints_contact_logout
|
42
|
+
# Logout from mints
|
43
|
+
@mints_contact.logout
|
44
|
+
# Delete local cookie
|
45
|
+
cookies.delete(:mints_contact_session_token)
|
46
|
+
cookies.delete(:mints_contact_id)
|
47
|
+
@contact_token = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def mints_contact_signed_in?
|
51
|
+
|
52
|
+
begin
|
53
|
+
# Check status in mints
|
54
|
+
# Check status in mints
|
55
|
+
response = @mints_contact.status
|
56
|
+
status = response['success'] || false
|
57
|
+
rescue => e
|
58
|
+
# Handle the client Unauthorized error
|
59
|
+
# if mints response is negative delete the session cookie
|
60
|
+
cookies.delete(:mints_contact_session_token)
|
61
|
+
|
62
|
+
status = false
|
63
|
+
end
|
64
|
+
|
65
|
+
status
|
66
|
+
end
|
67
|
+
end
|
@@ -10,9 +10,9 @@ module MintsHelper
|
|
10
10
|
#
|
11
11
|
def get_query_results(url, options = nil, use_post = true)
|
12
12
|
if use_post
|
13
|
-
|
13
|
+
@client.raw('post', "#{url}/query", options)
|
14
14
|
else
|
15
|
-
|
15
|
+
@client.raw('get', url, options)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -24,10 +24,12 @@ module MintsHelper
|
|
24
24
|
#
|
25
25
|
def data_transform(data)
|
26
26
|
data = correct_json(data)
|
27
|
+
|
27
28
|
unless data[:data]
|
28
29
|
data = {data: data}
|
29
30
|
end
|
30
|
-
|
31
|
+
|
32
|
+
data.to_json
|
31
33
|
end
|
32
34
|
|
33
35
|
# === Correct json.
|
@@ -40,8 +42,8 @@ module MintsHelper
|
|
40
42
|
if data.is_a? String
|
41
43
|
data = JSON.parse(data)
|
42
44
|
end
|
43
|
-
|
44
|
-
|
45
|
+
|
46
|
+
data.symbolize_keys
|
45
47
|
end
|
46
48
|
|
47
49
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'reverse_proxy/controller'
|
3
|
+
require 'reverse_proxy/client'
|
4
|
+
|
5
|
+
module ProxyControllersMethods
|
6
|
+
include ActionController::Cookies
|
7
|
+
include ReverseProxy::Controller
|
8
|
+
|
9
|
+
# === Index
|
10
|
+
# Is the base index method for all controllers, manage the headers depending
|
11
|
+
# on the controller type (Contact or User)
|
12
|
+
#
|
13
|
+
# ==== Parameters
|
14
|
+
# controller_type:: (String) -- Controller type that be called, this manages the headers to send (contact, user, pub).
|
15
|
+
# ==== Return
|
16
|
+
# Returns the response returned by send_mints_request
|
17
|
+
#
|
18
|
+
def index(controller_type = nil)
|
19
|
+
headers = {
|
20
|
+
'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
|
21
|
+
'ApiKey' => "#{@api_key}",
|
22
|
+
'Content-Type'=> 'application/json',
|
23
|
+
'Accept'=> 'application/json'
|
24
|
+
}
|
25
|
+
|
26
|
+
if %w[contact user].include? controller_type
|
27
|
+
session_token = cookies["mints_#{controller_type}_session_token".to_sym]
|
28
|
+
headers["Authorization"] = session_token ? "Bearer #{session_token}" : request.headers["Authorization"]
|
29
|
+
end
|
30
|
+
|
31
|
+
headers['ContactToken'] = cookies[:mints_contact_id] if controller_type === 'contact' and cookies[:mints_contact_id]
|
32
|
+
|
33
|
+
full_url = request.original_url
|
34
|
+
url_need_cache, time = url_need_cache?(full_url)
|
35
|
+
|
36
|
+
if @debug or true
|
37
|
+
puts "URL: #{full_url}"
|
38
|
+
puts "URL need cache: #{url_need_cache}"
|
39
|
+
puts "URL time cache: #{time}"
|
40
|
+
puts "Headers: #{headers}"
|
41
|
+
end
|
42
|
+
|
43
|
+
if url_need_cache
|
44
|
+
cached_response = @redis_server.get(full_url)
|
45
|
+
|
46
|
+
if cached_response
|
47
|
+
puts "RESPONSE FROM CACHE" if @debug
|
48
|
+
return render json: cached_response
|
49
|
+
end
|
50
|
+
|
51
|
+
send_mints_request(full_url, headers, true, time)
|
52
|
+
else
|
53
|
+
send_mints_request(full_url, headers)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# === Url need cache?
|
58
|
+
# Method used to check if the given URL should be cached and for how long
|
59
|
+
#
|
60
|
+
# ==== Parameters
|
61
|
+
# full_url:: (String) -- URL to check if has cache.
|
62
|
+
# ==== Return
|
63
|
+
# Returns if the URL has cache and the time to be cached
|
64
|
+
|
65
|
+
def url_need_cache?(full_url)
|
66
|
+
url_need_cache = false
|
67
|
+
time = 0
|
68
|
+
methods_with_cache = %w[GET]
|
69
|
+
|
70
|
+
if methods_with_cache.include? request.method
|
71
|
+
if @use_cache
|
72
|
+
@redis_config['groups'].each do |group|
|
73
|
+
group['urls'].each do |url|
|
74
|
+
|
75
|
+
if full_url.match url
|
76
|
+
time = group['time']
|
77
|
+
url_need_cache = true
|
78
|
+
break
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
break if url_need_cache
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
[url_need_cache, time]
|
89
|
+
end
|
90
|
+
|
91
|
+
# === Send mints request
|
92
|
+
# Method used to make each request to CXF, in addition to verifying and saving
|
93
|
+
# the response in cache for cases where it requires cache
|
94
|
+
#
|
95
|
+
# ==== Parameters
|
96
|
+
# full_url:: (String) -- URL to make the request.
|
97
|
+
# headers:: (Hash|Object) -- Headers to send in the request.
|
98
|
+
# cache_result:: (Boolean) -- This parameter controls whether the response will be cached..
|
99
|
+
# time:: (Integer) -- It is the time that the response will be stored in cache.
|
100
|
+
# ==== Return
|
101
|
+
# Returns the response given by CXF or Redis
|
102
|
+
|
103
|
+
def send_mints_request(full_url, headers, cache_result = false, time = 30)
|
104
|
+
puts "RESPONSE FROM MINTS.CLOUD" if @debug
|
105
|
+
|
106
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
107
|
+
|
108
|
+
if cache_result
|
109
|
+
# Request succeeded!
|
110
|
+
config.on_response do |code, response|
|
111
|
+
@redis_server.setex(
|
112
|
+
full_url,
|
113
|
+
time || 30,
|
114
|
+
response.body
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Request failed!
|
120
|
+
config.on_missing do |code, response|
|
121
|
+
# We got a 404!
|
122
|
+
raise ActionController::RoutingError.new('Not Found') if code == 404
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module UserAuthHelper
|
2
|
+
|
3
|
+
def mints_user_signed_in?
|
4
|
+
begin
|
5
|
+
# Check status in mints
|
6
|
+
response = @mints_user.me['data']
|
7
|
+
rescue => e
|
8
|
+
# Handle the client Unauthorized error
|
9
|
+
# if mints response is negative delete the session cookie
|
10
|
+
cookies.delete(:mints_user_session_token)
|
11
|
+
response = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
response
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# === Mints user Login.
|
19
|
+
# Starts a user session in mints.cloud and set a session cookie
|
20
|
+
def mints_user_login(email, password)
|
21
|
+
# Login in mints
|
22
|
+
response = @mints_user.login(email, password)
|
23
|
+
# Get session token from response
|
24
|
+
session_token = response['api_token']
|
25
|
+
# Set a permanent cookie with the session token
|
26
|
+
cookies[:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day }
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# === Mints user Login.
|
31
|
+
# Starts a user session in mints.cloud and set a session cookie
|
32
|
+
def mints_user_magic_link_login(hash)
|
33
|
+
# Login in mints
|
34
|
+
response = @mints_user.magic_link_login(hash)
|
35
|
+
if response['data']
|
36
|
+
# Set a cookie with the session token
|
37
|
+
cookies[:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day }
|
38
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
39
|
+
else
|
40
|
+
redirect_to '/'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# === Mints user Logout.
|
46
|
+
# Destroy session from mints.cloud and delete local session cookie
|
47
|
+
def mints_user_logout
|
48
|
+
# Logout from mints
|
49
|
+
# @mints_user.logout
|
50
|
+
# Delete local cookie
|
51
|
+
cookies.delete(:mints_user_session_token)
|
52
|
+
end
|
53
|
+
end
|
data/lib/mints.rb
CHANGED
@@ -7,5 +7,7 @@ require_relative "./mints/controllers/admin_base_controller.rb"
|
|
7
7
|
require_relative "./mints/controllers/public_api_controller.rb"
|
8
8
|
require_relative "./mints/controllers/contact_api_controller.rb"
|
9
9
|
require_relative "./mints/controllers/user_api_controller.rb"
|
10
|
+
require_relative './errors.rb'
|
11
|
+
|
10
12
|
module Mints
|
11
13
|
end
|