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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c247c54117a9cc63173173bb4c5ba9277109b96f7801557eec9a5a2cb333ba88
|
4
|
+
data.tar.gz: 4d467715b34ea8919e3cbb2c7fee2b92a5840cef2ab09db55bf28376ad11236a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc6602d5a072942ac14d7d4575911d828ccc5a7a95cdfad6021ecd38a6ad69e318ff3dd6d97b202e5d736a09069d238713fa4e9b9800901a13cd789d27a6a5ab
|
7
|
+
data.tar.gz: f86e5bfe64f7372bfc1ee21af5a62e3d58a063f3a4c978e6b3f8595d855ba8b7c0cfa34d1c4a421a7c318010e689234c47104e967b17fe93cf2168b4d807220e
|
data/Gemfile
CHANGED
data/lib/client.rb
CHANGED
@@ -22,25 +22,30 @@ module Mints
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def raw(action, url, options = nil, data = nil, base_url = nil, compatibility_options = {}, only_tracking = false)
|
25
|
-
if compatibility_options
|
26
|
-
|
27
|
-
|
28
|
-
base_url = @base_url if !base_url
|
25
|
+
compatibility_options = {} if compatibility_options.nil?
|
26
|
+
|
27
|
+
base_url = @base_url unless base_url
|
29
28
|
uri = ""
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
|
30
|
+
if options&.class == Hash
|
31
|
+
need_encoding = %w[ jfilters afilters rfilters ]
|
32
|
+
found_options_with_encoding = options.keys.select {|key| need_encoding.include?(key.to_s.downcase) and options[key]&.class == Hash}
|
33
|
+
|
34
|
+
found_options_with_encoding.each do |key|
|
35
|
+
options[key] = CGI::escape(Base64.encode64(options[key].to_json))
|
33
36
|
end
|
37
|
+
|
34
38
|
uri = Addressable::URI.new
|
35
39
|
uri.query_values = options
|
36
40
|
end
|
37
41
|
|
38
42
|
full_url = "#{@host}#{base_url}#{url}#{uri}"
|
39
43
|
response = nil
|
40
|
-
if action === 'get'
|
41
44
|
|
42
|
-
|
43
|
-
|
45
|
+
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
46
|
+
config = YAML.safe_load template.result(binding)
|
47
|
+
|
48
|
+
if action === 'get'
|
44
49
|
url_need_cache = false
|
45
50
|
result_from_cache = false
|
46
51
|
time = 0
|
@@ -74,7 +79,7 @@ module Mints
|
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
77
|
-
|
82
|
+
unless url_need_cache
|
78
83
|
response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
|
79
84
|
end
|
80
85
|
|
@@ -89,25 +94,23 @@ module Mints
|
|
89
94
|
response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
|
90
95
|
end
|
91
96
|
|
97
|
+
verify_response_status(response, config['sdk']['ignore_http_errors'])
|
98
|
+
|
92
99
|
begin
|
93
100
|
if result_from_cache
|
94
101
|
if @debug
|
95
102
|
puts "Method: #{action} \nURL: #{url} \nOptions: #{options.to_json} \nOnly tracking: #{only_tracking} \nResponse from: REDIS"
|
96
|
-
if
|
97
|
-
puts "Data: #{data.to_json}"
|
98
|
-
end
|
103
|
+
puts "Data: #{data.to_json}" if data
|
99
104
|
end
|
105
|
+
|
100
106
|
return JSON.parse(response)
|
101
107
|
else
|
102
|
-
|
103
|
-
raise 'NotFoundError'
|
104
|
-
end
|
108
|
+
|
105
109
|
if @debug
|
106
110
|
puts "Method: #{action} \nURL: #{url} \nOptions: #{options.to_json} \nOnly tracking: #{only_tracking} \nResponse from: CALI"
|
107
|
-
if
|
108
|
-
puts "Data: #{data.to_json}"
|
109
|
-
end
|
111
|
+
puts "Data: #{data.to_json}" if data
|
110
112
|
end
|
113
|
+
|
111
114
|
return JSON.parse(response.body)
|
112
115
|
end
|
113
116
|
rescue
|
@@ -123,7 +126,7 @@ module Mints
|
|
123
126
|
name_len = name_spplited.size
|
124
127
|
# the action always be the first element
|
125
128
|
action = name_spplited.first
|
126
|
-
raise 'NoActionError' unless [
|
129
|
+
raise 'NoActionError' unless %w[get create post update put delete destroy verify_response_status].include?(action)
|
127
130
|
# the object always be the last element
|
128
131
|
object = separator == "__" ? name_spplited.last.gsub("_","-") : name_spplited.last
|
129
132
|
# get intermediate url elements
|
@@ -143,7 +146,7 @@ module Mints
|
|
143
146
|
|
144
147
|
slug = nil
|
145
148
|
uri = Addressable::URI.new
|
146
|
-
if action ==
|
149
|
+
if action == 'get'
|
147
150
|
if args.first.class == Hash
|
148
151
|
uri.query_values = args.first
|
149
152
|
elsif args.first.class == String or Integer
|
@@ -152,7 +155,7 @@ module Mints
|
|
152
155
|
end
|
153
156
|
url = self.get_url(route, object, uri, slug)
|
154
157
|
response = self.send("#{@scope}_#{action}", url, nil, compatibility_options)
|
155
|
-
elsif action ==
|
158
|
+
elsif action == 'post' or action == "create"
|
156
159
|
if args[1].class == Hash
|
157
160
|
uri.query_values = args[1]
|
158
161
|
end
|
@@ -160,7 +163,7 @@ module Mints
|
|
160
163
|
action = 'post'
|
161
164
|
data = args[0]
|
162
165
|
response = self.send("#{@scope}_#{action}", url, {data: data}, compatibility_options)
|
163
|
-
elsif action ==
|
166
|
+
elsif action == 'put' or action == "update"
|
164
167
|
if args.first.class == String or Integer
|
165
168
|
slug = args.first
|
166
169
|
uri.query_values = args[2]
|
@@ -210,7 +213,7 @@ module Mints
|
|
210
213
|
end
|
211
214
|
end
|
212
215
|
|
213
|
-
#####
|
216
|
+
##### HTTP CLIENTS ######
|
214
217
|
# Simple HTTP GET
|
215
218
|
def http_get(url, headers = nil)
|
216
219
|
# if @debug
|
@@ -220,7 +223,7 @@ module Mints
|
|
220
223
|
# puts headers
|
221
224
|
# puts "Method: get"
|
222
225
|
# end
|
223
|
-
|
226
|
+
headers ? HTTParty.get(url, :headers => headers) : HTTParty.get(url)
|
224
227
|
end
|
225
228
|
|
226
229
|
# Simple HTTP POST
|
@@ -234,7 +237,7 @@ module Mints
|
|
234
237
|
# puts data
|
235
238
|
# puts "Method: post"
|
236
239
|
# end
|
237
|
-
|
240
|
+
headers ? HTTParty.post(url, :headers=> headers, :body => data) : HTTParty.post(url, :body => data)
|
238
241
|
end
|
239
242
|
|
240
243
|
# Simple HTTP PUT
|
@@ -248,7 +251,7 @@ module Mints
|
|
248
251
|
# puts data
|
249
252
|
# puts "Method: put"
|
250
253
|
# end
|
251
|
-
|
254
|
+
headers ? HTTParty.put(url, :headers=> headers, :body => data) : HTTParty.put(url, :body => data)
|
252
255
|
end
|
253
256
|
|
254
257
|
# Simple HTTP DELETE
|
@@ -262,7 +265,7 @@ module Mints
|
|
262
265
|
# puts data
|
263
266
|
# puts "Method: delete"
|
264
267
|
# end
|
265
|
-
|
268
|
+
headers ? HTTParty.delete(url, :headers=> headers, :body => data) : HTTParty.delete(url, :body => data)
|
266
269
|
end
|
267
270
|
|
268
271
|
# Start contact context
|
@@ -274,12 +277,14 @@ module Mints
|
|
274
277
|
}
|
275
278
|
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
276
279
|
h["Authorization"] = "Bearer #{@session_token}" if @session_token
|
280
|
+
|
277
281
|
if headers
|
278
282
|
headers.each do |k,v|
|
279
283
|
h[k] = v
|
280
284
|
end
|
281
285
|
end
|
282
|
-
|
286
|
+
|
287
|
+
self.http_get(url, h)
|
283
288
|
end
|
284
289
|
|
285
290
|
def contact_post(url, data, compatibility_options)
|
@@ -288,9 +293,11 @@ module Mints
|
|
288
293
|
"Accept" => "application/json",
|
289
294
|
"ContactToken" => @contact_token_id
|
290
295
|
}
|
296
|
+
|
291
297
|
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
292
298
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
293
|
-
|
299
|
+
|
300
|
+
self.http_post(url, headers, data)
|
294
301
|
end
|
295
302
|
|
296
303
|
def contact_put(url, data, compatibility_options)
|
@@ -301,7 +308,8 @@ module Mints
|
|
301
308
|
}
|
302
309
|
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
303
310
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
304
|
-
|
311
|
+
|
312
|
+
self.http_put(url, headers, data)
|
305
313
|
end
|
306
314
|
|
307
315
|
# Start User context
|
@@ -317,7 +325,8 @@ module Mints
|
|
317
325
|
h[k] = v
|
318
326
|
end
|
319
327
|
end
|
320
|
-
|
328
|
+
|
329
|
+
self.http_get(url, h)
|
321
330
|
end
|
322
331
|
|
323
332
|
def user_post(url, data, compatibility_options)
|
@@ -327,7 +336,8 @@ module Mints
|
|
327
336
|
}
|
328
337
|
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
329
338
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
330
|
-
|
339
|
+
|
340
|
+
self.http_post(url, headers, data)
|
331
341
|
end
|
332
342
|
|
333
343
|
def user_put(url, data, compatibility_options)
|
@@ -337,7 +347,8 @@ module Mints
|
|
337
347
|
}
|
338
348
|
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
339
349
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
340
|
-
|
350
|
+
|
351
|
+
self.http_put(url, headers, data)
|
341
352
|
end
|
342
353
|
|
343
354
|
def user_delete(url, data, compatibility_options)
|
@@ -347,7 +358,8 @@ module Mints
|
|
347
358
|
}
|
348
359
|
headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
349
360
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
350
|
-
|
361
|
+
|
362
|
+
self.http_delete(url, headers, data)
|
351
363
|
end
|
352
364
|
# End User Context
|
353
365
|
|
@@ -364,6 +376,7 @@ module Mints
|
|
364
376
|
h[k] = v
|
365
377
|
end
|
366
378
|
end
|
379
|
+
|
367
380
|
self.http_get(url, h)
|
368
381
|
end
|
369
382
|
|
@@ -373,12 +386,14 @@ module Mints
|
|
373
386
|
"ApiKey" => @api_key
|
374
387
|
}
|
375
388
|
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
376
|
-
h["ContactToken"] = @
|
389
|
+
h["ContactToken"] = @contact_token_id if @contact_token_id
|
390
|
+
|
377
391
|
if headers
|
378
392
|
headers.each do |k,v|
|
379
393
|
h[k] = v
|
380
394
|
end
|
381
395
|
end
|
396
|
+
|
382
397
|
self.http_post(url, h, data)
|
383
398
|
end
|
384
399
|
|
@@ -394,7 +409,30 @@ module Mints
|
|
394
409
|
h[k] = v
|
395
410
|
end
|
396
411
|
end
|
412
|
+
|
397
413
|
self.http_put(url, h, data)
|
398
414
|
end
|
415
|
+
|
416
|
+
def verify_response_status(response, ignore_http_errors)
|
417
|
+
# Verify if the response is cached
|
418
|
+
unless response.kind_of? String
|
419
|
+
# Raise an error if response code is not 2xx
|
420
|
+
http_status = response&.response&.code&.to_i || 500
|
421
|
+
is_success = (http_status >= 200 and http_status < 300)
|
422
|
+
|
423
|
+
if !is_success and !ignore_http_errors
|
424
|
+
title = "Request failed with status #{http_status}"
|
425
|
+
detail = response&.response&.message || 'Unknown error'
|
426
|
+
|
427
|
+
puts "Error detected: #{http_status}" if @debug
|
428
|
+
error_class = Errors::DynamicError.new(self, title, detail, http_status, response&.parsed_response)
|
429
|
+
|
430
|
+
raise error_class if @debug
|
431
|
+
|
432
|
+
raise error_class.error
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
399
437
|
end
|
400
438
|
end
|