qismo 0.8.7 → 0.9.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: 4e2ec0fd1f33602149f8bdee9c1f197470c9bac2f381460fd7ade574a3106941
4
- data.tar.gz: c08c1226ba080a9b42c114cf4e742efca2dc57c69d629c9402561c0fcb302b9a
3
+ metadata.gz: dbfbe5dc426f29f2bab1875e42889d559b0fb0936d471343e6dd2088ac1c0cc1
4
+ data.tar.gz: ca61c1154a98b662dbe05b87d6340a5a423b7665908b7ae7baa1f296ff03b8df
5
5
  SHA512:
6
- metadata.gz: 0e97d7caa322c1e60ad35316295fb1cf8107c3f9527abed5514e9ce83b20a1d141558356fe4fe825b259b849149402d71910a50d0e558dc358d581a8509c864d
7
- data.tar.gz: 795bfb449d7d08bb654bdaee29486a29b654b98c69ad30fa736a3d1d12ecd8139a7776b96de07c651f371497d52f431837d86e010d6afd866a125399cc446172
6
+ metadata.gz: 58b646f0e706c9193f46f60c6aa31aa1572539bbb098718e75725c6f7b197436a68c52e001b7bc9a46ea4fe04dd258eee8e2fcbe3a656c1364a6375ad231907d
7
+ data.tar.gz: 3d154d41d5a1a763da397b3b245b6087e8a2456028cfdabe32076471956491ca314931c9fc4d5d4340bbd2bd9c1b39281808310b664ad7e934d36ff4cea1dde8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qismo (0.8.6)
4
+ qismo (0.8.8)
5
5
  activesupport
6
6
  http
7
7
 
data/lib/qismo/api.rb CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  module Qismo
4
4
  module Api
5
- def rooms(**opt)
5
+ # List customer rooms
6
+ #
7
+ # @param opt [Hash]
8
+ # @return [Qismo::Collection]
9
+ def rooms(opt = {})
6
10
  body = post("/api/v2/customer_rooms", opt)
7
11
  Collection.new(
8
12
  body.data.customer_rooms,
@@ -13,6 +17,10 @@ module Qismo
13
17
  )
14
18
  end
15
19
 
20
+ # Get room by id
21
+ #
22
+ # @param room_id [Integer]
23
+ # @return [Qismo::DataObject]
16
24
  def room(room_id)
17
25
  body = get("/api/v2/customer_rooms/#{room_id}")
18
26
  if body.data.customer_room.nil?
@@ -22,36 +30,70 @@ module Qismo
22
30
  body.data.customer_room
23
31
  end
24
32
 
33
+ # List tags inside room
34
+ #
35
+ # @param room_id [Integer]
36
+ # @return [Qismo::DataObject]
25
37
  def room_tags(room_id)
26
38
  get("/api/v2/room_tags/#{room_id}").data
27
39
  end
28
40
 
41
+ # Add room tag
42
+ #
43
+ # @param room_id [Integer]
44
+ # @param tag [String]
45
+ # @return [Qismo::DataObject]
29
46
  def add_room_tag(room_id, tag)
30
47
  post("/api/v2/room_tags/#{room_id}", tag: tag).data
31
48
  end
32
49
 
50
+ # Delete room tag
51
+ #
52
+ # @param room_id [Integer]
53
+ # @param tag_id [Integer]
54
+ # @return [TrueClass]
33
55
  def delete_room_tag(room_id, tag_id)
34
56
  delete("/api/v2/room_tags/#{room_id}/#{tag_id}")
35
57
  true
36
58
  end
37
59
 
60
+ # List room additional info
61
+ #
62
+ # @param room_id [Integer]
63
+ # @return [Qismo::DataObject]
38
64
  def room_additional_info(room_id)
39
65
  body = get("/api/v1/qiscus/room/#{room_id}/user_info")
40
66
  body.data.extras.user_properties
41
67
  end
42
68
 
69
+ # Set room additional info
70
+ #
71
+ # @note This will replace your current room additional info
72
+ # @param room_id [Integer]
73
+ # @param *additional_info [Array<Hash>]
74
+ # @return [Qismo::DataObject]
43
75
  def set_room_additional_info(room_id, *additional_info)
