mints 0.0.15 → 0.0.19
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 +65 -30
- data/lib/contact.rb +146 -17
- data/lib/generators/mints_assets_controller.rb +3 -0
- data/lib/generators/mints_files_generator.rb +2 -0
- data/lib/mints/controllers/admin_base_controller.rb +28 -12
- data/lib/mints/controllers/base_api_controller.rb +97 -7
- data/lib/mints/controllers/base_controller.rb +48 -7
- data/lib/mints_helper.rb +47 -0
- data/lib/pub.rb +137 -52
- data/lib/user/config/api_keys.rb +65 -0
- data/lib/user/config/appointments.rb +221 -0
- data/lib/user/config/attribute_groups.rb +77 -0
- data/lib/user/config/attributes.rb +86 -0
- data/lib/user/config/calendars.rb +89 -0
- data/lib/user/config/config.rb +65 -0
- data/lib/user/config/importers.rb +184 -0
- data/lib/user/config/public_folders.rb +108 -0
- data/lib/user/config/relationships.rb +138 -0
- data/lib/user/config/roles.rb +84 -0
- data/lib/user/config/seeds.rb +14 -0
- data/lib/user/config/system_settings.rb +53 -0
- data/lib/user/config/tags.rb +63 -0
- data/lib/user/config/taxonomies.rb +124 -0
- data/lib/user/config/teams.rb +70 -0
- data/lib/user/config/users.rb +76 -0
- data/lib/user/contacts/contacts.rb +21 -0
- data/lib/user/content/assets.rb +98 -0
- data/lib/user/content/content.rb +235 -0
- data/lib/user/content/content_instances.rb +147 -0
- data/lib/user/content/content_templates.rb +111 -0
- data/lib/user/content/conversations.rb +174 -0
- data/lib/user/content/dam.rb +88 -0
- data/lib/user/content/forms.rb +168 -0
- data/lib/user/content/message_templates.rb +162 -0
- data/lib/user/content/messages.rb +90 -0
- data/lib/user/content/pages.rb +81 -0
- data/lib/user/content/stories.rb +164 -0
- data/lib/user/content/story_templates.rb +95 -0
- data/lib/user/crm/companies.rb +111 -0
- data/lib/user/crm/contacts.rb +312 -0
- data/lib/user/crm/crm.rb +21 -0
- data/lib/user/crm/deals.rb +111 -0
- data/lib/user/crm/favorites.rb +17 -0
- data/lib/user/crm/segments.rb +132 -0
- data/lib/user/crm/users.rb +22 -0
- data/lib/user/crm/workflow_step_objects.rb +89 -0
- data/lib/user/crm/workflow_steps.rb +49 -0
- data/lib/user/crm/workflows.rb +70 -0
- data/lib/user/ecommerce/ecommerce.rb +29 -0
- data/lib/user/ecommerce/item_prices.rb +86 -0
- data/lib/user/ecommerce/locations.rb +166 -0
- data/lib/user/ecommerce/order_items_groups.rb +109 -0
- data/lib/user/ecommerce/order_statuses.rb +26 -0
- data/lib/user/ecommerce/orders.rb +258 -0
- data/lib/user/ecommerce/price_lists.rb +73 -0
- data/lib/user/ecommerce/product_templates.rb +104 -0
- data/lib/user/ecommerce/product_variations.rb +129 -0
- data/lib/user/ecommerce/products.rb +169 -0
- data/lib/user/ecommerce/skus.rb +88 -0
- data/lib/user/ecommerce/taxes.rb +82 -0
- data/lib/user/ecommerce/variant_options.rb +69 -0
- data/lib/user/ecommerce/variant_values.rb +72 -0
- data/lib/user/helpers/helpers.rb +113 -0
- data/lib/user/helpers/object_activities.rb +83 -0
- data/lib/user/helpers/object_folders.rb +82 -0
- data/lib/user/helpers/user_folders.rb +83 -0
- data/lib/user/marketing/marketing.rb +120 -0
- data/lib/user/profile/profile.rb +111 -0
- data/lib/user.rb +36 -355
- metadata +64 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb39e61077ebde851f278b96e82be85962bdacd093158d179cc5107bf3a4c5b2
|
4
|
+
data.tar.gz: f5d84797fc4526b3f8c2164d79062b0035db452c0a3a62d02967e33f1649a78b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c902cadde2d3951e9aecf9e6a81f86f7af47224071a14ff0ea9b72fc4f2607f2c60729d2ce4843dbdf0d9e582135fba51cf84b37ed6d6908227e5438a217e4a
|
7
|
+
data.tar.gz: faed4589390dbe456f973212e9e2deaa759082f2ed02c6aedfea493147b80d3935261a50ce6d9d41b77a2e5b9fd2e9ef456b19e80914118f8e5c49d9a94b3684
|
data/lib/client.rb
CHANGED
@@ -20,8 +20,8 @@ module Mints
|
|
20
20
|
self.set_scope(scope)
|
21
21
|
end
|
22
22
|
|
23
|
-
def raw(action, url, options = nil, data = nil, base_url = nil)
|
24
|
-
|
23
|
+
def raw(action, url, options = nil, data = nil, base_url = nil, compatibility_options = {})
|
24
|
+
base_url = @base_url if !base_url
|
25
25
|
uri = ""
|
26
26
|
if (options && options.class == Hash)
|
27
27
|
if (options[:jfilters] && options[:jfilters].class == Hash)
|
@@ -52,7 +52,7 @@ module Mints
|
|
52
52
|
response = @redis_server.get(full_url)
|
53
53
|
result_from_cache = true
|
54
54
|
else
|
55
|
-
response = self.send("#{@scope}_#{action}", "#{full_url}")
|
55
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", compatibility_options)
|
56
56
|
@redis_server.setex(full_url,time,response)
|
57
57
|
end
|
58
58
|
break
|
@@ -63,15 +63,18 @@ module Mints
|
|
63
63
|
end
|
64
64
|
|
65
65
|
if !url_need_cache
|
66
|
-
response = self.send("#{@scope}_#{action}", "#{full_url}")
|
66
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", compatibility_options)
|
67
67
|
end
|
68
68
|
|
69
69
|
elsif action === 'create' or action === 'post'
|
70
70
|
action = 'post'
|
71
|
-
response = self.send("#{@scope}_#{action}", "#{full_url}", data)
|
71
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
|
72
72
|
elsif action === 'put' or action === 'patch' or action ==='update'
|
73
73
|
action = 'put'
|
74
|
-
response = self.send("#{@scope}_#{action}", "#{full_url}", data)
|
74
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
|
75
|
+
elsif action === 'delete' or action === 'destroy'
|
76
|
+
action = 'delete'
|
77
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
|
75
78
|
end
|
76
79
|
if result_from_cache
|
77
80
|
return parsed_response = JSON.parse(response)
|
@@ -93,7 +96,7 @@ module Mints
|
|
93
96
|
name_len = name_spplited.size
|
94
97
|
# the action always be the first element
|
95
98
|
action = name_spplited.first
|
96
|
-
raise 'NoActionError' unless ['get', 'create', 'post', 'update', 'put'].include?(action)
|
99
|
+
raise 'NoActionError' unless ['get', 'create', 'post', 'update', 'put', 'delete', 'destroy'].include?(action)
|
97
100
|
# the object always be the last element
|
98
101
|
object = separator == "__" ? name_spplited.last.gsub("_","-") : name_spplited.last
|
99
102
|
# get intermediate url elements
|
@@ -121,7 +124,7 @@ module Mints
|
|
121
124
|
uri.query_values = args[1]
|
122
125
|
end
|
123
126
|
url = self.get_url(route, object, uri, slug)
|
124
|
-
response = self.send("#{@scope}_#{action}", url)
|
127
|
+
response = self.send("#{@scope}_#{action}", url, compatibility_options)
|
125
128
|
elsif action == "post" or action == "create"
|
126
129
|
if args[1].class == Hash
|
127
130
|
uri.query_values = args[1]
|
@@ -129,7 +132,7 @@ module Mints
|
|
129
132
|
url = self.get_url(route, object, uri, slug)
|
130
133
|
action = 'post'
|
131
134
|
data = args[0]
|
132
|
-
response = self.send("#{@scope}_#{action}", url, {data: data})
|
135
|
+
response = self.send("#{@scope}_#{action}", url, {data: data}, compatibility_options)
|
133
136
|
elsif action == "put" or action == "update"
|
134
137
|
if args.first.class == String or Integer
|
135
138
|
slug = args.first
|
@@ -139,7 +142,7 @@ module Mints
|
|
139
142
|
action = 'put'
|
140
143
|
id = args[0]
|
141
144
|
data = args[1]
|
142
|
-
response = self.send("#{@scope}_#{action}", "#{url}", {data: data})
|
145
|
+
response = self.send("#{@scope}_#{action}", "#{url}", {data: data}, compatibility_options)
|
143
146
|
end
|
144
147
|
|
145
148
|
if response.response.code == "404"
|
@@ -188,6 +191,7 @@ module Mints
|
|
188
191
|
puts url
|
189
192
|
puts "Headers:"
|
190
193
|
puts headers
|
194
|
+
puts "Method: get"
|
191
195
|
end
|
192
196
|
return headers ? HTTParty.get(url, :headers => headers) : HTTParty.get(url)
|
193
197
|
end
|
@@ -201,6 +205,7 @@ module Mints
|
|
201
205
|
puts headers
|
202
206
|
puts "Data:"
|
203
207
|
puts data
|
208
|
+
puts "Method: post"
|
204
209
|
end
|
205
210
|
return headers ? HTTParty.post(url, :headers=> headers, :body => data) : HTTParty.post(url, :body => data)
|
206
211
|
end
|
@@ -214,77 +219,107 @@ module Mints
|
|
214
219
|
puts headers
|
215
220
|
puts "Data:"
|
216
221
|
puts data
|
222
|
+
puts "Method: put"
|
217
223
|
end
|
218
224
|
return headers ? HTTParty.put(url, :headers=> headers, :body => data) : HTTParty.put(url, :body => data)
|
219
225
|
end
|
220
226
|
|
227
|
+
# Simple HTTP DELETE
|
228
|
+
def http_delete(url, headers = nil, data = nil)
|
229
|
+
if @debug
|
230
|
+
puts "Url:"
|
231
|
+
puts url
|
232
|
+
puts "Headers:"
|
233
|
+
puts headers
|
234
|
+
puts "Data:"
|
235
|
+
puts data
|
236
|
+
puts "Method: delete"
|
237
|
+
end
|
238
|
+
return headers ? HTTParty.delete(url, :headers=> headers, :body => data) : HTTParty.delete(url, :body => data)
|
239
|
+
end
|
240
|
+
|
221
241
|
# Start contact context
|
222
|
-
def contact_get(url)
|
242
|
+
def contact_get(url, compatibility_options)
|
223
243
|
headers = {
|
224
244
|
"ApiKey" => @api_key,
|
225
245
|
"Accept" => "application/json",
|
226
246
|
"ContactToken" => @contact_token_id
|
227
247
|
}
|
248
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
228
249
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
229
250
|
return self.http_get(url, headers)
|
230
251
|
end
|
231
252
|
|
232
|
-
def contact_post(url, data)
|
253
|
+
def contact_post(url, data, compatibility_options)
|
233
254
|
headers = {
|
234
255
|
"ApiKey" => @api_key,
|
235
256
|
"Accept" => "application/json",
|
236
257
|
"ContactToken" => @contact_token_id
|
237
258
|
}
|
259
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
238
260
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
239
261
|
return self.http_post(url, headers, data)
|
240
262
|
end
|
241
263
|
|
242
|
-
def contact_put(url, data)
|
264
|
+
def contact_put(url, data, compatibility_options)
|
243
265
|
headers = {
|
244
266
|
"ApiKey" => @api_key,
|
245
267
|
"Accept" => "application/json",
|
246
268
|
"ContactToken" => @contact_token_id
|
247
269
|
}
|
270
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
248
271
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
249
|
-
return self.
|
272
|
+
return self.http_put(url, headers, data)
|
250
273
|
end
|
251
274
|
|
252
275
|
# Start User context
|
253
|
-
def user_get(url)
|
276
|
+
def user_get(url, compatibility_options)
|
254
277
|
headers = {
|
255
|
-
"
|
256
|
-
"
|
278
|
+
"Accept" => "application/json",
|
279
|
+
"ApiKey" => @api_key
|
257
280
|
}
|
281
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
258
282
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
259
283
|
return self.http_get(url, headers)
|
260
284
|
end
|
261
285
|
|
262
|
-
def user_post(url, data)
|
286
|
+
def user_post(url, data, compatibility_options)
|
263
287
|
headers = {
|
264
|
-
"
|
265
|
-
"
|
288
|
+
"Accept" => "application/json",
|
289
|
+
"ApiKey" => @api_key
|
266
290
|
}
|
291
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
267
292
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
268
293
|
return self.http_post(url, headers, data)
|
269
294
|
end
|
270
295
|
|
271
|
-
def user_put(url, data)
|
296
|
+
def user_put(url, data, compatibility_options)
|
272
297
|
headers = {
|
273
|
-
"ApiKey" => @api_key,
|
274
298
|
"Accept" => "application/json",
|
275
|
-
"
|
299
|
+
"ApiKey" => @api_key
|
276
300
|
}
|
301
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
277
302
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
278
303
|
return self.http_put(url, headers, data)
|
279
304
|
end
|
305
|
+
|
306
|
+
def user_delete(url, data, compatibility_options)
|
307
|
+
headers = {
|
308
|
+
"Accept" => "application/json",
|
309
|
+
"ApiKey" => @api_key
|
310
|
+
}
|
311
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
312
|
+
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
313
|
+
return self.http_delete(url, headers, data)
|
314
|
+
end
|
280
315
|
# End User Context
|
281
316
|
|
282
|
-
def public_get(url, headers = nil)
|
317
|
+
def public_get(url, headers = nil, compatibility_options)
|
283
318
|
h = {
|
284
319
|
"Accept" => "application/json",
|
285
|
-
"Content-Type" => "application/json",
|
286
320
|
"ApiKey" => @api_key
|
287
321
|
}
|
322
|
+
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
288
323
|
h["ContactToken"] = @contact_token_id if @contact_token_id
|
289
324
|
if headers
|
290
325
|
headers.each do |k,v|
|
@@ -294,12 +329,12 @@ module Mints
|
|
294
329
|
self.http_get(url, h)
|
295
330
|
end
|
296
331
|
|
297
|
-
def public_post(url, headers = nil, data)
|
332
|
+
def public_post(url, headers = nil, data, compatibility_options)
|
298
333
|
h = {
|
299
334
|
"Accept" => "application/json",
|
300
|
-
"Content-Type" => "application/json",
|
301
335
|
"ApiKey" => @api_key
|
302
336
|
}
|
337
|
+
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
303
338
|
h["ContactToken"] = @session_token if @session_token
|
304
339
|
if headers
|
305
340
|
headers.each do |k,v|
|
@@ -309,12 +344,12 @@ module Mints
|
|
309
344
|
self.http_post(url, h, data)
|
310
345
|
end
|
311
346
|
|
312
|
-
def public_put(url, headers = nil, data)
|
347
|
+
def public_put(url, headers = nil, data, compatibility_options)
|
313
348
|
h = {
|
314
|
-
"Accept" => "application/json",
|
315
|
-
"Content-Type" => "application/json",
|
349
|
+
"Accept" => "application/json",
|
316
350
|
"ApiKey" => @api_key
|
317
351
|
}
|
352
|
+
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
318
353
|
h["ContactToken"] = @contact_token_id if @contact_token_id
|
319
354
|
if headers
|
320
355
|
headers.each do |k,v|
|
data/lib/contact.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "./client.rb"
|
2
|
+
require_relative "./mints_helper.rb"
|
2
3
|
include ActionController::Cookies
|
3
4
|
module Mints
|
4
5
|
class Contact
|
@@ -7,30 +8,93 @@ module Mints
|
|
7
8
|
# === Initialize.
|
8
9
|
# Class constructor
|
9
10
|
#
|
11
|
+
# ==== Parameters
|
12
|
+
# host:: (String) -- It's the visitor IP.
|
13
|
+
# api_key:: (String) -- Mints instance api key.
|
14
|
+
# contact_token_id:: (Integer) -- Cookie 'mints_contact_id' value (mints_contact_token).
|
15
|
+
#
|
16
|
+
# ==== Return
|
17
|
+
# Returns a Contact object
|
10
18
|
def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
|
11
19
|
@client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
|
12
20
|
end
|
13
21
|
|
14
22
|
##
|
15
23
|
# === Login.
|
16
|
-
# Starts a contact session
|
24
|
+
# Starts a contact session.
|
25
|
+
#
|
26
|
+
# ==== Parameters:
|
27
|
+
# email:: (String) -- The email that will be logged.
|
28
|
+
# password:: (String) -- The password of the email.
|
17
29
|
#
|
30
|
+
# ==== Example
|
31
|
+
# @mints_contact.login("email@example.com", "password")
|
18
32
|
def login(email, password)
|
19
33
|
data = {
|
20
34
|
email: email,
|
21
35
|
password: password
|
22
36
|
}
|
23
|
-
response = @client.raw("post", "/contacts/login", nil, {data: data})
|
37
|
+
response = @client.raw("post", "/contacts/login", nil, {data: data}.to_json)
|
24
38
|
if response.key? "session_token"
|
25
39
|
@client.session_token = response["session_token"]
|
26
40
|
end
|
27
41
|
return response
|
28
42
|
end
|
29
43
|
|
44
|
+
##
|
45
|
+
# === Magic Link Login.
|
46
|
+
# Starts a contact session with a token received in the contact email. The token will be received by send_magic_link method.
|
47
|
+
#
|
48
|
+
# ==== Parameters:
|
49
|
+
# token:: (String) -- The email token that will be used to log in.
|
50
|
+
#
|
51
|
+
# ==== Example
|
52
|
+
# @mints_contact.magic_link_login(
|
53
|
+
# "d8618c6d-a165-41cb-b3ec-d053cbf30059:zm54HtRdfHED8dpILZpjyqjPIceiaXNLfOklqM92fveBS0nDtyPYBlI4CPlPe3zq"
|
54
|
+
# )
|
55
|
+
def magic_link_login(token)
|
56
|
+
response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
|
57
|
+
if response.key? "session_token"
|
58
|
+
@client.session_token = response["session_token"]
|
59
|
+
end
|
60
|
+
return response
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# === Send Magic Link
|
65
|
+
# Send magic link to contact by email. That magic link will be used in magic_link_login method.
|
66
|
+
#
|
67
|
+
# ==== Parameters:
|
68
|
+
# email:: (String) -- Contact's email.
|
69
|
+
# template_slug:: (String) -- Email template's slug to be used in the email.
|
70
|
+
# redirectUrl:: (String) -- Url to be redirected in the implemented page.
|
71
|
+
# lifeTime:: (Integer) -- Maximum time of use in minutes.
|
72
|
+
# maxVisits:: (Integer) -- The maximum number of uses of a token.
|
73
|
+
#
|
74
|
+
# ==== First Example
|
75
|
+
# @mints_contact.send_magic_link("email@example.com", "template_slug")
|
76
|
+
#
|
77
|
+
# ==== Second Example
|
78
|
+
# @mints_contact.send_magic_link("email@example.com", "template_slug", "", 1440, 3)
|
79
|
+
def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
|
80
|
+
data = {
|
81
|
+
email: email,
|
82
|
+
lifeTime: lifeTime,
|
83
|
+
maxVisits: maxVisits,
|
84
|
+
redirectUrl: redirectUrl,
|
85
|
+
templateId: template_slug
|
86
|
+
}
|
87
|
+
response = @client.raw("post", "/contacts/magic-link", nil, { data: data }.to_json, '/api/v1')
|
88
|
+
return response
|
89
|
+
end
|
90
|
+
|
30
91
|
##
|
31
92
|
# === Logout.
|
32
|
-
# Ends a contact session
|
93
|
+
# Ends a contact session previously logged.
|
33
94
|
#
|
95
|
+
# ==== Example
|
96
|
+
# @mints_contact.login("email@example.com", "password")
|
97
|
+
# @mints_contact.logout
|
34
98
|
def logout
|
35
99
|
response = @client.raw("post", "/contacts/logout") if session_token?
|
36
100
|
if response["success"]
|
@@ -41,62 +105,127 @@ module Mints
|
|
41
105
|
|
42
106
|
##
|
43
107
|
# === Change Password.
|
44
|
-
# Change password
|
108
|
+
# Change password without email. To change the password a contact must be logged.
|
45
109
|
#
|
110
|
+
# ==== Parameters:
|
111
|
+
# data:: (Hash) -- A new password allocated in a data key.
|
112
|
+
#
|
113
|
+
# ==== Example
|
114
|
+
# @mints_contact.login("email@example.com", "password")
|
115
|
+
# data = { "password": "123456" }
|
116
|
+
# @data = @mints_contact.change_password(data)
|
46
117
|
def change_password(data)
|
47
|
-
return @client.raw("post", "/contacts/change-password", nil, data)
|
118
|
+
return @client.raw("post", "/contacts/change-password", nil, data_transform(data))
|
48
119
|
end
|
49
120
|
|
50
121
|
##
|
51
122
|
# === Recover Password.
|
52
|
-
#
|
123
|
+
# Send a email that contains a token to a contact. That token will be used in reset_password to establish a new password.
|
124
|
+
#
|
125
|
+
# ==== Parameters:
|
126
|
+
# data:: (Hash) -- It's a data key where will be hosted the destination email.
|
53
127
|
#
|
128
|
+
# ==== Example
|
129
|
+
# data = { "email": "email@example.com" }
|
130
|
+
# @mints_contact.recover_password(data)
|
54
131
|
def recover_password(data)
|
55
|
-
return @client.raw("post", "/contacts/recover-password", nil, data)
|
132
|
+
return @client.raw("post", "/contacts/recover-password", nil, data_transform(data))
|
56
133
|
end
|
57
134
|
|
58
135
|
##
|
59
136
|
# === Reset Password.
|
60
|
-
# Reset password
|
137
|
+
# Reset password using a token. The token is obtained by recover_password method.
|
61
138
|
#
|
139
|
+
# ==== Parameters:
|
140
|
+
# data:: (Hash) -- It's a set of data which contains all the information to reset a contact password.
|
141
|
+
#
|
142
|
+
# ==== Example
|
143
|
+
# data = {
|
144
|
+
# "email": "email@example.com",
|
145
|
+
# "password": "password",
|
146
|
+
# "password_confirmation": "password",
|
147
|
+
# "token": "644aa3aa0831d782cc42e42b11aedea9a2234389af4f429a8d96651295ecfa09"
|
148
|
+
# }
|
149
|
+
# @mints_contact.reset_password(data)
|
62
150
|
def reset_password(data)
|
63
|
-
return @client.raw("post", "/contacts/reset-password", nil, data)
|
151
|
+
return @client.raw("post", "/contacts/reset-password", nil, data_transform(data))
|
64
152
|
end
|
65
153
|
|
66
154
|
##
|
67
155
|
# === OAuth Login.
|
68
|
-
# Login a contact using oauth
|
69
|
-
#
|
156
|
+
# Login a contact using oauth.
|
70
157
|
def oauth_login(data)
|
71
158
|
return @client.raw("post", "/contacts/oauth-login", nil, data)
|
72
159
|
end
|
73
160
|
|
74
161
|
##
|
75
162
|
# === Me.
|
76
|
-
# Get contact logged info
|
163
|
+
# Get contact logged info.
|
77
164
|
#
|
78
|
-
|
79
|
-
|
165
|
+
# ==== First Example
|
166
|
+
# @mints_contact.me
|
167
|
+
#
|
168
|
+
# ==== Second Example
|
169
|
+
# options = {
|
170
|
+
# "attributes": true,
|
171
|
+
# "taxonomies": true
|
172
|
+
# }
|
173
|
+
# @data = @mints_contact.me(options)
|
174
|
+
def me(options = nil)
|
175
|
+
return @client.raw("get", "/contacts/me", options)
|
80
176
|
end
|
81
177
|
|
82
178
|
##
|
83
179
|
# === Status.
|
84
|
-
# Get contact logged status
|
180
|
+
# Get contact logged status.
|
85
181
|
#
|
182
|
+
# ==== Example
|
183
|
+
# @mints_contact.status
|
86
184
|
def status
|
87
185
|
return @client.raw("get", "/contacts/status")
|
88
186
|
end
|
89
187
|
|
90
188
|
##
|
91
189
|
# === Update.
|
92
|
-
# Update logged contact attributes
|
190
|
+
# Update logged contact attributes.
|
191
|
+
#
|
192
|
+
# ==== Parameters:
|
193
|
+
# data:: (Hash) -- It's the data to update with a session active.
|
93
194
|
#
|
195
|
+
# ==== Example
|
196
|
+
# @mints_contact.login("email@example.com", "password")
|
197
|
+
# data = {
|
198
|
+
# "given_name": "Given Name",
|
199
|
+
# "last_name": "Last Name"
|
200
|
+
# }
|
201
|
+
# @mints_contact.update(data)
|
94
202
|
def update(data)
|
95
|
-
return @client.raw("put", "/contacts/update", nil, data)
|
203
|
+
return @client.raw("put", "/contacts/update", nil, data_transform(data))
|
204
|
+
end
|
205
|
+
|
206
|
+
##
|
207
|
+
# === Register.
|
208
|
+
# Register a contact.
|
209
|
+
#
|
210
|
+
# ==== Parameters:
|
211
|
+
# data:: (Hash) -- It's the register data.
|
212
|
+
#
|
213
|
+
# ==== Example
|
214
|
+
# data = {
|
215
|
+
# "email": "email@example.com",
|
216
|
+
# "given_name": "Given Name",
|
217
|
+
# "last_name": "Last Name",
|
218
|
+
# "password": "password"
|
219
|
+
# }
|
220
|
+
# @mints_contact.register(data);
|
221
|
+
def register(data)
|
222
|
+
return @client.raw("post", "/contacts/register", nil, data_transform(data))
|
96
223
|
end
|
97
224
|
|
98
225
|
private
|
99
226
|
|
227
|
+
include MintsHelper
|
228
|
+
|
100
229
|
def session_token?
|
101
230
|
if @client.session_token
|
102
231
|
return true
|
@@ -6,8 +6,10 @@ 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
14
|
match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
|
13
15
|
match '/contact/v1/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
|
@@ -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.
|
@@ -22,7 +22,22 @@ module Mints
|
|
22
22
|
# Get session token from response
|
23
23
|
session_token = response['api_token']
|
24
24
|
# Set a permanent cookie with the session token
|
25
|
-
cookies
|
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
|
26
41
|
end
|
27
42
|
|
28
43
|
##
|
@@ -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
|