mints 0.0.32 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8721bbc4b1c0b04f238ec5577801928582f5686030977cae483ef75a3625cf7e
4
- data.tar.gz: d81e367b63a8ebfe67915ed60238ea0fedf98066f5b9de567efc3361fd9a056c
3
+ metadata.gz: f991ed1a3bb4f7ace43a2c4e86dc7acbc799ec554563396dedfc9a1e249c1ac6
4
+ data.tar.gz: b576013f273dd87789211e2f1a27c24e76402dbbd4c3f68f78ed8c92adfaaf6b
5
5
  SHA512:
6
- metadata.gz: 5904fa1556491f7794221aaf51fe313f92243d5f959879cf997b3efe26ffc900bf0d3a846ae7f31aff15639fd02eb23957920722ba2c060f18bd744cb88d444a
7
- data.tar.gz: 29d380e6a824aedb240577b9ee40c29df92b62ec02090e690ec5537a5fb9fcda699b6eafea8ea52f9e07726aae3d4f7e6e85b5fb3f3b28fcc74232b3d400ced2
6
+ metadata.gz: b84b9b95d79a60bc0e678ccf352ca6caf3a5c193345be9dbc5bd07dfd2aeb0ff1bf07a6cc08cdcbfb2f0151660f3ffff589b1ff4aa60f4cf9069a955789d3bc6
7
+ data.tar.gz: 46438aa266b1444faa0f5c76af6079c78dba486675a15caff74fa9c81471179083d4e0f3fd439e5b38c1ce10f606f73dbdd36d924e60bfe9cd4269624b9a914f
data/Gemfile CHANGED
@@ -5,5 +5,6 @@ gem 'httparty'
5
5
  gem 'addressable'
6
6
  gem 'rails-reverse-proxy', '~> 0.9.1'
7
7
  gem 'redis'
8
- gem "mongo", "~> 2"
8
+ gem 'mongo', "~> 2"
9
+ gem 'concurrent-ruby', require: 'concurrent'
9
10
  gem 'rubocop', require: false
data/README.md CHANGED
@@ -135,6 +135,14 @@ it to the groups array and set the cache time.
135
135
  - urls:
136
136
  - group_of_urls
137
137
  time: time_that_will_be_applied_to_urls_in_seconds
138
+ sdk:
139
+ debug: false
140
+ # Timeout is specified in seconds
141
+ default_http_timeout: 30 # Allows setting a default timeout for all HTTP calls.
142
+ get_http_timeout: 30 # Allows setting a default timeout for all GET calls.
143
+ post_http_timeout: 30 # Allows setting a default timeout for all POST calls.
144
+ put_http_timeout: 30 # Allows setting a default timeout for all PUT calls.
145
+ delete_http_timeout: 30 # Allows setting a default timeout for all DELETE calls.
138
146
  ```
139
147
 
140
148
  To enable sdk debugging you can change the variable debug.
@@ -156,6 +164,7 @@ functionality, we recommend the use of the template).
156
164
  ## Override default clients
157
165
 
158
166
  If you want other clients for admin/base controller, you need to specify them with the "define_mints_clients" method
167
+
159
168
  Example:
160
169
 
161
170
  ```ruby
@@ -168,6 +177,28 @@ class AdminController < Mints::AdminBaseController
168
177
  end
