mints 0.0.16 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/client.rb +97 -38
  3. data/lib/contact.rb +124 -21
  4. data/lib/mints/controllers/admin_base_controller.rb +2 -2
  5. data/lib/mints/controllers/base_api_controller.rb +12 -11
  6. data/lib/mints/controllers/base_controller.rb +38 -9
  7. data/lib/mints_helper.rb +47 -0
  8. data/lib/pub.rb +147 -61
  9. data/lib/user/config/api_keys.rb +65 -0
  10. data/lib/user/config/appointments.rb +221 -0
  11. data/lib/user/config/attribute_groups.rb +77 -0
  12. data/lib/user/config/attributes.rb +86 -0
  13. data/lib/user/config/calendars.rb +89 -0
  14. data/lib/user/config/config.rb +65 -0
  15. data/lib/user/config/importers.rb +184 -0
  16. data/lib/user/config/public_folders.rb +108 -0
  17. data/lib/user/config/relationships.rb +138 -0
  18. data/lib/user/config/roles.rb +84 -0
  19. data/lib/user/config/seeds.rb +14 -0
  20. data/lib/user/config/system_settings.rb +53 -0
  21. data/lib/user/config/tags.rb +63 -0
  22. data/lib/user/config/taxonomies.rb +124 -0
  23. data/lib/user/config/teams.rb +70 -0
  24. data/lib/user/config/users.rb +76 -0
  25. data/lib/user/contacts/contacts.rb +21 -0
  26. data/lib/user/content/assets.rb +98 -0
  27. data/lib/user/content/content.rb +235 -0
  28. data/lib/user/content/content_instances.rb +147 -0
  29. data/lib/user/content/content_templates.rb +111 -0
  30. data/lib/user/content/conversations.rb +174 -0
  31. data/lib/user/content/dam.rb +88 -0
  32. data/lib/user/content/forms.rb +168 -0
  33. data/lib/user/content/message_templates.rb +162 -0
  34. data/lib/user/content/messages.rb +90 -0
  35. data/lib/user/content/pages.rb +81 -0
  36. data/lib/user/content/stories.rb +164 -0
  37. data/lib/user/content/story_templates.rb +95 -0
  38. data/lib/user/crm/companies.rb +111 -0
  39. data/lib/user/crm/contacts.rb +312 -0
  40. data/lib/user/crm/crm.rb +21 -0
  41. data/lib/user/crm/deals.rb +111 -0
  42. data/lib/user/crm/favorites.rb +17 -0
  43. data/lib/user/crm/segments.rb +132 -0
  44. data/lib/user/crm/users.rb +22 -0
  45. data/lib/user/crm/workflow_step_objects.rb +89 -0
  46. data/lib/user/crm/workflow_steps.rb +49 -0
  47. data/lib/user/crm/workflows.rb +70 -0
  48. data/lib/user/ecommerce/ecommerce.rb +29 -0
  49. data/lib/user/ecommerce/item_prices.rb +86 -0
  50. data/lib/user/ecommerce/locations.rb +166 -0
  51. data/lib/user/ecommerce/order_items_groups.rb +109 -0
  52. data/lib/user/ecommerce/order_statuses.rb +26 -0
  53. data/lib/user/ecommerce/orders.rb +258 -0
  54. data/lib/user/ecommerce/price_lists.rb +73 -0
  55. data/lib/user/ecommerce/product_templates.rb +104 -0
  56. data/lib/user/ecommerce/product_variations.rb +129 -0
  57. data/lib/user/ecommerce/products.rb +169 -0
  58. data/lib/user/ecommerce/skus.rb +88 -0
  59. data/lib/user/ecommerce/taxes.rb +82 -0
  60. data/lib/user/ecommerce/variant_options.rb +69 -0
  61. data/lib/user/ecommerce/variant_values.rb +72 -0
  62. data/lib/user/helpers/helpers.rb +113 -0
  63. data/lib/user/helpers/object_activities.rb +83 -0
  64. data/lib/user/helpers/object_folders.rb +82 -0
  65. data/lib/user/helpers/user_folders.rb +83 -0
  66. data/lib/user/marketing/marketing.rb +120 -0
  67. data/lib/user/profile/profile.rb +111 -0
  68. data/lib/user.rb +24 -368
  69. metadata +63 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9cce05094ead82499622fb1f66d7caa52848d7940c484917218563d32defa16
