mints 0.0.18 → 0.0.19
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 +38 -32
- data/lib/contact.rb +65 -60
- data/lib/mints/controllers/base_api_controller.rb +4 -4
- data/lib/mints/controllers/base_controller.rb +12 -3
- data/lib/mints_helper.rb +47 -0
- data/lib/pub.rb +75 -87
- 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 +22 -922
- metadata +61 -1
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,18 +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
75
|
elsif action === 'delete' or action === 'destroy'
|
76
76
|
action = 'delete'
|
77
|
-
response = self.send("#{@scope}_#{action}", "#{full_url}", data)
|
77
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
|
78
78
|
end
|
79
79
|
if result_from_cache
|
80
80
|
return parsed_response = JSON.parse(response)
|
@@ -124,7 +124,7 @@ module Mints
|
|
124
124
|
uri.query_values = args[1]
|
125
125
|
end
|
126
126
|
url = self.get_url(route, object, uri, slug)
|
127
|
-
response = self.send("#{@scope}_#{action}", url)
|
127
|
+
response = self.send("#{@scope}_#{action}", url, compatibility_options)
|
128
128
|
elsif action == "post" or action == "create"
|
129
129
|
if args[1].class == Hash
|
130
130
|
uri.query_values = args[1]
|
@@ -132,7 +132,7 @@ module Mints
|
|
132
132
|
url = self.get_url(route, object, uri, slug)
|
133
133
|
action = 'post'
|
134
134
|
data = args[0]
|
135
|
-
response = self.send("#{@scope}_#{action}", url, {data: data})
|
135
|
+
response = self.send("#{@scope}_#{action}", url, {data: data}, compatibility_options)
|
136
136
|
elsif action == "put" or action == "update"
|
137
137
|
if args.first.class == String or Integer
|
138
138
|
slug = args.first
|
@@ -142,7 +142,7 @@ module Mints
|
|
142
142
|
action = 'put'
|
143
143
|
id = args[0]
|
144
144
|
data = args[1]
|
145
|
-
response = self.send("#{@scope}_#{action}", "#{url}", {data: data})
|
145
|
+
response = self.send("#{@scope}_#{action}", "#{url}", {data: data}, compatibility_options)
|
146
146
|
end
|
147
147
|
|
148
148
|
if response.response.code == "404"
|
@@ -239,81 +239,87 @@ module Mints
|
|
239
239
|
end
|
240
240
|
|
241
241
|
# Start contact context
|
242
|
-
def contact_get(url)
|
242
|
+
def contact_get(url, compatibility_options)
|
243
243
|
headers = {
|
244
244
|
"ApiKey" => @api_key,
|
245
245
|
"Accept" => "application/json",
|
246
246
|
"ContactToken" => @contact_token_id
|
247
247
|
}
|
248
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
248
249
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
249
250
|
return self.http_get(url, headers)
|
250
251
|
end
|
251
252
|
|
252
|
-
def contact_post(url, data)
|
253
|
+
def contact_post(url, data, compatibility_options)
|
253
254
|
headers = {
|
254
255
|
"ApiKey" => @api_key,
|
255
256
|
"Accept" => "application/json",
|
256
257
|
"ContactToken" => @contact_token_id
|
257
258
|
}
|
259
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
258
260
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
259
261
|
return self.http_post(url, headers, data)
|
260
262
|
end
|
261
263
|
|
262
|
-
def contact_put(url, data)
|
264
|
+
def contact_put(url, data, compatibility_options)
|
263
265
|
headers = {
|
264
266
|
"ApiKey" => @api_key,
|
265
267
|
"Accept" => "application/json",
|
266
268
|
"ContactToken" => @contact_token_id
|
267
269
|
}
|
270
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
268
271
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
269
272
|
return self.http_put(url, headers, data)
|
270
273
|
end
|
271
274
|
|
272
275
|
# Start User context
|
273
|
-
def user_get(url)
|
276
|
+
def user_get(url, compatibility_options)
|
274
277
|
headers = {
|
275
|
-
"
|
276
|
-
"
|
278
|
+
"Accept" => "application/json",
|
279
|
+
"ApiKey" => @api_key
|
277
280
|
}
|
281
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
278
282
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
279
283
|
return self.http_get(url, headers)
|
280
284
|
end
|
281
285
|
|
282
|
-
def user_post(url, data)
|
286
|
+
def user_post(url, data, compatibility_options)
|
283
287
|
headers = {
|
284
|
-
"
|
285
|
-
"
|
288
|
+
"Accept" => "application/json",
|
289
|
+
"ApiKey" => @api_key
|
286
290
|
}
|
291
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
287
292
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
288
293
|
return self.http_post(url, headers, data)
|
289
294
|
end
|
290
295
|
|
291
|
-
def user_put(url, data)
|
296
|
+
def user_put(url, data, compatibility_options)
|
292
297
|
headers = {
|
293
|
-
"ApiKey" => @api_key,
|
294
298
|
"Accept" => "application/json",
|
295
|
-
"
|
299
|
+
"ApiKey" => @api_key
|
296
300
|
}
|
301
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
297
302
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
298
303
|
return self.http_put(url, headers, data)
|
299
304
|
end
|
300
305
|
|
301
|
-
def user_delete(url, data)
|
306
|
+
def user_delete(url, data, compatibility_options)
|
302
307
|
headers = {
|
303
|
-
"
|
304
|
-
"
|
308
|
+
"Accept" => "application/json",
|
309
|
+
"ApiKey" => @api_key
|
305
310
|
}
|
311
|
+
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
306
312
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
307
313
|
return self.http_delete(url, headers, data)
|
308
314
|
end
|
309
315
|
# End User Context
|
310
316
|
|
311
|
-
def public_get(url, headers = nil)
|
317
|
+
def public_get(url, headers = nil, compatibility_options)
|
312
318
|
h = {
|
313
319
|
"Accept" => "application/json",
|
314
|
-
"Content-Type" => "application/json",
|
315
320
|
"ApiKey" => @api_key
|
316
321
|
}
|
322
|
+
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
317
323
|
h["ContactToken"] = @contact_token_id if @contact_token_id
|
318
324
|
if headers
|
319
325
|
headers.each do |k,v|
|
@@ -323,12 +329,12 @@ module Mints
|
|
323
329
|
self.http_get(url, h)
|
324
330
|
end
|
325
331
|
|
326
|
-
def public_post(url, headers = nil, data)
|
332
|
+
def public_post(url, headers = nil, data, compatibility_options)
|
327
333
|
h = {
|
328
334
|
"Accept" => "application/json",
|
329
|
-
"Content-Type" => "application/json",
|
330
335
|
"ApiKey" => @api_key
|
331
336
|
}
|
337
|
+
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
332
338
|
h["ContactToken"] = @session_token if @session_token
|
333
339
|
if headers
|
334
340
|
headers.each do |k,v|
|
@@ -338,12 +344,12 @@ module Mints
|
|
338
344
|
self.http_post(url, h, data)
|
339
345
|
end
|
340
346
|
|
341
|
-
def public_put(url, headers = nil, data)
|
347
|
+
def public_put(url, headers = nil, data, compatibility_options)
|
342
348
|
h = {
|
343
|
-
"Accept" => "application/json",
|
344
|
-
"Content-Type" => "application/json",
|
349
|
+
"Accept" => "application/json",
|
345
350
|
"ApiKey" => @api_key
|
346
351
|
}
|
352
|
+
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
347
353
|
h["ContactToken"] = @contact_token_id if @contact_token_id
|
348
354
|
if headers
|
349
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,27 +8,33 @@ 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.
|
17
25
|
#
|
18
26
|
# ==== Parameters:
|
19
|
-
#
|
20
|
-
#
|
27
|
+
# email:: (String) -- The email that will be logged.
|
28
|
+
# password:: (String) -- The password of the email.
|
21
29
|
#
|
22
30
|
# ==== Example
|
23
|
-
# @mints_contact.login("
|
24
|
-
#
|
31
|
+
# @mints_contact.login("email@example.com", "password")
|
25
32
|
def login(email, password)
|
26
33
|
data = {
|
27
34
|
email: email,
|
28
35
|
password: password
|
29
36
|
}
|
30
|
-
response = @client.raw("post", "/contacts/login", nil, {data: data})
|
37
|
+
response = @client.raw("post", "/contacts/login", nil, {data: data}.to_json)
|
31
38
|
if response.key? "session_token"
|
32
39
|
@client.session_token = response["session_token"]
|
33
40
|
end
|
@@ -39,13 +46,12 @@ module Mints
|
|
39
46
|
# Starts a contact session with a token received in the contact email. The token will be received by send_magic_link method.
|
40
47
|
#
|
41
48
|
# ==== Parameters:
|
42
|
-
#
|
49
|
+
# token:: (String) -- The email token that will be used to log in.
|
43
50
|
#
|
44
51
|
# ==== Example
|
45
52
|
# @mints_contact.magic_link_login(
|
46
53
|
# "d8618c6d-a165-41cb-b3ec-d053cbf30059:zm54HtRdfHED8dpILZpjyqjPIceiaXNLfOklqM92fveBS0nDtyPYBlI4CPlPe3zq"
|
47
54
|
# )
|
48
|
-
#
|
49
55
|
def magic_link_login(token)
|
50
56
|
response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
|
51
57
|
if response.key? "session_token"
|
@@ -59,18 +65,17 @@ module Mints
|
|
59
65
|
# Send magic link to contact by email. That magic link will be used in magic_link_login method.
|
60
66
|
#
|
61
67
|
# ==== Parameters:
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
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.
|
67
73
|
#
|
68
74
|
# ==== First Example
|
69
|
-
# @mints_contact.send_magic_link("
|
75
|
+
# @mints_contact.send_magic_link("email@example.com", "template_slug")
|
70
76
|
#
|
71
77
|
# ==== Second Example
|
72
|
-
# @mints_contact.send_magic_link("
|
73
|
-
#
|
78
|
+
# @mints_contact.send_magic_link("email@example.com", "template_slug", "", 1440, 3)
|
74
79
|
def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
|
75
80
|
data = {
|
76
81
|
email: email,
|
@@ -79,7 +84,7 @@ module Mints
|
|
79
84
|
redirectUrl: redirectUrl,
|
80
85
|
templateId: template_slug
|
81
86
|
}
|
82
|
-
response = @client.raw("post", "/contacts/magic-link", nil, { data: data }, '/api/v1')
|
87
|
+
response = @client.raw("post", "/contacts/magic-link", nil, { data: data }.to_json, '/api/v1')
|
83
88
|
return response
|
84
89
|
end
|
85
90
|
|
@@ -88,9 +93,8 @@ module Mints
|
|
88
93
|
# Ends a contact session previously logged.
|
89
94
|
#
|
90
95
|
# ==== Example
|
91
|
-
# @mints_contact.login(
|
96
|
+
# @mints_contact.login("email@example.com", "password")
|
92
97
|
# @mints_contact.logout
|
93
|
-
#
|
94
98
|
def logout
|
95
99
|
response = @client.raw("post", "/contacts/logout") if session_token?
|
96
100
|
if response["success"]
|
@@ -104,15 +108,14 @@ module Mints
|
|
104
108
|
# Change password without email. To change the password a contact must be logged.
|
105
109
|
#
|
106
110
|
# ==== Parameters:
|
107
|
-
#
|
111
|
+
# data:: (Hash) -- A new password allocated in a data key.
|
108
112
|
#
|
109
113
|
# ==== Example
|
110
|
-
# @mints_contact.login(
|
111
|
-
# data = { "
|
112
|
-
# @mints_contact.change_password(data)
|
113
|
-
#
|
114
|
+
# @mints_contact.login("email@example.com", "password")
|
115
|
+
# data = { "password": "123456" }
|
116
|
+
# @data = @mints_contact.change_password(data)
|
114
117
|
def change_password(data)
|
115
|
-
return @client.raw("post", "/contacts/change-password", nil, data)
|
118
|
+
return @client.raw("post", "/contacts/change-password", nil, data_transform(data))
|
116
119
|
end
|
117
120
|
|
118
121
|
##
|
@@ -120,14 +123,13 @@ module Mints
|
|
120
123
|
# Send a email that contains a token to a contact. That token will be used in reset_password to establish a new password.
|
121
124
|
#
|
122
125
|
# ==== Parameters:
|
123
|
-
#
|
126
|
+
# data:: (Hash) -- It's a data key where will be hosted the destination email.
|
124
127
|
#
|
125
128
|
# ==== Example
|
126
|
-
# data = { "
|
129
|
+
# data = { "email": "email@example.com" }
|
127
130
|
# @mints_contact.recover_password(data)
|
128
|
-
#
|
129
131
|
def recover_password(data)
|
130
|
-
return @client.raw("post", "/contacts/recover-password", nil, data)
|
132
|
+
return @client.raw("post", "/contacts/recover-password", nil, data_transform(data))
|
131
133
|
end
|
132
134
|
|
133
135
|
##
|
@@ -135,25 +137,23 @@ module Mints
|
|
135
137
|
# Reset password using a token. The token is obtained by recover_password method.
|
136
138
|
#
|
137
139
|
# ==== Parameters:
|
138
|
-
#
|
140
|
+
# data:: (Hash) -- It's a set of data which contains all the information to reset a contact password.
|
139
141
|
#
|
140
142
|
# ==== Example
|
141
|
-
# data = {
|
142
|
-
# "email": "
|
143
|
-
# "password": "
|
144
|
-
# "password_confirmation": "
|
143
|
+
# data = {
|
144
|
+
# "email": "email@example.com",
|
145
|
+
# "password": "password",
|
146
|
+
# "password_confirmation": "password",
|
145
147
|
# "token": "644aa3aa0831d782cc42e42b11aedea9a2234389af4f429a8d96651295ecfa09"
|
146
|
-
# }
|
148
|
+
# }
|
147
149
|
# @mints_contact.reset_password(data)
|
148
|
-
#
|
149
150
|
def reset_password(data)
|
150
|
-
return @client.raw("post", "/contacts/reset-password", nil, data)
|
151
|
+
return @client.raw("post", "/contacts/reset-password", nil, data_transform(data))
|
151
152
|
end
|
152
153
|
|
153
154
|
##
|
154
155
|
# === OAuth Login.
|
155
|
-
# Login a contact using oauth
|
156
|
-
#
|
156
|
+
# Login a contact using oauth.
|
157
157
|
def oauth_login(data)
|
158
158
|
return @client.raw("post", "/contacts/oauth-login", nil, data)
|
159
159
|
end
|
@@ -162,11 +162,17 @@ module Mints
|
|
162
162
|
# === Me.
|
163
163
|
# Get contact logged info.
|
164
164
|
#
|
165
|
-
# ==== Example
|
165
|
+
# ==== First Example
|
166
166
|
# @mints_contact.me
|
167
167
|
#
|
168
|
-
|
169
|
-
|
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)
|
170
176
|
end
|
171
177
|
|
172
178
|
##
|
@@ -175,7 +181,6 @@ module Mints
|
|
175
181
|
#
|
176
182
|
# ==== Example
|
177
183
|
# @mints_contact.status
|
178
|
-
#
|
179
184
|
def status
|
180
185
|
return @client.raw("get", "/contacts/status")
|
181
186
|
end
|
@@ -185,18 +190,17 @@ module Mints
|
|
185
190
|
# Update logged contact attributes.
|
186
191
|
#
|
187
192
|
# ==== Parameters:
|
188
|
-
#
|
193
|
+
# data:: (Hash) -- It's the data to update with a session active.
|
189
194
|
#
|
190
195
|
# ==== Example
|
191
|
-
# @mints_contact.login("
|
192
|
-
# data = {
|
193
|
-
# "given_name": "
|
194
|
-
# "last_name": "
|
195
|
-
# }
|
196
|
+
# @mints_contact.login("email@example.com", "password")
|
197
|
+
# data = {
|
198
|
+
# "given_name": "Given Name",
|
199
|
+
# "last_name": "Last Name"
|
200
|
+
# }
|
196
201
|
# @mints_contact.update(data)
|
197
|
-
#
|
198
202
|
def update(data)
|
199
|
-
return @client.raw("put", "/contacts/update", nil, data)
|
203
|
+
return @client.raw("put", "/contacts/update", nil, data_transform(data))
|
200
204
|
end
|
201
205
|
|
202
206
|
##
|
@@ -204,23 +208,24 @@ module Mints
|
|
204
208
|
# Register a contact.
|
205
209
|
#
|
206
210
|
# ==== Parameters:
|
207
|
-
#
|
211
|
+
# data:: (Hash) -- It's the register data.
|
208
212
|
#
|
209
213
|
# ==== Example
|
210
|
-
# data = {
|
211
|
-
# "email": "
|
212
|
-
# "given_name": "
|
213
|
-
# "last_name": "
|
214
|
-
# "password": "
|
215
|
-
# }
|
214
|
+
# data = {
|
215
|
+
# "email": "email@example.com",
|
216
|
+
# "given_name": "Given Name",
|
217
|
+
# "last_name": "Last Name",
|
218
|
+
# "password": "password"
|
219
|
+
# }
|
216
220
|
# @mints_contact.register(data);
|
217
|
-
#
|
218
221
|
def register(data)
|
219
|
-
return @client.raw("post", "/contacts/register", nil, data)
|
222
|
+
return @client.raw("post", "/contacts/register", nil, data_transform(data))
|
220
223
|
end
|
221
224
|
|
222
225
|
private
|
223
226
|
|
227
|
+
include MintsHelper
|
228
|
+
|
224
229
|
def session_token?
|
225
230
|
if @client.session_token
|
226
231
|
return true
|
@@ -10,7 +10,7 @@ module Mints
|
|
10
10
|
response = @mints_contact.login(email, password)
|
11
11
|
# Get session token from response
|
12
12
|
session_token = response['session_token']
|
13
|
-
id_token = response['contact']['contact_token']
|
13
|
+
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
14
14
|
# Set a permanent cookie with the session token
|
15
15
|
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
16
16
|
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
@@ -18,15 +18,15 @@ module Mints
|
|
18
18
|
end
|
19
19
|
|
20
20
|
##
|
21
|
-
# === Mints
|
22
|
-
# Starts a
|
21
|
+
# === Mints contact Login.
|
22
|
+
# Starts a contact session in mints.cloud and set a session cookie
|
23
23
|
def mints_contact_magic_link_login(hash)
|
24
24
|
# Login in mints
|
25
25
|
response = @mints_contact.magic_link_login(hash)
|
26
26
|
if response['data']
|
27
27
|
# Get session token from response
|
28
28
|
session_token = response['data']['session_token']
|
29
|
-
id_token = response['data']['contact']['contact_token']
|
29
|
+
id_token = response['data']['contact']['contact_token'] ? response['data']['contact']['contact_token'] : response['data']['contact']['id_token']
|
30
30
|
# Set a permanent cookie with the session token
|
31
31
|
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
32
32
|
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
@@ -24,7 +24,7 @@ module Mints
|
|
24
24
|
response = @mints_contact.login(email, password)
|
25
25
|
# Get session token from response
|
26
26
|
session_token = response['session_token']
|
27
|
-
id_token = response['contact']['contact_token']
|
27
|
+
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
28
28
|
# Set a permanent cookie with the session token
|
29
29
|
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
30
30
|
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
@@ -39,7 +39,7 @@ module Mints
|
|
39
39
|
response = @mints_contact.login(email, password)
|
40
40
|
# Get session token from response
|
41
41
|
session_token = response['session_token']
|
42
|
-
id_token = response['contact']['contact_token']
|
42
|
+
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
43
43
|
# Set a permanent cookie with the session token
|
44
44
|
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
45
45
|
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
@@ -80,7 +80,7 @@ module Mints
|
|
80
80
|
if @debug
|
81
81
|
puts "RESPONSE IN REGISTER VISIT: #{response}"
|
82
82
|
end
|
83
|
-
@contact_token = response['contact_token']
|
83
|
+
@contact_token = response['contact_token'] ? response['contact_token'] : response['user_token']
|
84
84
|
@visit_id = response['visit_id']
|
85
85
|
cookies.permanent[:mints_contact_id] = { value: @contact_token, secure: true, httponly: true }
|
86
86
|
end
|
@@ -115,6 +115,15 @@ module Mints
|
|
115
115
|
# === Set mints contact client.
|
116
116
|
# Initialize the public client and set the contact token
|
117
117
|
def set_mints_contact_client
|
118
|
+
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
119
|
+
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
120
|
+
config = YAML.load template.result(binding)
|
121
|
+
@host = config["mints"]["host"]
|
122
|
+
@api_key = config["mints"]["api_key"]
|
123
|
+
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
124
|
+
else
|
125
|
+
raise 'MintsBadCredentialsError'
|
126
|
+
end
|
118
127
|
# Initialize mints clontact client
|
119
128
|
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
120
129
|
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
data/lib/mints_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module MintsHelper
|
3
|
+
# === Get query results.
|
4
|
+
# Method used to give the options to make a 'post' or 'get' request.
|
5
|
+
#
|
6
|
+
# ==== Parameters
|
7
|
+
# url:: (String) -- Url to make the request.
|
8
|
+
# options:: (Hash) -- List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter.
|
9
|
+
# use_post:: (Boolean) -- Variable to determine if the request is by 'post' or 'get' functions.
|
10
|
+
#
|
11
|
+
def get_query_results(url, options = nil, use_post = true)
|
12
|
+
if use_post
|
13
|
+
return @client.raw("post", "#{url}/query", options)
|
14
|
+
else
|
15
|
+
return @client.raw("get", url, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# === Data transform.
|
20
|
+
# Transform a 'data' variable to a standardized 'data' variable.
|
21
|
+
#
|
22
|
+
# ==== Parameters
|
23
|
+
# data:: (Hash) -- Data to be submited.
|
24
|
+
#
|
25
|
+
def data_transform(data)
|
26
|
+
data = correct_json(data)
|
27
|
+
unless data[:data]
|
28
|
+
data = {data: data}
|
29
|
+
end
|
30
|
+
return data.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
# === Correct json.
|
34
|
+
# Receives a json data and convert it to a symbolized object.
|
35
|
+
#
|
36
|
+
# ==== Parameters
|
37
|
+
# data:: (Hash) -- Data to be submited.
|
38
|
+
#
|
39
|
+
def correct_json(data)
|
40
|
+
if data.is_a? String
|
41
|
+
data = JSON.parse(data)
|
42
|
+
end
|
43
|
+
data = data.symbolize_keys
|
44
|
+
return data
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|