44
76
  body = post("/api/v1/qiscus/room/#{room_id}/user_info", user_properties: additional_info)
45
77
  body.data.extras.user_properties
46
78
  end
47
79
 
80
+ # Update room additional info
81
+ #
82
+ # @param room_id [Integer]
83
+ # @param *additional_info [Array]
84
+ # @return [Qismo::DataObject]
48
85
  def update_room_additional_info(room_id, *additional_info)
49
86
  old_additional_info = room_additional_info(room_id)
50
87
  new_additional_info = (additional_info + old_additional_info).uniq { |h| h.values_at("key") }
51
88
  set_room_additional_info(room_id, *new_additional_info)
52
89
  end
53
90
 
54
- def room_broadcast_history(room_id, **opt)
91
+ # List Whatsapp broadcast history inside room
92
+ #
93
+ # @param room_id [Integer]
94
+ # @param opt [Hash]
95
+ # @return [Qismo::Collection]
96
+ def room_broadcast_history(room_id, opt = {})
55
97
  body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", opt)
56
98
 
57
99
  next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
@@ -66,35 +108,67 @@ module Qismo
66
108
  )
67
109
  end
68
110
 
69
- def assign_agent(room_id, agent_id, **opt)
111
+ # Assign agent to room
112
+ #
113
+ # @param room_id [Integer]
114
+ # @param agent_id [Integer]
115
+ # @param opt [Hash]
116
+ # @return [Qismo::DataObject]
117
+ def assign_agent(room_id, agent_id, opt = {})
70
118
  body = post("/api/v1/admin/service/assign_agent", opt.merge(room_id: room_id.to_s, agent_id: agent_id))
71
119
  body.data.added_agent
72
120
  end
73
121
 
122
+ # Remove agent from room
123
+ #
124
+ # @param room_id [Integer]
125
+ # @param agent_id [Integer]
126
+ # @return [TrueClass]
74
127
  def remove_agent(room_id, agent_id)
75
128
  post("/api/v1/admin/service/remove_agent", room_id: room_id.to_s, agent_id: agent_id)
76
129
  true
77
130
  end
78
131
 
79
- def resolve(room_id, last_comment_id, **opt)
132
+ # Resolve room
133
+ #
134
+ # @param room_id [Integer]
135
+ # @param last_comment_id [Integer]
136
+ # @param opt [Hash]
137
+ # @return [Qismo::DataObject]
138
+ def resolve_room(room_id, last_comment_id, opt = {})
80
139
  body = post("/api/v1/admin/service/mark_as_resolved",
81
140
  opt.merge(room_id: room_id.to_s, last_comment_id: last_comment_id))
82
141
  body.data.service
83
142
  end
84
143
 
85
- alias_method :resolve_room, :resolve
144
+ alias_method :resolve, :resolve_room
86
145
 
87
- def allocate_agent(source, **opt)
146
+ # Get agent that can be assigned to room
147
+ #
148
+ # @param source [String]
149
+ # @param opt [Hash]
150
+ # @return [Qismo::DataObject]
151
+ def allocate_agent(source, opt = {})
88
152
  body = post("/api/v1/admin/service/allocate_agent", opt.merge(source: source))
89
153
  body.data.agent
90
154
  end
91
155
 
92
- def allocate_and_assign_agent(room_id, **opt)
156
+ # Get agent that can be allocated to room and automatically assign them
157
+ #
158
+ # @param room_id [Integer]
159
+ # @param opt [Hash]
160
+ # @return [Qismo::DataObject]
161
+ def allocate_and_assign_agent(room_id, opt = {})
93
162
  body = post("/api/v1/admin/service/allocate_assign_agent", opt.merge(room_id: room_id))
94
163
  body.data.agent
95
164
  end
96
165
 
97
- def other_agents(room_id, **opt)
166
+ # List agents that are not in room and can be assigned to room
167
+ #
168
+ # @param room_id [Integer]
169
+ # @param opt [Hash]
170
+ # @return [Qismo::Collection]
171
+ def other_agents(room_id, opt = {})
98
172
  body = get("/api/v2/admin/service/other_agents", opt.merge(room_id: room_id))