4
- data.tar.gz: 88e34ca4adfe1f77097206463f6c24a6479b63f2cfdf92bf3106152c00b8dd5a
3
+ metadata.gz: 805f9ad3f355a55e73dfeea6ace38749e32fdb5eb8427f003bd520fcd04204e6
4
+ data.tar.gz: b5aeb908efaf757a6bb1acb32c57a0330cc597549acdc9b539a048aacf1e3211
5
5
  SHA512:
6
- metadata.gz: fbd81e5fed7023a5b3d489c66bbcc1efa3304d2fe6a7492aef0f0c72f51ad98c2c77635377858e19df92d61fd5a1c26d7d7758d0fde57c223ee9c9968faf0337
7
- data.tar.gz: 6f8672d582a57aa9f2128b73b6fb8133387ea604082557b146eadc321cd9fbcd55a9da4bbba4ac9541cfc3225edcc6826858f314b104abea0bf887bd87bc5a0c
6
+ metadata.gz: 1d98cb6dd69f6e9e1e56f67ad1a352e865f8b71fea0ce1c4d207a78959ff3a28cdbda7aed3058a0b57f3d26ab9bff459de1cc7256ebd2268046c166e2d9afa22
7
+ data.tar.gz: 6bef5686332e40cf0c838bb0a7a32db247841864c3ac79e31f5eb0bfd934d13abd2e4061be0fa006f74f7b3ac2302ee613401958789da3b99d79492329b467a6
data/lib/client.rb CHANGED
@@ -11,16 +11,20 @@ module Mints
11
11
  attr_accessor :session_token
12
12
  attr_accessor :contact_token_id
13
13
 
14
- def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, debug = false)
14
+ def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, visit_id = nil, debug = false)
15
15
  @host = host
16
16
  @api_key = api_key
17
17
  @session_token = session_token
18
18
  @contact_token_id = contact_token_id
19
+ @visit_id = visit_id
19
20
  @debug = debug
20
21
  self.set_scope(scope)
21
22
  end
22
23
 
23
- def raw(action, url, options = nil, data = nil, base_url = nil)
24
+ def raw(action, url, options = nil, data = nil, base_url = nil, compatibility_options = {}, only_tracking = false)
25
+ if compatibility_options === nil
26
+ compatibility_options = {}
27
+ end
24
28
  base_url = @base_url if !base_url
25
29
  uri = ""
26
30
  if (options && options.class == Hash)
@@ -51,8 +55,18 @@ module Mints
51
55
  if @redis_server.get(full_url)
52
56
  response = @redis_server.get(full_url)
53
57
  result_from_cache = true
54
- else
55
- response = self.send("#{@scope}_#{action}", "#{full_url}")
58
+
59
+ headers = nil
60
+ if only_tracking
61
+ headers = {"Only-Tracking" => "true"}
62
+ end
63
+ #when is already in redis notify to California to register the object usage
64
+ cali_response = self.send("#{@scope}_#{action}", "#{full_url}", headers, compatibility_options)
65
+ if @debug
66
+ puts "CALI RESPONSE: #{cali_response}"
67
+ end
68
+ else
69
+ response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
56
70
  @redis_server.setex(full_url,time,response)
57
71
  end
58
72
  break
@@ -63,15 +77,18 @@ module Mints
63
77
  end
64
78
 
65
79
  if !url_need_cache
66
- response = self.send("#{@scope}_#{action}", "#{full_url}")
80
+ response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
67
81
  end
68
82
 
69
83
  elsif action === 'create' or action === 'post'
70
84
  action = 'post'
71
- response = self.send("#{@scope}_#{action}", "#{full_url}", data)
85
+ response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
72
86
  elsif action === 'put' or action === 'patch' or action ==='update'
