mints 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15db76401dfa74546139b780363014a6502c2d10409f5ba7199d27c16b746d64
4
- data.tar.gz: 52ad33837204580f17ade75c3777dea6aea97903a508968a8bff0e5cb52f098e
3
+ metadata.gz: f6d8aee8c612520fb307a45a4eb3c4f51168e1572af251c442a8ea69bbdc96fa
4
+ data.tar.gz: 7bf61be045e79a2a841fbeee3779003c20faef08c37fa90691dd5d6c67e4f7ac
5
5
  SHA512:
6
- metadata.gz: 4ddb5dda74b294e5d351a6d700e93aa0120b3ef94622203c52020317768c23f88fa855ffe10463efda4bcbb558aca783d8107eb2bc5005102410a0cabcc7f9df
7
- data.tar.gz: 928bc2bfa825d822b08a7f30f9ea4575f43e4db1888d58caa07eac4a443372499b2b6f75dd4f45189ef9c2870d42ed0aadc9481a95c578e7b345e06f0f65a4d0
6
+ metadata.gz: bc6d575393c24382aa39886ed9ef17aa9032228c00ff0d901475fc8126b6a255835df56545dd3198bdf006d3495eb622e2487a8f3e3a90e6d1ad2187c93e69c5
7
+ data.tar.gz: 4a262acdd3178caf9bc3cd785a4eb47843412ee75111868d01482838143f6fd8f1d106ad3b370c6e7742e49dae2b50048e197864e9bc7a40d4dffd2d2567dc8f
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
@@ -340,3 +340,8 @@ The current errors are:
340
340
 
341
341
  </details>
342
342
 
343
+ <details>
344
+ <summary> Mints::Threads </summary>
345
+
346
+ - [Mints::MakeMultipleRequest](doc/threads/make_multiple_request.md)
347
+ </details>
data/lib/client.rb CHANGED
@@ -4,13 +4,9 @@ require 'httparty'
4
4
  require 'json'
5
5
  require 'addressable'
6
6
  require 'redis'
7
- require_relative './mints/controllers/concerns/read_config_file'
8
7
 
9
8
  module Mints
10
9
  class Client
11
- extend ActiveSupport::Concern
12
-
13
- include ReadConfigFile
14
10
 
15
11
  attr_reader :host
16
12
  attr_reader :api_key
@@ -13,6 +13,6 @@ module ContactVouchers
13
13
  # data = { description: 'This is the transaction description', voucher_code: 'XAZWQ12MP' }
14
14
  # @data = @mints_contact.apply_voucher(1, data)
15
15
  def apply_voucher(order_id, data)
16
- @client.raw('post', "/ecommerce/orders/#{order_id}/voucher", nil, data_transform(data))
16
+ @client.raw('post', "/ecommerce/orders/#{order_id}/voucher", nil, data_transform(data), @contact_v1_url)
17
17
  end
18
18
  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
 
@@ -18,8 +18,11 @@ module ProxyControllersMethods
18
18
  # Returns the response returned by send_mints_request
19
19
  #
20
20
  def index(controller_type = nil)
21
+ host = @host.gsub('http://', '').gsub('https://', '')
22
+ host = host[0...-1] if host.end_with? '/'
23
+
21
24
  headers = {
22
- 'host' => @host.gsub('http://', '').gsub('https://', ''),
25
+ 'host' => host,
23
26
  'ApiKey' => @api_key.to_s,
24
27
  'Content-Type' => 'application/json',
25
28
  'Accept' => 'application/json'
@@ -50,7 +53,7 @@ module ProxyControllersMethods
50
53
  return render json: cached_response
51
54
  end
52
55
 
53
- send_mints_request(full_url, headers, true, time)
56
+ send_mints_request(full_url, headers, true, time: time)
54
57
  else
55
58
  send_mints_request(full_url, headers)
56
59
  end
@@ -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
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.
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,6 +47,7 @@ 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
 
metadata CHANGED
@@ -1,33 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.33
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-05-02 00:00:00.000000000 Z
11
+ date: 2023-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.7.0
20
- - - "~>"
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.7.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.7.0
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.7.0
33
33
  - !ruby/object:Gem::Dependency
@@ -68,42 +68,56 @@ dependencies:
68
68
  name: rails-reverse-proxy
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ">="
71
+ - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: 0.9.1
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 0.9.1
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: 0.9.1
84
- - - "~>"
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 0.9.1
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: redis
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ">="
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
93
  version: 4.2.2
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 4.2.2
97
97
  type: :runtime
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.2.2
101
104
  - - ">="
102
105
  - !ruby/object:Gem::Version
103
106
  version: 4.2.2
107
+ - !ruby/object:Gem::Dependency
108
+ name: concurrent-ruby
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
104
111
  - - "~>"
105
112
  - !ruby/object:Gem::Version
106
- version: 4.2.2
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
@@ -243,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
258
  - !ruby/object:Gem::Version
244
259
  version: '0'
245
260
  requirements: []
246
- rubygems_version: 3.0.3.1
261
+ rubygems_version: 3.1.6
247
262
  signing_key:
248
263
  specification_version: 4
249
264
  summary: MINTS gem allows to connect your Rails App to MINTS.CLOUD