mints 0.0.21 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/client.rb +394 -386
  3. data/lib/pub.rb +12 -12
  4. metadata +3 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2ab9b781d2576391b638771babe904c816f97dffb6e98644b98cd1906b3232d
4
- data.tar.gz: 4f065c57fab622ded6e65800a2eaa82d4d6773d66b313a8f0e2567d403645a02
3
+ metadata.gz: d71005d83085eec4a71aeeb68e1e83604aad1bdb2c9d6d9670e26d80833c968a
4
+ data.tar.gz: 6f469fe73f04248e1b227599d20273ea3de7f78555383b541cb18c1aec42ef03
5
5
  SHA512:
6
- metadata.gz: 52c8490021563ebfac12d93269c0757911647e8a7cefa99c42fb1cec62e956bde9427e19ad49353ae6aa688d359efbba4415e26fb0a290fd028b342c1c173454
7
- data.tar.gz: 88308f8b8536122d4db1bf38338cbd140f26edad3cf5ae7427d561941b2ab9ff1101135b2fdb5d3c1de8ea1d3b2d8a3a307ac5578c75ccfb5a025a9d999fda27
6
+ metadata.gz: 1dd19261bd09205152b353ec7770a82d20bea5e13bd5a75b938d6685de21c4fce334101249ee2d2f7a91d2a626cc1b980704dfe015cb83bd510407d3fe8bf9b6
7
+ data.tar.gz: 33c6fbbfdf46ca5b1fd330a80d05ff3efceb70ebe2406b6d943e19dc3b40c31953d86a8d20d9339eea44a3a0972f1f8169034ac000256c5c5664f618e2bf21eb
data/lib/client.rb CHANGED
@@ -1,386 +1,394 @@
1
- require "httparty"
2
- require "json"
3
- require "addressable"
4
- require "redis"
5
- module Mints
6
- class Client
7
- attr_reader :host
8
- attr_reader :api_key
9
- attr_reader :scope
10
- attr_reader :base_url
11
- attr_accessor :session_token
12
- attr_accessor :contact_token_id
13
-
14
- def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, visit_id = nil, debug = false)
15
- @host = host
16
- @api_key = api_key
17
- @session_token = session_token
18
- @contact_token_id = contact_token_id
19
- @visit_id = visit_id
20
- @debug = debug
21
- self.set_scope(scope)
22
- end
23
-
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
29
- uri = ""
30
- if (options && options.class == Hash)
31
- if (options[:jfilters] && options[:jfilters].class == Hash)
32
- options[:jfilters] = Base64.encode64(JSON.generate(options[:jfilters]))
33
- end
34
- uri = Addressable::URI.new
35
- uri.query_values = options
36
- end
37
-
38
- full_url = "#{@host}#{base_url}#{url}#{uri}"
39
- response = nil
40
- if action === 'get'
41
-
42
- template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
43
- config = YAML.load template.result(binding)
44
- url_need_cache = false
45
- result_from_cache = false
46
- time = 0
47
-
48
- if config['redis_cache']['use_cache']
49
- config['redis_cache']['groups'].each do |group|
50
- group['urls'].each do |url|
51
- if full_url.match url
52
- time = group['time']
53
- url_need_cache = true
54
- @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)
55
- if @redis_server.get(full_url)
56
- response = @redis_server.get(full_url)
57
- result_from_cache = true
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)
70
- @redis_server.setex(full_url,time,response)
71
- end
72
- break
73
- end
74
- end
75
- break if url_need_cache
76
- end
77
- end
78
-
79
- if !url_need_cache
80
- response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
81
- end
82
-
83
- elsif action === 'create' or action === 'post'
84
- action = 'post'
85
- response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
86
- elsif action === 'put' or action === 'patch' or action ==='update'
87
- action = 'put'
88
- response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
89
- elsif action === 'delete' or action === 'destroy'
90
- action = 'delete'
91
- response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
92
- end
93
- if result_from_cache
94
- return parsed_response = JSON.parse(response)
95
- else
96
- if (response.response.code == "404")
97
- raise 'NotFoundError'
98
- end
99
- parsed_response = JSON.parse(response.body)
100
- return parsed_response
101
- end
102
- end
103
-
104
- def method_missing(name, *args, &block)
105
- name.to_s.include?("__") ? separator = "__" : separator = "_"
106
- # split the name to identify their elements
107
- name_spplited = name.to_s.split(separator)
108
- # count the elments
109
- name_len = name_spplited.size
110
- # the action always be the first element
111
- action = name_spplited.first
112
- raise 'NoActionError' unless ['get', 'create', 'post', 'update', 'put', 'delete', 'destroy'].include?(action)
113
- # the object always be the last element
114
- object = separator == "__" ? name_spplited.last.gsub("_","-") : name_spplited.last
115
- # get intermediate url elements
116
- route_array = []
117
- (name_len-1).times do |n|
118
- if n == 0 or n == name_len-1
119
- next
120
- end
121
- n = name_spplited[n]
122
- self.replacements().each do |object|
123
- n = n.gsub(object[:old_value], object[:new_value])
124
- end
125
- route_array.push n
126
- end
127
- route = route_array.join("/")
128
-
129
-
130
- slug = nil
131
- uri = Addressable::URI.new
132
- if action == "get"
133
- if args.first.class == Hash
134
- uri.query_values = args.first
135
- elsif args.first.class == String or Integer
136
- slug = args.first
137
- uri.query_values = args[1]
138
- end
139
- url = self.get_url(route, object, uri, slug)
140
- response = self.send("#{@scope}_#{action}", url, nil, compatibility_options)
141
- elsif action == "post" or action == "create"
142
- if args[1].class == Hash
143
- uri.query_values = args[1]
144
- end
145
- url = self.get_url(route, object, uri, slug)
146
- action = 'post'
147
- data = args[0]
148
- response = self.send("#{@scope}_#{action}", url, {data: data}, compatibility_options)
149
- elsif action == "put" or action == "update"
150
- if args.first.class == String or Integer
151
- slug = args.first
152
- uri.query_values = args[2]
153
- end
154
- url = self.get_url(route, object, uri, slug)
155
- action = 'put'
156
- id = args[0]
157
- data = args[1]
158
- response = self.send("#{@scope}_#{action}", "#{url}", {data: data}, compatibility_options)
159
- end
160
-
161
- if response.response.code == "404"
162
- raise 'NotFoundError'
163
- elsif response.response.code == "500"
164
- raise 'InternalServerError'
165
- end
166
- return JSON.parse(response.body)
167
- end
168
-
169
- def get_url(route, object, uri, slug = nil)
170
- if (slug)
171
- return "#{@host}#{@base_url}/#{route}/#{object}/#{slug}#{uri}"
172
- else
173
- return "#{@host}#{@base_url}/#{route}/#{object}#{uri}"
174
- end
175
- end
176
-
177
- def replacements
178
- return [
179
- {old_value: '_', new_value: '-'},
180
- {old_value: 'people', new_value: 'crm'},
181
- {old_value: 'store', new_value: 'ecommerce'}
182
- ]
183
- end
184
-
185
- def set_scope(scope)
186
- @scope = scope
187
- if scope == "public"
188
- @base_url = "/api/v1"
189
- elsif scope == "contact"
190
- @base_url = "/api/v1"
191
- elsif scope == "user"
192
- @base_url = "/api/user/v1"
193
- else
194
- @scope = "public"
195
- @base_url = "/api/v1"
196
- end
197
- end
198
-
199
- ##### HTTTP CLIENTS ######
200
- # Simple HTTP GET
201
- def http_get(url, headers = nil)
202
- if @debug
203
- puts "Url:"
204
- puts url
205
- puts "Headers:"
206
- puts headers
207
- puts "Method: get"
208
- end
209
- return headers ? HTTParty.get(url, :headers => headers) : HTTParty.get(url)
210
- end
211
-
212
- # Simple HTTP POST
213
- def http_post(url, headers = nil, data = nil)
214
- if @debug
215
- puts "Url:"
216
- puts url
217
- puts "Headers:"
218
- puts headers
219
- puts "Data:"
220
- puts data
221
- puts "Method: post"
222
- end
223
- return headers ? HTTParty.post(url, :headers=> headers, :body => data) : HTTParty.post(url, :body => data)
224
- end
225
-
226
- # Simple HTTP PUT
227
- def http_put(url, headers = nil, data = nil)
228
- if @debug
229
- puts "Url:"
230
- puts url
231
- puts "Headers:"
232
- puts headers
233
- puts "Data:"
234
- puts data
235
- puts "Method: put"
236
- end
237
- return headers ? HTTParty.put(url, :headers=> headers, :body => data) : HTTParty.put(url, :body => data)
238
- end
239
-
240
- # Simple HTTP DELETE
241
- def http_delete(url, headers = nil, data = nil)
242
- if @debug
243
- puts "Url:"
244
- puts url
245
- puts "Headers:"
246
- puts headers
247
- puts "Data:"
248
- puts data
249
- puts "Method: delete"
250
- end
251
- return headers ? HTTParty.delete(url, :headers=> headers, :body => data) : HTTParty.delete(url, :body => data)
252
- end
253
-
254
- # Start contact context
255
- def contact_get(url, headers = nil, compatibility_options)
256
- h = {
257
- "ApiKey" => @api_key,
258
- "Accept" => "application/json",
259
- "ContactToken" => @contact_token_id
260
- }
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)
269
- end
270
-
271
- def contact_post(url, data, compatibility_options)
272
- headers = {
273
- "ApiKey" => @api_key,
274
- "Accept" => "application/json",
275
- "ContactToken" => @contact_token_id
276
- }
277
- headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
278
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
279
- return self.http_post(url, headers, data)
280
- end
281
-
282
- def contact_put(url, data, compatibility_options)
283
- headers = {
284
- "ApiKey" => @api_key,
285
- "Accept" => "application/json",
286
- "ContactToken" => @contact_token_id
287
- }
288
- headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
289
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
290
- return self.http_put(url, headers, data)
291
- end
292
-
293
- # Start User context
294
- def user_get(url, headers = nil, compatibility_options)
295
- h = {
296
- "Accept" => "application/json",
297
- "ApiKey" => @api_key
298
- }
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)
307
- end
308
-
309
- def user_post(url, data, compatibility_options)
310
- headers = {
311
- "Accept" => "application/json",
312
- "ApiKey" => @api_key
313
- }
314
- headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
315
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
316
- return self.http_post(url, headers, data)
317
- end
318
-
319
- def user_put(url, data, compatibility_options)
320
- headers = {
321
- "Accept" => "application/json",
322
- "ApiKey" => @api_key
323
- }
324
- headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
325
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
326
- return self.http_put(url, headers, data)
327
- end
328
-
329
- def user_delete(url, data, compatibility_options)
330
- headers = {
331
- "Accept" => "application/json",
332
- "ApiKey" => @api_key
333
- }
334
- headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
335
- headers["Authorization"] = "Bearer #{@session_token}" if @session_token
336
- return self.http_delete(url, headers, data)
337
- end
338
- # End User Context
339
-
340
- def public_get(url, headers = nil, compatibility_options)
341
- h = {
342
- "Accept" => "application/json",
343
- "ApiKey" => @api_key
344
- }
345
- h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
346
- h["ContactToken"] = @contact_token_id if @contact_token_id
347
- h["Visit-Id"] = @visit_id if @visit_id
348
- if headers
349
- headers.each do |k,v|
350
- h[k] = v
351
- end
352
- end
353
- self.http_get(url, h)
354
- end
355
-
356
- def public_post(url, headers = nil, data, compatibility_options)
357
- h = {
358
- "Accept" => "application/json",
359
- "ApiKey" => @api_key
360
- }
361
- h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
362
- h["ContactToken"] = @session_token if @session_token
363
- if headers
364
- headers.each do |k,v|
365
- h[k] = v
366
- end
367
- end
368
- self.http_post(url, h, data)
369
- end
370
-
371
- def public_put(url, headers = nil, data, compatibility_options)
372
- h = {
373
- "Accept" => "application/json",
374
- "ApiKey" => @api_key
375
- }
376
- h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
377
- h["ContactToken"] = @contact_token_id if @contact_token_id
378
- if headers
379
- headers.each do |k,v|
380
- h[k] = v
381
- end
382
- end
383
- self.http_put(url, h, data)
384
- end
385
- end
386
- end
1
+ require "httparty"
2
+ require "json"
3
+ require "addressable"
4
+ require "redis"
5
+ module Mints
6
+ class Client
7
+ attr_reader :host
8
+ attr_reader :api_key
9
+ attr_reader :scope
10
+ attr_reader :base_url
11
+ attr_accessor :session_token
12
+ attr_accessor :contact_token_id
13
+
14
+ def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, visit_id = nil, debug = false)
15
+ @host = host
16
+ @api_key = api_key
17
+ @session_token = session_token
18
+ @contact_token_id = contact_token_id
19
+ @visit_id = visit_id
20
+ @debug = debug
21
+ self.set_scope(scope)
22
+ end
23
+
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
29
+ uri = ""
30
+ if (options && options.class == Hash)
31
+ if (options[:jfilters] && options[:jfilters].class == Hash)
32
+ options[:jfilters] = Base64.encode64(JSON.generate(options[:jfilters]))
33
+ end
34
+ uri = Addressable::URI.new
35
+ uri.query_values = options
36
+ end
37
+
38
+ full_url = "#{@host}#{base_url}#{url}#{uri}"
39
+ response = nil
40
+ if action === 'get'
41
+
42
+ template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
43
+ config = YAML.load template.result(binding)
44
+ url_need_cache = false
45
+ result_from_cache = false
46
+ time = 0
47
+
48
+ if config['redis_cache']['use_cache']
49
+ config['redis_cache']['groups'].each do |group|
50
+ group['urls'].each do |url|
51
+ if full_url.match url
52
+ time = group['time']
53
+ url_need_cache = true
54
+ @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)
55
+ redis_response = @redis_server.get(full_url)
56
+ if redis_response
57
+ response = redis_response
58
+ result_from_cache = true
59
+
60
+ headers = nil
61
+ if only_tracking
62
+ headers = {"Only-Tracking" => "true"}
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 TRACKING RESPONSE: #{cali_response}"
67
+ end
68
+ end
69
+
70
+ if @debug
71
+ puts "REDIS RESPONSE: #{redis_response}"
72
+ end
73
+ else
74
+ response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
75
+ @redis_server.setex(full_url,time,response)
76
+ end
77
+ break
78
+ end
79
+ end
80
+ break if url_need_cache
81
+ end
82
+ end
83
+
84
+ if !url_need_cache
85
+ response = self.send("#{@scope}_#{action}", "#{full_url}", nil, compatibility_options)
86
+ end
87
+
88
+ elsif action === 'create' or action === 'post'
89
+ action = 'post'
90
+ response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
91
+ elsif action === 'put' or action === 'patch' or action ==='update'
92
+ action = 'put'
93
+ response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
94
+ elsif action === 'delete' or action === 'destroy'
95
+ action = 'delete'
96
+ response = self.send("#{@scope}_#{action}", "#{full_url}", data, compatibility_options)
97
+ end
98
+ begin
99
+ if result_from_cache
100
+ return JSON.parse(response)
101
+ else
102
+ if (response.response.code == "404")
103
+ raise 'NotFoundError'
104
+ end
105
+ return JSON.parse(response.body)
106
+ end
107
+ rescue
108
+ return response
109
+ end
110
+ end
111
+
112
+ def method_missing(name, *args, &block)
113
+ name.to_s.include?("__") ? separator = "__" : separator = "_"
114
+ # split the name to identify their elements
115
+ name_spplited = name.to_s.split(separator)
116
+ # count the elments
117
+ name_len = name_spplited.size
118
+ # the action always be the first element
119
+ action = name_spplited.first
120
+ raise 'NoActionError' unless ['get', 'create', 'post', 'update', 'put', 'delete', 'destroy'].include?(action)
121
+ # the object always be the last element
122
+ object = separator == "__" ? name_spplited.last.gsub("_","-") : name_spplited.last
123
+ # get intermediate url elements
124
+ route_array = []
125
+ (name_len-1).times do |n|
126
+ if n == 0 or n == name_len-1
127
+ next
128
+ end
129
+ n = name_spplited[n]
130
+ self.replacements().each do |object|
131
+ n = n.gsub(object[:old_value], object[:new_value])
132
+ end
133
+ route_array.push n
134
+ end
135
+ route = route_array.join("/")
136
+
137
+
138
+ slug = nil
139
+ uri = Addressable::URI.new
140
+ if action == "get"
141
+ if args.first.class == Hash
142
+ uri.query_values = args.first
143
+ elsif args.first.class == String or Integer
144
+ slug = args.first
145
+ uri.query_values = args[1]
146
+ end
147
+ url = self.get_url(route, object, uri, slug)
148
+ response = self.send("#{@scope}_#{action}", url, nil, compatibility_options)
149
+ elsif action == "post" or action == "create"
150
+ if args[1].class == Hash
151
+ uri.query_values = args[1]
152
+ end
153
+ url = self.get_url(route, object, uri, slug)
154
+ action = 'post'
155
+ data = args[0]
156
+ response = self.send("#{@scope}_#{action}", url, {data: data}, compatibility_options)
157
+ elsif action == "put" or action == "update"
158
+ if args.first.class == String or Integer
159
+ slug = args.first
160
+ uri.query_values = args[2]
161
+ end
162
+ url = self.get_url(route, object, uri, slug)
163
+ action = 'put'
164
+ id = args[0]
165
+ data = args[1]
166
+ response = self.send("#{@scope}_#{action}", "#{url}", {data: data}, compatibility_options)
167
+ end
168
+
169
+ if response.response.code == "404"
170
+ raise 'NotFoundError'
171
+ elsif response.response.code == "500"
172
+ raise 'InternalServerError'
173
+ end
174
+ return JSON.parse(response.body)
175
+ end
176
+
177
+ def get_url(route, object, uri, slug = nil)
178
+ if (slug)
179
+ return "#{@host}#{@base_url}/#{route}/#{object}/#{slug}#{uri}"
180
+ else
181
+ return "#{@host}#{@base_url}/#{route}/#{object}#{uri}"
182
+ end
183
+ end
184
+
185
+ def replacements
186
+ return [
187
+ {old_value: '_', new_value: '-'},
188
+ {old_value: 'people', new_value: 'crm'},
189
+ {old_value: 'store', new_value: 'ecommerce'}
190
+ ]
191
+ end
192
+
193
+ def set_scope(scope)
194
+ @scope = scope
195
+ if scope == "public"
196
+ @base_url = "/api/v1"
197
+ elsif scope == "contact"
198
+ @base_url = "/api/v1"
199
+ elsif scope == "user"
200
+ @base_url = "/api/user/v1"
201
+ else
202
+ @scope = "public"
203
+ @base_url = "/api/v1"
204
+ end
205
+ end
206
+
207
+ ##### HTTTP CLIENTS ######
208
+ # Simple HTTP GET
209
+ def http_get(url, headers = nil)
210
+ if @debug
211
+ puts "Url:"
212
+ puts url
213
+ puts "Headers:"
214
+ puts headers
215
+ puts "Method: get"
216
+ end
217
+ return headers ? HTTParty.get(url, :headers => headers) : HTTParty.get(url)
218
+ end
219
+
220
+ # Simple HTTP POST
221
+ def http_post(url, headers = nil, data = nil)
222
+ if @debug
223
+ puts "Url:"
224
+ puts url
225
+ puts "Headers:"
226
+ puts headers
227
+ puts "Data:"
228
+ puts data
229
+ puts "Method: post"
230
+ end
231
+ return headers ? HTTParty.post(url, :headers=> headers, :body => data) : HTTParty.post(url, :body => data)
232
+ end
233
+
234
+ # Simple HTTP PUT
235
+ def http_put(url, headers = nil, data = nil)
236
+ if @debug
237
+ puts "Url:"
238
+ puts url
239
+ puts "Headers:"
240
+ puts headers
241
+ puts "Data:"
242
+ puts data
243
+ puts "Method: put"
244
+ end
245
+ return headers ? HTTParty.put(url, :headers=> headers, :body => data) : HTTParty.put(url, :body => data)
246
+ end
247
+
248
+ # Simple HTTP DELETE
249
+ def http_delete(url, headers = nil, data = nil)
250
+ if @debug
251
+ puts "Url:"
252
+ puts url
253
+ puts "Headers:"
254
+ puts headers
255
+ puts "Data:"
256
+ puts data
257
+ puts "Method: delete"
258
+ end
259
+ return headers ? HTTParty.delete(url, :headers=> headers, :body => data) : HTTParty.delete(url, :body => data)
260
+ end
261
+
262
+ # Start contact context
263
+ def contact_get(url, headers = nil, compatibility_options)
264
+ h = {
265
+ "ApiKey" => @api_key,
266
+ "Accept" => "application/json",
267
+ "ContactToken" => @contact_token_id
268
+ }
269
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
270
+ h["Authorization"] = "Bearer #{@session_token}" if @session_token
271
+ if headers
272
+ headers.each do |k,v|
273
+ h[k] = v
274
+ end
275
+ end
276
+ return self.http_get(url, h)
277
+ end
278
+
279
+ def contact_post(url, data, compatibility_options)
280
+ headers = {
281
+ "ApiKey" => @api_key,
282
+ "Accept" => "application/json",
283
+ "ContactToken" => @contact_token_id
284
+ }
285
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
286
+ headers["Authorization"] = "Bearer #{@session_token}" if @session_token
287
+ return self.http_post(url, headers, data)
288
+ end
289
+
290
+ def contact_put(url, data, compatibility_options)
291
+ headers = {
292
+ "ApiKey" => @api_key,
293
+ "Accept" => "application/json",
294
+ "ContactToken" => @contact_token_id
295
+ }
296
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
297
+ headers["Authorization"] = "Bearer #{@session_token}" if @session_token
298
+ return self.http_put(url, headers, data)
299
+ end
300
+
301
+ # Start User context
302
+ def user_get(url, headers = nil, compatibility_options)
303
+ h = {
304
+ "Accept" => "application/json",
305
+ "ApiKey" => @api_key
306
+ }
307
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
308
+ h["Authorization"] = "Bearer #{@session_token}" if @session_token
309
+ if headers
310
+ headers.each do |k,v|
311
+ h[k] = v
312
+ end
313
+ end
314
+ return self.http_get(url, h)
315
+ end
316
+
317
+ def user_post(url, data, compatibility_options)
318
+ headers = {
319
+ "Accept" => "application/json",
320
+ "ApiKey" => @api_key
321
+ }
322
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
323
+ headers["Authorization"] = "Bearer #{@session_token}" if @session_token
324
+ return self.http_post(url, headers, data)
325
+ end
326
+
327
+ def user_put(url, data, compatibility_options)
328
+ headers = {
329
+ "Accept" => "application/json",
330
+ "ApiKey" => @api_key
331
+ }
332
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
333
+ headers["Authorization"] = "Bearer #{@session_token}" if @session_token
334
+ return self.http_put(url, headers, data)
335
+ end
336
+
337
+ def user_delete(url, data, compatibility_options)
338
+ headers = {
339
+ "Accept" => "application/json",
340
+ "ApiKey" => @api_key
341
+ }
342
+ headers["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
343
+ headers["Authorization"] = "Bearer #{@session_token}" if @session_token
344
+ return self.http_delete(url, headers, data)
345
+ end
346
+ # End User Context
347
+
348
+ def public_get(url, headers = nil, compatibility_options)
349
+ h = {
350
+ "Accept" => "application/json",
351
+ "ApiKey" => @api_key
352
+ }
353
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
354
+ h["ContactToken"] = @contact_token_id if @contact_token_id
355
+ h["Visit-Id"] = @visit_id if @visit_id
356
+ if headers
357
+ headers.each do |k,v|
358
+ h[k] = v
359
+ end
360
+ end
361
+ self.http_get(url, h)
362
+ end
363
+
364
+ def public_post(url, headers = nil, data, compatibility_options)
365
+ h = {
366
+ "Accept" => "application/json",
367
+ "ApiKey" => @api_key
368
+ }
369
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
370
+ h["ContactToken"] = @session_token if @session_token
371
+ if headers
372
+ headers.each do |k,v|
373
+ h[k] = v
374
+ end
375
+ end
376
+ self.http_post(url, h, data)
377
+ end
378
+
379
+ def public_put(url, headers = nil, data, compatibility_options)
380
+ h = {
381
+ "Accept" => "application/json",
382
+ "ApiKey" => @api_key
383
+ }
384
+ h["Content-Type"] = "application/json" unless compatibility_options['no_content_type']
385
+ h["ContactToken"] = @contact_token_id if @contact_token_id
386
+ if headers
387
+ headers.each do |k,v|
388
+ h[k] = v
389
+ end
390
+ end
391
+ self.http_put(url, h, data)
392
+ end
393
+ end
394
+ end
data/lib/pub.rb CHANGED
@@ -30,7 +30,7 @@ module Mints
30
30
  # { "fields": "id, title, slug" }
31
31
  # { "fields[products]": "id, title, slug" }
32
32
  #
33
- # == Resource collections options
33
+ # == Resource collections options
34
34
  # * +search+ - [_String_] If present, it will search for records matching the search string. _Example:_
35
35
  # { "search": "searchstring" }
36
36
  # * +scopes+ - [_String_] If present, it will apply the specified Model's scopes. _Example:_
@@ -49,7 +49,7 @@ module Mints
49
49
  # }
50
50
  # ],
51
51
  # "operator":"or"
52
- # }
52
+ # }
53
53
  # options = { "jfilters": jfilter }
54
54
  # * +catfilters+ - [_String_] filter by categories. _Example:_
55
55
  # { "catfilters": "categoryName" }
@@ -86,7 +86,7 @@ module Mints
86
86
  def initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false)