73
87
  action = 'put'
74
- response = self.send("#{@scope}_#{action}", "#{full_url}", data)
88
+ response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
89
+ elsif action === 'delete' or action === 'destroy'
90
+ action = 'delete'
91
+ response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
75
92
  end
76
93
  if result_from_cache
77
94
  return parsed_response = JSON.parse(response)
@@ -85,7 +102,6 @@ module Mints
85
102
  end
86
103
 
87
104
  def method_missing(name, *args, &block)
88
- puts name
89
105
  name.to_s.include?("__") ? separator = "__" : separator = "_"
90
106
  # split the name to identify their elements
91
107
  name_spplited = name.to_s.split(separator)
@@ -93,7 +109,7 @@ module Mints
93
109
  name_len = name_spplited.size
94
110
  # the action always be the first element
95
111
  action = name_spplited.first
96
- raise 'NoActionError' unless ['get', 'create', 'post', 'update', 'put'].include?(action)
112
+ raise 'NoActionError' unless ['get', 'create', 'post', 'update', 'put', 'delete', 'destroy'].include?(action)
97
113
  # the object always be the last element
98
114
  object = separator == "__" ? name_spplited.last.gsub("_","-") : name_spplited.last
99
115
  # get intermediate url elements
@@ -121,7 +137,7 @@ module Mints
121
137
  uri.query_values = args[1]
122
138
  end
123
139
  url = self.get_url(route, object, uri, slug)
124
- response = self.send("#{@scope}_#{action}", url)
140
+ response = self.send("#{@scope}_#{action}", url, nil, compatibility_options)
125
141
  elsif action == "post" or action == "create"
126
142
  if args[1].class == Hash
127
143
  uri.query_values = args[1]
@@ -129,7 +145,7 @@ module Mints
129
145
  url = self.get_url(route, object, uri, slug)
130
146
  action = 'post'
131
147
  data = args[0]
132
- response = self.send("#{@scope}_#{action}", url, {data: data})
148
+ response = self.send("#{@scope}_#{action}", url, {data: data}, compatibility_options)
133
149
  elsif action == "put" or action == "update"
134
150
  if args.first.class == String or Integer
135
151
  slug = args.first
@@ -139,7 +155,7 @@ module Mints
139
155
  action = 'put'
140
156
  id = args[0]
141
157
  data = args[1]
142
- response = self.send("#{@scope}_#{action}", "#{url}", {data: data})
158
+ response = self.send("#{@scope}_#{action}", "#{url}", {data: data}, compatibility_options)
143
159
  end
144
160
 
145
161
  if response.response.code == "404"
@@ -188,6 +204,7 @@ module Mints
188
204
  puts url
189
205
  puts "Headers:"
190
206
  puts headers
207
+ puts "Method: get"
191
208
  end
192
209
  return headers ? HTTParty.get(url, :headers => headers) : HTTParty.get(url)
193
210
  end
@@ -201,6 +218,7 @@ module Mints
201
218
  puts headers
202
219
  puts "Data:"
203
220
  puts data
221
+ puts "Method: post"
204
222
  end
205
223
  return headers ? HTTParty.post(url, :headers=> headers, :body => data) : HTTParty.post(url, :body => data)
206
224
  end
@@ -214,78 +232,119 @@ module Mints
214
232
  puts headers
215
233
  puts "Data:"
216
234
  puts data
235
+ puts "Method: put"
217
236
  end
218
237
  return headers ? HTTParty.put(url, :headers=> headers, :body => data) : HTTParty.put(url, :body => data)
219
238
  end
220
239
 
240
+ # Simple HTTP DELETE
241
+ def http_delete(url, headers = nil, data = nil)
242
+ if @debug
243
+ puts "Url:"
244
+ puts url
245
+ puts "Headers:"
246
+ puts headers
247
+ puts "Data:"
248
+ puts data
249
+ puts "Method: delete"
250
+ end
251
+ return headers ? HTTParty.delete(url, :headers=> headers, :body => data) : HTTParty.delete(url, :body => data)
252
+ end
253
+
221
254
  # Start contact context
