qismo 0.8.8 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e196e01cac13d44aad35e83f177ee216652905168e7a2a429530ccabe45ecdde
4
- data.tar.gz: 05400a68bed6f50255d058d77faa6e53bc8d84b86d0b1b6c9624481734bf771a
3
+ metadata.gz: e1b4c93e50732069adea997b37a9377cff4444c8785971e1a194eac896b4e18d
4
+ data.tar.gz: 2afff6846d7d8e981dbc8242bee37bdfe32d37845029ba11614365c898bd5f89
5
5
  SHA512:
6
- metadata.gz: 5e5981fd67c309df024443376ed65e782d4f906197a3f40d942388cfa6f0ffc8e00f109a18ad56632cdb76fc60022a6e89a50e2955fd7343e2c20e04736c93d2
7
- data.tar.gz: 88de21e6afd13aa6b88659d686c1f3a316c800d4c18618e886a99002d13a1b29266d1e09b35099dc0d3b21e84ebdb9b17cb3bce8c594bd1c05b507931c8b2e14
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qismo (0.8.7)
4
+ qismo (0.10.0)
5
5
  activesupport
6
6
  http
7
7
 
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::Collection]
9
- def rooms(**opt)
8
+ # @return [Qismo::CollectionObject]
9
+ def rooms(opt = {})
10
10
  body = post("/api/v2/customer_rooms", opt)
11
- Collection.new(
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::DataObject]
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::DataObject]
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 tag [String]
45
- # @return [Qismo::DataObject]
46
- def add_room_tag(room_id, tag)
47
- post("/api/v2/room_tags/#{room_id}", tag: tag).data
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::DataObject]
63
+ # @return [Qismo::CollectionObject]
64
64
  def room_additional_info(room_id)
65
- body = get("/api/v1/qiscus/room/#{room_id}/user_info")
66
- body.data.extras.user_properties
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 *additional_info [Array<Hash>]
74
- # @return [Qismo::DataObject]
75
- def set_room_additional_info(room_id, *additional_info)
76
- body = post("/api/v1/qiscus/room/#{room_id}/user_info", user_properties: additional_info)
77
- body.data.extras.user_properties
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 *additional_info [Array]
84
- # @return [Qismo::DataObject]
85
- def update_room_additional_info(room_id, *additional_info)
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, *new_additional_info)
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
- # @param **opt [Hash]
95
- # @return [Qismo::Collection]
96
- def room_broadcast_history(room_id, **opt)
101
+ # @param opt [Hash]
102
+ # @return [Qismo::CollectionObject]
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
- Collection.new(
109
+ CollectionObject.new(
103
110
  body.data.broadcast_logs,
104
111
  next_page: next_page,
105
112
  prev_page: prev_page,
@@ -112,9 +119,9 @@ module Qismo
112
119
  #
113
120
  # @param room_id [Integer]
114
121
  # @param agent_id [Integer]
115
- # @param **opt [Hash]
116
- # @return [Qismo::DataObject]
117
- def assign_agent(room_id, agent_id, **opt)
122
+ # @param opt [Hash]
123
+ # @return [Qismo::SingleObject]
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
120
127
  end
@@ -133,9 +140,9 @@ module Qismo
133
140
  #
134
141
  # @param room_id [Integer]
135
142
  # @param last_comment_id [Integer]
136
- # @param **opt [Hash]
137
- # @return [Qismo::DataObject]
138
- def resolve_room(room_id, last_comment_id, **opt)
143
+ # @param opt [Hash]
144
+ # @return [Qismo::SingleObject]
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))
141
148
  body.data.service
@@ -146,9 +153,9 @@ module Qismo
146
153
  # Get agent that can be assigned to room
147
154
  #
148
155
  # @param source [String]
149
- # @param **opt [Hash]
150
- # @return [Qismo::DataObject]
151
- def allocate_agent(source, **opt)
156
+ # @param opt [Hash]
157
+ # @return [Qismo::SingleObject]
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
154
161
  end
@@ -156,9 +163,9 @@ module Qismo
156
163
  # Get agent that can be allocated to room and automatically assign them
157
164
  #
158
165
  # @param room_id [Integer]