99
173
  Collection.new(
100
174
  body.data.agents,
@@ -105,7 +179,12 @@ module Qismo
105
179
  )
106
180
  end
107
181
 
108
- def available_agents(room_id, **opt)
182
+ # List available agents in room
183
+ #
184
+ # @param room_id [Integer]
185
+ # @param opt [Hash]
186
+ # @return [Qismo::Collection]
187
+ def available_agents(room_id, opt = {})
109
188
  body = get("/api/v2/admin/service/available_agents", opt.merge(room_id: room_id))
110
189
  Collection.new(
111
190
  body.data.agents,
@@ -116,31 +195,59 @@ module Qismo
116
195
  )
117
196
  end
118
197
 
198
+ # Get new session webhook config
199
+ #
200
+ # @return [Qismo::DataObject]
119
201
  def new_session_webhook
120
202
  get("/api/v2/app/config/new_session_webhook").data.configs
121
203
  end
122
204
 
123
- def set_new_session_webhook(url, **opt)
205
+ # Set new session webhook
206
+ #
207
+ # @param url [String]
208
+ # @param opt [Hash]
209
+ # @return [Qismo::DataObject]
210
+ def set_new_session_webhook(url, opt = {})
124
211
  post("/api/v2/app/config/new_session_webhook", opt.merge(url: url)).data.configs
125
212
  end
126
213
 
214
+ # Get auth webhook config
215
+ #
216
+ # @return [Qismo::DataObject]
127
217
  def auth_webhook
128
218
  get("/api/v2/app/config/auth_webhook").data.configs
129
219
  end
130
220
 
131
- def set_auth_webhook(url, **opt)
221
+ # Set auth webhook
222
+ #
223
+ # @param url [String]
224
+ # @param opt [Hash]
225
+ # @return [Qismo::DataObject]
226
+ def set_auth_webhook(url, opt = {})
132
227
  post("/api/v2/app/config/auth_webhook", opt.merge(url: url)).data.configs
133
228
  end
134
229
 
230
+ # Get resolve webhook config
231
+ #
232
+ # @return [Qismo::DataObject]
135
233
  def resolve_webhook
136
234
  get("/api/v1/app/webhook/mark_as_resolved").data
137
235
  end
138
236
 
139
- def set_resolve_webhook(url, **opt)
237
+ # Set resolve webhook
238
+ #
239
+ # @param url [String]
240
+ # @param opt [Hash]
241
+ # @return [Qismo::DataObject]
242
+ def set_resolve_webhook(url, opt = {})
140
243
  post("/api/v1/app/webhook/mark_as_resolved", opt.merge(url: url)).data
141
244
  end
142
245
 
143
- def agents(**opt)
246
+ # List agents
247
+ #
248
+ # @param opt [Hash]
249
+ # @return [Qismo::Collection]
250
+ def agents(opt = {})
144
251
  if opt[:page].nil? || opt[:page].empty?
145
252
  opt[:page] = 1
146
253
  end
@@ -160,11 +267,20 @@ module Qismo
160
267
  )
161
268
  end
162
269
 
270
+ # List agents by id
271
+ #
272
+ # @param *ids [Array<Integer>]
273
+ # @return [Qismo::DataObject]
163
274
  def agents_by_ids(*ids)
164
275
  get("/api/v1/admin/agents/get_by_ids", **{ "ids[]": ids }).data
165
276
  end
166
277
 
167
- def agents_by_divisions(*division_ids, **opt)
278
+ # List agents by divisions
279
+ #
280
+ # @param *division_ids [Array<Integer>]
281
+ # @param opt [Hash]
282
+ # @return [Qismo::Collection]
283
+ def agents_by_divisions(division_ids, opt = {})
168
284
  body = get("/api/v2/admin/agents/by_division", opt.merge({ "division_ids[]": division_ids }))
169
285
 
170
286
  next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