222
- def contact_get(url)
223
- headers = {
255
+ def contact_get(url, headers = nil, compatibility_options)
256
+ h = {
224
257
  "ApiKey" => @api_key,
225
258
  "Accept" => "application/json",
226
259
  "ContactToken" => @contact_token_id
227
260
  }
228
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
229
- return self.http_get(url, headers)
261
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
262
+ h["Authorization"] = "Bearer #{@session_token}" if @session_token
263
+ if headers
264
+ headers.each do |k,v|
265
+ h[k] = v
266
+ end
267
+ end
268
+ return self.http_get(url, h)
230
269
  end
231
270
 
232
- def contact_post(url, data)
271
+ def contact_post(url, data, compatibility_options)
233
272
  headers = {
234
273
  "ApiKey" => @api_key,
235
274
  "Accept" => "application/json",
236
275
  "ContactToken" => @contact_token_id
237
276
  }
277
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
238
278
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
239
279
  return self.http_post(url, headers, data)
240
280
  end
241
281
 
242
- def contact_put(url, data)
282
+ def contact_put(url, data, compatibility_options)
243
283
  headers = {
244
284
  "ApiKey" => @api_key,
245
285
  "Accept" => "application/json",
246
286
  "ContactToken" => @contact_token_id
247
287
  }
288
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
248
289
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
249
- return self.http_post(url, headers, data)
290
+ return self.http_put(url, headers, data)
250
291
  end
251
292
 
252
293
  # Start User context
253
- def user_get(url)
254
- headers = {
255
- "ApiKey" => @api_key,
256
- "Accept" => "application/json"
294
+ def user_get(url, headers = nil, compatibility_options)
295
+ h = {
296
+ "Accept" => "application/json",
297
+ "ApiKey" => @api_key
257
298
  }
258
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
259
- return self.http_get(url, headers)
299
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
300
+ h["Authorization"] = "Bearer #{@session_token}" if @session_token
301
+ if headers
302
+ headers.each do |k,v|
303
+ h[k] = v
304
+ end
305
+ end
306
+ return self.http_get(url, h)
260
307
  end
261
308
 
262
- def user_post(url, data)
309
+ def user_post(url, data, compatibility_options)
263
310
  headers = {
264
- "ApiKey" => @api_key,
265
- "Accept" => "application/json"
311
+ "Accept" => "application/json",
312
+ "ApiKey" => @api_key
266
313
  }
314
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
267
315
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
268
316
  return self.http_post(url, headers, data)
269
317
  end
270
318
 
271
- def user_put(url, data)
319
+ def user_put(url, data, compatibility_options)
272
320
  headers = {
273
- "ApiKey" => @api_key,
274
321
  "Accept" => "application/json",
275
- "Content-Type" => "application/json"
322
+ "ApiKey" => @api_key
276
323
  }
324
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
277
325
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
278
326
  return self.http_put(url, headers, data)
279
327
  end
328
+
329
+ def user_delete(url, data, compatibility_options)
330
+ headers = {
331
+ "Accept" => "application/json",
332
+ "ApiKey" => @api_key
333
+ }
334
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
335
+ headers["Authorization"] = "Bearer #{@session_token}" if @session_token
336
+ return self.http_delete(url, headers, data)
337
+ end
280
338
  # End User Context
281
339
 
282
- def public_get(url, headers = nil)
340
+ def public_get(url, headers = nil, compatibility_options)
283
341
  h = {
284
342
  "Accept" => "application/json",
285
- "Content-Type" => "application/json",
286
343
  "ApiKey" => @api_key
287
344
  }
345
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
288
346
  h["ContactToken"] = @contact_token_id if @contact_token_id
347
+ h["Visit-Id"] = @visit_id if @visit_id
289
348
  if headers
290
349
  headers.each do |k,v|
291
350
  h[k] = v
@@ -294,12 +353,12 @@ module Mints
294
353
  self.http_get(url, h)
295
354
  end
296
355
 
297
- def public_post(url, headers = nil, data)
356
+ def public_post(url, headers = nil, data, compatibility_options)
298
357
  h = {
299
358
  "Accept" => "application/json",
300
- "Content-Type" => "application/json",
301
359
  "ApiKey" => @api_key
302
360
  }
361
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
303
362
  h["ContactToken"] = @session_token if @session_token
304
363
  if headers
305
364
  headers.each do |k,v|
@@ -309,12 +368,12 @@ module Mints
309
368
  self.http_post(url, h, data)
310
369
  end
311
370
 
312
- def public_put(url, headers = nil, data)
371
+ def public_put(url, headers = nil, data, compatibility_options)
313
372
  h = {
314
- "Accept" => "application/json",
315
- "Content-Type" => "application/json",
373
+ "Accept" => "application/json",
316
374
  "ApiKey" => @api_key
317
375
  }
376
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
318
377
  h["ContactToken"] = @contact_token_id if @contact_token_id
319
378
  if headers
320
379
  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,20 +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
- @client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
19
+ @client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, nil, 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
@@ -29,8 +43,15 @@ module Mints
29
43
 
30
44
  ##
31
45
  # === Magic Link Login.
32
- # Starts a contact session
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.
33
50
  #
51
+ # ==== Example
52
+ # @mints_contact.magic_link_login(
53
+ # "d8618c6d-a165-41cb-b3ec-d053cbf30059:zm54HtRdfHED8dpILZpjyqjPIceiaXNLfOklqM92fveBS0nDtyPYBlI4CPlPe3zq"
54
+ # )
34
55
  def magic_link_login(token)
35
56
  response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
36
57
  if response.key? "session_token"
@@ -40,7 +61,21 @@ module Mints
40
61
  end
41
62
 
42
63
  ##
43
- # === Send magic link to contact
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)
44
79
  def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
45
80
  data = {
46
81
  email: email,
@@ -49,14 +84,17 @@ module Mints
49
84
  redirectUrl: redirectUrl,
50
85
  templateId: template_slug
51
86
  }
52
- 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')
53
88
  return response
54
89
  end
55
90
 
56
91
  ##
57
92
  # === Logout.
58
- # Ends a contact session
93
+ # Ends a contact session previously logged.
59
94
  #
95
+ # ==== Example
96
+ # @mints_contact.login("email@example.com", "password")
97
+ # @mints_contact.logout
60
98
  def logout
61
99
  response = @client.raw("post", "/contacts/logout") if session_token?
62
100
  if response["success"]
@@ -67,62 +105,127 @@ module Mints
67
105
 
68
106
  ##
69
107
  # === Change Password.
70
- # Change password
108
+ # Change password without email. To change the password a contact must be logged.
109
+ #
110
+ # ==== Parameters:
111
+ # data:: (Hash) -- A new password allocated in a data key.
71
112
  #
113
+ # ==== Example
114
+ # @mints_contact.login("email@example.com", "password")
115
+ # data = { "password": "123456" }
116
+ # @data = @mints_contact.change_password(data)
72
117
  def change_password(data)
73
- return @client.raw("post", "/contacts/change-password", nil, data)
118
+ return @client.raw("post", "/contacts/change-password", nil, data_transform(data))
74
119
  end
75
120
 
76
121
  ##
77
122
  # === Recover Password.
78
- # Recover password
123
+ # Send a email that contains a token to a contact. That token will be used in reset_password to establish a new password.
79
124
  #
125
+ # ==== Parameters:
126
+ # data:: (Hash) -- It's a data key where will be hosted the destination email.
127
+ #
128
+ # ==== Example
129
+ # data = { "email": "email@example.com" }
130
+ # @mints_contact.recover_password(data)
80
131
  def recover_password(data)
81
- return @client.raw("post", "/contacts/recover-password", nil, data)
132
+ return @client.raw("post", "/contacts/recover-password", nil, data_transform(data))
82
133
  end
83
134
 
84
135
  ##
85
136
  # === Reset Password.
86
- # Reset password
137
+ # Reset password using a token. The token is obtained by recover_password method.
138
+ #
139
+ # ==== Parameters:
140
+ # data:: (Hash) -- It's a set of data which contains all the information to reset a contact password.
87
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)
88
150
  def reset_password(data)
