qismo 0.8.6 → 0.8.8

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: 39920707bba81e3df5853731180b02e10d694a4cbf793c6f64c7bfe169a6a9c2
4
- data.tar.gz: 4871ab5d1557e8ccd6c249354b4117da16779b5ecdcafb906641597a8ca39358
3
+ metadata.gz: e196e01cac13d44aad35e83f177ee216652905168e7a2a429530ccabe45ecdde
4
+ data.tar.gz: 05400a68bed6f50255d058d77faa6e53bc8d84b86d0b1b6c9624481734bf771a
5
5
  SHA512:
6
- metadata.gz: 448f4ba83da3cc5adefebe4b893b1372f2b43e582fa7b3ee8cd6d1d4f8ff2e07fc43a0a27de438c80b30a2dc7f65e2e7af718ad61757c33111b22ff88d5c4af4
7
- data.tar.gz: 824b127bfbaad9e0f380f1765011cd76b626e7a957aa52a3845a25789a68860d23af2de435b3a543dab9428be052ffc49ada6710e088d30c6a6e998a774bf641
6
+ metadata.gz: 5e5981fd67c309df024443376ed65e782d4f906197a3f40d942388cfa6f0ffc8e00f109a18ad56632cdb76fc60022a6e89a50e2955fd7343e2c20e04736c93d2
7
+ data.tar.gz: 88de21e6afd13aa6b88659d686c1f3a316c800d4c18618e886a99002d13a1b29266d1e09b35099dc0d3b21e84ebdb9b17cb3bce8c594bd1c05b507931c8b2e14
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qismo (0.8.3)
4
+ qismo (0.8.7)
5
5
  activesupport
6
6
  http
7
7
 
data/lib/qismo/api.rb CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Qismo
4
4
  module Api
5
+ # List customer rooms
6
+ #
7
+ # @param opt [Hash]
8
+ # @return [Qismo::Collection]
5
9
  def rooms(**opt)
6
10
  body = post("/api/v2/customer_rooms", opt)
7
11
  Collection.new(
@@ -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,35 +30,69 @@ 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
 
91
+ # List Whatsapp broadcast history inside room
92
+ #
93
+ # @param room_id [Integer]
94
+ # @param **opt [Hash]
95
+ # @return [Qismo::Collection]
54
96
  def room_broadcast_history(room_id, **opt)
55
97
  body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", opt)
56
98
 
@@ -66,34 +108,66 @@ module Qismo
66
108
  )
67
109
  end
68
110
 
111
+ # Assign agent to room
112
+ #
113
+ # @param room_id [Integer]
114
+ # @param agent_id [Integer]
115
+ # @param **opt [Hash]
116
+ # @return [Qismo::DataObject]
69
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
 
146
+ # Get agent that can be assigned to room
147
+ #
148
+ # @param source [String]
149
+ # @param **opt [Hash]
150
+ # @return [Qismo::DataObject]
87
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
 
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]
92
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
 
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]
97
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(
@@ -105,6 +179,11 @@ module Qismo
105
179
  )
106
180
  end
107
181
 
182
+ # List available agents in room
183
+ #
184
+ # @param room_id [Integer]
185
+ # @param **opt [Hash]
186
+ # @return [Qismo::Collection]
108
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(
@@ -116,30 +195,58 @@ 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
 
205
+ # Set new session webhook
206
+ #
207
+ # @param url [String]
208
+ # @param **opt [Hash]
209
+ # @return [Qismo::DataObject]
123
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
 
221
+ # Set auth webhook
222
+ #
223
+ # @param url [String]
224
+ # @param **opt [Hash]
225
+ # @return [Qismo::DataObject]
131
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
 
237
+ # Set resolve webhook
238
+ #
239
+ # @param url [String]
240
+ # @param **opt [Hash]
241
+ # @return [Qismo::DataObject]
139
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
 
246
+ # List agents
247
+ #
248
+ # @param **opt [Hash]
249
+ # @return [Qismo::Collection]
143
250
  def agents(**opt)
144
251
  if opt[:page].nil? || opt[:page].empty?
145
252
  opt[:page] = 1
@@ -160,10 +267,19 @@ 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
 
278
+ # List agents by divisions
279
+ #
280
+ # @param *division_ids [Array<Integer>]
281
+ # @param **opt [Hash]
282
+ # @return [Qismo::Collection]
167
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
 
@@ -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,6 +314,10 @@ module Qismo
191
314
  DataObject.new(data_hash)
192
315
  end
193
316
 
317
+ # List WA broadcast templates
318
+ #
319
+ # @param **opt [Hash]
320
+ # @return [Qismo::Collection]
194
321
  def wa_broadcast_templates(**opt)
195
322
  body = get("/api/v3/admin/hsm", opt)
196
323
 
@@ -207,62 +334,145 @@ module Qismo
207
334
  )