@@ -179,10 +295,17 @@ module Qismo
179
295
  )
180
296
  end
181
297
 
298
+ # Get agent by id
299
+ #
300
+ # @param agent_id [Integer]
301
+ # @return [Qismo::DataObject]
182
302
  def agent(agent_id)
183
303
  get("/api/v2/admin/agent/#{agent_id}").data.agent
184
304
  end
185
305
 
306
+ # Get office hour config
307
+ #
308
+ # @return [Qismo::DataObject]
186
309
  def office_hours
187
310
  data = get("/api/v1/admin/office_hours").data
188
311
  data_hash = data.as_json
@@ -191,7 +314,11 @@ module Qismo
191
314
  DataObject.new(data_hash)
192
315
  end
193
316
 
194
- def wa_broadcast_templates(**opt)
317
+ # List WA broadcast templates
318
+ #
319
+ # @param opt [Hash]
320
+ # @return [Qismo::Collection]
321
+ def wa_broadcast_templates(opt = {})
195
322
  body = get("/api/v3/admin/hsm", opt)
196
323
 
197
324
  meta = body.meta
@@ -207,63 +334,146 @@ module Qismo
207
334
  )
208
335
  end
209
336
 
210
- def send_wa_outbound(**opt)
337
+ # Send WA outbound message
338
+ #
339
+ # @param opt [Hash]
340
+ # @return [Qismo::DataObject]
341
+ def send_wa_outbound(opt = {})
211
342
  post("/api/v3/admin/broadcast/client", opt).data
212
343
  end
213
344
 
345
+ # Upload wa broadcast file that want to be sent in broadcast
346
+ #
347
+ # @param file [HTTP::FormData]
348
+ # @param template_detail_id [Integer]
349
+ # @return [Qismo::DataObject]
214
350
  def upload_wa_broadcast_csv(file, template_detail_id)
215
351
  raise ArgumentError, "Invalid file" unless file.is_a?(HTTP::FormData::File)
216
352
 
217
353
  post_upload("/api/v3/admin/broadcast/upload_csv", file: file, template_detail_id: template_detail_id)
218
354
  end
219
355
 
220
- def send_wa_broadcast(**opt)
356
+ # Send wa broadcast
357
+ #
358
+ # @param opt [Hash]
359
+ # @return [Qismo::DataObject]
360
+ def send_wa_broadcast(opt = {})
221
361
  post("/api/v3/admin/broadcast/send_broadcast", opt).data.broadcast_job
222
362
  end
223
363
 
224
- def wa_broadcast_jobs(**opt)
225
- get("/api/v2/admin/broadcast_jobs", opt).data.broadcast_jobs
364
+ # List wa broadcast jobs
365
+ #
366
+ # @param opt [Hash]
367
+ # @return [Qismo::Collection]
368
+ def wa_broadcast_jobs(opt = {})
369
+ body = get("/api/v2/admin/broadcast_jobs", opt)
370
+
371
+ prev_page = body.meta.page > 1 ? (body.meta.meta - 1) : nil
372
+ next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
373
+
374
+ Collection.new(
375
+ body.data.broadcast_jobs,
376
+ next_page: next_page,
377
+ prev_page: prev_page,
378
+ next_func: -> { wa_broadcast_jobs(opt.merge(page: next_page)) },
379
+ prev_func: -> { wa_broadcast_jobs(opt.merge(page: prev_page)) },
380
+ )
226
381
  end
227
382
 
383
+ # Get wa broadcast job by id
384
+ #
385
+ # @param broadcast_job_id [Integer]
386
+ # @return [Qismo::DataObject]
228
387
  def wa_broadcast_job(broadcast_job_id)
229
388
  get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
230
389
  end
231
390
 
