qismo 0.9.0 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbfbe5dc426f29f2bab1875e42889d559b0fb0936d471343e6dd2088ac1c0cc1
4
- data.tar.gz: ca61c1154a98b662dbe05b87d6340a5a423b7665908b7ae7baa1f296ff03b8df
3
+ metadata.gz: 23e999cca8b986d2783ea662573e0fab71db0c0bb1e6bf0a1603b4442eea6acc
4
+ data.tar.gz: fc35ba076ba1c6597e1fb8f13b26c2a4319a92dc8c0a6215529c4f5aff2b9a09
5
5
  SHA512:
6
- metadata.gz: 58b646f0e706c9193f46f60c6aa31aa1572539bbb098718e75725c6f7b197436a68c52e001b7bc9a46ea4fe04dd258eee8e2fcbe3a656c1364a6375ad231907d
7
- data.tar.gz: 3d154d41d5a1a763da397b3b245b6087e8a2456028cfdabe32076471956491ca314931c9fc4d5d4340bbd2bd9c1b39281808310b664ad7e934d36ff4cea1dde8
6
+ metadata.gz: d45397820b9bdf5214ff8e45d164f2253824d20c4e8d2017d3c4cec9993c1e550e51754f4743be566b5296edb90d6eb7b1c6b82f098f25ce67b74db87422ee31
7
+ data.tar.gz: 40b3d89d5d06bce5e7460d7d36b3c0010da9fd583f0e7d66574a052be6b61bfda33688751380b32c1b6e436553f79f0661a739941e742aaf876800707fbb19cf
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.8)
4
+ qismo (0.10.0)
5
5
  activesupport
6
6
  http
7
7
 
data/lib/qismo/api.rb CHANGED
@@ -2,25 +2,29 @@
2
2
 
3
3
  module Qismo
4
4
  module Api
5
+ # @!parse include Qismo::Client
6
+
5
7
  # List customer rooms
6
8
  #