87
87
  @client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, visit_id, debug)
88
88
  end
89
-
89
+
90
90
  ##
91
91
  # === Register Visit.
92
92
  # Register a ghost/contact visit in Mints.Cloud.
@@ -206,7 +206,7 @@ module Mints
206
206
  # ==== Example
207
207
  # @data = @mints_pub.get_form("form_slug")
208
208
  def get_form(slug)
209
- return @client.raw("get", "/content/forms/#{slug}", nil, nil, nil, nil, true)
209
+ return @client.raw("get", "/content/forms/#{slug}", nil, nil, nil, nil, false)
210
210
  end
211
211
 
212
212
  ##
@@ -228,11 +228,11 @@ module Mints
228
228
  # @data = @mints_pub.submit_form(data)
229
229
  def submit_form(data)
230
230
  return @client.raw("post", "/content/forms/submit", nil, data_transform(data))
231
- end
231
+ end
232
232
 
233
233
  ##
234
234
  # === Get Content Instances.
235
- # Get a collection of content instances. _Note:_ Options must be specified.
235
+ # Get a collection of content instances. _Note:_ Options must be specified.
236
236
  #
237
237
  # ==== Parameters
238
238
  # options:: (Hash) -- List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter.
@@ -249,7 +249,7 @@ module Mints
249
249
  # "sort": "-id"