159
- # @param **opt [Hash]
160
- # @return [Qismo::DataObject]
161
- def allocate_and_assign_agent(room_id, **opt)
166
+ # @param opt [Hash]
167
+ # @return [Qismo::SingleObject]
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
164
171
  end
@@ -166,11 +173,11 @@ module Qismo
166
173
  # List agents that are not in room and can be assigned to room
167
174
  #
168
175
  # @param room_id [Integer]
169
- # @param **opt [Hash]
170
- # @return [Qismo::Collection]
171
- def other_agents(room_id, **opt)
176
+ # @param opt [Hash]
177
+ # @return [Qismo::CollectionObject]
178
+ def other_agents(room_id, opt = {})
172
179
  body = get("/api/v2/admin/service/other_agents", opt.merge(room_id: room_id))
173
- Collection.new(
180
+ CollectionObject.new(
174
181
  body.data.agents,
175
182
  prev_page: body.meta&.cursor_before,
176
183
  next_page: body.meta&.cursor_after,
@@ -182,11 +189,11 @@ module Qismo
182
189
  # List available agents in room
183
190
  #
184
191
  # @param room_id [Integer]
185
- # @param **opt [Hash]
186
- # @return [Qismo::Collection]
187
- def available_agents(room_id, **opt)
192
+ # @param opt [Hash]
193
+ # @return [Qismo::CollectionObject]
194
+ def available_agents(room_id, opt = {})
188
195
  body = get("/api/v2/admin/service/available_agents", opt.merge(room_id: room_id))
189
- Collection.new(
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::DataObject]
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
@@ -205,15 +212,15 @@ module Qismo
205
212
  # Set new session webhook
206
213
  #
207
214
  # @param url [String]
208
- # @param **opt [Hash]
209
- # @return [Qismo::DataObject]
210
- def set_new_session_webhook(url, **opt)
215
+ # @param opt [Hash]
216
+ # @return [Qismo::SingleObject]
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::DataObject]
223
+ # @return [Qismo::SingleObject]
217
224
  def auth_webhook
218
225
  get("/api/v2/app/config/auth_webhook").data.configs
219
226
  end
@@ -221,15 +228,15 @@ module Qismo
221
228
  # Set auth webhook
222
229
  #
223
230
  # @param url [String]
224
- # @param **opt [Hash]
225
- # @return [Qismo::DataObject]
226
- def set_auth_webhook(url, **opt)
231
+ # @param opt [Hash]
232
+ # @return [Qismo::SingleObject]
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::DataObject]
239
+ # @return [Qismo::SingleObject]
233
240
  def resolve_webhook
234
241
  get("/api/v1/app/webhook/mark_as_resolved").data
235
242
  end
@@ -237,17 +244,17 @@ module Qismo
237
244
  # Set resolve webhook
238
245
  #
239
246
  # @param url [String]
240
- # @param **opt [Hash]
241
- # @return [Qismo::DataObject]
242
- def set_resolve_webhook(url, **opt)
247
+ # @param opt [Hash]
248
+ # @return [Qismo::SingleObject]
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
245
252
 
246
253
  # List agents
247
254
  #
248
- # @param **opt [Hash]
249
- # @return [Qismo::Collection]
250
- def agents(**opt)
255
+ # @param opt [Hash]
256
+ # @return [Qismo::CollectionObject]
257
+ def agents(opt = {})
251
258
  if opt[:page].nil? || opt[:page].empty?
252
259
  opt[:page] = 1
253
260
  end
