mints 0.0.21 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/client.rb +394 -386
- data/lib/pub.rb +12 -12
- metadata +3 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d71005d83085eec4a71aeeb68e1e83604aad1bdb2c9d6d9670e26d80833c968a
|
4
|
+
data.tar.gz: 6f469fe73f04248e1b227599d20273ea3de7f78555383b541cb18c1aec42ef03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
response = self.send("#{@scope}_#{action}", url,
|
149
|
-
elsif action == "
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
def
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
def
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
puts "
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
puts "
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
puts "
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
"
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
h
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
h
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
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,
|
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,
|
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.
|
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:
|
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
|
-
|
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
|