169
178
  ```
170
179
 
180
+ ## Override default timeouts
181
+
182
+ If you want specific timeouts per instance, you can define mints_sdk_timeouts_config
183
+
184
+ Example:
185
+
186
+ ```ruby
187
+ # admin_controller.rb
188
+
189
+ class AdminController < Mints::AdminBaseController
190
+ def mints_sdk_timeouts_config
191
+ {
192
+ default: 30,
193
+ get: 50,
194
+ post: 40,
195
+ put: 30,
196
+ delete: 10
197
+ }
198
+ end
199
+ end
200
+ ```
201
+
171
202
  ## Error catching
172
203
 
173
204
  The SDK provides different errors that are identified according to the response provided by CXF,
@@ -244,7 +275,6 @@ The current errors are:
244
275
  - Mints::Pub::Ecommerce
245
276
  - [Mints::Pub::Ecommerce::Locations](doc/pub/ecommerce/locations.md)
246
277
  - [Mints::Pub::Ecommerce::Orders](doc/pub/ecommerce/orders.md)
247
- - [Mints::Pub::Ecommerce::Products](doc/pub/ecommerce/products.md)
248
278
 
249
279
  </details>
250
280
 
@@ -340,3 +370,8 @@ The current errors are:
340
370
 
341
371
  </details>
342
372
 
373
+ <details>
374
+ <summary> Mints::Threads </summary>
375
+
376
+ - [Mints::MakeMultipleRequest](doc/threads/make_multiple_request.md)
377
+ </details>
data/lib/client.rb CHANGED
@@ -10,8 +10,6 @@ module Mints
10
10
  class Client
11
11
  extend ActiveSupport::Concern
12
12
 
13
- include ReadConfigFile
14
-
15
13
  attr_reader :host
16
14
  attr_reader :api_key
17
15
  attr_reader :scope
@@ -19,7 +17,17 @@ module Mints
19
17
  attr_accessor :session_token
20
18
  attr_accessor :contact_token_id
21
19
 
22
- def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, visit_id = nil, debug = false)
20
+ def initialize(
21
+ host,
22
+ api_key,
23
+ scope = nil,
24
+ session_token = nil,
25
+ contact_token_id = nil,
26
+ visit_id = nil,
27
+ debug = false,
28
+ timeouts = {}
29
+ )
30
+
23
31
  @host = host
24
32
  @api_key = api_key
25
33
  @session_token = session_token
@@ -27,6 +35,14 @@ module Mints
27
35
  @visit_id = visit_id
28
36
  @debug = debug
29
37
 
38
+ config = read_config_file('sdk') || {}
39
+
40
+ @default_http_timeout = timeouts.fetch(:default, config.fetch('default_http_timeout', 30))
41
+ @get_http_timeout = timeouts.fetch(:get, config.fetch('get_http_timeout', @default_http_timeout))
42
+ @post_http_timeout = timeouts.fetch(:post, config.fetch('post_http_timeout', @default_http_timeout))
43
+ @put_http_timeout = timeouts.fetch(:put, config.fetch('put_http_timeout', @default_http_timeout))
44
+ @delete_http_timeout = timeouts.fetch(:delete, config.fetch('delete_http_timeout', @default_http_timeout))
45
+
30
46
  self.set_scope(scope)
31
47
  end
32
48
 
@@ -226,22 +242,22 @@ module Mints
226
242
  ##### HTTP CLIENTS ######
227
243
  # Simple HTTP GET
228
244
  def http_get(url, headers = nil)
229
- HTTParty.get(url, headers: headers)
245
+ HTTParty.get(url, headers: headers, timeout: @get_http_timeout)
230
246
  end
231
247
 
232
248
  # Simple HTTP POST
233
249
  def http_post(url, headers = nil, data = nil)
234
- HTTParty.post(url, headers: headers, body: data)
250
+ HTTParty.post(url, headers: headers, body: data, timeout: @post_http_timeout)
235
251
  end
236
252
 
237
253
  # Simple HTTP PUT
238
254
  def http_put(url, headers = nil, data = nil)
239
- HTTParty.put(url, headers: headers, body: data)
255
+ HTTParty.put(url, headers: headers, body: data, timeout: @put_http_timeout)
240
256
  end
241
257
 
242
258
  # Simple HTTP DELETE
243
259
  def http_delete(url, headers = nil, data = nil)
244
- HTTParty.delete(url, headers: headers, body: data)
260
+ HTTParty.delete(url, headers: headers, body: data, timeout: @delete_http_timeout)
245
261
  end
246
262
 
247
263
  # Start contact context
@@ -336,5 +352,41 @@ module Mints
336
352
  end
337
353
  end
338
354
 
355
+ # Timeouts methods
356
+
357
+ def timeout
358
+ {
359
+ default: @default_http_timeout,
360
+ get: @get_http_timeout,
361
+ post: @post_http_timeout,
362
+ put: @put_http_timeout,
363
+ delete: @delete_http_timeout
364
+ }
365
+ end
366
+
367
+ def timeout=(t)
368
+ if t.kind_of? Hash
369
+ t = t.with_indifferent_access
370
+ @default_http_timeout = t[:default] if t[:default]
371
+ @get_http_timeout = t[:get] if t[:get]
372
+ @post_http_timeout = t[:post] if t[:post]
373
+ @put_http_timeout = t[:put] if t[:put]
374
+ @delete_http_timeout = t[:delete] if t[:delete]
375
+ elsif t.kind_of? Integer
376
+ @default_http_timeout = t
377
+ @get_http_timeout = t
378
+ @post_http_timeout = t
379
+ @put_http_timeout = t
380
+ @delete_http_timeout = t
381
+ end
382
+ end
383
+
384
+ def read_config_file(config_key = nil)
385
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
386
+ config = YAML.safe_load template.result(binding)
387
+ config_key ? config[config_key] : config
388
+ rescue StandardError
389
+ nil
390
+ end
339
391
  end
340
392
  end
data/lib/contact.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative './client'
4
4
  require_relative './mints/helpers/mints_helper'
5
+ require_relative './mints/helpers/threads_helper'
5
6
  require_relative './contact/content/content'
6
7
  require_relative './contact/config/config'
7
8
  require_relative './contact/ecommerce/ecommerce'
@@ -14,6 +15,7 @@ module Mints
14
15
  include ContactContent
15
16
  include ContactEcommerce
16
17
  include MintsHelper
18
+ include ThreadsHelper
17
19
 
18
20
  attr_reader :client
19
21
 
@@ -28,9 +30,18 @@ module Mints
28
30
  #
29
31
  # ==== Return
30
32
  # Returns a Contact object
31
- def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
33
+ def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false, timeouts = {})
32
34
  @contact_v1_url = '/api/contact/v1'
33
- @client = Mints::Client.new(host, api_key, 'contact', session_token, contact_token_id, nil, debug)
35
+ @client = Mints::Client.new(
36
+ host,
37
+ api_key,
38
+ 'contact',
39
+ session_token,
40
+ contact_token_id,
41
+ nil,
42
+ debug,
43
+ timeouts
44
+ )
34
45
  end
35
46
 
36
47
  ### V1/CONTACTS ###
@@ -14,6 +14,12 @@ redis_cache:
14
14
  time: time_that_will_be_applied_to_urls_in_seconds
15
15
  sdk:
16
16
  debug: false
17
+ # Timeout is specified in seconds
18
+ default_http_timeout: 30 # Allows setting a default timeout for all HTTP calls.
19
+ get_http_timeout: 30 # Allows setting a default timeout for all GET calls.
20
+ post_http_timeout: 30 # Allows setting a default timeout for all POST calls.
21
+ put_http_timeout: 30 # Allows setting a default timeout for all PUT calls.
22
+ delete_http_timeout: 30 # Allows setting a default timeout for all DELETE calls.
17
23
  cookies_iframe:
18
24
  activated: boolean_value_to_enable_and_disable_cookies_iframe
19
25
  expire_time: expire_time_of_cookies_iframe_in_hours
@@ -46,7 +46,14 @@ module MintsClients
46
46
  visit_id = cookies[:mints_visit_id]
47
47
  contact_token_id = cookies[:mints_contact_id]
48
48
 
49
- @mints_pub = Mints::Pub.new(@host, @api_key, contact_token_id, visit_id, @debug)
49
+ @mints_pub = Mints::Pub.new(
50
+ @host,
51
+ @api_key,
52
+ contact_token_id,
53
+ visit_id,
54
+ @debug,
55
+ mints_sdk_timeouts_config
56
+ )
50
57
  end
51
58
 
52
59
  ##
@@ -56,7 +63,14 @@ module MintsClients
56
63
  # Initialize mints contact client
57
64
  contact_session_token = cookies[:mints_contact_session_token]
58
65
  contact_token_id = cookies[:mints_contact_id]
59
- @mints_contact = Mints::Contact.new(@host, @api_key, contact_session_token, contact_token_id, @debug)
66
+ @mints_contact = Mints::Contact.new(
67
+ @host,
68
+ @api_key,
69
+ contact_session_token,
70
+ contact_token_id,
71
+ @debug,
72
+ mints_sdk_timeouts_config
73
+ )
60
74
  end
61
75
 
62
76
  ##
@@ -65,7 +79,13 @@ module MintsClients
65
79
  def set_mints_user_client
66
80
  # Initialize mints user client
67
81
  user_session_token = cookies[:mints_user_session_token]
68
- @mints_user = Mints::User.new(@host, @api_key, user_session_token, @debug)
82
+ @mints_user = Mints::User.new(
83
+ @host,
84
+ @api_key,
85
+ user_session_token,
86
+ @debug,
87
+ mints_sdk_timeouts_config
88
+ )
69
89
  end
70
90
 
71
91
  ##
@@ -73,6 +93,12 @@ module MintsClients
73
93
  # Initialize the service account client
74
94
  def set_mints_service_account_client
75
95
  # Initialize service account client
76
- @mints_service_account = Mints::User.new(@host, @api_key, @api_key, @debug)
96
+ @mints_service_account = Mints::User.new(
97
+ @host,
98
+ @api_key,
99
+ @api_key,
100
+ @debug,
101
+ mints_sdk_timeouts_config
102
+ )
77
103
  end
78
104
  end
@@ -9,12 +9,12 @@ module ReadConfigFile
9
9
 
10
10
  def set_config_variables
11
11
  if File.exists?("#{Rails.root}/mints_config.yml.erb")
12
-
13
12
  template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
14
13
  config = YAML.safe_load template.result(binding)
15
- @host = config["mints"]["host"]
16
- @api_key = config["mints"]["api_key"]
17
- @debug = !!config["sdk"]["debug"]
14
+
15
+ @host = config['mints']['host']
16
+ @api_key = config['mints']['api_key']
17
+ @debug = !!config['sdk']['debug']
18
18
  @redis_config = config['redis_cache']
19
19
  @use_cache = config['redis_cache']['use_cache']
20
20
 
@@ -0,0 +1,109 @@
1
+ require 'concurrent/executor/thread_pool_executor'
2
+
3
+ module ThreadsHelper
4
+
5
+ def make_multiple_request(calls)
6
+ set_threads_config
7
+ payload_to_return = []
8
+ now = Time.now
9
+ calls = [calls] if !calls.kind_of?(Array) || (calls.kind_of?(Array) && calls.first.kind_of?(String))
10
+
11
+ if @debug
12
+ puts "min_threads_per_pool: #{@min_threads_per_pool}"
13
+ puts "max_threads_per_pool: #{@max_threads_per_pool}"
14
+ puts "max_threads_queue: #{@max_threads_queue}"
15
+ end
16
+
17
+ pool = Concurrent::ThreadPoolExecutor.new(
18
+ min_threads: @min_threads_per_pool,
19
+ max_threads: @max_threads_per_pool,
20
+ max_queue: @max_threads_queue,
21
+ fallback_policy: :caller_runs
22
+ )
23
+
24
+ calls.each_with_index do |call_data, index|
25
+ pool.post do
26
+ begin
27
+ payload_to_return[index] = make_call(call_data)
28
+ rescue => e
29
+ payload_to_return[index] = e
30
+ end
31
+ end
32
+ end
33
+
34
+ # tell the pool to shutdown in an orderly fashion, allowing in progress work to complete
35
+ pool.shutdown
36
+ # now wait for all work to complete, wait as long as it takes
37
+ pool.wait_for_termination
38
+
39
+ if @debug
40
+ end_time = Time.now
41
+ puts "Time to make all calls: #{end_time - now}"
42
+ end
43
+
44
+ payload_to_return
45
+ end
46
+
47
+ private
48
+
49
+ def set_threads_config
50
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
51
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
52
+ config = YAML.safe_load template.result(binding)
53
+ mints_config = get_mints_config(config)
54
+ @debug = !!config['sdk']['debug']
55
+
56
+ # All threads config
57
+ @min_threads_per_pool = mints_config['min_threads_per_pool'] || 2
58
+ @max_threads_per_pool = mints_config['max_threads_per_pool'] || 2
59
+ @max_threads_queue = mints_config['max_threads_queue'] || 10
60
+ end
61
+ end
62
+
63
+ def get_mints_config(config)
64
+ config['mints'].kind_of?(Hash) ? config['mints'] : {}
65
+ end
66
+
67
+ def make_call(call_data)
68
+ action, *all_options = generate_raw_data(call_data)
69
+
70
+ if if_is_raw_action(action)
71
+ self.client.raw(action, *all_options)
72
+ else
73
+ self.send(action, *all_options.compact)
74
+ end
75
+ end
76
+
77
+ def if_is_raw_action(action)
78
+ http_actions = %w[get create post update put patch delete destroy]
79
+ http_actions.include?(action.downcase)
80
+ end
81
+
82
+ def generate_raw_data(payload)
83
+ action = raw_attribute_data(payload, 'action')
84
+ url = raw_attribute_data(payload, 'url', 1)
85
+ options = raw_attribute_data(payload, 'options', 2)
86
+ data = raw_attribute_data(payload, 'data', 3)
87
+ base_url = raw_attribute_data(payload, 'base_url', 4)
88
+ compatibility_options = raw_attribute_data(payload, 'compatibility_options', 5)
89
+ only_tracking = raw_attribute_data(payload, 'only_tracking', 6)
90
+
91
+ [action, url, options, data, base_url, compatibility_options, only_tracking]
92
+ end
93
+
94
+ def raw_attribute_data(payload, attribute, array_index = 0)
95
+ attribute_data = nil
96
+
97
+ if payload.kind_of? Array
98
+ attribute_data = payload[array_index]
99
+ elsif payload.kind_of? Hash
100
+ if payload.key? attribute
101
+ attribute_data = payload[attribute]
102
+ elsif payload.key? attribute.to_sym
103
+ attribute_data = payload[attribute.to_sym]
104
+ end
105
+ end
106
+
107
+ attribute_data
108
+ end
109
+ end
@@ -3,12 +3,12 @@
3
3
  ### V1/ECOMMERCE ###
4
4
 
5
5
  require_relative './locations'
6
- require_relative './products'
6
+ require_relative './product_versions'
7
7
  require_relative './orders'
8
8
 
9
9
  module PublicEcommerce
10
10
  include PublicLocations
11
- include PublicProducts
11
+ include PublicProductVersions
12
12
  include PublicOrders
13
13
 
14
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PublicProducts
3
+ module PublicProductVersions
4
4
  ##
5
5
  # === Get Products.
6
6
  # Get a collection of products.
@@ -10,17 +10,17 @@ module PublicProducts
10
10
  # use_post:: (Boolean) -- Variable to determine if the request is by 'post' or 'get' functions.
11
11
  #
12
12
  # ==== First Example
13
- # @data = @mints_pub.get_products
13
+ # @data = @mints_pub.get_product_versions
14
14
  #
15
15
  # ==== Second Example
16
16
  # options = { fields: "title" }
17
- # @data = @mints_pub.get_products(options)
17
+ # @data = @mints_pub.get_product_versions(options)
18
18
  #
19
19
  # ==== Third Example
20
20
  # options = { fields: "title" }
21
- # @data = @mints_pub.get_products(options, false)
22
- def get_products(options = nil, use_post = true)
23
- get_query_results('/ecommerce/products', options, use_post)
21
+ # @data = @mints_pub.get_product_versions(options, false)
22
+ def get_product_versions(options = nil, use_post = true)
23
+ get_query_results('/ecommerce/product-versions', options, use_post)
24
24
  end
25
25
 
26
26
  ##
@@ -32,14 +32,14 @@ module PublicProducts
32
32
  # options:: (Hash) -- List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter.
33
33
  #
34
34
  # ==== First Example
35
- # @data = @mints_pub.get_product("product_slug")
35
+ # @data = @mints_pub.get_product_version("product_slug")
36
36
  #
37
37
  # ==== Second Example
38
38
  # options = {
39
39
  # fields: 'id, slug'
40
40
  # }
41
- # @data = @mints_pub.get_product("lego-set", options)
42
- def get_product(slug, options = nil)
43
- @client.raw('get', "/ecommerce/products/#{slug}", options)
41
+ # @data = @mints_pub.get_product_version("lego-set", options)
42
+ def get_product_version(slug, options = nil)
43
+ @client.raw('get', "/ecommerce/product-versions/#{slug}", options)
44
44
  end
45
45
  end
data/lib/pub.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'yaml'
4
4
  require_relative './client'
5
5
  require_relative './mints/helpers/mints_helper'
6
+ require_relative './mints/helpers/threads_helper'
6
7
  require_relative './pub/content/content'
7
8
  require_relative './pub/ecommerce/ecommerce'
8
9
  require_relative './pub/config/config'
@@ -67,6 +68,7 @@ module Mints
67
68
  include PublicContent
68
69
  include PublicEcommerce
69
70
  include PublicConfig
71
+ include ThreadsHelper
70
72
 
71
73
  ##
72
74
  # === Initialize.
@@ -79,8 +81,17 @@ module Mints
79
81
  #
80
82
  # ==== Return
81
83
  # Returns a Client object.
82
- def initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false)
83
- @client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, visit_id, debug)
84
+ def initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false, timeouts = {})
85
+ @client = Mints::Client.new(
86
+ host,
87
+ api_key,
88
+ 'public',
89
+ nil,
90
+ contact_token_id,
91
+ visit_id,
92
+ debug,
93
+ timeouts
94
+ )
84
95
  end
85
96
 
86
97
  ##
@@ -4,6 +4,7 @@ require_relative './assets'
4
4
  require_relative './content_instances'
5
5
  require_relative './content_templates'
6
6
  require_relative './conversations'
7
+ require_relative './conversation_templates'
7
8
  require_relative './dam'
8
9
  require_relative './forms'
9
10
  require_relative './message_templates'
@@ -18,6 +19,7 @@ module Content
18
19
  include ContentInstances
19
20
  include ContentTemplates
20
21
  include Conversations
22
+ include ConversationTemplates
21
23
  include DAM
22
24
  include Forms
23
25
  include MessageTemplates
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConversationTemplates
4
+ ##
5
+ # == Conversation templates
6
+ #
7
+
8
+ ###
9
+ # === Get conversation templates.
10
+ # Get a collection of conversation templates.
11
+ #
12
+ # ==== Parameters
13
+ # options:: (Hash) -- List of Resource Collection Options shown above can be used as parameter.
14
+ #
15
+ # ==== First Example
16
+ # @data = @mints_user.get_conversations
17
+ #
18
+ # ==== Second Example
19
+ # options = { fields: 'title' }
20
+ # @data = @mints_user.get_conversation_templates(options)
21
+ def get_conversation_templates(options = nil)
22
+ @client.raw('get', '/content/conversation-templates', options)
23
+ end
24
+
25
+ # === Get conversation template.
26
+ # Get a conversation template info.
27
+ #
28
+ # ==== Parameters
29
+ # id:: (Integer) -- Conversation id.
30
+ # options:: (Hash) -- List of Resource Collection Options shown above can be used as parameter.
31
+ #
32
+ # ==== First Example
33
+ # @data = @mints_user.get_conversation_template(1)
34
+ #
35
+ # ==== Second Example
36
+ # options = { fields: 'title' }
37
+ # @data = @mints_user.get_conversation_template(1, options)
38
+ def get_conversation_template(id, options = nil)
39
+ @client.raw('get', "/content/conversation-templates/#{id}", options)
40
+ end
41
+
42
+ # === Create conversation template.
43
+ # Create a conversation template with data.
44
+ #
45
+ # ==== Parameters
46
+ # data:: (Hash) -- Data to be submitted.
47
+ #
48
+ # ==== Example
49
+ # data = {
50
+ # title: 'New Conversation Template',
51
+ # slug: 'new-conversation-template'
52
+ # }
53
+ # @data = @mints_user.create_conversation_template(data)
54
+ def create_conversation_template(data, options = nil)
55
+ @client.raw('post', '/content/conversation-templates', options, data_transform(data))
56
+ end
57
+
58
+ # === Update conversation template.
59
+ # Update a conversation template info.
60
+ #
61
+ # ==== Parameters
62
+ # id:: (Integer) -- Conversation template id.
63
+ # data:: (Hash) -- Data to be submitted.
64
+ #
65
+ # ==== Example
66
+ # data = {
67
+ # title: 'Conversation Template'
68
+ # slug: 'conversation-template'
69
+ # }
70
+ # @data = @mints_user.update_conversation_template(13, data)
71
+ def update_conversation_template(id, data, options = nil)
72
+ @client.raw('put', "/content/conversation-templates/#{id}", options, data_transform(data))
73
+ end
74
+
75
+ # === Delete conversation template.
76
+ # Delete a conversation template.
77
+ #
78
+ # ==== Parameters
79
+ # id:: (Integer) -- Conversation template id.
80
+ #
81
+ # ==== Example
82
+ # @data = @mints_user.delete_conversation_template(11)
83
+ def delete_conversation_template(id)
84
+ @client.raw('delete', "/content/conversation-templates/#{id}")
85
+ end
86
+
87
+ # === Duplicate conversation template.
88
+ # Duplicate a conversation template.
89
+ #
90
+ # ==== Parameters
91
+ # id:: (Integer) -- Conversation template id.
92
+ # data:: (Hash) -- Data to be submitted.
93
+ #
94
+ # ==== Example
95
+ # data = {
96
+ # title: 'Duplicated conversation template'
97
+ # }
98
+ # @data = @mints_user.duplicate_conversation_template(13, data)
99
+ def duplicate_conversation_template(id, data)
100
+ @client.raw('put', "/content/conversation-templates/#{id}/duplicate", nil, data_transform(data))
101
+ end
102
+
103
+ # === Update activation words.
104
+ # Update activation words in a conversation template.
105
+ #
106
+ # ==== Parameters
107
+ # conversation_template_id:: (Integer) -- Conversation template id.
108
+ # data:: (Hash) -- Data to be submitted.
109
+ #
110
+ # ==== Example
111
+ # data = {
112
+ # activationWords: %w[ hello world ],
113
+ # formId: 1
114
+ # }
115
+ # @data = @mints_user.attach_user_in_conversation(13, data)
116
+ def update_activation_words(conversation_template_id, data)
117
+ url = "/content/conversation-templates/#{conversation_template_id}/activation-words"
118
+ @client.raw('post', url, nil, data_transform(data))
119
+ end
120
+
121
+ # === Attach form in conversation template.
122
+ # Attach a form in the conversation template.
123
+ #
124
+ # ==== Parameters
125
+ # id:: (Integer) -- Conversation template id.
126
+ # data:: (Hash) -- Data to be submitted.
127
+ #
128
+ # ==== Example
129
+ # data = {
130
+ # form_id: 2
131
+ # }
132
+ # @data = @mints_user.attach_form_in_conversation_template(13, data)
133
+ def attach_form_in_conversation_template(id, data)
134
+ @client.raw('post', "/content/conversation-templates/#{id}/attach-form", nil, data_transform(data))
135
+ end
136
+
137
+ # === Detach form in conversation template.
138
+ # Detach a form in a conversation template.
139
+ #
140
+ # ==== Parameters
141
+ # id:: (Integer) -- Conversation template id.
142
+ #
143
+ # ==== Example
144
+ # @data = @mints_user.detach_form_in_conversation_template(conversation_id, form_id)
145
+ def detach_form_in_conversation_template(id, form_id)
146
+ @client.raw('delete', "/content/conversation-templates/#{id}/detach-form/#{form_id}")
147
+ end
148
+ end
@@ -174,35 +174,4 @@ module Conversations
174
174
  @client.raw('post', "/content/conversations/#{id}/detach-contact", nil, data_transform(data))
175
175
  end
176
176
 
177
- # === Attach form in conversation.
178
- # Attach a form in a conversation.
179
- #
180
- # ==== Parameters
181
- # id:: (Integer) -- Conversation id.
182
- # data:: (Hash) -- Data to be submitted.
183
- #
184
- # ==== Example
185
- # data = {
186
- # form_id: 2
187
- # }
188
- # @data = @mints_user.attach_form_in_conversation(1, data)
189
- def attach_form_in_conversation(id, data)
190
- @client.raw('post', "/content/conversations/#{id}/attach-form", nil, data_transform(data))
191
- end
192
-
193
- # === Detach form in conversation.
194
- # Detach a form in a conversation.
195
- #
196
- # ==== Parameters
197
- # id:: (Integer) -- Contact id.
198
- # data:: (Hash) -- Data to be submitted.
199
- #
200
- # ==== Example
201
- # data = {
202
- # form_id: 2
203
- # }
204
- # @data = @mints_user.detach_form_in_conversation(1, data)
205
- def detach_form_in_conversation(id, data)
206
- @client.raw('post', "/content/conversations/#{id}/detach-form", nil, data_transform(data))
207
- end
208
177
  end
@@ -9,6 +9,7 @@ require_relative './price_lists'
9
9
  require_relative './product_templates'
10
10
  require_relative './product_variations'
11
11
  require_relative './products'
12
+ require_relative './product_versions'
12
13
  require_relative './skus'
13
14
  require_relative './taxes'
14
15
  require_relative './variant_options'
@@ -25,6 +26,7 @@ module Ecommerce
25
26
  include ProductTemplates
26
27
  include ProductVariations
27
28
  include Products
29
+ include ProductVersions
28
30
  include Skus
29
31
  include Taxes
30
32
  include VariantOptions
@@ -62,9 +62,9 @@ module Locations
62
62
  # data = {
63
63
  # title: 'New Location Modified'
64
64
  # }
65
- # @data = @mints_user.update_location(5, data.to_json)
65
+ # @data = @mints_user.update_location(5, data)
66
66
  def update_location(id, data, options = nil)
67
- @client.raw('put', "/ecommerce/locations/#{id}", options, data)
67
+ @client.raw('put', "/ecommerce/locations/#{id}", options, data_transform(data))
68
68
  end
69
69
 
70
70
  # === Delete location.
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProductVersions
4
+ ##
5
+ # === Get Product versions.
6
+ # Get a collection of product versions.
7
+ #
8
+ # ==== Parameters
9
+ # options:: (Hash) -- List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter.
10
+ # use_post:: (Boolean) -- Variable to determine if the request is by 'post' or 'get' functions.
11
+ #
12
+ # ==== First Example
13
+ # @data = @mints_user.get_product_versions
14
+ #
15
+ # ==== Second Example
16
+ # options = { fields: "title" }
17
+ # @data = @mints_user.get_product_versions(options)
18
+ #
19
+ # ==== Third Example
20
+ # options = { fields: "title" }
21
+ # @data = @mints_user.get_product_versions(options, false)
22
+ def get_product_versions(options = nil, use_post = true)
23
+ get_query_results('/ecommerce/product-versions', options, use_post)
24
+ end
25
+
26
+ ##
27
+ # === Get Product version.
28
+ # Get a single product version.
29
+ #
30
+ # ==== Parameters
31
+ # slug:: (String) -- It's the string identifier generated by Mints.
32
+ # options:: (Hash) -- List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter.
33
+ #
34
+ # ==== First Example
35
+ # @data = @mints_user.get_product_version("product_slug")
36
+ #
37
+ # ==== Second Example
38
+ # options = {
39
+ # fields: 'id, slug'
40
+ # }
41
+ # @data = @mints_user.get_product_version("lego-set", options)
42
+ def get_product_version(slug, options = nil)
43
+ @client.raw('get', "/ecommerce/product-versions/#{slug}", options)
44
+ end
45
+
46
+ # === Create product version.
47
+ # Create a product version with data.
48
+ #
49
+ # ==== Parameters
50
+ # data:: (Hash) -- Data to be submitted.
51
+ #
52
+ # ==== Example
53
+ # data = {
54
+ # title: 'New Product Version',
55
+ # slug: 'new-product-version',
56
+ # product_id: 1
57
+ # }
58
+ # @data = @mints_user.create_product_version(data)
59
+ def create_product_version(data, options = nil)
60
+ @client.raw('post', '/ecommerce/product-versions', options, data_transform(data))
61
+ end
62
+
63
+ # === Update product version.
64
+ # Update a product version info.
65
+ #
66
+ # ==== Parameters
67
+ # id:: (Integer) -- Product version id.
68
+ # data:: (Hash) -- Data to be submitted.
69
+ #
70
+ # ==== Example
71
+ # data = {
72
+ # title: 'New Product Version Modified',
73
+ # slug: 'new-product-version',
74
+ # product_id: 1
75
+ # }
76
+ # @data = @mints_user.update_product_version(9, data)
77
+ def update_product_version(id, data, options = nil)
78
+ @client.raw('put', "/ecommerce/product-versions/#{id}", options, data_transform(data))
79
+ end
80
+
81
+ # === Delete product version.
82
+ # Delete a product version.
83
+ #
84
+ # ==== Parameters
85
+ # id:: (Integer) -- Product version id.
86
+ #
87
+ def delete_product_version(id)
88
+ @client.raw('delete', "/ecommerce/product-versions/#{id}")
89
+ end
90
+
91
+ # === Publish product version.
92
+ # Publish a product version.
93
+ #
94
+ # ==== Parameters
95
+ # id:: (Integer) -- Product version id.
96
+ # data:: (Hash) -- Data to be submitted.
97
+ #
98
+ # ==== Example
99
+ # data = {
100
+ # title: 'New Publish'
101
+ # }
102
+ # @data = @mints_user.publish_product_version(2, data)
103
+ def publish_product_version(id, data)
104
+ @client.raw('put', "/ecommerce/product-versions/#{id}/publish", nil, data_transform(data))
105
+ end
106
+
107
+ end
@@ -36,22 +36,6 @@ module Products
36
36
  @client.raw('delete', "/ecommerce/products/#{id}")
37
37
  end
38
38
 
39
- # === Publish product.
40
- # Publish a product.
41
- #
42
- # ==== Parameters
43
- # id:: (Integer) -- Product id.
44
- # data:: (Hash) -- Data to be submitted.
45
- #
46
- # ==== Example
47
- # data = {
48
- # title: 'New Publish'
49
- # }
50
- # @data = @mints_user.publish_product(2, data)
51
- def publish_product(id, data)
52
- @client.raw('put', "/ecommerce/products/#{id}/publish", nil, data_transform(data))
53
- end
54
-
55
39
  # === Schedule product.
56
40
  # Schedule a product.
57
41
  #
data/lib/user.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative './client'
4
4
  require_relative './mints/helpers/mints_helper'
5
+ require_relative './mints/helpers/threads_helper'
5
6
  require_relative './user/crm/crm'
6
7
  require_relative './user/content/content'
7
8
  require_relative './user/marketing/marketing'
@@ -46,11 +47,21 @@ module Mints
46
47
  include Helpers
47
48
  include Contacts
48
49
  include MintsHelper
50
+ include ThreadsHelper
49
51
 
50
52
  attr_reader :client
51
53
 
52
- def initialize(host, api_key, session_token = nil, debug = false)
53
- @client = Mints::Client.new(host, api_key, 'user', session_token, nil, nil, debug)
54
+ def initialize(host, api_key, session_token = nil, debug = false, timeouts = {})
55
+ @client = Mints::Client.new(
56
+ host,
57
+ api_key,
58
+ 'user',
59
+ session_token,
60
+ nil,
61
+ nil,
62
+ debug,
63
+ timeouts
64
+ )
54
65
  end
55
66
 
56
67
  def login(email, password)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Gomez Garcia, Omar Mora, Luis Payan, Oscar Castillo, Fabian Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-10 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -104,6 +104,20 @@ dependencies:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
106
  version: 4.2.2
107
+ - !ruby/object:Gem::Dependency
108
+ name: concurrent-ruby
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: 1.2.2
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: 1.2.2
107
121
  description:
108
122
  email:
109
123
  executables: []
@@ -144,6 +158,7 @@ files:
144
158
  - lib/mints/helpers/contact_auth_helper.rb
145
159
  - lib/mints/helpers/mints_helper.rb
146
160
  - lib/mints/helpers/proxy_controllers_methods.rb
161
+ - lib/mints/helpers/threads_helper.rb
147
162
  - lib/mints/helpers/user_auth_helper.rb
148
163
  - lib/pub.rb
149
164
  - lib/pub/config/attributes.rb
@@ -162,7 +177,7 @@ files:
162
177
  - lib/pub/ecommerce/ecommerce.rb
163
178
  - lib/pub/ecommerce/locations.rb
164
179
  - lib/pub/ecommerce/orders.rb
165
- - lib/pub/ecommerce/products.rb
180
+ - lib/pub/ecommerce/product_versions.rb
166
181
  - lib/user.rb
167
182
  - lib/user/config/api_keys.rb
168
183
  - lib/user/config/appointments.rb
@@ -184,6 +199,7 @@ files:
184
199
  - lib/user/content/content.rb
185
200
  - lib/user/content/content_instances.rb
186
201
  - lib/user/content/content_templates.rb
202
+ - lib/user/content/conversation_templates.rb
187
203
  - lib/user/content/conversations.rb
188
204
  - lib/user/content/dam.rb
189
205
  - lib/user/content/forms.rb
@@ -212,6 +228,7 @@ files:
212
228
  - lib/user/ecommerce/price_lists.rb
213
229
  - lib/user/ecommerce/product_templates.rb
214
230
  - lib/user/ecommerce/product_variations.rb
231
+ - lib/user/ecommerce/product_versions.rb
215
232
  - lib/user/ecommerce/products.rb
216
233
  - lib/user/ecommerce/skus.rb
217
234
  - lib/user/ecommerce/taxes.rb