250
250
  # }
251
251
  # @data = @mints_pub.get_content_instances(options)
252
- def get_content_instances(options)
252
+ def get_content_instances(options)
253
253
  return @client.raw("get", "/content/content-instances", options)
254
254
  end
255
255
 
@@ -287,7 +287,7 @@ module Mints
287
287
  # ==== Example
288
288
  # @data = @mints_pub.get_content_page("test-page")
289
289
  def get_content_page(slug)
290
- return @client.raw("get", "/content/content-pages/#{slug}", nil, nil, nil, nil, true)
290
+ return @client.raw("get", "/content/content-pages/#{slug}", nil, nil, nil, nil, false)
291
291
  end
292
292
 
293
293
  ### V1/ECOMMERCE ###
@@ -313,7 +313,7 @@ module Mints
313
313
  def get_locations(options = nil, use_post = true)
314
314
  return get_query_results("/ecommerce/locations", options, use_post)
315
315
  end
316
-
316
+
317
317
  ##
318
318
  # === Get Products.
319
319
  # Get a collection of products.
@@ -444,7 +444,7 @@ module Mints
444
444
  def get_tag(slug, options = nil)
445
445
  return @client.raw("get", "/config/tags/#{slug}", options)
446
446
  end
447
-
447
+
448
448
  ##