89
- return @client.raw("post", "/contacts/reset-password", nil, data)
151
+ return @client.raw("post", "/contacts/reset-password", nil, data_transform(data))
90
152
  end
91
153
 
92
154
  ##
93
155
  # === OAuth Login.
94
- # Login a contact using oauth
95
- #
156
+ # Login a contact using oauth.
96
157
  def oauth_login(data)
97
158
  return @client.raw("post", "/contacts/oauth-login", nil, data)
98
159
  end
99
160
 
100
161
  ##
101
162
  # === Me.
102
- # Get contact logged info
163
+ # Get contact logged info.
164
+ #
165
+ # ==== First Example
166
+ # @mints_contact.me
103
167
  #
104
- def me
105
- return @client.raw("get", "/contacts/me")
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)
106
176
  end
107
177
 
108
178
  ##
109
179
  # === Status.
110
- # Get contact logged status
180
+ # Get contact logged status.
111
181
  #
182
+ # ==== Example
183
+ # @mints_contact.status
112
184
  def status
113
185
  return @client.raw("get", "/contacts/status")
114
186
  end
115
187
 
116
188
  ##
117
189
  # === Update.
118
- # 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.
119
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)
120
202
  def update(data)
121
- 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))
122
223
  end
123
224
 
124
225
  private
