mints 0.0.19 → 0.0.20
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 +4 -4
- data/lib/client.rb +42 -18
- data/lib/contact.rb +1 -1
- data/lib/mints/controllers/base_api_controller.rb +2 -1
- data/lib/mints/controllers/base_controller.rb +7 -2
- data/lib/pub.rb +10 -9
- data/lib/user/content/pages.rb +7 -7
- data/lib/user.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 805f9ad3f355a55e73dfeea6ace38749e32fdb5eb8427f003bd520fcd04204e6
|
4
|
+
data.tar.gz: b5aeb908efaf757a6bb1acb32c57a0330cc597549acdc9b539a048aacf1e3211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d98cb6dd69f6e9e1e56f67ad1a352e865f8b71fea0ce1c4d207a78959ff3a28cdbda7aed3058a0b57f3d26ab9bff459de1cc7256ebd2268046c166e2d9afa22
|
7
|
+
data.tar.gz: 6bef5686332e40cf0c838bb0a7a32db247841864c3ac79e31f5eb0bfd934d13abd2e4061be0fa006f74f7b3ac2302ee613401958789da3b99d79492329b467a6
|
data/lib/client.rb
CHANGED
@@ -11,17 +11,21 @@ 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, compatibility_options = {})
|
24
|
-
|
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
|
28
|
+
base_url = @base_url if !base_url
|
25
29
|
uri = ""
|
26
30
|
if (options && options.class == Hash)
|
27
31
|
if (options[:jfilters] && options[:jfilters].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
|
-
|
55
|
-
|
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,7 +77,7 @@ module Mints
|
|
63
77
|
end
|
64
78
|
|
65
79
|
if !url_need_cache
|
66
|
-
response = self.send("#{@scope}_#{action}", "#{full_url}", compatibility_options)
|
80
|
+
response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
|
67
81
|
end
|
68
82
|
|
69
83
|
elsif action === 'create' or action === 'post'
|
@@ -88,7 +102,6 @@ module Mints
|
|
88
102
|
end
|
89
103
|
|
90
104
|
def method_missing(name, *args, &block)
|
91
|
-
puts name
|
92
105
|
name.to_s.include?("__") ? separator = "__" : separator = "_"
|
93
106
|
# split the name to identify their elements
|
94
107
|
name_spplited = name.to_s.split(separator)
|
@@ -124,7 +137,7 @@ module Mints
|
|
124
137
|
uri.query_values = args[1]
|
125
138
|
end
|
126
139
|
url = self.get_url(route, object, uri, slug)
|
127
|
-
response = self.send("#{@scope}_#{action}", url, compatibility_options)
|
140
|
+
response = self.send("#{@scope}_#{action}", url, nil, compatibility_options)
|
128
141
|
elsif action == "post" or action == "create"
|
129
142
|
if args[1].class == Hash
|
130
143
|
uri.query_values = args[1]
|
@@ -239,15 +252,20 @@ module Mints
|
|
239
252
|
end
|
240
253
|
|
241
254
|
# Start contact context
|
242
|
-
def contact_get(url, compatibility_options)
|
243
|
-
|
255
|
+
def contact_get(url, headers = nil, compatibility_options)
|
256
|
+
h = {
|
244
257
|
"ApiKey" => @api_key,
|
245
258
|
"Accept" => "application/json",
|
246
259
|
"ContactToken" => @contact_token_id
|
247
260
|
}
|
248
|
-
|
249
|
-
|
250
|
-
|
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)
|
251
269
|
end
|
252
270
|
|
253
271
|
def contact_post(url, data, compatibility_options)
|
@@ -273,14 +291,19 @@ module Mints
|
|
273
291
|
end
|
274
292
|
|
275
293
|
# Start User context
|
276
|
-
def user_get(url, compatibility_options)
|
277
|
-
|
294
|
+
def user_get(url, headers = nil, compatibility_options)
|
295
|
+
h = {
|
278
296
|
"Accept" => "application/json",
|
279
297
|
"ApiKey" => @api_key
|
280
298
|
}
|
281
|
-
|
282
|
-
|
283
|
-
|
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)
|
284
307
|
end
|
285
308
|
|
286
309
|
def user_post(url, data, compatibility_options)
|
@@ -321,6 +344,7 @@ module Mints
|
|
321
344
|
}
|
322
345
|
h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
|
323
346
|
h["ContactToken"] = @contact_token_id if @contact_token_id
|
347
|
+
h["Visit-Id"] = @visit_id if @visit_id
|
324
348
|
if headers
|
325
349
|
headers.each do |k,v|
|
326
350
|
h[k] = v
|
data/lib/contact.rb
CHANGED
@@ -16,7 +16,7 @@ module Mints
|
|
16
16
|
# ==== Return
|
17
17
|
# Returns a Contact object
|
18
18
|
def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
|
19
|
-
@client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
|
19
|
+
@client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, nil, debug)
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
@@ -116,7 +116,8 @@ module Mints
|
|
116
116
|
def set_mints_pub_client
|
117
117
|
|
118
118
|
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
119
|
-
@
|
119
|
+
@visit_id = cookies[:mints_visit_id] ? cookies[:mints_visit_id] : nil
|
120
|
+
@mints_pub = Mints::Pub.new(@host, @api_key, nil, @visit_id, @debug)
|
120
121
|
# Set contact token from cookie
|
121
122
|
@mints_pub.client.session_token = @contact_token
|
122
123
|
end
|
@@ -73,7 +73,7 @@ module Mints
|
|
73
73
|
puts "FULLPATH REQUEST: #{request.fullpath}"
|
74
74
|
puts "HEADERS REQUEST: #{request.headers}"
|
75
75
|
puts "IP REQUEST: #{request.ip}"
|
76
|
-
puts "REQUEST IP
|
76
|
+
puts "REQUEST IP ADDRESS: #{request['ip_address']}"
|
77
77
|
puts "REQUEST REMOTE IP: #{request['remote_ip']}"
|
78
78
|
end
|
79
79
|
response = @mints_pub.register_visit(request)
|
@@ -82,7 +82,11 @@ module Mints
|
|
82
82
|
end
|
83
83
|
@contact_token = response['contact_token'] ? response['contact_token'] : response['user_token']
|
84
84
|
@visit_id = response['visit_id']
|
85
|
+
if @debug
|
86
|
+
puts "VISIT ID: #{@visit_id}"
|
87
|
+
end
|
85
88
|
cookies.permanent[:mints_contact_id] = { value: @contact_token, secure: true, httponly: true }
|
89
|
+
cookies.permanent[:mints_visit_id] = { value: @visit_id, secure: true, httponly: true }
|
86
90
|
end
|
87
91
|
|
88
92
|
##
|
@@ -99,7 +103,8 @@ module Mints
|
|
99
103
|
raise 'MintsBadCredentialsError'
|
100
104
|
end
|
101
105
|
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
102
|
-
@
|
106
|
+
@visit_id = cookies[:mints_visit_id] ? cookies[:mints_visit_id] : nil
|
107
|
+
@mints_pub = Mints::Pub.new(@host, @api_key, @contact_token, @visit_id, @debug)
|
103
108
|
# Set contact token from cookie
|
104
109
|
@mints_pub.client.session_token = @contact_token
|
105
110
|
end
|
data/lib/pub.rb
CHANGED
@@ -83,8 +83,8 @@ module Mints
|
|
83
83
|
#
|
84
84
|
# ==== Return
|
85
85
|
# Returns a Client object.
|
86
|
-
def initialize(host, api_key, contact_token_id = nil,
|
87
|
-
@client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, debug)
|
86
|
+
def initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false)
|
87
|
+
@client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, visit_id, debug)
|
88
88
|
end
|
89
89
|
|
90
90
|
##
|
@@ -165,7 +165,7 @@ module Mints
|
|
165
165
|
# ==== Example
|
166
166
|
# @mints_pub.get_story("story_slug")
|
167
167
|
def get_story(slug, options = nil)
|
168
|
-
return @client.raw("get", "/content/stories/#{slug}", options)
|
168
|
+
return @client.raw("get", "/content/stories/#{slug}", options, nil, nil, nil, true)
|
169
169
|
end
|
170
170
|
|
171
171
|
##
|
@@ -192,7 +192,7 @@ module Mints
|
|
192
192
|
# ==== Example
|
193
193
|
# @mints_pub.get_form("form_slug")
|
194
194
|
def get_form(slug, options = nil)
|
195
|
-
return @client.raw("get", "/content/forms/#{slug}", options)
|
195
|
+
return @client.raw("get", "/content/forms/#{slug}", options, nil, nil, nil, true)
|
196
196
|
end
|
197
197
|
|
198
198
|
##
|
@@ -240,15 +240,16 @@ module Mints
|
|
240
240
|
return @client.raw("get", "/content/content-instances/#{slug}", options)
|
241
241
|
end
|
242
242
|
|
243
|
+
#TODO: This method is commented for future use
|
243
244
|
##
|
244
245
|
# === Get Content Pages.
|
245
246
|
# Get all content pages.
|
246
247
|
#
|
247
248
|
# ==== Parameters
|
248
249
|
# options:: (Hash) -- List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter.
|
249
|
-
def get_content_pages(options = nil)
|
250
|
-
return @client.raw("get", "/content/content-pages", options)
|
251
|
-
end
|
250
|
+
# def get_content_pages(options = nil)
|
251
|
+
#return @client.raw("get", "/content/content-pages", options)
|
252
|
+
#end
|
252
253
|
|
253
254
|
##
|
254
255
|
# === Get Content Page.
|
@@ -261,7 +262,7 @@ module Mints
|
|
261
262
|
# ==== Example
|
262
263
|
# @mints_pub.get_content_page("test-page")
|
263
264
|
def get_content_page(slug, options = nil)
|
264
|
-
return @client.raw("get", "/content/content-pages/#{slug}", options)
|
265
|
+
return @client.raw("get", "/content/content-pages/#{slug}", options, nil, nil, nil, true)
|
265
266
|
end
|
266
267
|
|
267
268
|
##
|
@@ -301,7 +302,7 @@ module Mints
|
|
301
302
|
# ==== Example
|
302
303
|
# @mints_pub.get_product("product_slug")
|
303
304
|
def get_product(slug, options = nil)
|
304
|
-
return @client.raw("get", "/ecommerce/products/#{slug}", options)
|
305
|
+
return @client.raw("get", "/ecommerce/products/#{slug}", options, nil, nil, nil, true)
|
305
306
|
end
|
306
307
|
|
307
308
|
##
|
data/lib/user/content/pages.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Pages
|
2
2
|
##
|
3
|
-
# == Pages
|
3
|
+
# == Content Pages
|
4
4
|
#
|
5
5
|
|
6
6
|
###
|
7
7
|
# === Get page groups.
|
8
|
-
# Get page groups.
|
8
|
+
# Get content page groups.
|
9
9
|
#
|
10
10
|
# ==== Example
|
11
11
|
# @data = @mints_user.get_page_groups
|
@@ -14,7 +14,7 @@ module Pages
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# === Get pages.
|
17
|
-
# Get a collection of pages.
|
17
|
+
# Get a collection of content pages.
|
18
18
|
#
|
19
19
|
# ==== Example
|
20
20
|
# @data = @mints_user.get_pages
|
@@ -23,7 +23,7 @@ module Pages
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# === Get page.
|
26
|
-
# Get a page.
|
26
|
+
# Get a content page.
|
27
27
|
#
|
28
28
|
# ==== Parameters
|
29
29
|
# id:: (Integer) -- Page id.
|
@@ -35,7 +35,7 @@ module Pages
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# === Create page.
|
38
|
-
# Create a page with data.
|
38
|
+
# Create a content page with data.
|
39
39
|
#
|
40
40
|
# ==== Parameters
|
41
41
|
# data:: (Hash) -- Data to be submited.
|
@@ -52,7 +52,7 @@ module Pages
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# === Update page.
|
55
|
-
# Update a page info.
|
55
|
+
# Update a content page info.
|
56
56
|
#
|
57
57
|
# ==== Parameters
|
58
58
|
# id:: (Integer) -- Page id.
|
@@ -68,7 +68,7 @@ module Pages
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# === Delete page.
|
71
|
-
# Delete a page.
|
71
|
+
# Delete a content page.
|
72
72
|
#
|
73
73
|
# ==== Parameters
|
74
74
|
# id:: (Integer) -- Page id.
|
data/lib/user.rb
CHANGED
@@ -48,7 +48,7 @@ module Mints
|
|
48
48
|
|
49
49
|
attr_reader :client
|
50
50
|
def initialize(host, api_key, session_token = nil, debug = false)
|
51
|
-
@client = Mints::Client.new(host, api_key, 'user', session_token, nil, debug)
|
51
|
+
@client = Mints::Client.new(host, api_key, 'user', session_token, nil, nil, debug)
|
52
52
|
end
|
53
53
|
|
54
54
|
def login(email, password)
|