mints 0.0.5 → 0.0.10
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/Readme.md +5 -5
- data/lib/client.rb +57 -20
- data/lib/contact.rb +1 -14
- data/lib/generators/mints_config.yml.erb +13 -0
- data/lib/generators/mints_contact_controller.rb +1 -0
- data/lib/generators/mints_files_generator.rb +1 -1
- data/lib/generators/mints_public_controller.rb +1 -0
- data/lib/generators/mints_user_controller.rb +1 -0
- data/lib/mints/controllers/admin_base_controller.rb +3 -2
- data/lib/mints/controllers/base_controller.rb +9 -3
- data/lib/mints/controllers/contact_api_controller.rb +58 -7
- data/lib/mints/controllers/public_api_controller.rb +60 -7
- data/lib/mints/controllers/user_api_controller.rb +57 -6
- data/lib/pub.rb +2 -2
- metadata +24 -4
- data/lib/generators/mints_config.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ade2308c58baa5c1b9ec010767f715069af50a2204820c3df6d4cb31231ad9de
|
4
|
+
data.tar.gz: 9a4ad29bac5f2a290e7c248619f2994dda26bff74686ee851e5cabd6ba321d6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345e8d6efdc4c0f114adb3a3f1a0840050d5b447a38d07acf13a0d49a1c839a8cb33d6bbec95fd52f23b490b06947c672650830d0d62f18f3892fccc1d0978d5
|
7
|
+
data.tar.gz: 6b8e8682b9c64126399f105ee562103d95ebd14b6484b3b40a59bcda2c84cff710188514ad83363e8778fa476fba149469a76a16c38a3396b2bb25e16a6a616f
|
data/Gemfile
CHANGED
data/Readme.md
CHANGED
@@ -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
@@ -1,6 +1,7 @@
|
|
1
1
|
require "httparty"
|
2
2
|
require "json"
|
3
3
|
require "addressable"
|
4
|
+
require "redis"
|
4
5
|
module Mints
|
5
6
|
class Client
|
6
7
|
attr_reader :host
|
@@ -24,10 +25,42 @@ module Mints
|
|
24
25
|
uri = Addressable::URI.new
|
25
26
|
uri.query_values = options
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
full_url = "#{@host}#{base_url}#{url}#{uri}"
|
29
|
-
|
30
|
-
|
30
|
+
response = nil
|
31
|
+
if action === 'get'
|
32
|
+
|
33
|
+
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
34
|
+
config = YAML.load template.result(binding)
|
35
|
+
url_need_cache = false
|
36
|
+
result_from_cache = false
|
37
|
+
time = 0
|
38
|
+
|
39
|
+
if config['redis_cache']['use_cache']
|
40
|
+
config['redis_cache']['groups'].each do |group|
|
41
|
+
group['urls'].each do |url|
|
42
|
+
if full_url.match url
|
43
|
+
time = group['time']
|
44
|
+
url_need_cache = true
|
45
|
+
@redis_server = Redis.new(host: config['redis_cache']['redis_host'])
|
46
|
+
if @redis_server.get(full_url)
|
47
|
+
response = @redis_server.get(full_url)
|
48
|
+
result_from_cache = true
|
49
|
+
else
|
50
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}")
|
51
|
+
@redis_server.setex(full_url,time,response)
|
52
|
+
end
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
break if url_need_cache
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if !url_need_cache
|
61
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}")
|
62
|
+
end
|
63
|
+
|
31
64
|
elsif action === 'create' or action === 'post'
|
32
65
|
action = 'post'
|
33
66
|
response = self.send("#{@scope}_#{action}", "#{full_url}", data)
|
@@ -35,14 +68,15 @@ module Mints
|
|
35
68
|
action = 'put'
|
36
69
|
response = self.send("#{@scope}_#{action}", "#{full_url}", data)
|
37
70
|
end
|
38
|
-
if
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
71
|
+
if result_from_cache
|
72
|
+
return parsed_response = JSON.parse(response)
|
73
|
+
else
|
74
|
+
if (response.response.code == "404")
|
75
|
+
raise 'NotFoundError'
|
76
|
+
end
|
77
|
+
parsed_response = JSON.parse(response.body)
|
78
|
+
return parsed_response
|
79
|
+
end
|
46
80
|
end
|
47
81
|
|
48
82
|
def method_missing(name, *args, &block)
|
@@ -183,7 +217,8 @@ module Mints
|
|
183
217
|
def contact_get(url)
|
184
218
|
headers = {
|
185
219
|
"ApiKey" => @api_key,
|
186
|
-
"Accept" => "application/json"
|
220
|
+
"Accept" => "application/json",
|
221
|
+
"ContactToken" => @contact_token
|
187
222
|
}
|
188
223
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
189
224
|
return self.http_get(url, headers)
|
@@ -192,7 +227,8 @@ module Mints
|
|
192
227
|
def contact_post(url, data)
|
193
228
|
headers = {
|
194
229
|
"ApiKey" => @api_key,
|
195
|
-
"Accept" => "application/json"
|
230
|
+
"Accept" => "application/json",
|
231
|
+
"ContactToken" => @contact_token
|
196
232
|
}
|
197
233
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
198
234
|
return self.http_post(url, headers, data)
|
@@ -201,7 +237,8 @@ module Mints
|
|
201
237
|
def contact_put(url, data)
|
202
238
|
headers = {
|
203
239
|
"ApiKey" => @api_key,
|
204
|
-
"Accept" => "application/json"
|
240
|
+
"Accept" => "application/json",
|
241
|
+
"ContactToken" => @contact_token
|
205
242
|
}
|
206
243
|
headers["Authorization"] = "Bearer #{@session_token}" if @session_token
|
207
244
|
return self.http_post(url, headers, data)
|
@@ -241,9 +278,9 @@ module Mints
|
|
241
278
|
h = {
|
242
279
|
"Accept" => "application/json",
|
243
280
|
"Content-Type" => "application/json",
|
244
|
-
"ApiKey" => @api_key
|
245
|
-
"ContactToken" => @session_token
|
281
|
+
"ApiKey" => @api_key
|
246
282
|
}
|
283
|
+
h["ContactToken"] = @contact_token if @contact_token
|
247
284
|
if headers
|
248
285
|
headers.each do |k,v|
|
249
286
|
h[k] = v
|
@@ -256,9 +293,9 @@ module Mints
|
|
256
293
|
h = {
|
257
294
|
"Accept" => "application/json",
|
258
295
|
"Content-Type" => "application/json",
|
259
|
-
"ApiKey" => @api_key
|
260
|
-
"ContactToken" => @session_token
|
296
|
+
"ApiKey" => @api_key
|
261
297
|
}
|
298
|
+
h["ContactToken"] = @session_token if @session_token
|
262
299
|
if headers
|
263
300
|
headers.each do |k,v|
|
264
301
|
h[k] = v
|
@@ -271,9 +308,9 @@ module Mints
|
|
271
308
|
h = {
|
272
309
|
"Accept" => "application/json",
|
273
310
|
"Content-Type" => "application/json",
|
274
|
-
"ApiKey" => @api_key
|
275
|
-
"ContactToken" => @session_token
|
311
|
+
"ApiKey" => @api_key
|
276
312
|
}
|
313
|
+
h["ContactToken"] = @contact_token if @contact_token
|
277
314
|
if headers
|
278
315
|
headers.each do |k,v|
|
279
316
|
h[k] = v
|
data/lib/contact.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "./client.rb"
|
2
|
+
include ActionController::Cookies
|
2
3
|
module Mints
|
3
4
|
class Contact
|
4
5
|
attr_reader :client
|
@@ -10,20 +11,6 @@ module Mints
|
|
10
11
|
@client = Mints::Client.new(host, api_key, "contact", session_token, debug)
|
11
12
|
end
|
12
13
|
|
13
|
-
##
|
14
|
-
# === Register.
|
15
|
-
# Register a new contact
|
16
|
-
#
|
17
|
-
def register(given_name, last_name, email, password)
|
18
|
-
data = {
|
19
|
-
given_name: given_name,
|
20
|
-
last_name: last_name,
|
21
|
-
email: email,
|
22
|
-
password: password
|
23
|
-
}
|
24
|
-
return @client.raw("post", "/contacts/register", nil, {data: data})
|
25
|
-
end
|
26
|
-
|
27
14
|
##
|
28
15
|
# === Login.
|
29
16
|
# Starts a contact session
|
@@ -0,0 +1,13 @@
|
|
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
|
@@ -2,7 +2,7 @@ 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'
|
@@ -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
|
-
|
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
|
@@ -24,8 +24,11 @@ module Mints
|
|
24
24
|
response = @mints_contact.login(email, password)
|
25
25
|
# Get session token from response
|
26
26
|
session_token = response['session_token']
|
27
|
+
id_token = response['contact']['id_token']
|
27
28
|
# Set a permanent cookie with the session token
|
28
29
|
cookies.permanent[:mints_contact_session_token] = session_token
|
30
|
+
cookies.permanent[:mints_contact_id] = id_token
|
31
|
+
@contact_token = id_token
|
29
32
|
end
|
30
33
|
|
31
34
|
##
|
@@ -36,6 +39,8 @@ module Mints
|
|
36
39
|
@mints_contact.logout
|
37
40
|
# Delete local cookie
|
38
41
|
cookies.delete(:mints_contact_session_token)
|
42
|
+
cookies.delete(:mints_contact_id)
|
43
|
+
@contact_token = nil
|
39
44
|
end
|
40
45
|
|
41
46
|
private
|
@@ -54,15 +59,16 @@ module Mints
|
|
54
59
|
# === Set mints pub.
|
55
60
|
# Initialize the public client and set the contact token
|
56
61
|
def set_mints_pub_client
|
57
|
-
if File.exists?("#{Rails.root}/mints_config.yml")
|
58
|
-
|
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)
|
59
65
|
@host = config["mints"]["host"]
|
60
66
|
@api_key = config["mints"]["api_key"]
|
61
67
|
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
62
68
|
else
|
63
69
|
raise 'MintsBadCredentialsError'
|
64
70
|
end
|
65
|
-
# Initialize mints pub client, credentials taken from mints_config.yml file
|
71
|
+
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
66
72
|
@mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
|
67
73
|
# Set contact token from cookie
|
68
74
|
@mints_pub.client.session_token = @contact_token
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'reverse_proxy/controller'
|
2
|
+
require 'reverse_proxy/client'
|
2
3
|
module Mints
|
3
4
|
class ContactAPIController < ActionController::API
|
4
5
|
include AbstractController::Helpers
|
@@ -17,10 +18,56 @@ module Mints
|
|
17
18
|
session_token = cookies[:mints_contact_session_token]
|
18
19
|
headers["Authorization"] = "Bearer #{session_token}"
|
19
20
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
|
22
|
+
url_need_cache = false
|
23
|
+
result_from_cache = false
|
24
|
+
time = 0
|
25
|
+
full_url = request.original_url
|
26
|
+
|
27
|
+
if request.method == "GET"
|
28
|
+
if @use_cache
|
29
|
+
@redis_config['groups'].each do |group|
|
30
|
+
group['urls'].each do |url|
|
31
|
+
if full_url.match url
|
32
|
+
time = group['time']
|
33
|
+
url_need_cache = true
|
34
|
+
break
|
35
|
+
end
|
36
|
+
end
|
37
|
+
break if url_need_cache
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if url_need_cache
|
43
|
+
if @redis_server.get(full_url)
|
44
|
+
response = @redis_server.get(full_url)
|
45
|
+
result_from_cache = true
|
46
|
+
render json: response
|
47
|
+
else
|
48
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
49
|
+
# Request succeded!
|
50
|
+
config.on_response do |code, response|
|
51
|
+
@redis_server.setex(full_url,time,response.body)
|
52
|
+
end
|
53
|
+
# Request failed!
|
54
|
+
config.on_missing do |code, response|
|
55
|
+
# We got a 404!
|
56
|
+
if code == 404
|
57
|
+
raise ActionController::RoutingError.new('Not Found')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
64
|
+
# Request failed!
|
65
|
+
config.on_missing do |code, response|
|
66
|
+
# We got a 404!
|
67
|
+
if code == 404
|
68
|
+
raise ActionController::RoutingError.new('Not Found')
|
69
|
+
end
|
70
|
+
end
|
24
71
|
end
|
25
72
|
end
|
26
73
|
end
|
@@ -28,10 +75,14 @@ module Mints
|
|
28
75
|
private
|
29
76
|
|
30
77
|
def set_config_variables
|
31
|
-
if File.exists?("#{Rails.root}/mints_config.yml")
|
32
|
-
|
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)
|
33
81
|
@host = config["mints"]["host"]
|
34
|
-
@api_key = config["mints"]["api_key"]
|
82
|
+
@api_key = config["mints"]["api_key"]
|
83
|
+
@redis_server = Redis.new(host: config['redis_cache']['redis_host']) if config['redis_cache']['use_cache']
|
84
|
+
@redis_config = config['redis_cache']
|
85
|
+
@use_cache = config['redis_cache']['use_cache']
|
35
86
|
end
|
36
87
|
end
|
37
88
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'reverse_proxy/controller'
|
2
|
+
require 'reverse_proxy/client'
|
3
|
+
require 'redis'
|
2
4
|
module Mints
|
3
5
|
class PublicAPIController < ActionController::API
|
4
6
|
include ReverseProxy::Controller
|
@@ -11,21 +13,72 @@ module Mints
|
|
11
13
|
'Content-Type'=> 'application/json',
|
12
14
|
'Accept'=> 'application/json'
|
13
15
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
url_need_cache = false
|
18
|
+
result_from_cache = false
|
19
|
+
time = 0
|
20
|
+
full_url = request.original_url
|
21
|
+
|
22
|
+
if request.method == "GET"
|
23
|
+
if @use_cache
|
24
|
+
@redis_config['groups'].each do |group|
|
25
|
+
group['urls'].each do |url|
|
26
|
+
if full_url.match url
|
27
|
+
time = group['time']
|
28
|
+
url_need_cache = true
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
32
|
+
break if url_need_cache
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if url_need_cache
|
38
|
+
if @redis_server.get(full_url)
|
39
|
+
response = @redis_server.get(full_url)
|
40
|
+
result_from_cache = true
|
41
|
+
render json: response
|
42
|
+
else
|
43
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
44
|
+
# Request succeded!
|
45
|
+
config.on_response do |code, response|
|
46
|
+
@redis_server.setex(full_url,time,response.body)
|
47
|
+
end
|
48
|
+
# Request failed!
|
49
|
+
config.on_missing do |code, response|
|
50
|
+
# We got a 404!
|
51
|
+
if code == 404
|
52
|
+
raise ActionController::RoutingError.new('Not Found')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
59
|
+
# Request failed!
|
60
|
+
config.on_missing do |code, response|
|
61
|
+
# We got a 404!
|
62
|
+
if code == 404
|
63
|
+
raise ActionController::RoutingError.new('Not Found')
|
64
|
+
end
|
65
|
+
end
|
18
66
|
end
|
19
67
|
end
|
68
|
+
|
20
69
|
end
|
21
70
|
|
22
71
|
private
|
23
72
|
|
24
73
|
def set_config_variables
|
25
|
-
if File.exists?("#{Rails.root}/mints_config.yml")
|
26
|
-
|
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)
|
27
77
|
@host = config["mints"]["host"]
|
28
|
-
@api_key = config["mints"]["api_key"]
|
78
|
+
@api_key = config["mints"]["api_key"]
|
79
|
+
@redis_server = Redis.new(host: config['redis_cache']['redis_host']) if config['redis_cache']['use_cache']
|
80
|
+
@redis_config = config['redis_cache']
|
81
|
+
@use_cache = config['redis_cache']['use_cache']
|
29
82
|
end
|
30
83
|
end
|
31
84
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'reverse_proxy/controller'
|
2
|
+
require 'reverse_proxy/client'
|
2
3
|
module Mints
|
3
4
|
class UserAPIController < ActionController::API
|
4
5
|
include AbstractController::Helpers
|
@@ -17,10 +18,56 @@ module Mints
|
|
17
18
|
session_token = cookies[:mints_user_session_token]
|
18
19
|
headers["Authorization"] = "Bearer #{session_token}"
|
19
20
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
|
22
|
+
url_need_cache = false
|
23
|
+
result_from_cache = false
|
24
|
+
time = 0
|
25
|
+
full_url = request.original_url
|
26
|
+
|
27
|
+
if request.method == "GET"
|
28
|
+
if url_need_cache
|
29
|
+
@redis_config['groups'].each do |group|
|
30
|
+
group['urls'].each do |url|
|
31
|
+
if full_url.match url
|
32
|
+
time = group['time']
|
33
|
+
url_need_cache = true
|
34
|
+
break
|
35
|
+
end
|
36
|
+
end
|
37
|
+
break if url_need_cache
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if url_need_cache
|
43
|
+
if @redis_server.get(full_url)
|
44
|
+
response = @redis_server.get(full_url)
|
45
|
+
result_from_cache = true
|
46
|
+
render json: response
|
47
|
+
else
|
48
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
49
|
+
# Request succeded!
|
50
|
+
config.on_response do |code, response|
|
51
|
+
@redis_server.setex(full_url,time,response.body)
|
52
|
+
end
|
53
|
+
# Request failed!
|
54
|
+
config.on_missing do |code, response|
|
55
|
+
# We got a 404!
|
56
|
+
if code == 404
|
57
|
+
raise ActionController::RoutingError.new('Not Found')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
64
|
+
# Request failed!
|
65
|
+
config.on_missing do |code, response|
|
66
|
+
# We got a 404!
|
67
|
+
if code == 404
|
68
|
+
raise ActionController::RoutingError.new('Not Found')
|
69
|
+
end
|
70
|
+
end
|
24
71
|
end
|
25
72
|
end
|
26
73
|
end
|
@@ -28,10 +75,14 @@ module Mints
|
|
28
75
|
private
|
29
76
|
|
30
77
|
def set_config_variables
|
31
|
-
if File.exists?("#{Rails.root}/mints_config.yml")
|
32
|
-
|
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)
|
33
81
|
@host = config["mints"]["host"]
|
34
82
|
@api_key = config["mints"]["api_key"]
|
83
|
+
@redis_server = Redis.new(host: config['redis_cache']['redis_host'])
|
84
|
+
@redis_config = config['redis_cache']
|
85
|
+
@use_cache = config['redis_cache']['use_cache'] if config['redis_cache']['use_cache']
|
35
86
|
end
|
36
87
|
end
|
37
88
|
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
|
@@ -61,7 +61,7 @@ module Mints
|
|
61
61
|
user_agent: user_agent || request.user_agent,
|
62
62
|
url: url || request.fullpath
|
63
63
|
}
|
64
|
-
response = @client.raw("post", "/register-visit", nil, data)
|
64
|
+
response = @client.raw("post", "/register-visit", nil, data.to_json)
|
65
65
|
return response
|
66
66
|
end
|
67
67
|
|
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.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Ruben Gomez Garcia, Omar Mora
|
7
|
+
- Ruben Gomez Garcia, Omar Mora, Luis Payan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -50,6 +50,26 @@ dependencies:
|
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 0.18.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: redis
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 4.2.2
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 4.2.2
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.2.2
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 4.2.2
|
53
73
|
- !ruby/object:Gem::Dependency
|
54
74
|
name: addressable
|
55
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,7 +120,7 @@ files:
|
|
100
120
|
- Readme.md
|
101
121
|
- lib/client.rb
|
102
122
|
- lib/contact.rb
|
103
|
-
- lib/generators/mints_config.yml
|
123
|
+
- lib/generators/mints_config.yml.erb
|
104
124
|
- lib/generators/mints_contact_controller.rb
|
105
125
|
- lib/generators/mints_files_generator.rb
|
106
126
|
- lib/generators/mints_public_controller.rb
|