232
- def wa_broadcast_logs(broadcast_job_id, **opt)
233
- get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", opt).data.broadcast_logs
391
+ # List wa broadcast logs
392
+ #
393
+ # @param broadcast_job_id [Integer]
394
+ # @param opt [Hash]
395
+ # @return [Qismo::Collection]
396
+ def wa_broadcast_logs(broadcast_job_id, opt = {})
397
+ body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", opt)
398
+
399
+ prev_page = body.meta.page > 1 ? (body.meta.meta - 1) : nil
400
+ next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
401
+
402
+ Collection.new(
403
+ body.data.broadcast_logs,
404
+ next_page: next_page,
405
+ prev_page: prev_page,
406
+ next_func: -> { wa_broadcast_logs(opt.merge(page: next_page)) },
407
+ prev_func: -> { wa_broadcast_jobs(opt.merge(page: prev_page)) },
408
+ )
234
409
  end
235
410
 
236
- def send_bot_message(**opt)
411
+ # Send message as bot
412
+ #
413
+ # @param opt [Hash]
414
+ # @return [TrueClass]
415
+ def send_bot_message(opt = {})
237
416
  post("#{app_id}/bot", opt)
238
417
  true
239
418
  end
240
419
 
420
+ # Enable chabot in room
421
+ #
422
+ # @param room_id [Integer]
423
+ # @return [TrueClass]
241
424
  def enable_chatbot_in_room(room_id)
242
425
  post("/bot/#{room_id}/activate", is_active: true)
243
426
  true
244
427
  end
245
428
 
429
+ # Disable chabot in room
430
+ #
431
+ # @param room_id [Integer]
432
+ # @return [TrueClass]
246
433
  def disable_chatbot_in_room(room_id)
247
434
  post("/bot/#{room_id}/activate", is_active: false)
248
435
  true
249
436
  end
250
437
 
438
+ # Handover room from chatbot to human agent
439
+ #
440
+ # @param room_id [Integer]
441
+ # @return [TrueClass]
251
442
  def handover_room_from_bot(room_id)
252
443
  post("/#{app_id}/bot/#{room_id}/hand_over")
253
444
  true
254
445
  end
255
446
 
256
- def handover_room_from_bot_to_division(room_id, *roles, **opt)
447
+ # Handover room from chatbot to human agent in specific divisions
448
+ #
449
+ # @param room_id [Integer]
450
+ # @param *roles [Array<Integer>]
451
+ # @param opt [Hash]
452
+ # @return [TrueClass]
453
+ def handover_room_from_bot_to_division(room_id, roles, opt = {})
257
454
  post("/#{app_id}/bot/#{room_id}/hand_over_to_role", opt.merge(roles: roles))
258
455
  true
259
456
  end
260
457
 
261
- def initiate_widget_chat(user_id, name, **opt)
458
+ # Initiate chat using Qiscus widget channel
459
+ #
460
+ # @param user_id [String]
461
+ # @param name [String]
462
+ # @param opt [Hash]
463
+ # @return [Qismo::DataObject]
464
+ def initiate_widget_chat(user_id, name, opt = {})
262
465
  opt = opt.merge(app_id: app_id, user_id: user_id, name: name)
263
466
  post("/api/v2/qiscus/initiate_chat", opt).data.customer_room
264
467
  end
265
468
 
266
- def send_message_to_custom_channel(identifier_key, user_id, name, **opt)
469
+ # Send message to custom channel
470
+ #
471
+ # @param identifier_key [String]
472
+ # @param user_id [String]
473
+ # @param name [String]
474
+ # @param opt [Hash]
475
+ # @return [Qismo::DataObject]
476
+ def send_message_to_custom_channel(identifier_key, user_id, name, opt = {})
267
477
  post("/#{app_id}/api/v2/custom_channel/send",
268
478
  opt.merge(identifier_key: identifier_key, user_id: user_id, name: name)).data
269
479
  end
data/lib/qismo/client.rb CHANGED
@@ -4,10 +4,16 @@ module Qismo
4
4
  class Client
5
5
  include Qismo::Api
6
6
 
7
+ # @return [String, NilClass]
7
8
  DEFAULT_APP_ID = ENV["QISCUS_APP_ID"]
9
+
10
+ # @return [String, NilClass]
8
11
  DEFAULT_SECRET_KEY = ENV["QISCUS_SECRET_KEY"]
12
+
13
+ # @return [String]
9
14
  DEFAULT_URL = ENV["QISCUS_OMNICHANNEL_URL"] || "https://qismo.qiscus.com"
