mints 0.0.9 → 0.0.14

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: 91ef0909fa4361a6a3644378c438c64341bfbf31bc6d9ef7f0ed178bd35b5dac
4
- data.tar.gz: 0a4c5c14a4550ac56917259ecc822d9afbe779e95507f9607c9248ce19c53caa
3
+ metadata.gz: 3deabf302a32fac1452e45f7ab9753ec0a1ee7973535b0371b9c67a25cb60cc7
4
+ data.tar.gz: 9589dacb58814ad17c5a2826f866b929f862d7ce7ce3fc745dcd3e191c2f19c9
5
5
  SHA512:
6
- metadata.gz: 1df0f3a2b3f2ff3c27a61221fab855138508991a0ea552e1111f15df723473e5eeb3ec8c46650aa1670bc00bef8242424fd88e20d90c729d12deac15d25453a4
7
- data.tar.gz: c9fb8c066bdcb38237d394bcef4d155bd8bcc29ac3f19b1f4adb905b7483b678c1dbb1625ba8b31be6cada2b565c465f3da3a1d0e6f62cae50c7cfcbc0bfcf44
6
+ metadata.gz: d1bc7c183bc20b9dbe25f4f5d7770ee0492d0f2e773cdfb6934af7afe0056bf8f38f7277440a821e71f22a4abda51c11f7b8c2dd5f6279e22b9c68c7fe703d82
7
+ data.tar.gz: 2f7ebc2b2f8977f5009bafc4e42348cc4a7494729fb1aa15ccf69a8e7937c9872120a2bc81711fcd22153fa5cb05e71c462dc0c67645f350c5e5021f1e7a71f9
data/Gemfile CHANGED
File without changes
@@ -30,7 +30,7 @@ con.login(email, password)
30
30
  con.get_contacts
31
31
  ```
32
32
  ## Generate mints files
33
- This command will generate the mints_config.yml file, API controlles and routes to have available the mints endpoints
33
+ This command will generate the mints_config.yml.erb file, API controlles and routes to have available the mints endpoints
34
34
  ```bash
35
35
  rails generate mints_files