449
449
  # === Get Taxonomies.
450
450
  # Get a collection of taxonomies.
@@ -458,13 +458,13 @@ module Mints
458
458
  #
459
459
  # ==== Second Example
460
460
  # options = {
461
- # "fields": "id, title"
461
+ # "fields": "id, title"
462
462
  # }
463
463
  # @data = @mints_pub.get_taxonomies(options)
464
464
  #
465
465
  # ==== Third Example
466
466
  # options = {
467
- # "fields": "id, title"
467
+ # "fields": "id, title"
468
468
  # }
469
469
  # @data = @mints_pub.get_taxonomies(options, false)
470
470
  def get_taxonomies(options = nil, use_post = true)
metadata CHANGED
@@ -1,22 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Gomez Garcia, Omar Mora, Luis Payan, Oscar Castillo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-02 00:00:00.000000000 Z
11
+ date: 2022-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.8.3
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 1.8.3
@@ -24,9 +21,6 @@ dependencies:
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 1.8.3
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
26
  version: 1.8.3
@@ -216,8 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
210
  - !ruby/object:Gem::Version
217
211
  version: '0'
218
212
  requirements: []
219
- rubyforge_project:
220
- rubygems_version: 2.7.6.2
213
+ rubygems_version: 3.1.6
221
214
  signing_key:
222
215
  specification_version: 4
223
216
  summary: MINTS gem allows to connect your Rails App to MINTS.CLOUD