125
226
 
227
+ include MintsHelper
228
+
126
229
  def session_token?
127
230
  if @client.session_token
128
231
  return true
@@ -22,7 +22,7 @@ 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.permanent[:mints_user_session_token] = session_token
25
+ cookies[:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day }
26
26
  end
27
27
 
28
28
  ##
@@ -33,7 +33,7 @@ module Mints
33
33
  response = @mints_user.magic_link_login(hash)
34
34
  if response['data'] && response['data']['redirect_url']
35
35
  # Set a cookie with the session token
36
- cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day }
36
+ cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day, secure: true, httponly: true }
37
37
  redirect_to response['data']['redirect_url']
38
38
  else
39
39
  redirect_to '/'
@@ -10,26 +10,26 @@ 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']['id_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
- cookies.permanent[:mints_contact_session_token] = session_token
16
- cookies.permanent[:mints_contact_id] = id_token
15
+ cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
16
+ cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
17
17
  @contact_token = id_token
18
18
  end
19
19
 
20
20
  ##
21
- # === Mints cotnact Login.
22
- # Starts a cotnact session in mints.cloud and set a session cookie
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']['id_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
- cookies.permanent[:mints_contact_session_token] = session_token
32
- cookies.permanent[:mints_contact_id] = id_token
31
+ cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
32
+ cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
33
33
  @contact_token = id_token
34
34
  redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
35
35
  else
@@ -58,7 +58,7 @@ module Mints
58
58
  # Get session token from response
59
59
  session_token = response['api_token']
60
60
  # Set a permanent cookie with the session token
61
- cookies.permanent[:mints_user_session_token] = session_token
61
+ cookies[:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day }
62
62
  end
63
63
 
64
64
  ##
@@ -69,7 +69,7 @@ module Mints
69
69
  response = @mints_user.magic_link_login(hash)
70
70
  if response['data']
71
71
  # Set a cookie with the session token
72
- cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day }
72
+ cookies[:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day }
73
73
  redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
74
74
  else
75
75
  redirect_to '/'
@@ -116,7 +116,8 @@ module Mints
116
116
  def set_mints_pub_client
117
117
 
118
118
  # Initialize mints pub client, credentials taken from mints_config.yml.erb file
119
- @mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
119
+ @visit_id = cookies[:mints_visit_id] ? cookies[:mints_visit_id] : nil
120
+ @mints_pub = Mints::Pub.new(@host, @api_key, nil, @visit_id, @debug)
120
121
  # Set contact token from cookie
121
122
  @mints_pub.client.session_token = @contact_token
122
123
  end