7
- # @param opt [Hash]
8
- # @return [Qismo::Collection]
9
- def rooms(opt = {})
10
- body = post("/api/v2/customer_rooms", opt)
11
- Collection.new(
9
+ # @see https://s.id/list-customer-rooms
10
+ # @param options [Hash]
11
+ # @return [Qismo::CollectionObject]
12
+ def rooms(options = {})
13
+ body = post("/api/v2/customer_rooms", options)
14
+ CollectionObject.new(
12
15
  body.data.customer_rooms,
13
16
  prev_page: body.meta&.cursor_before,
14
17
  next_page: body.meta&.cursor_after,
15
- prev_func: -> { rooms(opt.merge(cursor_before: body.meta&.cursor_before)) },
16
- next_func: -> { rooms(opt.merge(cursor_after: body.meta&.cursor_after)) },
18
+ prev_func: -> { rooms(options.merge(cursor_before: body.meta&.cursor_before)) },
19
+ next_func: -> { rooms(options.merge(cursor_after: body.meta&.cursor_after)) },
17
20
  )
18
21
  end
19
22
 
20
23
  # Get room by id
21
24
  #
25
+ # @see https://s.id/get-room-by-room-id
22
26
  # @param room_id [Integer]
23
- # @return [Qismo::DataObject]
27
+ # @return [Qismo::SingleObject]
24
28
  def room(room_id)
25
29
  body = get("/api/v2/customer_rooms/#{room_id}")
26
30
  if body.data.customer_room.nil?
@@ -32,23 +36,26 @@ module Qismo
32
36
 
33
37
  # List tags inside room
34
38
  #
39
+ # @see https://s.id/list-room-tags
35
40
  # @param room_id [Integer]
36
- # @return [Qismo::DataObject]
41
+ # @return [Qismo::CollectionObject]
37
42
  def room_tags(room_id)
38
- get("/api/v2/room_tags/#{room_id}").data
43
+ CollectionObject.new(get("/api/v2/room_tags/#{room_id}").data)
39
44
  end
40
45
 
41
46
  # Add room tag
42
47
  #
48
+ # @see https://s.id/add-room-tag
43
49
  # @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
50
+ # @param tag_name [String]
51
+ # @return [Qismo::SingleObject]
52
+ def add_room_tag(room_id, tag_name)
53
+ post("/api/v2/room_tags/#{room_id}", tag: tag_name).data
48
54
  end
49
55
 
50
56
  # Delete room tag
51
57
  #
58
+ # @see https://s.id/delete-room-tag
52
59
  # @param room_id [Integer]
53
60
  # @param tag_id [Integer]
54
61
  # @return [TrueClass]
@@ -59,68 +66,88 @@ module Qismo
59
66
 
60
67
  # List room additional info
61
68
  #
69
+ # @see https://s.id/list-room-info
62
70
  # @param room_id [Integer]
63
- # @return [Qismo::DataObject]
71
+ # @return [Qismo::CollectionObject]
64
72
  def room_additional_info(room_id)
65
- body = get("/api/v1/qiscus/room/#{room_id}/user_info")
66
- body.data.extras.user_properties
73
+ CollectionObject.new(
74
+ get(
75
+ "/api/v1/qiscus/room/#{room_id}/user_info",
76
+ ).data&.extras&.user_properties,
77
+ ) || CollectionObject.new
67
78
  end
68
79
 
80
+ alias_method :room_info, :room_additional_info
81
+
69
82
  # Set room additional info
70
83
  #
84
+ # @see https://s.id/set-room-info
71
85
  # @note This will replace your current room additional info
72
86
  # @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
87
+ # @param additional_info [Array<Hash>]
88
+ # @return [Qismo::CollectionObject]
89
+ def set_room_additional_info(room_id, additional_info)
90
+ CollectionObject.new(
91
+ post(
92
+ "/api/v1/qiscus/room/#{room_id}/user_info",
93
+ user_properties: additional_info,
94
+ ).data&.extras&.user_properties,
95
+ ) || CollectionObject.new
78
96
  end
79
97
 
98
+ alias_method :set_room_info, :set_room_additional_info
99
+ alias_method :create_room_info, :set_room_additional_info
100
+ alias_method :create_room_additional_info, :set_room_additional_info
101
+
80
102
  # Update room additional info
81
103
  #
82
104
  # @param room_id [Integer]
83
- # @param *additional_info [Array]
84
- # @return [Qismo::DataObject]
85
- def update_room_additional_info(room_id, *additional_info)
105
+ # @param additional_info [Array]
106
+ # @return [Qismo::CollectionObject]
107
+ def update_room_additional_info(room_id, additional_info)
86
108
  old_additional_info = room_additional_info(room_id)
87
109
  new_additional_info = (additional_info + old_additional_info).uniq { |h| h.values_at("key") }
88
- set_room_additional_info(room_id, *new_additional_info)
110
+ set_room_additional_info(room_id, new_additional_info)
89
111
  end
90
112
 
113
+ alias_method :update_room_info, :update_room_additional_info
114
+
91
115
  # List Whatsapp broadcast history inside room
92
116
  #
117
+ # @see https://s.id/list-room-broadcast-history
93
118
  # @param room_id [Integer]
94
- # @param opt [Hash]
95
- # @return [Qismo::Collection]
96
- def room_broadcast_history(room_id, opt = {})
97
- body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", opt)
119
+ # @param options [Hash]
120
+ # @return [Qismo::CollectionObject]
121
+ def room_broadcast_history(room_id, options = {})
122
+ body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", options)
98
123
 
99
124
  next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
100
125
  prev_page = body.meta.page > 1 ? (body.meta.page - 1) : nil
101
126
 
102
- Collection.new(
127
+ CollectionObject.new(
103
128
  body.data.broadcast_logs,
104
129
  next_page: next_page,
105
130
  prev_page: prev_page,
106
- next_func: -> { room_broadcast_history(opt.merge(page: next_page)) },
107
- prev_func: -> { room_broadcast_history(opt.merge(page: prev_page)) },
131
+ next_func: -> { room_broadcast_history(options.merge(page: next_page)) },
132
+ prev_func: -> { room_broadcast_history(options.merge(page: prev_page)) },
108
133
  )
109
134
  end
110
135
 
111
136
  # Assign agent to room
112
137
  #
138
+ # @see https://s.id/assign-agent
113
139
  # @param room_id [Integer]
114
140
  # @param agent_id [Integer]
115
- # @param opt [Hash]
116
- # @return [Qismo::DataObject]
117
- def assign_agent(room_id, agent_id, opt = {})
118
- body = post("/api/v1/admin/service/assign_agent", opt.merge(room_id: room_id.to_s, agent_id: agent_id))
141
+ # @param options [Hash]
142
+ # @return [Qismo::SingleObject]
143
+ def assign_agent(room_id, agent_id, options = {})
144
+ body = post("/api/v1/admin/service/assign_agent", options.merge(room_id: room_id.to_s, agent_id: agent_id))
119
145
  body.data.added_agent
120
146
  end
121
147
 
122
148
  # Remove agent from room
123
149
  #
150
+ # @see https://s.id/remove-agent
124
151
  # @param room_id [Integer]
125
152
  # @param agent_id [Integer]
126
153
  # @return [TrueClass]
@@ -131,13 +158,14 @@ module Qismo
131
158
 
132
159
  # Resolve room
133
160
  #
161
+ # @see https://s.id/resolve-room
134
162
  # @param room_id [Integer]
135
163
  # @param last_comment_id [Integer]
136
- # @param opt [Hash]
137
- # @return [Qismo::DataObject]
138
- def resolve_room(room_id, last_comment_id, opt = {})
164
+ # @param options [Hash]
165
+ # @return [Qismo::SingleObject]
166
+ def resolve_room(room_id, last_comment_id, options = {})
139
167
  body = post("/api/v1/admin/service/mark_as_resolved",
140
- opt.merge(room_id: room_id.to_s, last_comment_id: last_comment_id))
168
+ options.merge(room_id: room_id.to_s, last_comment_id: last_comment_id))
141
169
  body.data.service
142
170
  end
143
171
 
@@ -145,59 +173,63 @@ module Qismo
145
173
 
146
174
  # Get agent that can be assigned to room
147
175
  #
176
+ # @see https://s.id/allocate-agent
148
177
  # @param source [String]
149
- # @param opt [Hash]
150
- # @return [Qismo::DataObject]
151
- def allocate_agent(source, opt = {})
152
- body = post("/api/v1/admin/service/allocate_agent", opt.merge(source: source))
178
+ # @param options [Hash]
179
+ # @return [Qismo::SingleObject]
180
+ def allocate_agent(source, options = {})
181
+ body = post("/api/v1/admin/service/allocate_agent", options.merge(source: source))
153
182
  body.data.agent
154
183
  end
155
184
 
156
185
  # Get agent that can be allocated to room and automatically assign them
157
186
  #
187
+ # @see https://s.id/allocate-and-assign-agent
158
188
  # @param room_id [Integer]
159
- # @param opt [Hash]
160
- # @return [Qismo::DataObject]
161
- def allocate_and_assign_agent(room_id, opt = {})
162
- body = post("/api/v1/admin/service/allocate_assign_agent", opt.merge(room_id: room_id))
189
+ # @param options [Hash]
190
+ # @return [Qismo::SingleObject]
191
+ def allocate_and_assign_agent(room_id, options = {})
192
+ body = post("/api/v1/admin/service/allocate_assign_agent", options.merge(room_id: room_id))
163
193
  body.data.agent
164
194
  end
165
195
 
166
196
  # List agents that are not in room and can be assigned to room
167
197
  #
198
+ # @see https://s.id/list-other-agents
168
199
  # @param room_id [Integer]
169
- # @param opt [Hash]
170
- # @return [Qismo::Collection]
171
- def other_agents(room_id, opt = {})
172
- body = get("/api/v2/admin/service/other_agents", opt.merge(room_id: room_id))
173
- Collection.new(
200
+ # @param options [Hash]
201
+ # @return [Qismo::CollectionObject]
202
+ def other_agents(room_id, options = {})
203
+ body = get("/api/v2/admin/service/other_agents", options.merge(room_id: room_id))
204
+ CollectionObject.new(
174
205
  body.data.agents,
175
206
  prev_page: body.meta&.cursor_before,
176
207
  next_page: body.meta&.cursor_after,
177
- prev_func: -> { other_agents(opt.merge(cursor_before: body.meta&.cursor_before)) },
178
- next_func: -> { other_agents(opt.merge(cursor_after: body.meta&.cursor_after)) },
208
+ prev_func: -> { other_agents(options.merge(cursor_before: body.meta&.cursor_before)) },
209
+ next_func: -> { other_agents(options.merge(cursor_after: body.meta&.cursor_after)) },
179
210
  )
180
211
  end
181
212
 
182
213
  # List available agents in room
183
214
  #
215
+ # @see https://s.id/list-available-agents
184
216
  # @param room_id [Integer]
185
- # @param opt [Hash]
186
- # @return [Qismo::Collection]
187
- def available_agents(room_id, opt = {})
188
- body = get("/api/v2/admin/service/available_agents", opt.merge(room_id: room_id))
189
- Collection.new(
217
+ # @param options [Hash]
218
+ # @return [Qismo::CollectionObject]
219
+ def available_agents(room_id, options = {})
220
+ body = get("/api/v2/admin/service/available_agents", options.merge(room_id: room_id))
221
+ CollectionObject.new(
190
222
  body.data.agents,
191
223
  prev_page: body.meta&.cursor_before,
192
224
  next_page: body.meta&.cursor_after,
193
- prev_func: -> { available_agents(opt.merge(cursor_before: body.meta&.cursor_before)) },
194
- next_func: -> { available_agents(opt.merge(cursor_after: body.meta&.cursor_after)) },
225
+ prev_func: -> { available_agents(options.merge(cursor_before: body.meta&.cursor_before)) },
226
+ next_func: -> { available_agents(options.merge(cursor_after: body.meta&.cursor_after)) },
195
227
  )
196
228
  end
197
229
 
198
230
  # Get new session webhook config
199
231
  #
200
- # @return [Qismo::DataObject]
232
+ # @return [Qismo::SingleObject]
201
233
  def new_session_webhook
202
234
  get("/api/v2/app/config/new_session_webhook").data.configs
203
235
  end
@@ -205,15 +237,15 @@ module Qismo
205
237
  # Set new session webhook
206
238
  #
207
239
  # @param url [String]
208
- # @param opt [Hash]
209
- # @return [Qismo::DataObject]
210
- def set_new_session_webhook(url, opt = {})
211
- post("/api/v2/app/config/new_session_webhook", opt.merge(url: url)).data.configs
240
+ # @param options [Hash]
241
+ # @return [Qismo::SingleObject]
242
+ def set_new_session_webhook(url, options = {})
243
+ post("/api/v2/app/config/new_session_webhook", options.merge(url: url)).data.configs
212
244
  end
213
245
 
214
246
  # Get auth webhook config
215
247
  #
216
- # @return [Qismo::DataObject]
248
+ # @return [Qismo::SingleObject]
217
249
  def auth_webhook
218
250
  get("/api/v2/app/config/auth_webhook").data.configs
219
251
  end
@@ -221,15 +253,15 @@ module Qismo
221
253
  # Set auth webhook
222
254
  #
223
255
  # @param url [String]
224
- # @param opt [Hash]
225
- # @return [Qismo::DataObject]
226
- def set_auth_webhook(url, opt = {})
227
- post("/api/v2/app/config/auth_webhook", opt.merge(url: url)).data.configs
256
+ # @param options [Hash]
257
+ # @return [Qismo::SingleObject]
258
+ def set_auth_webhook(url, options = {})
259
+ post("/api/v2/app/config/auth_webhook", options.merge(url: url)).data.configs
228
260
  end
229
261
 
230
262
  # Get resolve webhook config
231
263
  #
232
- # @return [Qismo::DataObject]
264
+ # @return [Qismo::SingleObject]
233
265
  def resolve_webhook
234
266
  get("/api/v1/app/webhook/mark_as_resolved").data
235
267
  end
@@ -237,116 +269,127 @@ module Qismo
237
269
  # Set resolve webhook
238
270
  #
239
271
  # @param url [String]
240
- # @param opt [Hash]
241
- # @return [Qismo::DataObject]
242
- def set_resolve_webhook(url, opt = {})
243
- post("/api/v1/app/webhook/mark_as_resolved", opt.merge(url: url)).data
272
+ # @param options [Hash]
273
+ # @return [Qismo::SingleObject]
274
+ def set_resolve_webhook(url, options = {})
275
+ post("/api/v1/app/webhook/mark_as_resolved", options.merge(url: url)).data
244
276
  end
245
277
 
246
278
  # List agents
247
279
  #
248
- # @param opt [Hash]
249
- # @return [Qismo::Collection]
250
- def agents(opt = {})
251
- if opt[:page].nil? || opt[:page].empty?
252
- opt[:page] = 1
280
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#849205ca-00d9-4356-9fdd-f05bff777b4e
281
+ # @param options [Hash]
282
+ # @return [Qismo::CollectionObject]
283
+ def agents(options = {})
284
+ if options[:page].nil? || options[:page].empty?
285
+ options[:page] = 1
253
286
  end
254
287
 
255
- body = get("/api/v2/admin/agents", opt)
288
+ body = get("/api/v2/admin/agents", options)
256
289
 
257
290
  total_page = (body.meta.total_count.to_f / body.meta.per_page.to_f).ceil
258
- next_page = opt[:page] < total_page ? (opt[:page] + 1) : nil
259
- prev_page = opt[:page] > 1 ? (opt[:page] - 1) : nil
291
+ next_page = options[:page] < total_page ? (options[:page] + 1) : nil
292
+ prev_page = options[:page] > 1 ? (options[:page] - 1) : nil
260
293
 
261
- Collection.new(
294
+ CollectionObject.new(
262
295
  body.data.agents,
263
296
  next_page: next_page,
264
297
  prev_page: prev_page,
265
- next_func: -> { agents(opt.merge(page: next_page)) },
266
- prev_func: -> { agents(opt.merge(page: prev_page)) },
298
+ next_func: -> { agents(options.merge(page: next_page)) },
299
+ prev_func: -> { agents(options.merge(page: prev_page)) },
267
300
  )
268
301
  end
269
302
 
270
303
  # List agents by id
271
304
  #
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
305
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3db6c8c8-8ffe-4a88-b630-41f9d5b62298
306
+ # @param ids [Array<Integer>]
307
+ # @return [Qismo::CollectionObject]
308
+ def agents_by_ids(ids)
309
+ CollectionObject.new(get("/api/v1/admin/agents/get_by_ids", { "ids[]": ids }).data) || CollectionObject.new
276
310
  end
277
311
 
278
312
  # List agents by divisions
279
313
  #
280
- # @param *division_ids [Array<Integer>]
281
- # @param opt [Hash]
282
- # @return [Qismo::Collection]
283
- def agents_by_divisions(division_ids, opt = {})
284
- body = get("/api/v2/admin/agents/by_division", opt.merge({ "division_ids[]": division_ids }))
314
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#94eeb9cb-dd70-4baf-9f63-361e7922299a
315
+ # @param division_ids [Array<Integer>]
316
+ # @param options [Hash]
317
+ # @return [Qismo::CollectionObject]
318
+ def agents_by_divisions(division_ids, options = {})
319
+ body = get("/api/v2/admin/agents/by_division", options.merge({ "division_ids[]": division_ids }))
285
320
 
286
321
  next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
287
322
  prev_page = body.meta.page > 1 ? (body.meta.page - 1) : nil
288
323
 
289
- Collection.new(
324
+ CollectionObject.new(
290
325
  body.data,
291
326
  next_page: next_page,
292
327
  prev_page: prev_page,
293
- next_func: -> { agents_by_divisions(opt.merge(page: next_page)) },
294
- prev_func: -> { agents_by_divisions(opt.merge(page: prev_page)) },
328
+ next_func: -> { agents_by_divisions(options.merge(page: next_page)) },
329
+ prev_func: -> { agents_by_divisions(options.merge(page: prev_page)) },
295
330
  )
296
331
  end
297
332
 
298
333
  # Get agent by id
299
334
  #
335
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#c6184a6b-ba4d-4f3e-a4da-c6d0fa4597af
300
336
  # @param agent_id [Integer]
301
- # @return [Qismo::DataObject]
337
+ # @return [Qismo::SingleObject]
302
338
  def agent(agent_id)
303
339
  get("/api/v2/admin/agent/#{agent_id}").data.agent
304
340
  end
305
341
 
306
342
  # Get office hour config
307
343
  #
308
- # @return [Qismo::DataObject]
344
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#6f3f0cb0-a391-4945-b01a-95ce81138913
345
+ # @return [Qismo::SingleObject]
309
346
  def office_hours
310
347
  data = get("/api/v1/admin/office_hours").data
311
348
  data_hash = data.as_json
312
349
  data_hash["is_in_office_hour"] = Util.in_office_hour?(data)
313
350
 
314
- DataObject.new(data_hash)
351
+ SingleObject.new(data_hash)
315
352
  end
316
353
 
317
354
  # List WA broadcast templates
318
355
  #
319
- # @param opt [Hash]
320
- # @return [Qismo::Collection]
321
- def wa_broadcast_templates(opt = {})
322
- body = get("/api/v3/admin/hsm", opt)
356
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#e38d2244-9559-4015-99d5-8c707f6c01bd
357
+ # @param options [Hash]
358
+ # @return [Qismo::CollectionObject]
359
+ def wa_broadcast_templates(options = {})
360
+ body = get("/api/v3/admin/hsm", options)
323
361
 
324
362
  meta = body.meta
325
363
  next_page = meta.page < meta.total_page ? (meta.page + 1) : nil
326
364
  prev_page = meta.page > 1 ? (meta.page - 1) : nil
327
365
 
328
- Collection.new(
366
+ CollectionObject.new(
329
367
  body.data.hsm_templates,
330
368
  next_page: next_page,
331
369
  prev_page: prev_page,
332
- next_func: -> { wa_broadcast_templates(opt.merge(page: next_page)) },
333
- prev_func: -> { wa_broadcast_templates(opt.merge(page: prev_page)) },
370
+ next_func: -> { wa_broadcast_templates(options.merge(page: next_page)) },
371
+ prev_func: -> { wa_broadcast_templates(options.merge(page: prev_page)) },
334
372
  )
335
373
  end
336
374
 
375
+ alias_method :wa_message_templates, :wa_broadcast_templates
376
+ alias_method :wa_outbound_templates, :wa_broadcast_templates
377
+
337
378
  # Send WA outbound message
338
379
  #
339
- # @param opt [Hash]
340
- # @return [Qismo::DataObject]
341
- def send_wa_outbound(opt = {})
342
- post("/api/v3/admin/broadcast/client", opt).data
380
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#d0183cf6-deca-439b-aff3-2e2f007c15a9
381
+ # @param options [Hash]
382
+ # @return [Qismo::SingleObject]
383
+ def send_wa_outbound(options = {})
384
+ post("/api/v3/admin/broadcast/client", options).data
343
385
  end
344
386
 
345
387
  # Upload wa broadcast file that want to be sent in broadcast
346
388
  #
389
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#030acde2-21cf-4373-8d11-075206053c1d
347
390
  # @param file [HTTP::FormData]
348
391
  # @param template_detail_id [Integer]
349
- # @return [Qismo::DataObject]
392
+ # @return [Qismo::SingleObject]
350
393
  def upload_wa_broadcast_csv(file, template_detail_id)
351
394
  raise ArgumentError, "Invalid file" unless file.is_a?(HTTP::FormData::File)
352
395
 
@@ -355,88 +398,98 @@ module Qismo
355
398
 
356
399
  # Send wa broadcast
357
400
  #
358
- # @param opt [Hash]
359
- # @return [Qismo::DataObject]
360
- def send_wa_broadcast(opt = {})
361
- post("/api/v3/admin/broadcast/send_broadcast", opt).data.broadcast_job
401
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#717c1a12-facb-4945-aed5-04557696b873
402
+ # @param options [Hash]
403
+ # @return [Qismo::SingleObject]
404
+ def send_wa_broadcast(options = {})
405
+ post("/api/v3/admin/broadcast/send_broadcast", options).data.broadcast_job
362
406
  end
363
407
 
408
+ alias_method :create_wa_broadcast, :send_wa_broadcast
409
+
364
410
  # List wa broadcast jobs
365
411
  #
366
- # @param opt [Hash]
367
- # @return [Qismo::Collection]
368
- def wa_broadcast_jobs(opt = {})
369
- body = get("/api/v2/admin/broadcast_jobs", opt)
412
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3a4caa8b-eef4-427f-adcb-d065989899c9
413
+ # @param options [Hash]
414
+ # @return [Qismo::CollectionObject]
415
+ def wa_broadcast_jobs(options = {})
416
+ body = get("/api/v2/admin/broadcast_jobs", options)
370
417
 
371
418
  prev_page = body.meta.page > 1 ? (body.meta.meta - 1) : nil
372
419
  next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
373
420
 
374
- Collection.new(
421
+ CollectionObject.new(
375
422
  body.data.broadcast_jobs,
376
423
  next_page: next_page,
377
424
  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)) },
425
+ next_func: -> { wa_broadcast_jobs(options.merge(page: next_page)) },
426
+ prev_func: -> { wa_broadcast_jobs(options.merge(page: prev_page)) },
380
427
  )
381
428
  end
382
429
 
383
430
  # Get wa broadcast job by id
384
431
  #
432
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#ed0806c8-2e4a-4ea4-8acb-45c84c63c2da
385
433
  # @param broadcast_job_id [Integer]
386
- # @return [Qismo::DataObject]
434
+ # @return [Qismo::SingleObject]
387
435
  def wa_broadcast_job(broadcast_job_id)
388
436
  get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
389
437
  end
390
438
 
391
439
  # List wa broadcast logs
392
440
  #
441
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3f2d8ba8-ab14-43b2-af82-74c8b766216f
393
442
  # @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)
443
+ # @param options [Hash]
444
+ # @return [Qismo::CollectionObject]
445
+ def wa_broadcast_logs(broadcast_job_id, options = {})
446
+ body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", options)
398
447
 
399
448
  prev_page = body.meta.page > 1 ? (body.meta.meta - 1) : nil
400
449
  next_page = body.meta.page < body.meta.total_page ? (body.meta.page + 1) : nil
401
450
 
402
- Collection.new(
451
+ CollectionObject.new(
403
452
  body.data.broadcast_logs,
404
453
  next_page: next_page,
405
454
  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)) },
455
+ next_func: -> { wa_broadcast_logs(options.merge(page: next_page)) },
456
+ prev_func: -> { wa_broadcast_jobs(options.merge(page: prev_page)) },
408
457
  )
409
458
  end
410
459
 
411
460
  # Send message as bot
412
461
  #
413
- # @param opt [Hash]
462
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#bb77c653-5daa-4e1c-a866-43bca7c494fc
463
+ # @param options [Hash]
414
464
  # @return [TrueClass]
415
- def send_bot_message(opt = {})
416
- post("#{app_id}/bot", opt)
465
+ def send_bot_message(options = {})
466
+ post("#{app_id}/bot", options)
417
467
  true
418
468
  end
419
469
 
420
470
  # Enable chabot in room
421
471
  #
472
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#494d825f-a49c-4b18-954e-eaaccb738bcd
422
473
  # @param room_id [Integer]
423
474
  # @return [TrueClass]
424
- def enable_chatbot_in_room(room_id)
475
+ def enable_bot_in_room(room_id)
425
476
  post("/bot/#{room_id}/activate", is_active: true)
426
477
  true
427
478
  end
428
479
 
429
- # Disable chabot in room
480
+ # Disable chatbot in room
430
481
  #
482
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#494d825f-a49c-4b18-954e-eaaccb738bcd
431
483
  # @param room_id [Integer]
432
484
  # @return [TrueClass]
433
- def disable_chatbot_in_room(room_id)
485
+ def disable_bot_in_room(room_id)
434
486
  post("/bot/#{room_id}/activate", is_active: false)
435
487
  true
436
488
  end
437
489
 
438
490
  # Handover room from chatbot to human agent
439
491
  #
492
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#40867e85-7412-4e0d-84bd-e2506df23df8
440
493
  # @param room_id [Integer]
441
494
  # @return [TrueClass]
442
495
  def handover_room_from_bot(room_id)
@@ -446,36 +499,110 @@ module Qismo
446
499
 
447
500
  # Handover room from chatbot to human agent in specific divisions
448
501
  #
502
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#8218db08-9753-4d74-ae5f-0ee62f8579b9
449
503
  # @param room_id [Integer]
450
- # @param *roles [Array<Integer>]
451
- # @param opt [Hash]
504
+ # @param roles [Array<Integer>]
505
+ # @param options [Hash]
452
506
  # @return [TrueClass]
453
- def handover_room_from_bot_to_division(room_id, roles, opt = {})
454
- post("/#{app_id}/bot/#{room_id}/hand_over_to_role", opt.merge(roles: roles))
507
+ def handover_room_from_bot_to_division(room_id, roles, options = {})
508
+ post("/#{app_id}/bot/#{room_id}/hand_over_to_role", options.merge(roles: roles))
455
509
  true
456
510
  end
457
511
 
458
512
  # Initiate chat using Qiscus widget channel
459
513
  #
514
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#d5a555de-59e0-4705-9582-c216d79e9390
460
515
  # @param user_id [String]
461
516
  # @param name [String]
462
- # @param opt [Hash]
463
- # @return [Qismo::DataObject]
464
- def initiate_widget_chat(user_id, name, opt = {})
465
- opt = opt.merge(app_id: app_id, user_id: user_id, name: name)
466
- post("/api/v2/qiscus/initiate_chat", opt).data.customer_room
517
+ # @param options [Hash]
518
+ # @return [Qismo::SingleObject]
519
+ def initiate_widget_chat(user_id, name, options = {})
520
+ options = options.merge(app_id: app_id, user_id: user_id, name: name)
521
+ post("/api/v2/qiscus/initiate_chat", options).data.customer_room
467
522
  end
468
523
 
524
+ alias_method :initiate_chat, :initiate_widget_chat
525
+
469
526
  # Send message to custom channel
470
527
  #
528
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#aee54b21-68f1-4d31-9d81-d3c73b3e125b
471
529
  # @param identifier_key [String]
472
530
  # @param user_id [String]
473
531
  # @param name [String]
474
- # @param opt [Hash]
475
- # @return [Qismo::DataObject]
476
- def send_message_to_custom_channel(identifier_key, user_id, name, opt = {})
532
+ # @param options [Hash]
533
+ # @return [Qismo::SingleObject]
534
+ def send_message_to_custom_channel(identifier_key, user_id, name, options = {})
477
535
  post("/#{app_id}/api/v2/custom_channel/send",
478
- opt.merge(identifier_key: identifier_key, user_id: user_id, name: name)).data
536
+ options.merge(identifier_key: identifier_key, user_id: user_id, name: name)).data
537
+ end
538
+
539
+ # List integrated channels
540
+ #
541
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#aee54b21-68f1-4d31-9d81-d3c73b3e125b
542
+ # @return [Qismo::SingleObject]
543
+ def channels
544
+ get("/api/v2/channels").data
545
+ end
546
+
547
+ # Create customchannel
548
+ #
549
+ # @param identifier_key [String]
550
+ # @param name [String]
551
+ # @param webhook_url [String]
552
+ # @param options [Hash]
553
+ # @return [Qismo::SingleObject]
554
+ def create_custom_channel(identifier_key, name, webhook_url, options = {})
555
+ options = options.merge(
556
+ identifier_key: identifier_key,
557
+ name: name,
558
+ webhook_url: webhook_url,
559
+ )
560
+
561
+ options[:is_active] = true unless options[:is_active].nil?
562
+
563
+ post("/api/v1/custom_channel/connect", options.merge).data
564
+ end
565
+
566
+ # Update custom channel
567
+ #
568
+ # @param id [Integer]
569
+ # @param options [Hash]
570
+ # @return [Qismo::SingleObject]
571
+ def update_custom_channel(id, options = {})
572
+ channel = channels.custom_channels.find { |cc| cc.id == id }
573
+ if channel.nil?
574
+ raise Qismo::NotFoundError.new("Channel not found", status_code: 404, response_body: nil)
575
+ end
576
+
577
+ channel_hash = JSON.parse(channel.to_json, symbolize_names: true)
578
+ new_channel_config = channel_hash.merge(options)
579
+
580
+ post("/api/v1/custom_channel/connect/update", new_channel_config).data
581
+ end
582
+
583
+ # Activate custom channel
584
+ #
585
+ # @param id [Integer]
586
+ # @return [Qismo::SingleObject]
587
+ def activate_custom_channel(id)
588
+ update_custom_channel(id, is_active: true)
589
+ end
590
+
591
+ # Deactivate custom channel
592
+ #
593
+ # @param id [Integer]
594
+ # @return [Qismo::SingleObject]
595
+ def deactivate_custom_channel(id)
596
+ update_custom_channel(id, is_active: false)
597
+ end
598
+
599
+ # Delete custom channel
600
+ #
601
+ # @param id [Integer]
602
+ # @return [TrueClass]
603
+ def delete_custom_channel(id)
604
+ post("/api/v2/custom_channel/connect/#{id}/delete")
605
+ true
479
606
  end
480
607
  end
481
608
  end
data/lib/qismo/client.rb CHANGED
@@ -28,9 +28,9 @@ module Qismo
28
28
 
29
29
  # Initialize client
30
30
  #
31
- # @param opt [Hash]
32
- def initialize(opt = {})
33
- DEFAULT_OPTIONS.merge(opt).each do |key, value|
31
+ # @param options [Hash]
32
+ def initialize(options = {})
33
+ DEFAULT_OPTIONS.merge(options).each do |key, value|
34
34
  instance_variable_set("@#{key}", value)
35
35
  end
36
36
  end
@@ -39,43 +39,55 @@ 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
46
46
 
47
- # Http request with post method to upload file
47
+ # Send HTTP request with post method to upload file
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
55
55
 
56
- # Send http request with get method
56
+ # Send HTTP request with get method
57
57
  #
58
58
  # @param path [String]
59
59
  # @param params [Hash]
60
- # @return [Qismo::DataObject]
61
- def get(path, **params)
60
+ # @return [Qismo::SingleObject]
61
+ def get(path, params = {})
62
62
  request(:get, path, params: params)
63
63
  end
64
64
 
65
- def delete(path)
66
- request(:delete, path)
65
+ # Send HTTP request with delete method
66
+ #
67
+ # @param path [String]
68
+ # @param params [Hash]
69
+ # @return [Qismo::SingleObject]
70
+ def delete(path, params = {})
71
+ request(:delete, path, params: params)
67
72
  end
68
73
 
69
- # Send http request
74
+ # Send HTTP request
70
75
  #
71
76
  # @param method [Symbol, String]
72
77
  # @param path [String]
73
- # @param body [Hash]
74
- # @return [Qismo::DataObject]
75
- def request(method, path, opt = {})
76
- res = connection.request(method, @url + path, opt.compact)
78
+ # @param headers [Hash]
79
+ # @param params [Hash]
80
+ # @param json [Hash]
81
+ # @return [Qismo::SingleObject]
82
+ def request(method, path, headers: {}, params: {}, json: {})
83
+ res = connection.request(method, @url + path, {
84
+ headers: headers,
85
+ params: params,
86
+ json: json,
87
+ })
88
+
77
89
  if res.status.success?
78
- return DataObject.new(JSON.parse(res.to_s))
90
+ return SingleObject.new(JSON.parse(res.to_s))
79
91
  end
80
92
 
81
93
  if res.status.server_error?
@@ -83,10 +95,10 @@ module Qismo
83
95
  end
84
96
 
85
97
  if res.status.client_error?
86
- body = DataObject.new(JSON.parse(res.to_s))
98
+ body = SingleObject.new(JSON.parse(res.to_s))
87
99
 
88
100
  error = body.errors
89
- error = error.message if error.is_a?(DataObject)
101
+ error = error.message if error.is_a?(SingleObject)
90
102
 
91
103
  error_klass_map = {
92
104
  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 = {})
11
- opt.each do |key, value|
9
+ # @param options [Hash]
10
+ def initialize(options = {})
11
+ options.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.9.0"
5
+ VERSION = "0.11.0"
6
6
  end
data/lib/qismo.rb CHANGED
@@ -11,7 +11,8 @@ require "qismo/api"
11
11
  require "qismo/client"
12
12
 
13
13
  module Qismo
14
- # @!method rooms
14
+ # @!parse extend Qismo::Api
15
+
15
16
  class << self
16
17
  def configure
17
18
  yield client
@@ -21,34 +22,31 @@ module Qismo
21
22
 
22
23
  # Initiate Qismo ruby client
23
24
  #
24
- # @param opt [Hash]
25
+ # @param options [Hash]
25
26
  # @return [Qismo::Client]
26
- def new(opt = {})
27
- @client = Client.new(opt)
27
+ def new(options = {})
28
+ @client = Client.new(options)
28
29
  end
29
30
 
30
- if Gem::Version.new(RUBY_VERSION).release >= Gem::Version.new("3.0.0")
31
- def method_missing(method, *args, **kwargs, &block)
32
- return super unless client.respond_to?(method)
31
+ # @return [Qismo::Client]
32
+ def client
33
+ @client ||= Client.new
34
+ end
33
35
 
34
- client.send(method, *args, **kwargs, &block)
35
- end
36
- else
37
- def method_missing(method, *args, &block)
38
- return super unless client.respond_to?(method)
36
+ private
39
37
 
40
- client.send(method, *args, &block)
41
- end
42
- end
38
+ def method_missing(method, *args, &block)
39
+ return super unless client.respond_to?(method)
43
40
 
44
- def respond_to_missing?(method_name, *args)
45
- Qismo::Client.instance_methods.include?(method_name)
41
+ client.send(method * args, &block)
46
42
  end
47
43
 
48
- private
44
+ def respond_to?(method_name, include_private = false)
45
+ client.respond_to?(method_name, include_private) || super(method_name, include_private)
46
+ end
49
47
 
50
- def client
51
- @client ||= Client.new
48
+ def respond_to_missing?(method_name, include_private = false)
49
+ client.respond_to?(method_name, include_private) || super(method_name, include_private)
52
50
  end
53
51
  end
54
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.9.0
4
+ version: 0.11.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-06 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,12 +129,14 @@ files:
129
129
  - lib/qismo/model.rb
130
130
  - lib/qismo/util.rb
131
131
  - lib/qismo/version.rb
132
- homepage: https://qiscus.com
132
+ homepage: https://bitbucket.org/qiscus/qismo-rb
133
133
  licenses:
134
134
  - MIT
135
135
  metadata:
136
136
  allowed_push_host: https://rubygems.org
137
137
  source_code_uri: https://bitbucket.org/qiscus/qismo-rb
138
+ homepage_uri: https://bitbucket.org/qiscus/qismo-rb
139
+ documentation_uri: https://www.rubydoc.info/gems/qismo
138
140
  post_install_message:
139
141
  rdoc_options: []
140
142
  require_paths:
@@ -153,5 +155,5 @@ requirements: []
153
155
  rubygems_version: 3.1.6
154
156
  signing_key:
155
157
  specification_version: 4
156
- summary: Qiscus Omnichannel Ruby Gem
158
+ summary: Ruby wrapper for Qiscus Omnichannel public API
157
159
  test_files: []