mints 0.0.26 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/lib/client.rb +75 -37
- data/lib/contact.rb +61 -62
- data/lib/errors.rb +98 -0
- data/lib/generators/mints_config.yml.erb +0 -2
- data/lib/generators/mints_link.rb +3 -3
- data/lib/mints/controllers/admin_base_controller.rb +8 -66
- data/lib/mints/controllers/base_api_controller.rb +16 -134
- data/lib/mints/controllers/base_controller.rb +20 -106
- data/lib/mints/controllers/concerns/mints_clients.rb +74 -0
- data/lib/mints/controllers/concerns/read_config_file.rb +28 -0
- data/lib/mints/controllers/contact_api_controller.rb +6 -85
- data/lib/mints/controllers/public_api_controller.rb +6 -79
- data/lib/mints/controllers/user_api_controller.rb +7 -82
- data/lib/mints/helpers/contact_auth_helper.rb +67 -0
- data/lib/{mints_helper.rb → mints/helpers/mints_helper.rb} +7 -5
- data/lib/mints/helpers/proxy_controllers_methods.rb +126 -0
- data/lib/mints/helpers/user_auth_helper.rb +53 -0
- data/lib/mints.rb +2 -0
- data/lib/pub.rb +56 -56
- data/lib/user/config/api_keys.rb +7 -7
- data/lib/user/config/appointments.rb +16 -16
- data/lib/user/config/attribute_groups.rb +10 -10
- data/lib/user/config/attributes.rb +10 -10
- data/lib/user/config/calendars.rb +9 -9
- data/lib/user/config/config.rb +7 -7
- data/lib/user/config/importers.rb +15 -15
- data/lib/user/config/public_folders.rb +11 -11
- data/lib/user/config/relationships.rb +11 -11
- data/lib/user/config/roles.rb +9 -9
- data/lib/user/config/seeds.rb +5 -5
- data/lib/user/config/system_settings.rb +5 -5
- data/lib/user/config/tags.rb +5 -5
- data/lib/user/config/taxonomies.rb +15 -15
- data/lib/user/config/teams.rb +67 -68
- data/lib/user/config/users.rb +70 -71
- data/lib/user/contacts/contacts.rb +19 -20
- data/lib/user/content/assets.rb +273 -278
- data/lib/user/content/content.rb +48 -48
- data/lib/user/content/content_instances.rb +136 -138
- data/lib/user/content/content_templates.rb +103 -103
- data/lib/user/content/conversations.rb +193 -193
- data/lib/user/content/dam.rb +83 -80
- data/lib/user/content/forms.rb +229 -233
- data/lib/user/content/message_templates.rb +152 -151
- data/lib/user/content/messages.rb +87 -87
- data/lib/user/content/pages.rb +82 -82
- data/lib/user/content/stories.rb +101 -101
- data/lib/user/content/story_templates.rb +88 -88
- data/lib/user/content/story_versions.rb +115 -117
- data/lib/user/crm/companies.rb +103 -105
- data/lib/user/crm/contacts.rb +285 -292
- data/lib/user/crm/crm.rb +19 -19
- data/lib/user/crm/deals.rb +103 -103
- data/lib/user/crm/favorites.rb +14 -13
- data/lib/user/crm/segments.rb +121 -123
- data/lib/user/crm/users.rb +20 -20
- data/lib/user/crm/workflow_step_objects.rb +84 -84
- data/lib/user/crm/workflow_steps.rb +45 -45
- data/lib/user/crm/workflows.rb +65 -65
- data/lib/user/ecommerce/ecommerce.rb +27 -27
- data/lib/user/ecommerce/item_prices.rb +82 -81
- data/lib/user/ecommerce/locations.rb +160 -160
- data/lib/user/ecommerce/order_items_groups.rb +107 -105
- data/lib/user/ecommerce/order_statuses.rb +24 -24
- data/lib/user/ecommerce/orders.rb +250 -246
- data/lib/user/ecommerce/price_lists.rb +68 -68
- data/lib/user/ecommerce/product_templates.rb +99 -99
- data/lib/user/ecommerce/product_variations.rb +122 -120
- data/lib/user/ecommerce/products.rb +160 -159
- data/lib/user/ecommerce/skus.rb +85 -85
- data/lib/user/ecommerce/taxes.rb +79 -79
- data/lib/user/ecommerce/variant_options.rb +66 -66
- data/lib/user/ecommerce/variant_values.rb +69 -69
- data/lib/user/helpers/helpers.rb +102 -101
- data/lib/user/helpers/object_activities.rb +78 -78
- data/lib/user/helpers/object_folders.rb +76 -76
- data/lib/user/helpers/user_folders.rb +77 -77
- data/lib/user/marketing/marketing.rb +114 -113
- data/lib/user/profile/profile.rb +94 -103
- data/lib/user.rb +4 -4
- metadata +41 -35
data/lib/contact.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative "./client.rb"
|
2
|
-
require_relative "./mints_helper.rb"
|
2
|
+
require_relative "./mints/helpers/mints_helper.rb"
|
3
3
|
include ActionController::Cookies
|
4
4
|
module Mints
|
5
5
|
class Contact
|
@@ -38,7 +38,7 @@ module Mints
|
|
38
38
|
# }
|
39
39
|
# @mints_contact.register(data);
|
40
40
|
def register(data)
|
41
|
-
|
41
|
+
@client.raw('post', "/contacts/register", nil, data_transform(data))
|
42
42
|
end
|
43
43
|
|
44
44
|
##
|
@@ -56,11 +56,10 @@ module Mints
|
|
56
56
|
email: email,
|
57
57
|
password: password
|
58
58
|
}
|
59
|
-
response = @client.raw(
|
60
|
-
if response.key? "session_token"
|
61
|
-
|
62
|
-
|
63
|
-
return response
|
59
|
+
response = @client.raw('post', "/contacts/login", nil, data_transform(data))
|
60
|
+
@client.session_token = response["session_token"] if response.key? "session_token"
|
61
|
+
|
62
|
+
response
|
64
63
|
end
|
65
64
|
|
66
65
|
##
|
@@ -74,7 +73,7 @@ module Mints
|
|
74
73
|
# data = { "email": "email@example.com" }
|
75
74
|
# @mints_contact.recover_password(data)
|
76
75
|
def recover_password(data)
|
77
|
-
|
76
|
+
@client.raw('post', "/contacts/recover-password", nil, data_transform(data))
|
78
77
|
end
|
79
78
|
|
80
79
|
##
|
@@ -93,14 +92,14 @@ module Mints
|
|
93
92
|
# }
|
94
93
|
# @mints_contact.reset_password(data)
|
95
94
|
def reset_password(data)
|
96
|
-
|
95
|
+
@client.raw('post', "/contacts/reset-password", nil, data_transform(data))
|
97
96
|
end
|
98
97
|
|
99
98
|
##
|
100
99
|
# === OAuth Login.
|
101
100
|
# Login a contact using oauth.
|
102
101
|
def oauth_login(data)
|
103
|
-
|
102
|
+
@client.raw('post', "/contacts/oauth-login", nil, data)
|
104
103
|
end
|
105
104
|
|
106
105
|
##
|
@@ -115,7 +114,7 @@ module Mints
|
|
115
114
|
# "d8618c6d-a165-41cb-b3ec-d053cbf30059:zm54HtRdfHED8dpILZpjyqjPIceiaXNLfOklqM92fveBS0nDtyPYBlI4CPlPe3zq"
|
116
115
|
# )
|
117
116
|
def magic_link_login(token)
|
118
|
-
response = @client.raw(
|
117
|
+
response = @client.raw('get', "/contacts/magic-link-login/#{token}", nil, '/api/v1')
|
119
118
|
if response.key? "session_token"
|
120
119
|
@client.session_token = response["session_token"]
|
121
120
|
end
|
@@ -151,7 +150,7 @@ module Mints
|
|
151
150
|
else
|
152
151
|
data['email'] = email_or_phone
|
153
152
|
end
|
154
|
-
|
153
|
+
@client.raw('post', "/contacts/magic-link", nil, data_transform(data), '/api/v1')
|
155
154
|
end
|
156
155
|
|
157
156
|
### CONTACT/V1 ###
|
@@ -173,7 +172,7 @@ module Mints
|
|
173
172
|
# }
|
174
173
|
# @data = @mints_contact.me(options)
|
175
174
|
def me(options = nil)
|
176
|
-
|
175
|
+
@client.raw('get', "/me", options, nil, @contact_v1_url)
|
177
176
|
end
|
178
177
|
|
179
178
|
##
|
@@ -183,7 +182,7 @@ module Mints
|
|
183
182
|
# ==== Example
|
184
183
|
# @data = @mints_contact.status
|
185
184
|
def status
|
186
|
-
|
185
|
+
@client.raw('get', "/status", nil, nil, @contact_v1_url)
|
187
186
|
end
|
188
187
|
|
189
188
|
##
|
@@ -200,7 +199,7 @@ module Mints
|
|
200
199
|
# }
|
201
200
|
# @data = @mints_contact.update(data)
|
202
201
|
def update(data)
|
203
|
-
|
202
|
+
@client.raw('put', "/update", nil, data_transform(data), @contact_v1_url)
|
204
203
|
end
|
205
204
|
|
206
205
|
##
|
@@ -210,7 +209,7 @@ module Mints
|
|
210
209
|
# ==== Example
|
211
210
|
# @data = @mints_contact.logout
|
212
211
|
def logout
|
213
|
-
response = @client.raw(
|
212
|
+
response = @client.raw('post', "/logout", nil, nil, @contact_v1_url) if session_token?
|
214
213
|
if response["success"]
|
215
214
|
@client.session_token = nil
|
216
215
|
end
|
@@ -228,7 +227,7 @@ module Mints
|
|
228
227
|
# data = { "password": "new_password" }
|
229
228
|
# @data = @mints_contact.change_password(data)
|
230
229
|
def change_password(data)
|
231
|
-
|
230
|
+
@client.raw('post', "/change-password", nil, data_transform(data), @contact_v1_url)
|
232
231
|
end
|
233
232
|
|
234
233
|
# Conversations
|
@@ -241,7 +240,7 @@ module Mints
|
|
241
240
|
# options:: (Hash) -- List of Resource Collection Options shown above can be used as parameter.
|
242
241
|
# FIXME: This method doesn't return data.
|
243
242
|
def get_conversations(options = nil)
|
244
|
-
|
243
|
+
@client.raw('get', "/content/conversations", options, nil, @contact_v1_url)
|
245
244
|
end
|
246
245
|
|
247
246
|
##
|
@@ -253,7 +252,7 @@ module Mints
|
|
253
252
|
# options:: (Hash) -- List of Resource Collection Options shown above can be used as parameter.
|
254
253
|
# FIXME: This method doesn't return data.
|
255
254
|
def get_conversation(id, options = nil)
|
256
|
-
|
255
|
+
@client.raw('get', "/content/conversations/#{id}", options, nil, @contact_v1_url)
|
257
256
|
end
|
258
257
|
|
259
258
|
##
|
@@ -265,11 +264,11 @@ module Mints
|
|
265
264
|
#
|
266
265
|
# ==== Example
|
267
266
|
# data = {
|
268
|
-
#
|
267
|
+
# title: "New Conversation To Test"
|
269
268
|
# }
|
270
269
|
# @data = @mints_contact.create_conversation(data)
|
271
270
|
def create_conversation(data)
|
272
|
-
|
271
|
+
@client.raw('post', "/content/conversations", nil, data_transform(data), @contact_v1_url)
|
273
272
|
end
|
274
273
|
|
275
274
|
##
|
@@ -281,7 +280,7 @@ module Mints
|
|
281
280
|
# data:: (Hash) -- Data to be submitted.
|
282
281
|
# FIXME: This method doesn't locate conversation id to be updated.
|
283
282
|
def update_conversation(id, data)
|
284
|
-
|
283
|
+
@client.raw('put', "/content/conversations/#{id}", nil, data_transform(data), @contact_v1_url)
|
285
284
|
end
|
286
285
|
|
287
286
|
##
|
@@ -293,7 +292,7 @@ module Mints
|
|
293
292
|
# data:: (Hash) -- Data to be submitted.
|
294
293
|
# FIXME: This method doesn't locate conversation id to be updated.
|
295
294
|
def update_conversation_status(id, data)
|
296
|
-
|
295
|
+
@client.raw('put', "/content/conversations/#{id}/status", nil, data_transform(data), @contact_v1_url)
|
297
296
|
end
|
298
297
|
|
299
298
|
##
|
@@ -305,7 +304,7 @@ module Mints
|
|
305
304
|
# FIXME: This method doesn't locate conversation id to be updated.
|
306
305
|
def get_conversation_participants(id)
|
307
306
|
#TODO: Test if this method needs data in options.
|
308
|
-
|
307
|
+
@client.raw('get', "/content/conversations/#{id}/participants", nil, nil, @contact_v1_url)
|
309
308
|
end
|
310
309
|
|
311
310
|
##
|
@@ -316,7 +315,7 @@ module Mints
|
|
316
315
|
# options:: (Hash) -- List of Resource Collection Options shown above can be used as parameter.
|
317
316
|
# FIXME: This method doesn't return data.
|
318
317
|
def get_messages(options = nil)
|
319
|
-
|
318
|
+
@client.raw('get', '/content/messages', options, nil, @contact_v1_url)
|
320
319
|
end
|
321
320
|
|
322
321
|
##
|
@@ -328,7 +327,7 @@ module Mints
|
|
328
327
|
# options:: (Hash) -- List of Resource Collection Options shown above can be used as parameter.
|
329
328
|
# FIXME: This method doesn't return data.
|
330
329
|
def get_message(id, options = nil)
|
331
|
-
|
330
|
+
@client.raw('get', "/content/messages/#{id}", options, nil, @contact_v1_url)
|
332
331
|
end
|
333
332
|
|
334
333
|
##
|
@@ -348,7 +347,7 @@ module Mints
|
|
348
347
|
# }
|
349
348
|
# @data = @mints_contact.create_message(data)
|
350
349
|
def create_message(data)
|
351
|
-
|
350
|
+
@client.raw('post', '/content/messages', nil, data_transform(data), @contact_v1_url)
|
352
351
|
end
|
353
352
|
|
354
353
|
# Appointments
|
@@ -365,11 +364,11 @@ module Mints
|
|
365
364
|
#
|
366
365
|
# ==== Second Example
|
367
366
|
# options = {
|
368
|
-
#
|
367
|
+
# fields: "id, created_at"
|
369
368
|
# }
|
370
369
|
# @data = @mints_contact.get_appointments(options)
|
371
370
|
def get_appointments(options = nil)
|
372
|
-
|
371
|
+
@client.raw('get', "/contacts/appointments", options)
|
373
372
|
end
|
374
373
|
|
375
374
|
##
|
@@ -384,11 +383,11 @@ module Mints
|
|
384
383
|
#
|
385
384
|
# ==== Second Example
|
386
385
|
# options = {
|
387
|
-
#
|
386
|
+
# fields: "id, created_at"
|
388
387
|
# }
|
389
388
|
# @data = @mints_contact.get_appointment(1, options)
|
390
389
|
def get_appointment(id, options = nil)
|
391
|
-
|
390
|
+
@client.raw('get', "/contacts/appointments/#{id}", options)
|
392
391
|
end
|
393
392
|
|
394
393
|
##
|
@@ -402,13 +401,13 @@ module Mints
|
|
402
401
|
# data = {
|
403
402
|
# "object_model": "products",
|
404
403
|
# "object_id": 1,
|
405
|
-
#
|
404
|
+
# title: "New Appointment",
|
406
405
|
# "start": "2021-11-25T14:15:00+00:00",
|
407
406
|
# "end": "2022-01-01T13:00:00+00:00"
|
408
407
|
# }
|
409
408
|
# @data = @mints_contact.create_appointment(data)
|
410
409
|
def create_appointment(data)
|
411
|
-
|
410
|
+
@client.raw('post', "/contacts/appointments", nil, data_transform(data))
|
412
411
|
end
|
413
412
|
|
414
413
|
##
|
@@ -425,7 +424,7 @@ module Mints
|
|
425
424
|
# }
|
426
425
|
# @data = @mints_contact.update_appointment(1, data)
|
427
426
|
def update_appointment(id, data)
|
428
|
-
|
427
|
+
@client.raw('put', "/contacts/appointments/#{id}", nil, data_transform(data))
|
429
428
|
end
|
430
429
|
|
431
430
|
##
|
@@ -444,7 +443,7 @@ module Mints
|
|
444
443
|
# }
|
445
444
|
# @data = @mints_contact.scheduled_appointments(data)
|
446
445
|
def scheduled_appointments(data)
|
447
|
-
|
446
|
+
@client.raw('post', "/contacts/appointments/scheduled-appointments", nil, data_transform(data))
|
448
447
|
end
|
449
448
|
|
450
449
|
##
|
@@ -461,7 +460,7 @@ module Mints
|
|
461
460
|
# }
|
462
461
|
# @data = @mints_contact.attach_invitee(data)
|
463
462
|
def attach_invitee(data)
|
464
|
-
|
463
|
+
@client.raw('post', "/contacts/appointments/attach-invitee", nil, data_transform(data))
|
465
464
|
end
|
466
465
|
|
467
466
|
##
|
@@ -478,7 +477,7 @@ module Mints
|
|
478
477
|
# }
|
479
478
|
# @data = @mints_contact.attach_follower(data)
|
480
479
|
def attach_follower(data)
|
481
|
-
|
480
|
+
@client.raw('post', "/contacts/appointments/attach-follower", nil, data_transform(data))
|
482
481
|
end
|
483
482
|
|
484
483
|
##
|
@@ -495,7 +494,7 @@ module Mints
|
|
495
494
|
# }
|
496
495
|
# @data = @mints_contact.detach_invitee(data)
|
497
496
|
def detach_invitee(data)
|
498
|
-
|
497
|
+
@client.raw('post', "/contacts/appointments/detach-invitee", nil, data_transform(data))
|
499
498
|
end
|
500
499
|
|
501
500
|
##
|
@@ -512,7 +511,7 @@ module Mints
|
|
512
511
|
# }
|
513
512
|
# @data = @mints_contact.detach_follower(data)
|
514
513
|
def detach_follower(data)
|
515
|
-
|
514
|
+
@client.raw('post', "/contacts/appointments/detach-follower", nil, data_transform(data))
|
516
515
|
end
|
517
516
|
|
518
517
|
##
|
@@ -529,7 +528,7 @@ module Mints
|
|
529
528
|
# }
|
530
529
|
# @data = @mints_contact.sync_invitee(data)
|
531
530
|
def sync_invitee(data)
|
532
|
-
|
531
|
+
@client.raw('post', "/contacts/appointments/sync-invitee", nil, data_transform(data))
|
533
532
|
end
|
534
533
|
|
535
534
|
##
|
@@ -546,7 +545,7 @@ module Mints
|
|
546
545
|
# }
|
547
546
|
# @data = @mints_contact.sync_follower(data)
|
548
547
|
def sync_follower(data)
|
549
|
-
|
548
|
+
@client.raw('post', "/contacts/appointments/sync-follower", nil, data_transform(data))
|
550
549
|
end
|
551
550
|
|
552
551
|
##
|
@@ -561,17 +560,17 @@ module Mints
|
|
561
560
|
# @data = @mints_pub.get_orders
|
562
561
|
#
|
563
562
|
# ==== Second Example
|
564
|
-
# options = {
|
563
|
+
# options = { fields: "title" }
|
565
564
|
# @data = @mints_pub.get_orders(options)
|
566
565
|
#
|
567
566
|
# ==== Third Example
|
568
|
-
# options = {
|
567
|
+
# options = { fields: "title" }
|
569
568
|
# @data = @mints_pub.get_orders(options, false)
|
570
569
|
def get_orders(options = nil, use_post = true)
|
571
570
|
if use_post
|
572
|
-
|
571
|
+
@client.raw('post', "/ecommerce/orders/query", options, nil, @contact_v1_url)
|
573
572
|
else
|
574
|
-
|
573
|
+
@client.raw('get', "/ecommerce/orders", options, nil, @contact_v1_url)
|
575
574
|
end
|
576
575
|
end
|
577
576
|
|
@@ -588,11 +587,11 @@ module Mints
|
|
588
587
|
#
|
589
588
|
# ==== Second Example
|
590
589
|
# options = {
|
591
|
-
#
|
590
|
+
# fields: "title"
|
592
591
|
# }
|
593
592
|
# @data = @mints_pub.get_product(25, options)
|
594
593
|
def get_order(id, options = nil)
|
595
|
-
|
594
|
+
@client.raw('get', "/ecommerce/orders/#{id}", options, nil, @contact_v1_url)
|
596
595
|
end
|
597
596
|
|
598
597
|
##
|
@@ -610,7 +609,7 @@ module Mints
|
|
610
609
|
# }
|
611
610
|
# @data = @mints_pub.create_order(data)
|
612
611
|
def create_order(data)
|
613
|
-
|
612
|
+
@client.raw('post', "/ecommerce/orders", nil, data_transform(data), @contact_v1_url)
|
614
613
|
end
|
615
614
|
|
616
615
|
##
|
@@ -622,7 +621,7 @@ module Mints
|
|
622
621
|
# data:: (Hash) -- Data to be submitted.
|
623
622
|
# FIXME: This method doesnt update an order.
|
624
623
|
def update_order(id, data)
|
625
|
-
|
624
|
+
@client.raw('put', "/ecommerce/orders/#{id}", nil, data_transform(data), @contact_v1_url)
|
626
625
|
end
|
627
626
|
|
628
627
|
#TODO: No tested
|
@@ -634,7 +633,7 @@ module Mints
|
|
634
633
|
# groupId:: (Integer) -- Order items group id.
|
635
634
|
#
|
636
635
|
def detach_order_item_from_order_item_group(orderItemId, groupId)
|
637
|
-
|
636
|
+
@client.raw('put', "/ecommerce/order-items/detach/#{orderItemId}/order-items-groups/#{groupId}", nil, nil, @contact_v1_url)
|
638
637
|
end
|
639
638
|
|
640
639
|
#TODO: No tested
|
@@ -646,7 +645,7 @@ module Mints
|
|
646
645
|
# groupId:: (Integer) -- Order items group id.
|
647
646
|
#
|
648
647
|
def update_order_item_from_order_item_group(orderItemId, groupId, data)
|
649
|
-
|
648
|
+
@client.raw('put', "/ecommerce/order-items/update/#{orderItemId}/order-items-groups/#{groupId}", nil, data_transform(data), @contact_v1_url)
|
650
649
|
end
|
651
650
|
|
652
651
|
##
|
@@ -657,7 +656,7 @@ module Mints
|
|
657
656
|
# @data = @mints_contact.get_my_shopping_cart
|
658
657
|
# FIXME: This method returns a nil data.
|
659
658
|
def get_my_shopping_cart(options = nil)
|
660
|
-
|
659
|
+
@client.raw('get', "/ecommerce/my-shopping-cart", options, nil, @contact_v1_url)
|
661
660
|
end
|
662
661
|
|
663
662
|
##
|
@@ -675,7 +674,7 @@ module Mints
|
|
675
674
|
# }
|
676
675
|
# @data = @mints_contact.add_item_to_shopping_cart(data)
|
677
676
|
def add_item_to_shopping_cart(data, options = nil)
|
678
|
-
|
677
|
+
@client.raw('post', "/ecommerce/shopping-cart", options, data_transform(data), @contact_v1_url)
|
679
678
|
end
|
680
679
|
|
681
680
|
##
|
@@ -683,7 +682,7 @@ module Mints
|
|
683
682
|
# Get a collection of order items.
|
684
683
|
#TODO: Find a way to show order items.
|
685
684
|
def get_order_items(options = nil)
|
686
|
-
|
685
|
+
@client.raw('get', "/ecommerce/order-items", options, nil, @contact_v1_url)
|
687
686
|
end
|
688
687
|
|
689
688
|
##
|
@@ -691,7 +690,7 @@ module Mints
|
|
691
690
|
# Get an order item info.
|
692
691
|
#TODO: Find a way to show order items.
|
693
692
|
def get_order_item(id, options = nil)
|
694
|
-
|
693
|
+
@client.raw('get', "/ecommerce/order-items/#{id}", options, nil, @contact_v1_url)
|
695
694
|
end
|
696
695
|
|
697
696
|
##
|
@@ -706,11 +705,11 @@ module Mints
|
|
706
705
|
#
|
707
706
|
# ==== Second Example
|
708
707
|
# options = {
|
709
|
-
#
|
708
|
+
# fields: "id"
|
710
709
|
# }
|
711
710
|
# @data = @mints_contact.get_order_item_groups(options)
|
712
711
|
def get_order_item_groups(options = nil)
|
713
|
-
|
712
|
+
@client.raw('get', "/ecommerce/order-items-groups", options, nil, @contact_v1_url)
|
714
713
|
end
|
715
714
|
|
716
715
|
##
|
@@ -726,11 +725,11 @@ module Mints
|
|
726
725
|
#
|
727
726
|
# ==== Second Example
|
728
727
|
# options = {
|
729
|
-
#
|
728
|
+
# fields: "id"
|
730
729
|
# }
|
731
730
|
# @data = @mints_contact.get_order_item_group(130, options)
|
732
731
|
def get_order_item_group(id, options = nil)
|
733
|
-
|
732
|
+
@client.raw('get', "/ecommerce/order-items-groups/#{id}", options, nil, @contact_v1_url)
|
734
733
|
end
|
735
734
|
|
736
735
|
##
|
@@ -758,7 +757,7 @@ module Mints
|
|
758
757
|
# }
|
759
758
|
# @data = @mints_contact.create_order_item_group(data)
|
760
759
|
def create_order_item_group(data)
|
761
|
-
|
760
|
+
@client.raw('post', "/ecommerce/order-items-groups", nil, data_transform(data), @contact_v1_url)
|
762
761
|
end
|
763
762
|
|
764
763
|
##
|
@@ -775,7 +774,7 @@ module Mints
|
|
775
774
|
# }
|
776
775
|
# @data = @mints_contact.update_order_item_group(130, data)
|
777
776
|
def update_order_item_group(id, data)
|
778
|
-
|
777
|
+
@client.raw('put', "/ecommerce/order-items-groups/#{id}", nil, data_transform(data), @contact_v1_url)
|
779
778
|
end
|
780
779
|
|
781
780
|
##
|
@@ -783,7 +782,7 @@ module Mints
|
|
783
782
|
# Delete an order item group.
|
784
783
|
# FIXME: This method doesn't work. Throw no action error.
|
785
784
|
def delete_order_item_group(id)
|
786
|
-
|
785
|
+
@client.raw('delete', "/ecommerce/order-items-groups/#{id}", nil, nil, @contact_v1_url)
|
787
786
|
end
|
788
787
|
|
789
788
|
private
|
data/lib/errors.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Mints
|
2
|
+
|
3
|
+
module Errors
|
4
|
+
|
5
|
+
class NonSupportedRubyVersionError < RuntimeError; end
|
6
|
+
|
7
|
+
class DynamicError < RuntimeError
|
8
|
+
ERRORS = {
|
9
|
+
'401' => 'AccessDeniedException',
|
10
|
+
'404' => 'ResourceNotFoundException',
|
11
|
+
'422' => 'ValidationException',
|
12
|
+
'405' => 'MethodNotAllowed',
|
13
|
+
'default' => 'InternalServerException',
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(client, title, detail, http_status, response)
|
17
|
+
@http_status = http_status
|
18
|
+
@error = error_class.constantize&.new(client, title, detail, http_status, response)
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :error, :http_status
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
error_class
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def error_class
|
30
|
+
"Mints::Errors::#{ERRORS[http_status.to_s] || ERRORS['default']}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ServiceError < RuntimeError
|
35
|
+
# @param [Client] client
|
36
|
+
# @param [String] title
|
37
|
+
# @param [String] detail
|
38
|
+
# @param [Integer] http_status
|
39
|
+
# @param [String Object Array] response
|
40
|
+
def initialize(client, title, detail, http_status, response)
|
41
|
+
@title = title
|
42
|
+
@client = client
|
43
|
+
@response = response
|
44
|
+
@http_status = http_status
|
45
|
+
@detail = detail && !detail.empty? ? detail : self.class.to_s
|
46
|
+
|
47
|
+
super(@detail)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String]
|
51
|
+
def detail
|
52
|
+
@detail
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_h(extra_fields = {})
|
56
|
+
default_fields = {
|
57
|
+
client: client,
|
58
|
+
title: title,
|
59
|
+
detail: detail,
|
60
|
+
http_status: http_status,
|
61
|
+
response: response
|
62
|
+
}
|
63
|
+
|
64
|
+
default_fields.merge(extra_fields)
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
to_h.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :client, :detail, :title, :http_status, :response
|
72
|
+
end
|
73
|
+
|
74
|
+
class AccessDeniedException < ServiceError; end
|
75
|
+
|
76
|
+
class ResourceNotFoundException < ServiceError; end
|
77
|
+
|
78
|
+
class MethodNotAllowedException < ServiceError; end
|
79
|
+
|
80
|
+
class ValidationException < ServiceError
|
81
|
+
|
82
|
+
def to_h
|
83
|
+
super(errors_hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
def errors_hash
|
87
|
+
{
|
88
|
+
errors: response.keys.reduce([]) {|carry, error_key| carry + response[error_key]}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
attr_reader :failed_validations
|
93
|
+
end
|
94
|
+
|
95
|
+
class InternalServerException < ServiceError; end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -3,8 +3,6 @@ mints:
|
|
3
3
|
host: http://your_host_goes_here.com
|
4
4
|
api_key: your_mints_api_key_goes_here
|
5
5
|
mints_slug: slug_id #save id and token in redis
|
6
|
-
user_email: mints_user_email
|
7
|
-
user_password: mints_user_password
|
8
6
|
redis_cache:
|
9
7
|
use_cache: boolean_value_to_enable_and_disable_cache
|
10
8
|
redis_host: your_redis_server_host
|
@@ -44,14 +44,14 @@ class MintsLink
|
|
44
44
|
result.n === 1
|
45
45
|
end
|
46
46
|
|
47
|
-
def get_visits(filter, page = 1,
|
47
|
+
def get_visits(filter, page = 1, page_size = 1000)
|
48
48
|
collection = @sl_visits
|
49
|
-
collection.find(filter).sort( {_id: 1}).skip(page *
|
49
|
+
collection.find(filter).sort( {_id: 1}).skip(page * page_size - page_size).limit(page_size)
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
53
53
|
def random_string(length = 6)
|
54
|
-
rand(32**length).to_s(32)
|
54
|
+
rand((32 ** length).to_i).to_s(32)
|
55
55
|
end
|
56
56
|
|
57
57
|
def generate_indexes
|
@@ -1,73 +1,15 @@
|
|
1
|
+
require_relative "./concerns/mints_clients.rb"
|
2
|
+
require_relative "../helpers/user_auth_helper.rb"
|
3
|
+
|
1
4
|
module Mints
|
2
5
|
class AdminBaseController < ActionController::Base
|
3
|
-
before_action :set_mints_user_client
|
4
|
-
|
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
|
-
|
16
|
-
##
|
17
|
-
# === Mints user Login.
|
18
|
-
# Starts a user session in mints.cloud and set a session cookie
|
19
|
-
def mints_user_login(email, password)
|
20
|
-
# Login in mints
|
21
|
-
response = @mints_user.login(email, password)
|
22
|
-
# Get session token from response
|
23
|
-
session_token = response['api_token']
|
24
|
-
# Set a permanent cookie with the session token
|
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
|
41
|
-
end
|
42
6
|
|
43
|
-
|
44
|
-
|
45
|
-
# Destroy session from mints.cloud and delete local session cookie
|
46
|
-
def mints_user_logout
|
47
|
-
# Logout from mints
|
48
|
-
# @mints_user.logout
|
49
|
-
# Delete local cookie
|
50
|
-
cookies.delete(:mints_user_session_token)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
7
|
+
include MintsClients
|
8
|
+
include UserAuthHelper
|
54
9
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def set_mints_user_client
|
59
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
60
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
61
|
-
config = YAML.load template.result(binding)
|
62
|
-
@host = config["mints"]["host"]
|
63
|
-
@api_key = config["mints"]["api_key"]
|
64
|
-
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
65
|
-
else
|
66
|
-
raise 'MintsBadCredentialsError'
|
67
|
-
end
|
68
|
-
# Initialize mints user client
|
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)
|
10
|
+
# Override default values for mints clients concern
|
11
|
+
def define_mints_clients
|
12
|
+
%w[ user service_account ]
|
71
13
|
end
|
72
14
|
end
|
73
15
|
end
|