mints 0.0.19 → 0.0.22
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/lib/client.rb +394 -362
- data/lib/contact.rb +633 -73
- data/lib/generators/mints_files_generator.rb +6 -0
- data/lib/generators/mints_link.rb +61 -0
- data/lib/generators/short_link_controller.rb +41 -0
- data/lib/mints/controllers/base_api_controller.rb +2 -1
- data/lib/mints/controllers/base_controller.rb +7 -2
- data/lib/mints_helper.rb +2 -2
- data/lib/pub.rb +208 -77
- data/lib/user/content/assets.rb +196 -34
- data/lib/user/content/pages.rb +7 -7
- data/lib/user.rb +1 -1
- metadata +21 -26
data/lib/client.rb
CHANGED
@@ -1,362 +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, debug = false)
|
15
|
-
@host = host
|
16
|
-
@api_key = api_key
|
17
|
-
@session_token = session_token
|
18
|
-
@contact_token_id = contact_token_id
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
149
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
else
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
"
|
256
|
-
|
257
|
-
"
|
258
|
-
|
259
|
-
headers
|
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
|
-
headers
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
headers
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
headers = {
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
def
|
318
|
-
|
319
|
-
"Accept" => "application/json",
|
320
|
-
"ApiKey" => @api_key
|
321
|
-
}
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
self.
|
345
|
-
end
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
"
|
351
|
-
|
352
|
-
|
353
|
-
h["
|
354
|
-
if
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
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
|