10
15
 
16
+ # @return [Hash]
11
17
  DEFAULT_OPTIONS = {
12
18
  app_id: DEFAULT_APP_ID,
13
19
  secret_key: DEFAULT_SECRET_KEY,
@@ -20,20 +26,38 @@ module Qismo
20
26
 
21
27
  attr_accessor(*DEFAULT_OPTIONS.keys)
22
28
 
23
- def initialize(**opt)
29
+ # Initialize client
30
+ #
31
+ # @param opt [Hash]
32
+ def initialize(opt = {})
24
33
  DEFAULT_OPTIONS.merge(opt).each do |key, value|
25
34
  instance_variable_set("@#{key}", value)
26
35
  end
27
36
  end
28
37
 
38
+ # Send http request with post method
39
+ #
40
+ # @param path [String]
41
+ # @param body [Hash]
42
+ # @return [Qismo::DataObject]
29
43
  def post(path, body = {})
30
44
  request(:post, path, json: body)
31
45
  end
32
46
 
47
+ # Http request with post method to upload file
48
+ #
49
+ # @param path [String]
50
+ # @param body [Hash]
51
+ # @return [Qismo::DataObject]
33
52
  def post_upload(path, body = {})
34
53
  request(:post, form: body)
35
54
  end
36
55
 
56
+ # Send http request with get method
57
+ #
58
+ # @param path [String]
59
+ # @param params [Hash]
60
+ # @return [Qismo::DataObject]
37
61
  def get(path, **params)
38
62
  request(:get, path, params: params)
39
63
  end
@@ -42,7 +66,13 @@ module Qismo
42
66
  request(:delete, path)
43
67
  end
44
68
 
45
- def request(method, path, **opt)
69
+ # Send http request
70
+ #
71
+ # @param method [Symbol, String]
72
+ # @param path [String]
73
+ # @param body [Hash]
74
+ # @return [Qismo::DataObject]
75
+ def request(method, path, opt = {})
46
76
  res = connection.request(method, @url + path, opt.compact)
47
77
  if res.status.success?
48
78
  return DataObject.new(JSON.parse(res.to_s))
@@ -72,6 +102,9 @@ module Qismo
72
102
  end
73
103
  end
74
104
 
105
+ # Http connection config
106
+ #
107
+ # @return [HTTP::Chainable]
75
108
  def connection
76
109
  http = HTTP
77
110
 
@@ -102,6 +135,9 @@ module Qismo
102
135
  })
103
136
  end
104
137
 
138
+ # Http user agent config
139
+ #
140
+ # @return [Hash]
105
141
  def user_agent