208
335
  end
209
336
 
337
+ # Send WA outbound message
338
+ #
339
+ # @param **opt [Hash]
340
+ # @return [Qismo::DataObject]
210
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
 
356
+ # Send wa broadcast
357
+ #
358
+ # @param **opt [Hash]
359
+ # @return [Qismo::DataObject]
220
360
  def send_wa_broadcast(**opt)
221
361
  post("/api/v3/admin/broadcast/send_broadcast", opt).data.broadcast_job
222
362
  end
223
363
 
364
+ # List wa broadcast jobs
365
+ #
366
+ # @param **opt [Hash]
367
+ # @return [Qismo::Collection]
224
368
  def wa_broadcast_jobs(**opt)
225
- get("/api/v2/admin/broadcast_jobs", opt).data.broadcast_jobs
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
 
391
+ # List wa broadcast logs
392
+ #
393
+ # @param broadcast_job_id [Integer]
394
+ # @param **opt [Hash]
395
+ # @return [Qismo::Collection]
232
396
  def wa_broadcast_logs(broadcast_job_id, **opt)
233
- get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", opt).data.broadcast_logs
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
 
411
+ # Send message as bot
412
+ #
413
+ # @param **opt [Hash]
414
+ # @return [TrueClass]
236
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
 
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]
256
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
 
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]
261
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
 
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]
266
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
data/lib/qismo/client.rb CHANGED
@@ -4,28 +4,60 @@ module Qismo
4
4
  class Client
5
5
  include Qismo::Api
6
6
 
7
- VALID_OPTIONS = [:app_id, :secret_key, :url, :logger, :instrumentation, :timeout, :proxy]
8
-
9
- attr_accessor(*VALID_OPTIONS)
10
-
7
+ # @return [String, NilClass]
8
+ DEFAULT_APP_ID = ENV["QISCUS_APP_ID"]
9
+
10
+ # @return [String, NilClass]
11
+ DEFAULT_SECRET_KEY = ENV["QISCUS_SECRET_KEY"]
12
+
13
+ # @return [String]
14
+ DEFAULT_URL = ENV["QISCUS_OMNICHANNEL_URL"] || "https://qismo.qiscus.com"
15
+
16
+ # @return [Hash]
17
+ DEFAULT_OPTIONS = {
18
+ app_id: DEFAULT_APP_ID,
19
+ secret_key: DEFAULT_SECRET_KEY,
20
+ url: DEFAULT_URL,
21
+ logger: nil,
22
+ instrumentation: nil,
23
+ timeout: nil,
24
+ proxy: nil,
25
+ }
26
+
27
+ attr_accessor(*DEFAULT_OPTIONS.keys)
28
+
29
+ # Initialize client
30
+ #
31
+ # @param **opt [Hash]
11
32
  def initialize(**opt)
12
- @app_id = opt[:app_id] || ENV["QISCUS_APP_ID"]
13
- @secret_key = opt[:secret_key] || ENV["QISCUS_SECRET_KEY"]
14
- @url = opt[:url] || ENV["QISCUS_OMNICHANNEL_URL"] || "https://qismo.qiscus.com"
15
- @logger = opt[:logger]
16
- @instrumentation = opt[:instrumentation]
17
- @timeout = opt[:timeout]
18
- @proxy = opt[:proxy]
33
+ DEFAULT_OPTIONS.merge(opt).each do |key, value|
34
+ instance_variable_set("@#{key}", value)
35
+ end
19
36
  end
20
37
 
38
+ # Send http request with post method
39
+ #
40
+ # @param path [String]
41
+ # @param body [Hash]
42
+ # @return [Qismo::DataObject]
21
43
  def post(path, body = {})
22
44
  request(:post, path, json: body)
23
45
  end
24
46
 
47
+ # Http request with post method to upload file
48
+ #
49
+ # @param path [String]
50
+ # @param body [Hash]
51
+ # @return [Qismo::DataObject]
25
52
  def post_upload(path, body = {})
26
53
  request(:post, form: body)
27
54
  end
28
55
 
56
+ # Send http request with get method
57
+ #
58
+ # @param path [String]
59
+ # @param params [Hash]
60
+ # @return [Qismo::DataObject]
29
61
  def get(path, **params)
30
62
  request(:get, path, params: params)
31
63
  end
@@ -34,6 +66,12 @@ module Qismo
34
66
  request(:delete, path)
