qismo 0.9.0 → 0.10.0
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/.rubocop.yml +1 -12
- data/Gemfile.lock +1 -1
- data/lib/qismo/api.rb +133 -65
- data/lib/qismo/client.rb +7 -7
- data/lib/qismo/model.rb +7 -7
- data/lib/qismo/util.rb +1 -1
- data/lib/qismo/version.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: e1b4c93e50732069adea997b37a9377cff4444c8785971e1a194eac896b4e18d
|
4
|
+
data.tar.gz: 2afff6846d7d8e981dbc8242bee37bdfe32d37845029ba11614365c898bd5f89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a12795cfc80d51487a8c5242f11b5796e2292e6fc440f1fab7a05ad32bc616ffb5c129d43679f622397a19001cc56fa4fb229f0f20473c40dec4961593f4d4b
|
7
|
+
data.tar.gz: c6bb012dc5209dd55409c4cdcad760f4bc7a2686ee3265cd758bc9228be0ca0643a9d40cb54932815d9095d3722ee934a5d6ecaea1f9fbba2a5711bbb9f6de45
|
data/.rubocop.yml
CHANGED
@@ -5,15 +5,4 @@ AllCops:
|
|
5
5
|
TargetRubyVersion: 2.6
|
6
6
|
Exclude:
|
7
7
|
- "bin/**/*"
|
8
|
-
- "examples/*"
|
9
|
-
|
10
|
-
Style/StringLiterals:
|
11
|
-
Enabled: true
|
12
|
-
EnforcedStyle: double_quotes
|
13
|
-
|
14
|
-
Style/StringLiteralsInInterpolation:
|
15
|
-
Enabled: true
|
16
|
-
EnforcedStyle: double_quotes
|
17
|
-
|
18
|
-
Layout/LineLength:
|
19
|
-
Max: 120
|
8
|
+
- "examples/*"
|
data/Gemfile.lock
CHANGED
data/lib/qismo/api.rb
CHANGED
@@ -5,10 +5,10 @@ module Qismo
|
|
5
5
|
# List customer rooms
|
6
6
|
#
|
7
7
|
# @param opt [Hash]
|
8
|
-
# @return [Qismo::
|
8
|
+
# @return [Qismo::CollectionObject]
|
9
9
|
def rooms(opt = {})
|
10
10
|
body = post("/api/v2/customer_rooms", opt)
|
11
|
-
|
11
|
+
CollectionObject.new(
|
12
12
|
body.data.customer_rooms,
|
13
13
|
prev_page: body.meta&.cursor_before,
|
14
14
|
next_page: body.meta&.cursor_after,
|
@@ -20,7 +20,7 @@ module Qismo
|
|
20
20
|
# Get room by id
|
21
21
|
#
|
22
22
|
# @param room_id [Integer]
|
23
|
-
# @return [Qismo::
|
23
|
+
# @return [Qismo::SingleObject]
|
24
24
|
def room(room_id)
|
25
25
|
body = get("/api/v2/customer_rooms/#{room_id}")
|
26
26
|
if body.data.customer_room.nil?
|
@@ -33,18 +33,18 @@ module Qismo
|
|
33
33
|
# List tags inside room
|
34
34
|
#
|
35
35
|
# @param room_id [Integer]
|
36
|
-
# @return [Qismo::
|
36
|
+
# @return [Qismo::CollectionObject]
|
37
37
|
def room_tags(room_id)
|
38
|
-
get("/api/v2/room_tags/#{room_id}").data
|
38
|
+
CollectionObject.new(get("/api/v2/room_tags/#{room_id}").data)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Add room tag
|
42
42
|
#
|
43
43
|
# @param room_id [Integer]
|
44
|
-
# @param
|
45
|
-
# @return [Qismo::
|
46
|
-
def add_room_tag(room_id,
|
47
|
-
post("/api/v2/room_tags/#{room_id}", tag:
|
44
|
+
# @param tag_name [String]
|
45
|
+
# @return [Qismo::SingleObject]
|
46
|
+
def add_room_tag(room_id, tag_name)
|
47
|
+
post("/api/v2/room_tags/#{room_id}", tag: tag_name).data
|
48
48
|
end
|
49
49
|
|
50
50
|
# Delete room tag
|
@@ -60,46 +60,53 @@ module Qismo
|
|
60
60
|
# List room additional info
|
61
61
|
#
|
62
62
|
# @param room_id [Integer]
|
63
|
-
# @return [Qismo::
|
63
|
+
# @return [Qismo::CollectionObject]
|
64
64
|
def room_additional_info(room_id)
|
65
|
-
|
66
|
-
|
65
|
+
CollectionObject.new(
|
66
|
+
get(
|
67
|
+
"/api/v1/qiscus/room/#{room_id}/user_info",
|
68
|
+
).data&.extras&.user_properties,
|
69
|
+
) || CollectionObject.new
|
67
70
|
end
|
68
71
|
|
69
72
|
# Set room additional info
|
70
73
|
#
|
71
74
|
# @note This will replace your current room additional info
|
72
75
|
# @param room_id [Integer]
|
73
|
-
# @param
|
74
|
-
# @return [Qismo::
|
75
|
-
def set_room_additional_info(room_id,
|
76
|
-
|
77
|
-
|
76
|
+
# @param additional_info [Array<Hash>]
|
77
|
+
# @return [Qismo::CollectionObject]
|
78
|
+
def set_room_additional_info(room_id, additional_info)
|
79
|
+
CollectionObject.new(
|
80
|
+
post(
|
81
|
+
"/api/v1/qiscus/room/#{room_id}/user_info",
|
82
|
+
user_properties: additional_info,
|
83
|
+
).data&.extras&.user_properties,
|
84
|
+
) || CollectionObject.new
|
78
85
|
end
|
79
86
|
|
80
87
|
# Update room additional info
|
81
88
|
#
|
82
89
|
# @param room_id [Integer]
|
83
|
-
# @param
|
84
|
-
# @return [Qismo::
|
85
|
-
def update_room_additional_info(room_id,
|
90
|
+
# @param additional_info [Array]
|
91
|
+
# @return [Qismo::CollectionObject]
|
92
|
+
def update_room_additional_info(room_id, additional_info)
|
86
93
|
old_additional_info = room_additional_info(room_id)
|
87
94
|
new_additional_info = (additional_info + old_additional_info).uniq { |h| h.values_at("key") }
|
88
|
-
set_room_additional_info(room_id,
|
95
|
+
set_room_additional_info(room_id, new_additional_info)
|
89
96
|
end
|
90
97
|
|
91
98
|
# List Whatsapp broadcast history inside room
|
92
99
|
#
|
93
100
|
# @param room_id [Integer]
|
94
101
|
# @param opt [Hash]
|
95
|
-
# @return [Qismo::
|
102
|
+
# @return [Qismo::CollectionObject]
|
96
103
|
def room_broadcast_history(room_id, opt = {})
|
97
104
|
body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", opt)
|
98
105
|
|
99
106
|
next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
|
100
107
|
prev_page = body.meta.page > 1 ? (body.meta.page - 1) : nil
|
101
108
|
|
102
|
-
|
109
|
+
CollectionObject.new(
|
103
110
|
body.data.broadcast_logs,
|
104
111
|
next_page: next_page,
|
105
112
|
prev_page: prev_page,
|
@@ -113,7 +120,7 @@ module Qismo
|
|
113
120
|
# @param room_id [Integer]
|
114
121
|
# @param agent_id [Integer]
|
115
122
|
# @param opt [Hash]
|
116
|
-
# @return [Qismo::
|
123
|
+
# @return [Qismo::SingleObject]
|
117
124
|
def assign_agent(room_id, agent_id, opt = {})
|
118
125
|
body = post("/api/v1/admin/service/assign_agent", opt.merge(room_id: room_id.to_s, agent_id: agent_id))
|
119
126
|
body.data.added_agent
|
@@ -134,7 +141,7 @@ module Qismo
|
|
134
141
|
# @param room_id [Integer]
|
135
142
|
# @param last_comment_id [Integer]
|
136
143
|
# @param opt [Hash]
|
137
|
-
# @return [Qismo::
|
144
|
+
# @return [Qismo::SingleObject]
|
138
145
|
def resolve_room(room_id, last_comment_id, opt = {})
|
139
146
|
body = post("/api/v1/admin/service/mark_as_resolved",
|
140
147
|
opt.merge(room_id: room_id.to_s, last_comment_id: last_comment_id))
|
@@ -147,7 +154,7 @@ module Qismo
|
|
147
154
|
#
|
148
155
|
# @param source [String]
|
149
156
|
# @param opt [Hash]
|
150
|
-
# @return [Qismo::
|
157
|
+
# @return [Qismo::SingleObject]
|
151
158
|
def allocate_agent(source, opt = {})
|
152
159
|
body = post("/api/v1/admin/service/allocate_agent", opt.merge(source: source))
|
153
160
|
body.data.agent
|
@@ -157,7 +164,7 @@ module Qismo
|
|
157
164
|
#
|
158
165
|
# @param room_id [Integer]
|
159
166
|
# @param opt [Hash]
|
160
|
-
# @return [Qismo::
|
167
|
+
# @return [Qismo::SingleObject]
|
161
168
|
def allocate_and_assign_agent(room_id, opt = {})
|
162
169
|
body = post("/api/v1/admin/service/allocate_assign_agent", opt.merge(room_id: room_id))
|
163
170
|
body.data.agent
|
@@ -167,10 +174,10 @@ module Qismo
|
|
167
174
|
#
|
168
175
|
# @param room_id [Integer]
|
169
176
|
# @param opt [Hash]
|
170
|
-
# @return [Qismo::
|
177
|
+
# @return [Qismo::CollectionObject]
|
171
178
|
def other_agents(room_id, opt = {})
|
172
179
|
body = get("/api/v2/admin/service/other_agents", opt.merge(room_id: room_id))
|
173
|
-
|
180
|
+
CollectionObject.new(
|
174
181
|
body.data.agents,
|
175
182
|
prev_page: body.meta&.cursor_before,
|
176
183
|
next_page: body.meta&.cursor_after,
|
@@ -183,10 +190,10 @@ module Qismo
|
|
183
190
|
#
|
184
191
|
# @param room_id [Integer]
|
185
192
|
# @param opt [Hash]
|
186
|
-
# @return [Qismo::
|
193
|
+
# @return [Qismo::CollectionObject]
|
187
194
|
def available_agents(room_id, opt = {})
|
188
195
|
body = get("/api/v2/admin/service/available_agents", opt.merge(room_id: room_id))
|
189
|
-
|
196
|
+
CollectionObject.new(
|
190
197
|
body.data.agents,
|
191
198
|
prev_page: body.meta&.cursor_before,
|
192
199
|
next_page: body.meta&.cursor_after,
|
@@ -197,7 +204,7 @@ module Qismo
|
|
197
204
|
|
198
205
|
# Get new session webhook config
|
199
206
|
#
|
200
|
-
# @return [Qismo::
|
207
|
+
# @return [Qismo::SingleObject]
|
201
208
|
def new_session_webhook
|
202
209
|
get("/api/v2/app/config/new_session_webhook").data.configs
|
203
210
|
end
|
@@ -206,14 +213,14 @@ module Qismo
|
|
206
213
|
#
|
207
214
|
# @param url [String]
|
208
215
|
# @param opt [Hash]
|
209
|
-
# @return [Qismo::
|
216
|
+
# @return [Qismo::SingleObject]
|
210
217
|
def set_new_session_webhook(url, opt = {})
|
211
218
|
post("/api/v2/app/config/new_session_webhook", opt.merge(url: url)).data.configs
|
212
219
|
end
|
213
220
|
|
214
221
|
# Get auth webhook config
|
215
222
|
#
|
216
|
-
# @return [Qismo::
|
223
|
+
# @return [Qismo::SingleObject]
|
217
224
|
def auth_webhook
|
218
225
|
get("/api/v2/app/config/auth_webhook").data.configs
|
219
226
|
end
|
@@ -222,14 +229,14 @@ module Qismo
|
|
222
229
|
#
|
223
230
|
# @param url [String]
|
224
231
|
# @param opt [Hash]
|
225
|
-
# @return [Qismo::
|
232
|
+
# @return [Qismo::SingleObject]
|
226
233
|
def set_auth_webhook(url, opt = {})
|
227
234
|
post("/api/v2/app/config/auth_webhook", opt.merge(url: url)).data.configs
|
228
235
|
end
|
229
236
|
|
230
237
|
# Get resolve webhook config
|
231
238
|
#
|
232
|
-
# @return [Qismo::
|
239
|
+
# @return [Qismo::SingleObject]
|
233
240
|
def resolve_webhook
|
234
241
|
get("/api/v1/app/webhook/mark_as_resolved").data
|
235
242
|
end
|
@@ -238,7 +245,7 @@ module Qismo
|
|
238
245
|
#
|
239
246
|
# @param url [String]
|
240
247
|
# @param opt [Hash]
|
241
|
-
# @return [Qismo::
|
248
|
+
# @return [Qismo::SingleObject]
|
242
249
|
def set_resolve_webhook(url, opt = {})
|
243
250
|
post("/api/v1/app/webhook/mark_as_resolved", opt.merge(url: url)).data
|
244
251
|
end
|
@@ -246,7 +253,7 @@ module Qismo
|
|
246
253
|
# List agents
|
247
254
|
#
|
248
255
|
# @param opt [Hash]
|
249
|
-
# @return [Qismo::
|
256
|
+
# @return [Qismo::CollectionObject]
|
250
257
|
def agents(opt = {})
|
251
258
|
if opt[:page].nil? || opt[:page].empty?
|
252
259
|
opt[:page] = 1
|
@@ -258,7 +265,7 @@ module Qismo
|
|
258
265
|
next_page = opt[:page] < total_page ? (opt[:page] + 1) : nil
|
259
266
|
prev_page = opt[:page] > 1 ? (opt[:page] - 1) : nil
|
260
267
|
|
261
|
-
|
268
|
+
CollectionObject.new(
|
262
269
|
body.data.agents,
|
263
270
|
next_page: next_page,
|
264
271
|
prev_page: prev_page,
|
@@ -269,24 +276,24 @@ module Qismo
|
|
269
276
|
|
270
277
|
# List agents by id
|
271
278
|
#
|
272
|
-
# @param
|
273
|
-
# @return [Qismo::
|
274
|
-
def agents_by_ids(
|
275
|
-
get("/api/v1/admin/agents/get_by_ids",
|
279
|
+
# @param ids [Array<Integer>]
|
280
|
+
# @return [Qismo::CollectionObject]
|
281
|
+
def agents_by_ids(ids)
|
282
|
+
CollectionObject.new(get("/api/v1/admin/agents/get_by_ids", { "ids[]": ids }).data) || CollectionObject.new
|
276
283
|
end
|
277
284
|
|
278
285
|
# List agents by divisions
|
279
286
|
#
|
280
|
-
# @param
|
287
|
+
# @param division_ids [Array<Integer>]
|
281
288
|
# @param opt [Hash]
|
282
|
-
# @return [Qismo::
|
289
|
+
# @return [Qismo::CollectionObject]
|
283
290
|
def agents_by_divisions(division_ids, opt = {})
|
284
291
|
body = get("/api/v2/admin/agents/by_division", opt.merge({ "division_ids[]": division_ids }))
|
285
292
|
|
286
293
|
next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
|
287
294
|
prev_page = body.meta.page > 1 ? (body.meta.page - 1) : nil
|
288
295
|
|
289
|
-
|
296
|
+
CollectionObject.new(
|
290
297
|
body.data,
|
291
298
|
next_page: next_page,
|
292
299
|
prev_page: prev_page,
|
@@ -298,26 +305,26 @@ module Qismo
|
|
298
305
|
# Get agent by id
|
299
306
|
#
|
300
307
|
# @param agent_id [Integer]
|
301
|
-
# @return [Qismo::
|
308
|
+
# @return [Qismo::SingleObject]
|
302
309
|
def agent(agent_id)
|
303
310
|
get("/api/v2/admin/agent/#{agent_id}").data.agent
|
304
311
|
end
|
305
312
|
|
306
313
|
# Get office hour config
|
307
314
|
#
|
308
|
-
# @return [Qismo::
|
315
|
+
# @return [Qismo::SingleObject]
|
309
316
|
def office_hours
|
310
317
|
data = get("/api/v1/admin/office_hours").data
|
311
318
|
data_hash = data.as_json
|
312
319
|
data_hash["is_in_office_hour"] = Util.in_office_hour?(data)
|
313
320
|
|
314
|
-
|
321
|
+
SingleObject.new(data_hash)
|
315
322
|
end
|
316
323
|
|
317
324
|
# List WA broadcast templates
|
318
325
|
#
|
319
326
|
# @param opt [Hash]
|
320
|
-
# @return [Qismo::
|
327
|
+
# @return [Qismo::CollectionObject]
|
321
328
|
def wa_broadcast_templates(opt = {})
|
322
329
|
body = get("/api/v3/admin/hsm", opt)
|
323
330
|
|
@@ -325,7 +332,7 @@ module Qismo
|
|
325
332
|
next_page = meta.page < meta.total_page ? (meta.page + 1) : nil
|
326
333
|
prev_page = meta.page > 1 ? (meta.page - 1) : nil
|
327
334
|
|
328
|
-
|
335
|
+
CollectionObject.new(
|
329
336
|
body.data.hsm_templates,
|
330
337
|
next_page: next_page,
|
331
338
|
prev_page: prev_page,
|
@@ -337,7 +344,7 @@ module Qismo
|
|
337
344
|
# Send WA outbound message
|
338
345
|
#
|
339
346
|
# @param opt [Hash]
|
340
|
-
# @return [Qismo::
|
347
|
+
# @return [Qismo::SingleObject]
|
341
348
|
def send_wa_outbound(opt = {})
|
342
349
|
post("/api/v3/admin/broadcast/client", opt).data
|
343
350
|
end
|
@@ -346,7 +353,7 @@ module Qismo
|
|
346
353
|
#
|
347
354
|
# @param file [HTTP::FormData]
|
348
355
|
# @param template_detail_id [Integer]
|
349
|
-
# @return [Qismo::
|
356
|
+
# @return [Qismo::SingleObject]
|
350
357
|
def upload_wa_broadcast_csv(file, template_detail_id)
|
351
358
|
raise ArgumentError, "Invalid file" unless file.is_a?(HTTP::FormData::File)
|
352
359
|
|
@@ -356,7 +363,7 @@ module Qismo
|
|
356
363
|
# Send wa broadcast
|
357
364
|
#
|
358
365
|
# @param opt [Hash]
|
359
|
-
# @return [Qismo::
|
366
|
+
# @return [Qismo::SingleObject]
|
360
367
|
def send_wa_broadcast(opt = {})
|
361
368
|
post("/api/v3/admin/broadcast/send_broadcast", opt).data.broadcast_job
|
362
369
|
end
|
@@ -364,14 +371,14 @@ module Qismo
|
|
364
371
|
# List wa broadcast jobs
|
365
372
|
#
|
366
373
|
# @param opt [Hash]
|
367
|
-
# @return [Qismo::
|
374
|
+
# @return [Qismo::CollectionObject]
|
368
375
|
def wa_broadcast_jobs(opt = {})
|
369
376
|
body = get("/api/v2/admin/broadcast_jobs", opt)
|
370
377
|
|
371
378
|
prev_page = body.meta.page > 1 ? (body.meta.meta - 1) : nil
|
372
379
|
next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
|
373
380
|
|
374
|
-
|
381
|
+
CollectionObject.new(
|
375
382
|
body.data.broadcast_jobs,
|
376
383
|
next_page: next_page,
|
377
384
|
prev_page: prev_page,
|
@@ -383,7 +390,7 @@ module Qismo
|
|
383
390
|
# Get wa broadcast job by id
|
384
391
|
#
|
385
392
|
# @param broadcast_job_id [Integer]
|
386
|
-
# @return [Qismo::
|
393
|
+
# @return [Qismo::SingleObject]
|
387
394
|
def wa_broadcast_job(broadcast_job_id)
|
388
395
|
get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
|
389
396
|
end
|
@@ -392,14 +399,14 @@ module Qismo
|
|
392
399
|
#
|
393
400
|
# @param broadcast_job_id [Integer]
|
394
401
|
# @param opt [Hash]
|
395
|
-
# @return [Qismo::
|
402
|
+
# @return [Qismo::CollectionObject]
|
396
403
|
def wa_broadcast_logs(broadcast_job_id, opt = {})
|
397
404
|
body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", opt)
|
398
405
|
|
399
406
|
prev_page = body.meta.page > 1 ? (body.meta.meta - 1) : nil
|
400
407
|
next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
|
401
408
|
|
402
|
-
|
409
|
+
CollectionObject.new(
|
403
410
|
body.data.broadcast_logs,
|
404
411
|
next_page: next_page,
|
405
412
|
prev_page: prev_page,
|
@@ -421,16 +428,16 @@ module Qismo
|
|
421
428
|
#
|
422
429
|
# @param room_id [Integer]
|
423
430
|
# @return [TrueClass]
|
424
|
-
def
|
431
|
+
def enable_bot_in_room(room_id)
|
425
432
|
post("/bot/#{room_id}/activate", is_active: true)
|
426
433
|
true
|
427
434
|
end
|
428
435
|
|
429
|
-
# Disable
|
436
|
+
# Disable chatbot in room
|
430
437
|
#
|
431
438
|
# @param room_id [Integer]
|
432
439
|
# @return [TrueClass]
|
433
|
-
def
|
440
|
+
def disable_bot_in_room(room_id)
|
434
441
|
post("/bot/#{room_id}/activate", is_active: false)
|
435
442
|
true
|
436
443
|
end
|
@@ -447,7 +454,7 @@ module Qismo
|
|
447
454
|
# Handover room from chatbot to human agent in specific divisions
|
448
455
|
#
|
449
456
|
# @param room_id [Integer]
|
450
|
-
# @param
|
457
|
+
# @param roles [Array<Integer>]
|
451
458
|
# @param opt [Hash]
|
452
459
|
# @return [TrueClass]
|
453
460
|
def handover_room_from_bot_to_division(room_id, roles, opt = {})
|
@@ -460,7 +467,7 @@ module Qismo
|
|
460
467
|
# @param user_id [String]
|
461
468
|
# @param name [String]
|
462
469
|
# @param opt [Hash]
|
463
|
-
# @return [Qismo::
|
470
|
+
# @return [Qismo::SingleObject]
|
464
471
|
def initiate_widget_chat(user_id, name, opt = {})
|
465
472
|
opt = opt.merge(app_id: app_id, user_id: user_id, name: name)
|
466
473
|
post("/api/v2/qiscus/initiate_chat", opt).data.customer_room
|
@@ -472,10 +479,71 @@ module Qismo
|
|
472
479
|
# @param user_id [String]
|
473
480
|
# @param name [String]
|
474
481
|
# @param opt [Hash]
|
475
|
-
# @return [Qismo::
|
482
|
+
# @return [Qismo::SingleObject]
|
476
483
|
def send_message_to_custom_channel(identifier_key, user_id, name, opt = {})
|
477
484
|
post("/#{app_id}/api/v2/custom_channel/send",
|
478
485
|
opt.merge(identifier_key: identifier_key, user_id: user_id, name: name)).data
|
479
486
|
end
|
487
|
+
|
488
|
+
def channels
|
489
|
+
get("/api/v2/channels").data
|
490
|
+
end
|
491
|
+
|
492
|
+
# Create customchannel
|
493
|
+
#
|
494
|
+
# @param identifier_key [String]
|
495
|
+
# @param name [String]
|
496
|
+
# @param webhook_url [String]
|
497
|
+
# @param opt [Hash]
|
498
|
+
# @return [Qismo::SingleObject]
|
499
|
+
def create_custom_channel(identifier_key, name, webhook_url, opt = {})
|
500
|
+
opt = opt.merge(
|
501
|
+
identifier_key: identifier_key,
|
502
|
+
name: name,
|
503
|
+
webhook_url: webhook_url,
|
504
|
+
)
|
505
|
+
|
506
|
+
opt[:is_active] = true unless opt[:is_active].nil?
|
507
|
+
|
508
|
+
post("/api/v1/custom_channel/connect", opt.merge).data
|
509
|
+
end
|
510
|
+
|
511
|
+
# Update custom channel
|
512
|
+
#
|
513
|
+
# @param id [Integer]
|
514
|
+
# @param opt [Hash]
|
515
|
+
# @return [Qismo::SingleObject]
|
516
|
+
def update_custom_channel(id, opt = {})
|
517
|
+
channel = channels.custom_channels.find { |cc| cc.id == id }
|
518
|
+
if channel.nil?
|
519
|
+
raise Qismo::NotFoundError.new("Channel not found", status_code: 404, response_body: nil)
|
520
|
+
end
|
521
|
+
|
522
|
+
channel_hash = JSON.parse(channel.to_json, symbolize_names: true)
|
523
|
+
new_channel_config = channel_hash.merge(opt)
|
524
|
+
|
525
|
+
post("/api/v1/custom_channel/connect/update", new_channel_config).data
|
526
|
+
end
|
527
|
+
|
528
|
+
# Activate custom channel
|
529
|
+
#
|
530
|
+
# @param id [Integer]
|
531
|
+
# @return [Qismo::SingleObject]
|
532
|
+
def activate_custom_channel(id)
|
533
|
+
update_custom_channel(id, is_active: true)
|
534
|
+
end
|
535
|
+
|
536
|
+
# Deactivate custom channel
|
537
|
+
#
|
538
|
+
# @param id [Integer]
|
539
|
+
# @return [Qismo::SingleObject]
|
540
|
+
def deactivate_custom_channel(id)
|
541
|
+
update_custom_channel(id, is_active: false)
|
542
|
+
end
|
543
|
+
|
544
|
+
def delete_custom_channel(id)
|
545
|
+
post("/api/v2/custom_channel/connect/#{id}/delete")
|
546
|
+
true
|
547
|
+
end
|
480
548
|
end
|
481
549
|
end
|
data/lib/qismo/client.rb
CHANGED
@@ -39,7 +39,7 @@ module Qismo
|
|
39
39
|
#
|
40
40
|
# @param path [String]
|
41
41
|
# @param body [Hash]
|
42
|
-
# @return [Qismo::
|
42
|
+
# @return [Qismo::SingleObject]
|
43
43
|
def post(path, body = {})
|
44
44
|
request(:post, path, json: body)
|
45
45
|
end
|
@@ -48,7 +48,7 @@ module Qismo
|
|
48
48
|
#
|
49
49
|
# @param path [String]
|
50
50
|
# @param body [Hash]
|
51
|
-
# @return [Qismo::
|
51
|
+
# @return [Qismo::SingleObject]
|
52
52
|
def post_upload(path, body = {})
|
53
53
|
request(:post, form: body)
|
54
54
|
end
|
@@ -57,7 +57,7 @@ module Qismo
|
|
57
57
|
#
|
58
58
|
# @param path [String]
|
59
59
|
# @param params [Hash]
|
60
|
-
# @return [Qismo::
|
60
|
+
# @return [Qismo::SingleObject]
|
61
61
|
def get(path, **params)
|
62
62
|
request(:get, path, params: params)
|
63
63
|
end
|
@@ -71,11 +71,11 @@ module Qismo
|
|
71
71
|
# @param method [Symbol, String]
|
72
72
|
# @param path [String]
|
73
73
|
# @param body [Hash]
|
74
|
-
# @return [Qismo::
|
74
|
+
# @return [Qismo::SingleObject]
|
75
75
|
def request(method, path, opt = {})
|
76
76
|
res = connection.request(method, @url + path, opt.compact)
|
77
77
|
if res.status.success?
|
78
|
-
return
|
78
|
+
return SingleObject.new(JSON.parse(res.to_s))
|
79
79
|
end
|
80
80
|
|
81
81
|
if res.status.server_error?
|
@@ -83,10 +83,10 @@ module Qismo
|
|
83
83
|
end
|
84
84
|
|
85
85
|
if res.status.client_error?
|
86
|
-
body =
|
86
|
+
body = SingleObject.new(JSON.parse(res.to_s))
|
87
87
|
|
88
88
|
error = body.errors
|
89
|
-
error = error.message if error.is_a?(
|
89
|
+
error = error.message if error.is_a?(SingleObject)
|
90
90
|
|
91
91
|
error_klass_map = {
|
92
92
|
400 => BadRequestError,
|
data/lib/qismo/model.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
module Qismo
|
4
4
|
# Class to handle http response body
|
5
5
|
#
|
6
|
-
class
|
6
|
+
class SingleObject
|
7
7
|
# Initiate data object
|
8
8
|
#
|
9
9
|
# @param opt [Hash]
|
10
10
|
def initialize(opt = {})
|
11
11
|
opt.each do |key, value|
|
12
12
|
value = if value.is_a?(Array)
|
13
|
-
handle_array(value)
|
13
|
+
CollectionObject.new(handle_array(value))
|
14
14
|
elsif value.is_a?(Hash)
|
15
15
|
self.class.new(value)
|
16
16
|
elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
@@ -54,15 +54,15 @@ module Qismo
|
|
54
54
|
|
55
55
|
# Class to handle response body that contain pagination
|
56
56
|
#
|
57
|
-
class
|
57
|
+
class CollectionObject < Array
|
58
58
|
# Initiate collection
|
59
59
|
#
|
60
|
-
# @param data [Qismo::
|
60
|
+
# @param data [Qismo::SingleObject]
|
61
61
|
# @param prev_page [String, Integer]
|
62
62
|
# @param next_page [String, Integer]
|
63
63
|
# @param prev_func [Proc, NilClass]
|
64
64
|
# @param next_func [Proc, NilClass]
|
65
|
-
def initialize(data, prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
|
65
|
+
def initialize(data = [], prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
|
66
66
|
super(data)
|
67
67
|
|
68
68
|
@prev_page = prev_page
|
@@ -87,14 +87,14 @@ module Qismo
|
|
87
87
|
|
88
88
|
# Call api request for next page
|
89
89
|
#
|
90
|
-
# @return [Qismo::
|
90
|
+
# @return [Qismo::SingleObject, Qismo::CollectionObject]
|
91
91
|
def next_page
|
92
92
|
@next_func.call if has_next_page?
|
93
93
|
end
|
94
94
|
|
95
95
|
# Call api request for previous page
|
96
96
|
#
|
97
|
-
# @return [Qismo::
|
97
|
+
# @return [Qismo::SingleObject, Qismo::CollectionObject]
|
98
98
|
def prev_page
|
99
99
|
@prev_func.call if has_prev_page?
|
100
100
|
end
|
data/lib/qismo/util.rb
CHANGED
data/lib/qismo/version.rb
CHANGED