mints 0.0.13 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/client.rb +13 -8
- data/lib/contact.rb +133 -9
- data/lib/generators/mints_assets_controller.rb +3 -0
- data/lib/generators/mints_files_generator.rb +5 -2
- data/lib/mints/controllers/admin_base_controller.rb +27 -11
- data/lib/mints/controllers/base_api_controller.rb +94 -4
- data/lib/mints/controllers/base_controller.rb +19 -2
- data/lib/pub.rb +205 -102
- data/lib/user.rb +26 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f269f998c9cc9cb3dc69f3ec70cc2ff4522a97c14a9da0bfb6ca4cba40b0654
|
4
|
+
data.tar.gz: e6b867ce7e3623b05c7aad402462f09b0b1a71a3750549c669407bcff6d2aa2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1128997e3df23340e780e4dcc9bb84389df6062eaae3683dff653b440887a5c4d04059141e8472e3762c3ce856df795c26ef7e376c72c38e494880aef5ab830b
|
7
|
+
data.tar.gz: '09b6774bb218dc40cd0083fc54428225999736f5452911c7b482a22b928d41dea91fe343ecbab96543be6c602393f6f13aaa9d9d1ee489b8e4a697bf61eda20f'
|
data/lib/client.rb
CHANGED
@@ -8,12 +8,14 @@ module Mints
|
|
8
8
|
attr_reader :api_key
|
9
9
|
attr_reader :scope
|
10
10
|
attr_reader :base_url
|
11
|
-
attr_accessor :session_token
|
11
|
+
attr_accessor :session_token
|
12
|
+
attr_accessor :contact_token_id
|
12
13
|
|
13
|
-
def initialize(host, api_key, scope = nil, session_token = nil, debug = false)
|
14
|
+
def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, debug = false)
|
14
15
|
@host = host
|
15
16
|
@api_key = api_key
|
16
17
|
@session_token = session_token
|
18
|
+
@contact_token_id = contact_token_id
|
17
19
|
@debug = debug
|
18
20
|
self.set_scope(scope)
|
19
21
|
end
|
@@ -22,6 +24,9 @@ module Mints
|
|
22
24
|
base_url = @base_url if !base_url
|
23
25
|
uri = ""
|
24
26
|
if (options && options.class == Hash)
|
27
|
+
if (options[:jfilters] && options[:jfilters].class == Hash)
|
28
|
+
options[:jfilters] = Base64.encode64(JSON.generate(options[:jfilters]))
|
29
|
+
end
|
25
30
|
uri = Addressable::URI.new
|
26
31
|
uri.query_values = options
|
27
32
|
end
|
@@ -218,7 +223,7 @@ module Mints
|
|
218
223
|
headers = {
|
219
224
|
"ApiKey" => @api_key,
|
220
225
|
"Accept" => "application/json",
|
221
|
-
"ContactToken" => @
|
226
|
+
"ContactToken" => @contact_token_id
|
222
227
|
}
|
223
228
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
224
229
|
return self.http_get(url, headers)
|
@@ -228,7 +233,7 @@ module Mints
|
|
228
233
|
headers = {
|
229
234
|
"ApiKey" => @api_key,
|
230
235
|
"Accept" => "application/json",
|
231
|
-
"ContactToken" => @
|
236
|
+
"ContactToken" => @contact_token_id
|
232
237
|
}
|
233
238
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
234
239
|
return self.http_post(url, headers, data)
|
@@ -238,10 +243,10 @@ module Mints
|
|
238
243
|
headers = {
|
239
244
|
"ApiKey" => @api_key,
|
240
245
|
"Accept" => "application/json",
|
241
|
-
"ContactToken" => @
|
246
|
+
"ContactToken" => @contact_token_id
|
242
247
|
}
|
243
248
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
244
|
-
return self.
|
249
|
+
return self.http_put(url, headers, data)
|
245
250
|
end
|
246
251
|
|
247
252
|
# Start User context
|
@@ -280,7 +285,7 @@ module Mints
|
|
280
285
|
"Content-Type" => "application/json",
|
281
286
|
"ApiKey" => @api_key
|
282
287
|
}
|
283
|
-
h["ContactToken"] = @
|
288
|
+
h["ContactToken"] = @contact_token_id if @contact_token_id
|
284
289
|
if headers
|
285
290
|
headers.each do |k,v|
|
286
291
|
h[k] = v
|
@@ -310,7 +315,7 @@ module Mints
|
|
310
315
|
"Content-Type" => "application/json",
|
311
316
|
"ApiKey" => @api_key
|
312
317
|
}
|
313
|
-
h["ContactToken"] = @
|
318
|
+
h["ContactToken"] = @contact_token_id if @contact_token_id
|
314
319
|
if headers
|
315
320
|
headers.each do |k,v|
|
316
321
|
h[k] = v
|
data/lib/contact.rb
CHANGED
@@ -7,14 +7,21 @@ module Mints
|
|
7
7
|
# === Initialize.
|
8
8
|
# Class constructor
|
9
9
|
#
|
10
|
-
def initialize(host, api_key, session_token = nil, debug = false)
|
11
|
-
@client = Mints::Client.new(host, api_key, "contact", session_token, debug)
|
10
|
+
def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
|
11
|
+
@client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
|
12
12
|
end
|
13
13
|
|
14
14
|
##
|
15
15
|
# === Login.
|
16
16
|
# Starts a contact session
|
17
17
|
#
|
18
|
+
# ==== Parameters:
|
19
|
+
# * +email+ - [_String_] The email that will be logged.
|
20
|
+
# * +password+ - [_String_] The password of the email.
|
21
|
+
#
|
22
|
+
# ==== Example
|
23
|
+
# @mints_contact.login("brown.abigail@dubuque.com", "helloword")
|
24
|
+
#
|
18
25
|
def login(email, password)
|
19
26
|
data = {
|
20
27
|
email: email,
|
@@ -27,9 +34,62 @@ module Mints
|
|
27
34
|
return response
|
28
35
|
end
|
29
36
|
|
37
|
+
##
|
38
|
+
# === Magic Link Login.
|
39
|
+
# Starts a contact session with a token received in the contact email. The token will be received by send_magic_link method.
|
40
|
+
#
|
41
|
+
# ==== Parameters:
|
42
|
+
# * +token+ - [_String_] The email that will be logged.
|
43
|
+
#
|
44
|
+
# ==== Example
|
45
|
+
# @mints_contact.magic_link_login(
|
46
|
+
# "d8618c6d-a165-41cb-b3ec-d053cbf30059:zm54HtRdfHED8dpILZpjyqjPIceiaXNLfOklqM92fveBS0nDtyPYBlI4CPlPe3zq"
|
47
|
+
# )
|
48
|
+
#
|
49
|
+
def magic_link_login(token)
|
50
|
+
response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
|
51
|
+
if response.key? "session_token"
|
52
|
+
@client.session_token = response["session_token"]
|
53
|
+
end
|
54
|
+
return response
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# === Send Magic Link
|
59
|
+
# Send magic link to contact by email. That magic link will be used in magic_link_login method.
|
60
|
+
#
|
61
|
+
# ==== Parameters:
|
62
|
+
# * +email+ - [_String_] Contact's email.
|
63
|
+
# * +template_slug+ - [_String_] Email template's slug to be used in the email.
|
64
|
+
# * +redirectUrl+ - [_String_] Url to be redirected in the implemented page.
|
65
|
+
# * +lifeTime+ - [_Integer_] Maximum time of use in minutes.
|
66
|
+
# * +maxVisits+ - [_Integer_] The maximum number of uses of a token.
|
67
|
+
#
|
68
|
+
# ==== First Example
|
69
|
+
# @mints_contact.send_magic_link("brown.abigail@dubuque.com", "")
|
70
|
+
#
|
71
|
+
# ==== Second Example
|
72
|
+
# @mints_contact.send_magic_link("brown.abigail@dubuque.com", "", "", 1440, 3)
|
73
|
+
#
|
74
|
+
def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
|
75
|
+
data = {
|
76
|
+
email: email,
|
77
|
+
lifeTime: lifeTime,
|
78
|
+
maxVisits: maxVisits,
|
79
|
+
redirectUrl: redirectUrl,
|
80
|
+
templateId: template_slug
|
81
|
+
}
|
82
|
+
response = @client.raw("post", "/contacts/magic-link", nil, { data: data }, '/api/v1')
|
83
|
+
return response
|
84
|
+
end
|
85
|
+
|
30
86
|
##
|
31
87
|
# === Logout.
|
32
|
-
# Ends a contact session
|
88
|
+
# Ends a contact session previously logged.
|
89
|
+
#
|
90
|
+
# ==== Example
|
91
|
+
# @mints_contact.login('brown.abigail@dubuque.com', 'helloword')
|
92
|
+
# @mints_contact.logout
|
33
93
|
#
|
34
94
|
def logout
|
35
95
|
response = @client.raw("post", "/contacts/logout") if session_token?
|
@@ -41,7 +101,15 @@ module Mints
|
|
41
101
|
|
42
102
|
##
|
43
103
|
# === Change Password.
|
44
|
-
# Change password
|
104
|
+
# Change password without email. To change the password a contact must be logged.
|
105
|
+
#
|
106
|
+
# ==== Parameters:
|
107
|
+
# * +data+ - [] A new password allocated in a data key.
|
108
|
+
#
|
109
|
+
# ==== Example
|
110
|
+
# @mints_contact.login('brown.abigail@dubuque.com', 'helloword')
|
111
|
+
# data = { "data": { "password": "123456" } }
|
112
|
+
# @mints_contact.change_password(data)
|
45
113
|
#
|
46
114
|
def change_password(data)
|
47
115
|
return @client.raw("post", "/contacts/change-password", nil, data)
|
@@ -49,7 +117,14 @@ module Mints
|
|
49
117
|
|
50
118
|
##
|
51
119
|
# === Recover Password.
|
52
|
-
#
|
120
|
+
# Send a email that contains a token to a contact. That token will be used in reset_password to establish a new password.
|
121
|
+
#
|
122
|
+
# ==== Parameters:
|
123
|
+
# * +data+ - [] It's a data key where will be hosted the destination email.
|
124
|
+
#
|
125
|
+
# ==== Example
|
126
|
+
# data = { "data": { "email": "brown.abigail@dubuque.com" } }
|
127
|
+
# @mints_contact.recover_password(data)
|
53
128
|
#
|
54
129
|
def recover_password(data)
|
55
130
|
return @client.raw("post", "/contacts/recover-password", nil, data)
|
@@ -57,7 +132,19 @@ module Mints
|
|
57
132
|
|
58
133
|
##
|
59
134
|
# === Reset Password.
|
60
|
-
# Reset password
|
135
|
+
# Reset password using a token. The token is obtained by recover_password method.
|
136
|
+
#
|
137
|
+
# ==== Parameters:
|
138
|
+
# * +data+ - [] It's a set of data which contains all the information to reset a contact password.
|
139
|
+
#
|
140
|
+
# ==== Example
|
141
|
+
# data = { "data": {
|
142
|
+
# "email": "brown.abigail@dubuque.com",
|
143
|
+
# "password": "helloword",
|
144
|
+
# "password_confirmation": "helloword",
|
145
|
+
# "token": "644aa3aa0831d782cc42e42b11aedea9a2234389af4f429a8d96651295ecfa09"
|
146
|
+
# } }
|
147
|
+
# @mints_contact.reset_password(data)
|
61
148
|
#
|
62
149
|
def reset_password(data)
|
63
150
|
return @client.raw("post", "/contacts/reset-password", nil, data)
|
@@ -73,7 +160,10 @@ module Mints
|
|
73
160
|
|
74
161
|
##
|
75
162
|
# === Me.
|
76
|
-
# Get contact logged info
|
163
|
+
# Get contact logged info.
|
164
|
+
#
|
165
|
+
# ==== Example
|
166
|
+
# @mints_contact.me
|
77
167
|
#
|
78
168
|
def me
|
79
169
|
return @client.raw("get", "/contacts/me")
|
@@ -81,7 +171,10 @@ module Mints
|
|
81
171
|
|
82
172
|
##
|
83
173
|
# === Status.
|
84
|
-
# Get contact logged status
|
174
|
+
# Get contact logged status.
|
175
|
+
#
|
176
|
+
# ==== Example
|
177
|
+
# @mints_contact.status
|
85
178
|
#
|
86
179
|
def status
|
87
180
|
return @client.raw("get", "/contacts/status")
|
@@ -89,12 +182,43 @@ module Mints
|
|
89
182
|
|
90
183
|
##
|
91
184
|
# === Update.
|
92
|
-
# Update logged contact attributes
|
185
|
+
# Update logged contact attributes.
|
186
|
+
#
|
187
|
+
# ==== Parameters:
|
188
|
+
# * +data+ - [] It's the data to update with a session active.
|
189
|
+
#
|
190
|
+
# ==== Example
|
191
|
+
# @mints_contact.login("brown.abigail@dubuque.com", "helloword")
|
192
|
+
# data = { "data": {
|
193
|
+
# "given_name": "Alonso",
|
194
|
+
# "last_name": "Garcia"
|
195
|
+
# } }
|
196
|
+
# @mints_contact.update(data)
|
93
197
|
#
|
94
198
|
def update(data)
|
95
199
|
return @client.raw("put", "/contacts/update", nil, data)
|
96
200
|
end
|
97
201
|
|
202
|
+
##
|
203
|
+
# === Register.
|
204
|
+
# Register a contact.
|
205
|
+
#
|
206
|
+
# ==== Parameters:
|
207
|
+
# * +data+ - [] It's the register data.
|
208
|
+
#
|
209
|
+
# ==== Example
|
210
|
+
# data = { "data": {
|
211
|
+
# "email": "carlos@mints.cloud",
|
212
|
+
# "given_name": "Carlos",
|
213
|
+
# "last_name": "Fernandez",
|
214
|
+
# "password": "123456"
|
215
|
+
# } }
|
216
|
+
# @mints_contact.register(data);
|
217
|
+
#
|
218
|
+
def register(data)
|
219
|
+
return @client.raw("post", "/contacts/register", nil, data)
|
220
|
+
end
|
221
|
+
|
98
222
|
private
|
99
223
|
|
100
224
|
def session_token?
|
@@ -6,12 +6,15 @@ class MintsFilesGenerator < Rails::Generators::Base
|
|
6
6
|
copy_file 'mints_user_controller.rb', './app/controllers/api/mints_user_controller.rb'
|
7
7
|
copy_file 'mints_contact_controller.rb', './app/controllers/api/v1/mints_contact_controller.rb'
|
8
8
|
copy_file 'mints_public_controller.rb', './app/controllers/api/v1/mints_public_controller.rb'
|
9
|
+
copy_file 'mints_assets_controller.rb', './app/controllers/mints_assets_controller.rb'
|
9
10
|
route <<-eos
|
10
11
|
# Mints auto-generated routes (proxy to send request to mints.cloud)
|
12
|
+
match '/public-assets/*path' => 'mints_assets#index', via: [:get, :post, :put, :patch, :delete]
|
11
13
|
namespace :api, defaults: { format: :json } do
|
12
|
-
match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
|
14
|
+
match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
|
15
|
+
match '/contact/v1/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
|
13
16
|
namespace :v1 do
|
14
|
-
match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
|
17
|
+
match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
|
15
18
|
match '/*path' => 'mints_public#index', via: [:get, :post, :put, :patch, :delete]
|
16
19
|
end
|
17
20
|
end
|
@@ -2,16 +2,16 @@ module Mints
|
|
2
2
|
class AdminBaseController < ActionController::Base
|
3
3
|
before_action :set_mints_user_client
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
15
|
|
16
16
|
##
|
17
17
|
# === Mints user Login.
|
@@ -25,6 +25,21 @@ module Mints
|
|
25
25
|
cookies.permanent[:mints_user_session_token] = session_token
|
26
26
|
end
|
27
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 }
|
37
|
+
redirect_to response['data']['redirect_url']
|
38
|
+
else
|
39
|
+
redirect_to '/'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
28
43
|
##
|
29
44
|
# === Mints user Logout.
|
30
45
|
# Destroy session from mints.cloud and delete local session cookie
|
@@ -51,7 +66,8 @@ module Mints
|
|
51
66
|
raise 'MintsBadCredentialsError'
|
52
67
|
end
|
53
68
|
# Initialize mints user client
|
54
|
-
|
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)
|
55
71
|
end
|
56
72
|
end
|
57
73
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Mints
|
2
2
|
class BaseApiController < ActionController::Base
|
3
|
-
before_action :
|
3
|
+
before_action :set_mints_clients
|
4
4
|
|
5
5
|
##
|
6
6
|
# === Mints Contact Login.
|
@@ -15,6 +15,26 @@ module Mints
|
|
15
15
|
cookies.permanent[:mints_contact_session_token] = session_token
|
16
16
|
cookies.permanent[:mints_contact_id] = id_token
|
17
17
|
@contact_token = id_token
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# === Mints cotnact Login.
|
22
|
+
# Starts a cotnact 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']['id_token']
|
30
|
+
# Set a permanent cookie with the session token
|
31
|
+
cookies.permanent[:mints_contact_session_token] = session_token
|
32
|
+
cookies.permanent[:mints_contact_id] = id_token
|
33
|
+
@contact_token = id_token
|
34
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
35
|
+
else
|
36
|
+
redirect_to '/'
|
37
|
+
end
|
18
38
|
end
|
19
39
|
|
20
40
|
##
|
@@ -28,26 +48,96 @@ module Mints
|
|
28
48
|
cookies.delete(:mints_contact_id)
|
29
49
|
@contact_token = nil
|
30
50
|
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# === Mints user Login.
|
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.permanent[:mints_user_session_token] = session_token
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# === Mints user Login.
|
66
|
+
# Starts a user session in mints.cloud and set a session cookie
|
67
|
+
def mints_user_magic_link_login(hash)
|
68
|
+
# Login in mints
|
69
|
+
response = @mints_user.magic_link_login(hash)
|
70
|
+
if response['data']
|
71
|
+
# Set a cookie with the session token
|
72
|
+
cookies[:mints_user_session_token] = { value: response['data']['api_token'], 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
|
31
88
|
|
32
89
|
private
|
33
90
|
|
34
91
|
##
|
35
|
-
# === Set mints pub
|
36
|
-
# Initialize
|
37
|
-
def
|
92
|
+
# === Set mints clients (pub, user and contact)
|
93
|
+
# Initialize all clients from mitns
|
94
|
+
def set_mints_clients
|
38
95
|
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
39
96
|
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
40
97
|
config = YAML.load template.result(binding)
|
41
98
|
@host = config["mints"]["host"]
|
42
99
|
@api_key = config["mints"]["api_key"]
|
43
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
|
44
108
|
else
|
45
109
|
raise 'MintsBadCredentialsError'
|
46
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
|
+
|
47
118
|
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
48
119
|
@mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
|
49
120
|
# Set contact token from cookie
|
50
121
|
@mints_pub.client.session_token = @contact_token
|
51
122
|
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# === Set mints contact client.
|
126
|
+
# Initialize the public client and set the contact token
|
127
|
+
def set_mints_contact_client
|
128
|
+
# Initialize mints clontact client
|
129
|
+
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
130
|
+
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
131
|
+
@mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# === Set Mints user client.
|
136
|
+
# Initialize the public client and set the user token
|
137
|
+
def set_mints_user_client
|
138
|
+
# Initialize mints user client
|
139
|
+
session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
|
140
|
+
@mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
|
141
|
+
end
|
52
142
|
end
|
53
143
|
end
|
@@ -31,6 +31,21 @@ module Mints
|
|
31
31
|
@contact_token = id_token
|
32
32
|
end
|
33
33
|
|
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']['id_token']
|
43
|
+
# Set a permanent cookie with the session token
|
44
|
+
cookies.permanent[:mints_contact_session_token] = session_token
|
45
|
+
cookies.permanent[:mints_contact_id] = id_token
|
46
|
+
@contact_token = id_token
|
47
|
+
end
|
48
|
+
|
34
49
|
##
|
35
50
|
# === Mints Contact Logout.
|
36
51
|
# Destroy session from mints.cloud and delete local session cookie
|
@@ -69,7 +84,7 @@ module Mints
|
|
69
84
|
raise 'MintsBadCredentialsError'
|
70
85
|
end
|
71
86
|
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
72
|
-
@mints_pub = Mints::Pub.new(@host, @api_key,
|
87
|
+
@mints_pub = Mints::Pub.new(@host, @api_key, @contact_token, @debug)
|
73
88
|
# Set contact token from cookie
|
74
89
|
@mints_pub.client.session_token = @contact_token
|
75
90
|
end
|
@@ -86,7 +101,9 @@ module Mints
|
|
86
101
|
# Initialize the public client and set the contact token
|
87
102
|
def set_mints_contact_client
|
88
103
|
# Initialize mints clontact client
|
89
|
-
|
104
|
+
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
105
|
+
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
106
|
+
@mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
|
90
107
|
end
|
91
108
|
end
|
92
109
|
end
|
data/lib/pub.rb
CHANGED
@@ -5,6 +5,10 @@ module Mints
|
|
5
5
|
# == Public context API
|
6
6
|
# Pub class contains functions that needs only an API key as authentication
|
7
7
|
# == Usage example
|
8
|
+
# === For Mints::BaseController inheritance:
|
9
|
+
# If the controller is inheriting from Mints::BaseController, Only use the class variable *mints_pub* _Example:_
|
10
|
+
# @mints_pub.get_stories
|
11
|
+
# === For standalone usage:
|
8
12
|
# Initialize
|
9
13
|
# pub = Mints::Pub.new(mints_url, api_key)
|
10
14
|
# or if host and api_key are provided by mints_config.yml.erb
|
@@ -12,23 +16,58 @@ module Mints
|
|
12
16
|
# Call any function
|
13
17
|
# pub.get_products
|
14
18
|
# == Single resource options
|
15
|
-
# * +include+ - [
|
16
|
-
#
|
17
|
-
# * +
|
18
|
-
#
|
19
|
+
# * +include+ - [_String_] Specify additional information to be included in the results from the objects relations. _Example:_
|
20
|
+
# { "include": "events" }
|
21
|
+
# * +attributes+ - [_Boolean_] If present, attributes will be returned for each record in the results. _Example:_
|
22
|
+
# { "attributes": true }
|
23
|
+
# * +categories+ - [_Boolean_] If present, categories will be returned for each record in the results. _Example:_
|
24
|
+
# { "categories": true }
|
25
|
+
# * +tags+ - [_Boolean_] If present, tags will be returned for each record in the results. _Example:_
|
26
|
+
# { "tags": true }
|
27
|
+
# * +fields+ - [_String_] Specify the fields that you want to be returned. If empty, all fields are returned. The object index can also be used to specify specific fields from relations. _Example:_
|
28
|
+
# { "fields": "id, title, slug" }
|
29
|
+
# { "fields[products]": "id, title, slug" }
|
30
|
+
#
|
19
31
|
# == Resource collections options
|
20
|
-
# * +search+ - [
|
21
|
-
#
|
22
|
-
# * +
|
23
|
-
#
|
24
|
-
# * +
|
25
|
-
#
|
26
|
-
# * +
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
+
# * +search+ - [_String_] If present, it will search for records matching the search string. _Example:_
|
33
|
+
# { "search": "searchstring" }
|
34
|
+
# * +scopes+ - [_String_] If present, it will apply the specified Model's scopes. _Example:_
|
35
|
+
# { "scopes": "approved, recent" }
|
36
|
+
# * +filters+ - [_String_] This is a powerful parameter that allows the data to be filtered by any of its fields. Currently only exact matches are supported. _Example:_
|
37
|
+
# { "filters[title]": "titleToFilter" }
|
38
|
+
# * +jfilters+ - [_String_] A complex filter configuration, as used in segments, in JSON format, base64 encoded and URLencoded. _Example:_
|
39
|
+
# jfilter = {
|
40
|
+
# "type":"group",
|
41
|
+
# "items":[
|
42
|
+
# {
|
43
|
+
# "type":"attribute",
|
44
|
+
# "operator":"==",
|
45
|
+
# "slug":"title",
|
46
|
+
# "value":"Action movies"
|
47
|
+
# }
|
48
|
+
# ],
|
49
|
+
# "operator":"or"
|
50
|
+
# }
|
51
|
+
# options = { "jfilters": jfilter }
|
52
|
+
# * +catfilters+ - [_String_] filter by categories. _Example:_
|
53
|
+
# { "catfilters": "categoryName" }
|
54
|
+
# * +fields+ - [_String_] Specify the fields that you want to be returned. If empty, all fields are returned. The object index can also be used to specify specific fields from relations. _Example:_
|
55
|
+
# { "fields": "id, title, slug" }
|
56
|
+
# { "fields[products]": "id, title, slug" }
|
57
|
+
# * +sort+ - [_String_] The name of the field to perform the sort. Prefix the value with a minus sign - for ascending order. _Example:_
|
58
|
+
# { "sort": "title" }
|
59
|
+
# { "sort": "-title" }
|
60
|
+
# * +include+ - [_String_] Specify additional information to be included in the results from the objects relations. _Example:_
|
61
|
+
# { "include": "events" }
|
62
|
+
# * +attributes+ - [_Boolean_] If present, attributes will be returned for each record in the results. _Example:_
|
63
|
+
# { "attributes": true }
|
64
|
+
# * +categories+ - [_Boolean_] If present, categories will be returned for each record in the results. _Example:_
|
65
|
+
# { "categories": true }
|
66
|
+
# * +taxonomies+ - [_Boolean_] If present, taxonomies will be returned for each record in the results. _Example:_
|
67
|
+
# { "taxonomies": true }
|
68
|
+
# * +tags+ - [_Boolean_] If present, tags will be returned for each record in the results. _Example:_
|
69
|
+
# { "tags": true }
|
70
|
+
|
32
71
|
class Pub
|
33
72
|
attr_reader :client
|
34
73
|
|
@@ -42,8 +81,8 @@ module Mints
|
|
42
81
|
# * +contact_token+ - [String] Cookie 'mints_contact_id' value (mints_contact_token)
|
43
82
|
# ==== Return
|
44
83
|
# Returns a Client object
|
45
|
-
def initialize(host, api_key,
|
46
|
-
@client = Mints::Client.new(host, api_key, 'public',
|
84
|
+
def initialize(host, api_key, contact_token_id = nil, debug = false)
|
85
|
+
@client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, debug)
|
47
86
|
end
|
48
87
|
|
49
88
|
##
|
@@ -55,6 +94,15 @@ module Mints
|
|
55
94
|
# * +ip+ - [String] It's the visitor IP
|
56
95
|
# * +user_agent+ - The visitor's browser user agent
|
57
96
|
# * +url+ - [String] URL visited
|
97
|
+
#
|
98
|
+
# ==== Example
|
99
|
+
# request = {
|
100
|
+
# "remote_ip" => "http://864.401.156.12/",
|
101
|
+
# "user_agent" => "User Agent",
|
102
|
+
# "fullpath" => "https://mints.cloud/blog"
|
103
|
+
# }
|
104
|
+
# @mints_pub.register_visit(request, request["remote_ip"], request["user_agent"], request["fullpath"])
|
105
|
+
#
|
58
106
|
def register_visit(request, ip = nil, user_agent = nil, url = nil)
|
59
107
|
data = {
|
60
108
|
ip_address: ip || request.remote_ip,
|
@@ -72,69 +120,38 @@ module Mints
|
|
72
120
|
# ==== Parameters
|
73
121
|
# * +visit+ - [String] It's the visitor IP
|
74
122
|
# * +time+ - [Integer] The visitor's browser user agent
|
123
|
+
#
|
124
|
+
# ==== Example
|
125
|
+
# @mints_pub.register_visit_timer("60da2325d29acc7e55684472", 4)
|
126
|
+
#
|
75
127
|
def register_visit_timer(visit, time)
|
76
128
|
return @client.raw("get", "/register-visit-timer?visit=#{visit}&time=#{time}")
|
77
129
|
end
|
78
130
|
|
79
131
|
##
|
80
|
-
# === Get
|
81
|
-
# Get a
|
132
|
+
# === Get Asset Info.
|
133
|
+
# Get a description of an Asset
|
82
134
|
#
|
83
135
|
# ==== Parameters
|
84
|
-
# * +slug+ - [String] It's the
|
85
|
-
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
86
|
-
def get_content_page(slug, options = nil)
|
87
|
-
return @client.raw("get", "/content/content-pages/#{slug}", options)
|
88
|
-
end
|
89
|
-
|
90
|
-
##
|
91
|
-
# === Get Content Templates.
|
92
|
-
# Get a collection of content templates
|
93
|
-
#
|
94
|
-
# ==== Parameters
|
95
|
-
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
96
|
-
def get_content_templates(options = nil)
|
97
|
-
return @client.raw("get", "/content/content-templates", options)
|
98
|
-
end
|
99
|
-
|
100
|
-
##
|
101
|
-
# === Get Content Template.
|
102
|
-
# Get a single content template.
|
136
|
+
# * +slug+ - [String] It's the string identifier of the asset.
|
103
137
|
#
|
104
|
-
# ====
|
105
|
-
#
|
106
|
-
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
107
|
-
def get_content_template(slug, options = nil)
|
108
|
-
return @client.raw("get", "/content/content-templates/#{slug}", options)
|
109
|
-
end
|
110
|
-
|
111
|
-
##
|
112
|
-
# === Get Content Instances.
|
113
|
-
# Get a collection of content instances
|
138
|
+
# ==== Example
|
139
|
+
# @mints_pub.get_asset_info("quaerat")
|
114
140
|
#
|
115
|
-
|
116
|
-
|
117
|
-
def get_content_instances(options)
|
118
|
-
return @client.raw("get", "/content/content-instances", options)
|
141
|
+
def get_asset_info(slug)
|
142
|
+
return @client.raw("get", "/content/asset-info/#{slug}")
|
119
143
|
end
|
120
|
-
|
121
|
-
##
|
122
|
-
# === Get Content Instance.
|
123
|
-
# Get a single content instance.
|
124
|
-
#
|
125
|
-
# ==== Parameters
|
126
|
-
# * +slug+ - [String] It's the string identifier generated by Mints
|
127
|
-
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
128
|
-
def get_content_instance(slug, options = nil)
|
129
|
-
return @client.raw("get", "/content/content-instances/#{slug}", options)
|
130
|
-
end
|
131
|
-
|
144
|
+
|
132
145
|
##
|
133
146
|
# === Get Stories.
|
134
147
|
# Get a collection of stories
|
135
148
|
#
|
136
149
|
# ==== Parameters
|
137
150
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
151
|
+
#
|
152
|
+
# ==== Example
|
153
|
+
# @mints_pub.get_stories
|
154
|
+
#
|
138
155
|
def get_stories(options = nil)
|
139
156
|
return @client.raw("get", "/content/stories", options)
|
140
157
|
end
|
@@ -146,6 +163,10 @@ module Mints
|
|
146
163
|
# ==== Parameters
|
147
164
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
148
165
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
166
|
+
#
|
167
|
+
# ==== Example
|
168
|
+
# @mints_pub.get_story("getting-ready-for-e3")
|
169
|
+
#
|
149
170
|
def get_story(slug, options = nil)
|
150
171
|
return @client.raw("get", "/content/stories/#{slug}", options)
|
151
172
|
end
|
@@ -156,6 +177,10 @@ module Mints
|
|
156
177
|
#
|
157
178
|
# ==== Parameters
|
158
179
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
180
|
+
#
|
181
|
+
# ==== Example
|
182
|
+
# @mints_pub.get_forms
|
183
|
+
#
|
159
184
|
def get_forms(options = nil)
|
160
185
|
return @client.raw("get", "/content/forms", options)
|
161
186
|
end
|
@@ -167,6 +192,10 @@ module Mints
|
|
167
192
|
# ==== Parameters
|
168
193
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
169
194
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
195
|
+
#
|
196
|
+
# ==== Example
|
197
|
+
# @mints_pub.get_form("survey")
|
198
|
+
#
|
170
199
|
def get_form(slug, options = nil)
|
171
200
|
return @client.raw("get", "/content/forms/#{slug}", options)
|
172
201
|
end
|
@@ -177,79 +206,126 @@ module Mints
|
|
177
206
|
#
|
178
207
|
# ==== Parameters
|
179
208
|
# * +data+ - [Hash] Data to be submited
|
209
|
+
#
|
210
|
+
# ==== Example
|
211
|
+
# data_form = {
|
212
|
+
# "data": {
|
213
|
+
# 'form_slug': 'formulario',
|
214
|
+
# 'email': 'oscar@mints.cloud',
|
215
|
+
# 'ingrese-un-texto': 'hola'
|
216
|
+
# }
|
217
|
+
# }
|
218
|
+
# @mints_pub.submit_form(data_form.to_json)
|
219
|
+
#
|
180
220
|
def submit_form(data)
|
181
221
|
return @client.raw("post", "/content/forms/submit", nil, data)
|
182
|
-
end
|
222
|
+
end
|
183
223
|
|
184
224
|
##
|
185
|
-
# === Get
|
186
|
-
# Get a collection of
|
225
|
+
# === Get Content Instances.
|
226
|
+
# Get a collection of content instances. _Note:_ Options must be specified.
|
187
227
|
#
|
188
228
|
# ==== Parameters
|
189
229
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
190
|
-
def
|
191
|
-
return @client.raw("get", "/
|
230
|
+
def get_content_instances(options = nil)
|
231
|
+
return @client.raw("get", "/content/content-instances", options)
|
192
232
|
end
|
193
233
|
|
194
234
|
##
|
195
|
-
# === Get
|
196
|
-
# Get a single
|
235
|
+
# === Get Content Instance.
|
236
|
+
# Get a single content instance.
|
197
237
|
#
|
198
238
|
# ==== Parameters
|
199
239
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
200
240
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
201
|
-
|
202
|
-
|
241
|
+
#
|
242
|
+
# ==== Example
|
243
|
+
# @mints_pub.get_content_instance("bill-gates")
|
244
|
+
#
|
245
|
+
def get_content_instance(slug, options = nil)
|
246
|
+
return @client.raw("get", "/content/content-instances/#{slug}", options)
|
203
247
|
end
|
204
248
|
|
205
249
|
##
|
206
|
-
# === Get
|
207
|
-
# Get
|
250
|
+
# === Get Content Pages.
|
251
|
+
# Get all content pages.
|
208
252
|
#
|
209
253
|
# ==== Parameters
|
210
254
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
211
|
-
def
|
212
|
-
return @client.raw("get", "/
|
255
|
+
def get_content_pages(options = nil)
|
256
|
+
return @client.raw("get", "/content/content-pages", options)
|
213
257
|
end
|
214
258
|
|
215
259
|
##
|
216
|
-
# === Get
|
217
|
-
# Get a
|
260
|
+
# === Get Content Page.
|
261
|
+
# Get a single content page
|
218
262
|
#
|
219
263
|
# ==== Parameters
|
220
|
-
# * +slug+ - [String] It's the
|
264
|
+
# * +slug+ - [String] It's the slug
|
221
265
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
222
|
-
|
223
|
-
|
266
|
+
#
|
267
|
+
# ==== Example
|
268
|
+
# @mints_pub.get_content_page("test-page")
|
269
|
+
#
|
270
|
+
def get_content_page(slug, options = nil)
|
271
|
+
return @client.raw("get", "/content/content-pages/#{slug}", options)
|
224
272
|
end
|
225
273
|
|
226
274
|
##
|
227
|
-
# === Get
|
228
|
-
# Get
|
275
|
+
# === Get Locations.
|
276
|
+
# Get all locations.
|
229
277
|
#
|
230
278
|
# ==== Parameters
|
231
279
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
232
|
-
|
233
|
-
|
280
|
+
#
|
281
|
+
# ==== Example
|
282
|
+
# @mints_pub.get_locations
|
283
|
+
#
|
284
|
+
def get_locations(options = nil)
|
285
|
+
return @client.raw("get", "/ecommerce/locations", options)
|
234
286
|
end
|
235
287
|
|
236
288
|
##
|
237
|
-
# === Get
|
238
|
-
# Get a
|
289
|
+
# === Get Products.
|
290
|
+
# Get a collection of products.
|
291
|
+
#
|
292
|
+
# ==== Parameters
|
293
|
+
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
294
|
+
#
|
295
|
+
# ==== Example
|
296
|
+
# @mints_pub.get_products
|
297
|
+
#
|
298
|
+
def get_products(options = nil)
|
299
|
+
return @client.raw("get", "/ecommerce/products", options)
|
300
|
+
end
|
301
|
+
|
302
|
+
##
|
303
|
+
# === Get Product.
|
304
|
+
# Get a single product.
|
239
305
|
#
|
240
306
|
# ==== Parameters
|
241
307
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
242
308
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
243
|
-
|
244
|
-
|
309
|
+
#
|
310
|
+
# ==== Example
|
311
|
+
# @mints_pub.get_product("batman-shirt")
|
312
|
+
#
|
313
|
+
def get_product(slug, options = nil)
|
314
|
+
return @client.raw("get", "/ecommerce/products/#{slug}", options)
|
245
315
|
end
|
246
|
-
|
316
|
+
|
247
317
|
##
|
248
318
|
# === Get categories.
|
249
319
|
# Get a collection of categories.
|
250
320
|
#
|
251
321
|
# ==== Parameters
|
252
322
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
323
|
+
#
|
324
|
+
# ==== Example
|
325
|
+
# options = {
|
326
|
+
# "object_type": "stories"
|
327
|
+
# }
|
328
|
+
# @mints_pub.get_categories(options)
|
253
329
|
def get_categories(options = nil)
|
254
330
|
return @client.raw("get", "/config/categories", options)
|
255
331
|
end
|
@@ -261,6 +337,13 @@ module Mints
|
|
261
337
|
# ==== Parameters
|
262
338
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
263
339
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
340
|
+
#
|
341
|
+
# ==== Example
|
342
|
+
# options = {
|
343
|
+
# "object_type": "locations"
|
344
|
+
# }
|
345
|
+
# @mints_pub.get_category("atm", options)
|
346
|
+
#
|
264
347
|
def get_category(slug, options = nil)
|
265
348
|
return @client.raw("get", "/config/categories/#{slug}", options)
|
266
349
|
end
|
@@ -271,6 +354,10 @@ module Mints
|
|
271
354
|
#
|
272
355
|
# ==== Parameters
|
273
356
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
357
|
+
#
|
358
|
+
# ==== Example
|
359
|
+
# @mints_pub.get_tags
|
360
|
+
#
|
274
361
|
def get_tags(options = nil)
|
275
362
|
return @client.raw("get", "/config/tags", options)
|
276
363
|
end
|
@@ -282,26 +369,24 @@ module Mints
|
|
282
369
|
# ==== Parameters
|
283
370
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
284
371
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
372
|
+
#
|
373
|
+
# ==== Example
|
374
|
+
# @mints_pub.get_tag("ad-0")
|
375
|
+
#
|
285
376
|
def get_tag(slug, options = nil)
|
286
377
|
return @client.raw("get", "/config/tags/#{slug}", options)
|
287
378
|
end
|
288
379
|
|
289
|
-
##
|
290
|
-
# === Get Attributes.
|
291
|
-
# Get a collection of attributes.
|
292
|
-
#
|
293
|
-
# ==== Parameters
|
294
|
-
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
295
|
-
def get_attributes(options = nil)
|
296
|
-
return @client.raw("get", "/config/attributes", options)
|
297
|
-
end
|
298
|
-
|
299
380
|
##
|
300
381
|
# === Get Taxonomies.
|
301
382
|
# Get a collection of taxonomies.
|
302
383
|
#
|
303
384
|
# ==== Parameters
|
304
385
|
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
386
|
+
#
|
387
|
+
# ==== Example
|
388
|
+
# @mints_pub.get_taxonomies
|
389
|
+
#
|
305
390
|
def get_taxonomies(options = nil)
|
306
391
|
return @client.raw("get", "/config/taxonomies", options)
|
307
392
|
end
|
@@ -313,8 +398,26 @@ module Mints
|
|
313
398
|
# ==== Parameters
|
314
399
|
# * +slug+ - [String] It's the string identifier generated by Mints
|
315
400
|
# * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
|
401
|
+
#
|
402
|
+
# ==== Example
|
403
|
+
# @mints_pub.get_taxonomy("unit_pricing_measure")
|
404
|
+
#
|
316
405
|
def get_taxonomy(slug, options = nil)
|
317
406
|
return @client.raw("get", "/config/taxonomies/#{slug}", options)
|
318
407
|
end
|
408
|
+
|
409
|
+
##
|
410
|
+
# === Get Attributes.
|
411
|
+
# Get a collection of attributes.
|
412
|
+
#
|
413
|
+
# ==== Parameters
|
414
|
+
# * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
|
415
|
+
#
|
416
|
+
# ==== Example
|
417
|
+
# @mints_pub.get_attributes
|
418
|
+
#
|
419
|
+
def get_attributes(options = nil)
|
420
|
+
return @client.raw("get", "/config/attributes", options)
|
421
|
+
end
|
319
422
|
end
|
320
423
|
end
|
data/lib/user.rb
CHANGED
@@ -29,7 +29,7 @@ module Mints
|
|
29
29
|
class User
|
30
30
|
attr_reader :client
|
31
31
|
def initialize(host, api_key, session_token = nil, debug = false)
|
32
|
-
@client = Mints::Client.new(host, api_key, 'user', session_token, debug)
|
32
|
+
@client = Mints::Client.new(host, api_key, 'user', session_token, nil, debug)
|
33
33
|
end
|
34
34
|
|
35
35
|
def login(email, password)
|
@@ -43,6 +43,31 @@ module Mints
|
|
43
43
|
end
|
44
44
|
return response
|
45
45
|
end
|
46
|
+
|
47
|
+
def magic_link_login(token)
|
48
|
+
response = @client.raw("get", "/users/magic-link-login/#{token}", nil, nil, '/api/v1')
|
49
|
+
return response
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# === Send magic link to user
|
54
|
+
def send_magic_link(email, redirectUrl = '', lifeTime = 24)
|
55
|
+
data = {
|
56
|
+
email: email,
|
57
|
+
redirectUrl: redirectUrl,
|
58
|
+
lifeTime: lifeTime
|
59
|
+
}
|
60
|
+
response = @client.raw("post", "/users/magic-link", nil, { data: data }, '/api/v1')
|
61
|
+
return response
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# === Me.
|
66
|
+
# Get contact logged info
|
67
|
+
#
|
68
|
+
def me
|
69
|
+
return @client.get__profile__me
|
70
|
+
end
|
46
71
|
######################################### CRM #########################################
|
47
72
|
##
|
48
73
|
# === Get contacts.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Ruben Gomez Garcia, Omar Mora, Luis Payan
|
7
|
+
- Ruben Gomez Garcia, Omar Mora, Luis Payan, Oscar Castillo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- README.md
|
121
121
|
- lib/client.rb
|
122
122
|
- lib/contact.rb
|
123
|
+
- lib/generators/mints_assets_controller.rb
|
123
124
|
- lib/generators/mints_config.yml.erb
|
124
125
|
- lib/generators/mints_contact_controller.rb
|
125
126
|
- lib/generators/mints_files_generator.rb
|