106
142
  {
107
143
  lib_version: Qismo::VERSION,
data/lib/qismo/error.rb CHANGED
@@ -1,19 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qismo
4
+ # Qismo ruby base error
5
+ #
4
6
  class Error < StandardError
5
7
  attr_reader :message
6
8
  end
7
9
 
10
+ # Http timeout error
11
+ #
8
12
  class HTTPTimeoutError < Error
9
13
  def initialize(message)
10
14
  super(message)
11
15
  end
12
16
  end
13
17
 
18
+ # Http request error
19
+ #
14
20
  class HTTPRequestError < Error
15
21
  attr_reader :message, :status_code, :response_body
16
22
 
23
+ # Initiate error
24
+ #
25
+ # @param message [String]
26
+ # @param status_code [Integer]
27
+ # @param response_body [String]
17
28
  def initialize(message, status_code:, response_body:)
18
29
  super(message.to_s)
19
30
 
@@ -23,30 +34,38 @@ module Qismo
23
34
  end
24
35
  end
25
36
 
37
+ # Http internal server error
38
+ #
26
39
  class InternalServerError < HTTPRequestError
27
40
  end
28
41
 
29
- # 400
42
+ # Http 400 bad request error
43
+ #
30
44
  class BadRequestError < HTTPRequestError
31
45
  end
32
46
 
33
- # 401
47
+ # Http 401 unauthorized error
48
+ #
34
49
  class UnauthorizedError < HTTPRequestError
35
50
  end
36
51
 
37
- # 402
52
+ # Http 402 payment required error
53
+ #
38
54
  class PaymentRequiredError < HTTPRequestError
39
55
  end
40
56
 
41
- # 403
57
+ # Http 403 forbidden error
58
+ #
42
59
  class ForbiddenError < HTTPRequestError
43
60
  end
44
61
 
45
- # 404
62
+ # Http 404 not found error
63
+ #
46
64
  class NotFoundError < HTTPRequestError
47
65
  end
48
66
 
49
- # 429
67
+ # Http 429 too many requests error
68
+ #
50
69
  class TooManyRequestError < HTTPRequestError
51
70
  end
52
71
  end
data/lib/qismo/model.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qismo
4
+ # Class to handle http response body
5
+ #
4
6
  class DataObject
5
- def initialize(**opt)
7
+ # Initiate data object
8
+ #
9
+ # @param opt [Hash]
10
+ def initialize(opt = {})
6
11
  opt.each do |key, value|
7
12
  value = if value.is_a?(Array)
8
13
  handle_array(value)
@@ -47,7 +52,16 @@ module Qismo
47
52
  end
48
53
  end
49
54
 
55
+ # Class to handle response body that contain pagination
56
+ #
50
57
  class Collection < Array
58
+ # Initiate collection
59
+ #
60
+ # @param data [Qismo::DataObject]
61
+ # @param prev_page [String, Integer]
62
+ # @param next_page [String, Integer]
63
+ # @param prev_func [Proc, NilClass]
64
+ # @param next_func [Proc, NilClass]
51
65
  def initialize(data, prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
52
66
  super(data)
53
67
 
@@ -57,22 +71,30 @@ module Qismo
57
71
  @next_func = next_func
58
72
  end
59
73
 
74
+ # @return [TrueClass, FalseClass]
60
75
  def has_next_page?
61
76
  @next_page != nil
62
77
  end
63
78
 
64
79
  alias_method :next_page?, :has_next_page?
65
80
 
81
+ # @return [TrueClass, FalseClass]
66
82
  def has_prev_page?
67
83
  @prev_page != nil
68
84
  end
69
85
 
70
86
  alias_method :prev_page?, :has_prev_page?
71
87
 
88
+ # Call api request for next page
89
+ #
90
+ # @return [Qismo::DataObject, Qismo::Collection]
72
91
  def next_page
73
92
  @next_func.call if has_next_page?
74
93
  end
75
94
 
95
+ # Call api request for previous page
96
+ #
97
+ # @return [Qismo::DataObject, Qismo::Collection]
76
98
  def prev_page
77
99
  @prev_func.call if has_prev_page?
78
100
  end
data/lib/qismo/util.rb CHANGED
@@ -3,6 +3,10 @@
3
3
  module Qismo
4
4
  class Util
5
5
  class << self
6
+ # Check if now is in office hour or not
7
+ #
8
+ # @param data [Qismo::DataObject]
9
+ # @return [TrueClass, FalseClass]
6
10
  def in_office_hour?(data)
7
11
  return false if data.timezone.blank?
8
12
 
data/lib/qismo/version.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qismo
4
- VERSION = "0.8.7"
4
+ # @return [String]
5
+ VERSION = "0.9.0"
5
6
  end
data/lib/qismo.rb CHANGED
@@ -10,8 +10,8 @@ require "qismo/model"
10
10
  require "qismo/api"
11
11
  require "qismo/client"
12
12
 
13
- # Qismo
14
13
  module Qismo
14
+ # @!method rooms
15
15
  class << self
16
16
  def configure
17
17
  yield client
@@ -19,7 +19,11 @@ module Qismo
19
19
  client
20
20
  end
21
21
 
22
- def new(**opt)
22
+ # Initiate Qismo ruby client
23
+ #
24
+ # @param opt [Hash]
25
+ # @return [Qismo::Client]
26
+ def new(opt = {})
23
27
  @client = Client.new(opt)
24
28
  end
25
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qismo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qiscus Integration
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport