mints 0.0.17 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/lib/client.rb +96 -37
  4. data/lib/contact.rb +659 -94
  5. data/lib/generators/mints_files_generator.rb +6 -0
  6. data/lib/generators/mints_link.rb +61 -0
  7. data/lib/generators/short_link_controller.rb +41 -0
  8. data/lib/mints/controllers/admin_base_controller.rb +2 -2
  9. data/lib/mints/controllers/base_api_controller.rb +12 -11
  10. data/lib/mints/controllers/base_controller.rb +38 -9
  11. data/lib/mints_helper.rb +47 -0
  12. data/lib/pub.rb +258 -139
  13. data/lib/user/config/api_keys.rb +65 -0
  14. data/lib/user/config/appointments.rb +221 -0
  15. data/lib/user/config/attribute_groups.rb +77 -0
  16. data/lib/user/config/attributes.rb +86 -0
  17. data/lib/user/config/calendars.rb +89 -0
  18. data/lib/user/config/config.rb +65 -0
  19. data/lib/user/config/importers.rb +184 -0
  20. data/lib/user/config/public_folders.rb +108 -0
  21. data/lib/user/config/relationships.rb +138 -0
  22. data/lib/user/config/roles.rb +84 -0
  23. data/lib/user/config/seeds.rb +14 -0
  24. data/lib/user/config/system_settings.rb +53 -0
  25. data/lib/user/config/tags.rb +63 -0
  26. data/lib/user/config/taxonomies.rb +124 -0
  27. data/lib/user/config/teams.rb +70 -0
  28. data/lib/user/config/users.rb +76 -0
  29. data/lib/user/contacts/contacts.rb +21 -0
  30. data/lib/user/content/assets.rb +260 -0
  31. data/lib/user/content/content.rb +235 -0
  32. data/lib/user/content/content_instances.rb +147 -0
  33. data/lib/user/content/content_templates.rb +111 -0
  34. data/lib/user/content/conversations.rb +174 -0
  35. data/lib/user/content/dam.rb +88 -0
  36. data/lib/user/content/forms.rb +168 -0
  37. data/lib/user/content/message_templates.rb +162 -0
  38. data/lib/user/content/messages.rb +90 -0
  39. data/lib/user/content/pages.rb +81 -0
  40. data/lib/user/content/stories.rb +164 -0
  41. data/lib/user/content/story_templates.rb +95 -0
  42. data/lib/user/crm/companies.rb +111 -0
  43. data/lib/user/crm/contacts.rb +312 -0
  44. data/lib/user/crm/crm.rb +21 -0
  45. data/lib/user/crm/deals.rb +111 -0
  46. data/lib/user/crm/favorites.rb +17 -0
  47. data/lib/user/crm/segments.rb +132 -0
  48. data/lib/user/crm/users.rb +22 -0
  49. data/lib/user/crm/workflow_step_objects.rb +89 -0
  50. data/lib/user/crm/workflow_steps.rb +49 -0
  51. data/lib/user/crm/workflows.rb +70 -0
  52. data/lib/user/ecommerce/ecommerce.rb +29 -0
  53. data/lib/user/ecommerce/item_prices.rb +86 -0
  54. data/lib/user/ecommerce/locations.rb +166 -0
  55. data/lib/user/ecommerce/order_items_groups.rb +109 -0
  56. data/lib/user/ecommerce/order_statuses.rb +26 -0
  57. data/lib/user/ecommerce/orders.rb +258 -0
  58. data/lib/user/ecommerce/price_lists.rb +73 -0
  59. data/lib/user/ecommerce/product_templates.rb +104 -0
  60. data/lib/user/ecommerce/product_variations.rb +129 -0
  61. data/lib/user/ecommerce/products.rb +169 -0
  62. data/lib/user/ecommerce/skus.rb +88 -0
  63. data/lib/user/ecommerce/taxes.rb +82 -0
  64. data/lib/user/ecommerce/variant_options.rb +69 -0
  65. data/lib/user/ecommerce/variant_values.rb +72 -0
  66. data/lib/user/helpers/helpers.rb +113 -0
  67. data/lib/user/helpers/object_activities.rb +83 -0
  68. data/lib/user/helpers/object_folders.rb +82 -0
  69. data/lib/user/helpers/user_folders.rb +83 -0
  70. data/lib/user/marketing/marketing.rb +120 -0
  71. data/lib/user/profile/profile.rb +111 -0
  72. data/lib/user.rb +24 -368
  73. metadata +64 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f269f998c9cc9cb3dc69f3ec70cc2ff4522a97c14a9da0bfb6ca4cba40b0654
4
- data.tar.gz: e6b867ce7e3623b05c7aad402462f09b0b1a71a3750549c669407bcff6d2aa2b
3
+ metadata.gz: f2ab9b781d2576391b638771babe904c816f97dffb6e98644b98cd1906b3232d
4
+ data.tar.gz: 4f065c57fab622ded6e65800a2eaa82d4d6773d66b313a8f0e2567d403645a02
5
5
  SHA512:
6
- metadata.gz: 1128997e3df23340e780e4dcc9bb84389df6062eaae3683dff653b440887a5c4d04059141e8472e3762c3ce856df795c26ef7e376c72c38e494880aef5ab830b
7
- data.tar.gz: '09b6774bb218dc40cd0083fc54428225999736f5452911c7b482a22b928d41dea91fe343ecbab96543be6c602393f6f13aaa9d9d1ee489b8e4a697bf61eda20f'
6
+ metadata.gz: 52c8490021563ebfac12d93269c0757911647e8a7cefa99c42fb1cec62e956bde9427e19ad49353ae6aa688d359efbba4415e26fb0a290fd028b342c1c173454
7
+ data.tar.gz: 88308f8b8536122d4db1bf38338cbd140f26edad3cf5ae7427d561941b2ab9ff1101135b2fdb5d3c1de8ea1d3b2d8a3a307ac5578c75ccfb5a025a9d999fda27
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ gem 'json'
4
4
  gem 'httparty'
5
5
  gem 'addressable'
6
6
  gem 'rails-reverse-proxy', '~> 0.9.1'
7
- gem 'redis'
7
+ gem 'redis'
8
+ gem "mongo", "~> 2"
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
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|