36
36
  ```
@@ -46,8 +46,8 @@ This heritance will make the following class variables available:
46
46
 
47
47
  | Variable | Description |
48
48
  | --- | :---: |
49
- | @host | Host defined in mints_config.yml file |
50
- | @api_key | API key defined in mints_config.yml file |
49
+ | @host | Host defined in mints_config.yml.erb file |
50
+ | @api_key | API key defined in mints_config.yml.erb file |
51
51
  | @mints_pub | An already instanced public client |
52
52
  | @contact_token | A token used by mints to identify the contact |
53
53
  | @visit_id | An identifier of the visit registered |
@@ -73,8 +73,8 @@ end
73
73
  This heritance will make the following class variables available:
74
74
  | Variable | Description |
75
75
  | --- | :---: |
76
- | @host | Host defined in mints_config.yml file |
77
- | @api_key | API key defined in mints_config.yml file |
76
+ | @host | Host defined in mints_config.yml.erb file |
77
+ | @api_key | API key defined in mints_config.yml.erb file |
78
78
  | @mints_user | An already instanced user client (not usable until call the user login method) |
79
79
 
80
80
  And the following controller methods:
data/lib/client.rb CHANGED
@@ -8,12 +8,14 @@ module Mints
8
8
  attr_reader :api_key
9
9
  attr_reader :scope
10
10
  attr_reader :base_url
11
- attr_accessor :session_token
11
+ attr_accessor :session_token
12
+ attr_accessor :contact_token_id
12
13
 
13
- def initialize(host, api_key, scope = nil, session_token = nil, debug = false)
14
+ def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, debug = false)
14
15
  @host = host
15
16
  @api_key = api_key
16
17
  @session_token = session_token
18
+ @contact_token_id = contact_token_id
17
19
  @debug = debug
18
20
  self.set_scope(scope)
19
21
  end
@@ -30,7 +32,8 @@ module Mints
30
32
  response = nil
31
33
  if action === 'get'
32
34
 
33
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
35
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
36
+ config = YAML.load template.result(binding)
34
37
  url_need_cache = false
35
38
  result_from_cache = false
36
39
  time = 0
@@ -41,7 +44,7 @@ module Mints
41
44
  if full_url.match url
42
45
  time = group['time']
43
46
  url_need_cache = true
44
- @redis_server = Redis.new(host: config['redis_cache']['redis_host'])
47
+ @redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1)
45
48
  if @redis_server.get(full_url)
46
49
  response = @redis_server.get(full_url)
47
50
  result_from_cache = true
@@ -217,7 +220,7 @@ module Mints
217
220
  headers = {
218
221
  "ApiKey" => @api_key,
219
222
  "Accept" => "application/json",
220
- "ContactToken" => @contact_token
223
+ "ContactToken" => @contact_token_id
221
224
  }
222
225
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
223
226
  return self.http_get(url, headers)
@@ -227,7 +230,7 @@ module Mints
227
230
  headers = {
228
231
  "ApiKey" => @api_key,
229
232
  "Accept" => "application/json",
230
- "ContactToken" => @contact_token
233
+ "ContactToken" => @contact_token_id
231
234
  }
232
235
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
233
236
  return self.http_post(url, headers, data)
@@ -237,7 +240,7 @@ module Mints
237
240
  headers = {
238
241
  "ApiKey" => @api_key,
239
242
  "Accept" => "application/json",
240
- "ContactToken" => @contact_token
243
+ "ContactToken" => @contact_token_id
241
244
  }
242
245
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
243
246
  return self.http_post(url, headers, data)
@@ -279,7 +282,7 @@ module Mints
279
282
  "Content-Type" => "application/json",
280
283
  "ApiKey" => @api_key
281
284
  }
282
- h["ContactToken"] = @contact_token if @contact_token
285
+ h["ContactToken"] = @contact_token_id if @contact_token_id
283
286
  if headers
284
287
  headers.each do |k,v|
285
288
  h[k] = v
@@ -309,7 +312,7 @@ module Mints
309
312
  "Content-Type" => "application/json",
310
313
  "ApiKey" => @api_key
311
314
  }
312
- h["ContactToken"] = @contact_token if @contact_token
315
+ h["ContactToken"] = @contact_token_id if @contact_token_id
313
316
  if headers
314
317
  headers.each do |k,v|
315
318
  h[k] = v
data/lib/contact.rb CHANGED
@@ -7,8 +7,8 @@ module Mints
7
7
  # === Initialize.
8
8
  # Class constructor
9
9
  #
10
- def initialize(host, api_key, session_token = nil, debug = false)
11
- @client = Mints::Client.new(host, api_key, "contact", session_token, debug)
10
+ def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
11
+ @client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
12
12
  end
13
13
 
14
14
  ##
@@ -0,0 +1,23 @@
1
+ # Mints connection configuration
2
+ mints:
3
+ host: http://your_host_goes_here.com
4
+ api_key: your_mints_api_key_goes_here
5
+ mints_slug: slug_id #save id and token in redis
6
+ user_email: mints_user_email
7
+ user_password: mints_user_password
8
+ redis_cache:
9
+ use_cache: boolean_value_to_enable_and_disable_cache
10
+ redis_host: your_redis_server_host
11
+ redis_port: your_redis_server_port
12
+ redis_db: your_redis_database
13
+ groups:
14
+ - urls:
15
+ - group_of_urls
16
+ time: time_that_will_be_applied_to_urls_in_seconds
17
+ sdk:
18
+ debug: false
19
+ cookies_iframe:
20
+ activated: boolean_value_to_enable_and_disable_cookies_iframe
21
+ expire_time: expire_time_of_cookies_iframe_in_hours
22
+ hosts:
23
+ - array_of_host_to_send_cookies
File without changes
@@ -2,16 +2,17 @@ class MintsFilesGenerator < Rails::Generators::Base
2
2
  source_root(File.expand_path(File.dirname(__FILE__)))
3
3
  include Rails::Generators::Actions
4
4
  def create_mints_files
5
- copy_file 'mints_config.yml', 'mints_config.yml'
5
+ copy_file 'mints_config.yml.erb', 'mints_config.yml.erb'
6
6
  copy_file 'mints_user_controller.rb', './app/controllers/api/mints_user_controller.rb'
7
7
  copy_file 'mints_contact_controller.rb', './app/controllers/api/v1/mints_contact_controller.rb'
8
8
  copy_file 'mints_public_controller.rb', './app/controllers/api/v1/mints_public_controller.rb'
9
9
  route <<-eos
10
10
  # Mints auto-generated routes (proxy to send request to mints.cloud)
11
11
  namespace :api, defaults: { format: :json } do
12
- match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
12
+ match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
13
+ match '/contact/v1/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
13
14
  namespace :v1 do
14
- match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
15
+ match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
15
16
  match '/*path' => 'mints_public#index', via: [:get, :post, :put, :patch, :delete]
16
17
  end
17
18
  end
File without changes
File without changes
data/lib/mints.rb CHANGED
@@ -2,6 +2,7 @@ require_relative "./pub.rb"
2
2
  require_relative "./contact.rb"
3
3
  require_relative "./user.rb"
4
4
  require_relative "./mints/controllers/base_controller.rb"
5
+ require_relative "./mints/controllers/base_api_controller.rb"
5
6
  require_relative "./mints/controllers/admin_base_controller.rb"
6
7
  require_relative "./mints/controllers/public_api_controller.rb"
7
8
  require_relative "./mints/controllers/contact_api_controller.rb"
@@ -41,8 +41,9 @@ module Mints
41
41
  # === Set Mints user client.
42
42
  # Initialize the public client and set the user token
43
43
  def set_mints_user_client
44
- if File.exists?("#{Rails.root}/mints_config.yml")
45
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
44
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
45
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
46
+ config = YAML.load template.result(binding)
46
47
  @host = config["mints"]["host"]
47
48
  @api_key = config["mints"]["api_key"]
48
49
  @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
@@ -0,0 +1,53 @@
1
+ module Mints
2
+ class BaseApiController < ActionController::Base
3
+ before_action :set_mints_pub_client
4
+
5
+ ##
6
+ # === Mints Contact Login.
7
+ # Starts a contact session in mints.cloud and set a session cookie
8
+ def mints_contact_login(email, password)
9
+ # Login in mints
10
+ response = @mints_contact.login(email, password)
11
+ # Get session token from response
12
+ session_token = response['session_token']
13
+ id_token = response['contact']['id_token']
14
+ # Set a permanent cookie with the session token
15
+ cookies.permanent[:mints_contact_session_token] = session_token
16
+ cookies.permanent[:mints_contact_id] = id_token
17
+ @contact_token = id_token
18
+ end
19
+
20
+ ##
21
+ # === Mints Contact Logout.
22
+ # Destroy session from mints.cloud and delete local session cookie
23
+ def mints_contact_logout
24
+ # Logout from mints
25
+ @mints_contact.logout
26
+ # Delete local cookie
27
+ cookies.delete(:mints_contact_session_token)
28
+ cookies.delete(:mints_contact_id)
29
+ @contact_token = nil
30
+ end
31
+
32
+ private
33
+
34
+ ##
35
+ # === Set mints pub.
36
+ # Initialize the public client and set the contact token
37
+ def set_mints_pub_client
38
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
39
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
40
+ config = YAML.load template.result(binding)
41
+ @host = config["mints"]["host"]
42
+ @api_key = config["mints"]["api_key"]
43
+ @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
44
+ else
45
+ raise 'MintsBadCredentialsError'
46
+ end
47
+ # Initialize mints pub client, credentials taken from mints_config.yml.erb file
48
+ @mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
49
+ # Set contact token from cookie
50
+ @mints_pub.client.session_token = @contact_token
51
+ end
52
+ end
53
+ end
@@ -59,15 +59,16 @@ module Mints
59
59
  # === Set mints pub.
60
60
  # Initialize the public client and set the contact token
61
61
  def set_mints_pub_client
62
- if File.exists?("#{Rails.root}/mints_config.yml")
63
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
62
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
63
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
64
+ config = YAML.load template.result(binding)
64
65
  @host = config["mints"]["host"]
65
66
  @api_key = config["mints"]["api_key"]
66
67
  @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
67
68
  else
68
69
  raise 'MintsBadCredentialsError'
69
70
  end
70
- # Initialize mints pub client, credentials taken from mints_config.yml file
71
+ # Initialize mints pub client, credentials taken from mints_config.yml.erb file
71
72
  @mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
72
73
  # Set contact token from cookie
73
74
  @mints_pub.client.session_token = @contact_token
@@ -14,6 +14,11 @@ module Mints
14
14
  'Content-Type'=> 'application/json',
15
15
  'Accept'=> 'application/json'
16
16
  }
17
+ # Set contact token id as header
18
+ if cookies[:mints_contact_id]
19
+ headers['ContactToken'] = cookies[:mints_contact_id]
20
+ end
21
+ # Set contact session token as header
17
22
  if cookies[:mints_contact_session_token]
18
23
  session_token = cookies[:mints_contact_session_token]
19
24
  headers["Authorization"] = "Bearer #{session_token}"
@@ -75,11 +80,12 @@ module Mints
75
80
  private
76
81
 
77
82
  def set_config_variables
78
- if File.exists?("#{Rails.root}/mints_config.yml")
79
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
83
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
84
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
85
+ config = YAML.load template.result(binding)
80
86
  @host = config["mints"]["host"]
81
87
  @api_key = config["mints"]["api_key"]
82
- @redis_server = Redis.new(host: config['redis_cache']['redis_host']) if config['redis_cache']['use_cache']
88
+ @redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
83
89
  @redis_config = config['redis_cache']
84
90
  @use_cache = config['redis_cache']['use_cache']
85
91
  end
@@ -71,11 +71,12 @@ module Mints
71
71
  private
72
72
 
73
73
  def set_config_variables
74
- if File.exists?("#{Rails.root}/mints_config.yml")
75
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
74
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
75
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
76
+ config = YAML.load template.result(binding)
76
77
  @host = config["mints"]["host"]
77
78
  @api_key = config["mints"]["api_key"]
78
- @redis_server = Redis.new(host: config['redis_cache']['redis_host']) if config['redis_cache']['use_cache']
79
+ @redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
79
80
  @redis_config = config['redis_cache']
80
81
  @use_cache = config['redis_cache']['use_cache']
81
82
  end
@@ -14,7 +14,7 @@ module Mints
14
14
  'Content-Type'=> 'application/json',
15
15
  'Accept'=> 'application/json'
16
16
  }
17
- if cookies[:mints_contact_session_token]
17
+ if cookies[:mints_user_session_token]
18
18
  session_token = cookies[:mints_user_session_token]
19
19
  headers["Authorization"] = "Bearer #{session_token}"
20
20
  end
@@ -75,11 +75,12 @@ module Mints
75
75
  private
76
76
 
77
77
  def set_config_variables
78
- if File.exists?("#{Rails.root}/mints_config.yml")
79
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
78
+ if File.exists?("#{Rails.root}/mints_config.yml.erb")
79
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
80
+ config = YAML.load template.result(binding)
80
81
  @host = config["mints"]["host"]
81
82
  @api_key = config["mints"]["api_key"]
82
- @redis_server = Redis.new(host: config['redis_cache']['redis_host'])
83
+ @redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
83
84
  @redis_config = config['redis_cache']
84
85
  @use_cache = config['redis_cache']['use_cache'] if config['redis_cache']['use_cache']
85
86
  end
data/lib/pub.rb CHANGED
@@ -7,7 +7,7 @@ module Mints
7
7
  # == Usage example
8
8
  # Initialize
9
9
  # pub = Mints::Pub.new(mints_url, api_key)
10
- # or if host and api_key are provided by mints_config.yml
10
+ # or if host and api_key are provided by mints_config.yml.erb
11
11
  # pub = Mints::Pub.new
12
12
  # Call any function
13
13
  # pub.get_products
@@ -42,8 +42,8 @@ module Mints
42
42
  # * +contact_token+ - [String] Cookie 'mints_contact_id' value (mints_contact_token)
43
43
  # ==== Return
44
44
  # Returns a Client object
45
- def initialize(host, api_key, contact_token = nil, debug = false)
46
- @client = Mints::Client.new(host, api_key, contact_token, debug)
45
+ def initialize(host, api_key, contact_token_id = nil, debug = false)
46
+ @client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, debug)
47
47
  end
48
48
 
49
49
  ##
@@ -178,7 +178,7 @@ module Mints
178
178
  # ==== Parameters
179
179
  # * +data+ - [Hash] Data to be submited
180
180
  def submit_form(data)
181
- return @client.raw("post", "/forms/store", nil, data)
181
+ return @client.raw("post", "/content/forms/submit", nil, data)
182
182
  end
183
183
 
184
184
  ##
data/lib/user.rb CHANGED
@@ -29,7 +29,7 @@ module Mints
29
29
  class User
30
30
  attr_reader :client
31
31
  def initialize(host, api_key, session_token = nil, debug = false)
32
- @client = Mints::Client.new(host, api_key, 'user', session_token, debug)
32
+ @client = Mints::Client.new(host, api_key, 'user', session_token, nil, debug)
33
33
  end
34
34
 
35
35
  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.9
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Gomez Garcia, Omar Mora, Luis Payan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-28 00:00:00.000000000 Z
11
+ date: 2021-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -117,16 +117,17 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - Gemfile
120
- - Readme.md
120
+ - README.md
121
121
  - lib/client.rb
122
122
  - lib/contact.rb
123
- - lib/generators/mints_config.yml
123
+ - lib/generators/mints_config.yml.erb
124
124
  - lib/generators/mints_contact_controller.rb
125
125
  - lib/generators/mints_files_generator.rb
126
126
  - lib/generators/mints_public_controller.rb
127
127
  - lib/generators/mints_user_controller.rb
128
128
  - lib/mints.rb
129
129
  - lib/mints/controllers/admin_base_controller.rb
130
+ - lib/mints/controllers/base_api_controller.rb
130
131
  - lib/mints/controllers/base_controller.rb
131
132
  - lib/mints/controllers/contact_api_controller.rb
132
133
  - lib/mints/controllers/public_api_controller.rb
@@ -1,13 +0,0 @@
1
- # Mints connection configuration
2
- mints:
3
- host: http://your_host_goes_here.com
4
- api_key: your_mints_api_key_goes_here
5
- redis_cache:
6
- use_cache: boolean_value_to_enable_and_disable_cache
7
- redis_host: your_redis_host
8
- groups:
9
- - urls:
10
- - group_of_urls
11
- time: time_that_will_be_applied_to_urls_in_seconds
12
- sdk:
13
- debug: false