35
67
  end
36
68
 
69
+ # Send http request
70
+ #
71
+ # @param method [Symbol, String]
72
+ # @param path [String]
73
+ # @param body [Hash]
74
+ # @return [Qismo::DataObject]
37
75
  def request(method, path, **opt)
38
76
  res = connection.request(method, @url + path, opt.compact)
39
77
  if res.status.success?
@@ -64,6 +102,9 @@ module Qismo
64
102
  end
65
103
  end
66
104
 
105
+ # Http connection config
106
+ #
107
+ # @return [HTTP::Chainable]
67
108
  def connection
68
109
  http = HTTP
69
110
 
@@ -94,6 +135,9 @@ module Qismo
94
135
  })
95
136
  end
96
137
 
138
+ # Http user agent config
139
+ #
140
+ # @return [Hash]
97
141
  def user_agent
98
142
  {
99
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,25 +1,23 @@
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)
9
- # instance_variable_set("@#{key}", handle_array(value))
10
14
  elsif value.is_a?(Hash)
11
15
  self.class.new(value)
12
- # instance_variable_set("@#{key}", self.class.new(value))
13
16
  elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
14
- method_name = key.to_s.delete_prefix("is_")
15
- method_name = "#{method_name}?".to_sym
16
-
17
- self.class.define_method(method_name) { value }
18
-
17
+ self.class.define_method("#{key.to_s.delete_prefix("is_")}?".to_sym) { value }
19
18
  value
20
19
  else
21
20
  value
22
- # instance_variable_set("@#{key}", value)
23
21
  end
24
22
 
25
23
  self.class.attr_reader(key.to_sym)
@@ -54,7 +52,16 @@ module Qismo
54
52
  end
55
53
  end
56
54
 
55
+ # Class to handle response body that contain pagination
56
+ #
57
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]
58
65
  def initialize(data, prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
59
66
  super(data)
60
67
 
@@ -64,22 +71,30 @@ module Qismo
64
71
  @next_func = next_func
65
72
  end
66
73
 
74
+ # @return [TrueClass, FalseClass]
67
75
  def has_next_page?
68
76
  @next_page != nil
69
77
  end
70
78
 
71
79
  alias_method :next_page?, :has_next_page?
72
80
 
81
+ # @return [TrueClass, FalseClass]
73
82
  def has_prev_page?
74
83
  @prev_page != nil
75
84
  end
76
85
 
77
86
  alias_method :prev_page?, :has_prev_page?
78
87
 
88
+ # Call api request for next page
89
+ #
90
+ # @return [Qismo::DataObject, Qismo::Collection]
79
91
  def next_page
80
92
  @next_func.call if has_next_page?
81
93
  end
82
94
 
95
+ # Call api request for previous page
96
+ #
97
+ # @return [Qismo::DataObject, Qismo::Collection]
83
98
  def prev_page
84
99
  @prev_func.call if has_prev_page?
85
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
 
@@ -15,8 +19,10 @@ module Qismo
15
19
  start_hour = today_office_hour.starttime
16
20
  end_hour = today_office_hour.endtime
17
21
 
22
+ # rubocop:disable Layout/LineLength
18
23
  start_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{start_hour} #{data.timezone}")
19
24
  end_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{end_hour} #{data.timezone}")
25
+ # rubocop:enable Layout/LineLength
20
26
 
21
27
  tz_current.between?(start_time, end_time)
22
28
  end
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.6"
4
+ # @return [String]
5
+ VERSION = "0.8.8"
5
6
  end
data/lib/qismo.rb CHANGED
@@ -10,17 +10,21 @@ 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
- attr_reader(*Qismo::Client::VALID_OPTIONS)
17
-
18
16
  def configure
19
17
  yield client
20
18
 
21
- Qismo::Client::VALID_OPTIONS.each do |opt|
22
- instance_variable_set("@#{opt}", client.send(opt))
23
- end
19
+ client
20
+ end
21
+
22
+ # Initiate Qismo ruby client
23
+ #
24
+ # @param **opt [Hash]
25
+ # @return [Qismo::Client]
26
+ def new(**opt)
27
+ @client = Client.new(opt)
24
28
  end
25
29
 
26
30
  if Gem::Version.new(RUBY_VERSION).release >= Gem::Version.new("3.0.0")
@@ -41,6 +45,8 @@ module Qismo
41
45
  Qismo::Client.instance_methods.include?(method_name)
42
46
  end
43
47
 
48
+ private
49
+
44
50
  def client
45
51
  @client ||= Client.new
46
52
  end
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.6
4
+ version: 0.8.8
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