@@ -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
- Collection.new(
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 *ids [Array<Integer>]
273
- # @return [Qismo::DataObject]
274
- def agents_by_ids(*ids)
275
- get("/api/v1/admin/agents/get_by_ids", **{ "ids[]": ids }).data
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 *division_ids [Array<Integer>]
281
- # @param **opt [Hash]
282
- # @return [Qismo::Collection]
283
- def agents_by_divisions(*division_ids, **opt)
287
+ # @param division_ids [Array<Integer>]
288
+ # @param opt [Hash]
289
+ # @return [Qismo::CollectionObject]
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
- Collection.new(
296
+ CollectionObject.new(
290
297
  body.data,
291
298
  next_page: next_page,
292
299
  prev_page: prev_page,
@@ -298,34 +305,34 @@ module Qismo
298
305
  # Get agent by id
299
306
  #
300
307
  # @param agent_id [Integer]
301
- # @return [Qismo::DataObject]
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::DataObject]
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
- DataObject.new(data_hash)
321
+ SingleObject.new(data_hash)
315
322
  end
316
323
 
317
324
  # List WA broadcast templates
318
325
  #
319
- # @param **opt [Hash]
320
- # @return [Qismo::Collection]
321
- def wa_broadcast_templates(**opt)
326
+ # @param opt [Hash]
327
+ # @return [Qismo::CollectionObject]
328
+ def wa_broadcast_templates(opt = {})
322
329
  body = get("/api/v3/admin/hsm", opt)
323
330
 
324
331
  meta = body.meta
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
- Collection.new(
335
+ CollectionObject.new(
329
336
  body.data.hsm_templates,
330
337
  next_page: next_page,
331
338
  prev_page: prev_page,
@@ -336,9 +343,9 @@ module Qismo
336
343
 
337
344
  # Send WA outbound message
338
345
  #
339
- # @param **opt [Hash]
340
- # @return [Qismo::DataObject]
341
- def send_wa_outbound(**opt)
346
+ # @param opt [Hash]
347
+ # @return [Qismo::SingleObject]
348
+ def send_wa_outbound(opt = {})
342
349
  post("/api/v3/admin/broadcast/client", opt).data
343
350
  end
344
351
 
@@ -346,7 +353,7 @@ module Qismo
346
353
  #
347
354
  # @param file [HTTP::FormData]
348
355
  # @param template_detail_id [Integer]
349
- # @return [Qismo::DataObject]
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
 
@@ -355,23 +362,23 @@ module Qismo
355
362
 
356
363
  # Send wa broadcast
357
364
  #
358
- # @param **opt [Hash]
359
- # @return [Qismo::DataObject]
360
- def send_wa_broadcast(**opt)
365
+ # @param opt [Hash]
366
+ # @return [Qismo::SingleObject]
367
+ def send_wa_broadcast(opt = {})
361
368
  post("/api/v3/admin/broadcast/send_broadcast", opt).data.broadcast_job
362
369
  end
363
370
 
364
371
  # List wa broadcast jobs
365
372
  #
366
- # @param **opt [Hash]
367
- # @return [Qismo::Collection]
368
- def wa_broadcast_jobs(**opt)
373
+ # @param opt [Hash]
374
+ # @return [Qismo::CollectionObject]
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
- Collection.new(
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::DataObject]
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
@@ -391,15 +398,15 @@ module Qismo
391
398
  # List wa broadcast logs
392
399
  #
393
400
  # @param broadcast_job_id [Integer]
394
- # @param **opt [Hash]
395
- # @return [Qismo::Collection]
396
- def wa_broadcast_logs(broadcast_job_id, **opt)
401
+ # @param opt [Hash]
402
+ # @return [Qismo::CollectionObject]
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
- Collection.new(
409
+ CollectionObject.new(
403
410
  body.data.broadcast_logs,
404
411
  next_page: next_page,
405
412
  prev_page: prev_page,
@@ -410,9 +417,9 @@ module Qismo
410
417
 
411
418
  # Send message as bot
412
419
  #
413
- # @param **opt [Hash]
420
+ # @param opt [Hash]
414
421
  # @return [TrueClass]
415
- def send_bot_message(**opt)
422
+ def send_bot_message(opt = {})
416
423
  post("#{app_id}/bot", opt)
417
424
  true
418
425
  end
@@ -421,16 +428,16 @@ module Qismo
421
428
  #
422
429
  # @param room_id [Integer]
423
430
  # @return [TrueClass]
424
- def enable_chatbot_in_room(room_id)
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 chabot in room
436
+ # Disable chatbot in room
430
437
  #
431
438
  # @param room_id [Integer]
432
439
  # @return [TrueClass]
433
- def disable_chatbot_in_room(room_id)
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,10 +454,10 @@ module Qismo
447
454
  # Handover room from chatbot to human agent in specific divisions
448
455
  #
449
456
  # @param room_id [Integer]
450
- # @param *roles [Array<Integer>]
451
- # @param **opt [Hash]
457
+ # @param roles [Array<Integer>]
458
+ # @param opt [Hash]
452
459
  # @return [TrueClass]
453
- def handover_room_from_bot_to_division(room_id, *roles, **opt)
460
+ def handover_room_from_bot_to_division(room_id, roles, opt = {})
454
461
  post("/#{app_id}/bot/#{room_id}/hand_over_to_role", opt.merge(roles: roles))
455
462
  true
456
463
  end
@@ -459,9 +466,9 @@ module Qismo
459
466
  #
460
467
  # @param user_id [String]
461
468
  # @param name [String]
462
- # @param **opt [Hash]
463
- # @return [Qismo::DataObject]
464
- def initiate_widget_chat(user_id, name, **opt)
469
+ # @param opt [Hash]
470
+ # @return [Qismo::SingleObject]
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
467
474
  end
@@ -471,11 +478,72 @@ module Qismo
471
478
  # @param identifier_key [String]
472
479
  # @param user_id [String]
473
480
  # @param name [String]
474
- # @param **opt [Hash]
475
- # @return [Qismo::DataObject]
476
- def send_message_to_custom_channel(identifier_key, user_id, name, **opt)
481
+ # @param opt [Hash]
482
+ # @return [Qismo::SingleObject]
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
@@ -28,8 +28,8 @@ module Qismo
28
28
 
29
29
  # Initialize client
30
30
  #
31
- # @param **opt [Hash]
32
- def initialize(**opt)
31
+ # @param opt [Hash]
32
+ def initialize(opt = {})
33
33
  DEFAULT_OPTIONS.merge(opt).each do |key, value|
34
34
  instance_variable_set("@#{key}", value)
35
35
  end
@@ -39,7 +39,7 @@ module Qismo
39
39
  #
40
40
  # @param path [String]
41
41
  # @param body [Hash]
42
- # @return [Qismo::DataObject]
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::DataObject]
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::DataObject]
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::DataObject]
75
- def request(method, path, **opt)
74
+ # @return [Qismo::SingleObject]
75
+ def request(method, path, opt = {})
76
76
  res = connection.request(method, @url + path, opt.compact)
77
77
  if res.status.success?
78
- return DataObject.new(JSON.parse(res.to_s))
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 = DataObject.new(JSON.parse(res.to_s))
86
+ body = SingleObject.new(JSON.parse(res.to_s))
87
87
 
88
88
  error = body.errors
89
- error = error.message if error.is_a?(DataObject)
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 DataObject
6
+ class SingleObject
7
7
  # Initiate data object
8
8
  #
9
- # @param **opt [Hash]
10
- def initialize(**opt)
9
+ # @param opt [Hash]
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 Collection < Array
57
+ class CollectionObject < Array
58
58
  # Initiate collection
59
59
  #
60
- # @param data [Qismo::DataObject]
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::DataObject, Qismo::Collection]
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::DataObject, Qismo::Collection]
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
@@ -5,7 +5,7 @@ module Qismo
5
5
  class << self
6
6
  # Check if now is in office hour or not
7
7
  #
8
- # @param data [Qismo::DataObject]
8
+ # @param data [Qismo::SingleObject]
9
9
  # @return [TrueClass, FalseClass]
10
10
  def in_office_hour?(data)
11
11
  return false if data.timezone.blank?
data/lib/qismo/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Qismo
4
4
  # @return [String]
5
- VERSION = "0.8.8"
5
+ VERSION = "0.10.0"
6
6
  end
data/lib/qismo.rb CHANGED
@@ -21,9 +21,9 @@ module Qismo
21
21
 
22
22
  # Initiate Qismo ruby client
23
23
  #
24
- # @param **opt [Hash]
24
+ # @param opt [Hash]
25
25
  # @return [Qismo::Client]
26
- def new(**opt)
26
+ def new(opt = {})
27
27
  @client = Client.new(opt)
28
28
  end
29
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qismo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qiscus Integration