qismo 0.17.10 → 0.18.1

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: 438e37ba8805d97e8cc2265c11929b274b8fa5387293b2e2f20fe5add2b54c9f
4
- data.tar.gz: acb21b8465d43cbadb921578df6f6332ef660d55fd907e03508491074c36cbce
3
+ metadata.gz: 4b5821ce5a3af4f9c2c0b8b2ff1436ee77c8395a4b98f06b3c64c45afc188cbf
4
+ data.tar.gz: ece73a2396b03a38acbb7e64352d4121988f2e5850018bab9d95c10ba88bc3ce
5
5
  SHA512:
6
- metadata.gz: b7ed4f10abe1da26a27ebe6994075e0346abcbbe56175f5d81a465e4514a98095775d21bb508ee46e67f027040b6276104eb3500f6011764507a4905d0122653
7
- data.tar.gz: 29e8e66f501de53c1f9264827dd0105b18594c9d183e97476f040666c456ce66347f513150e7db1e46459b312af3da4e79ee2a2d95bd14994dee2702ccf4d4db
6
+ metadata.gz: 4c605b2d1f6dd5ba69ff9dab9927dbeb63f9678f2b953364448893d2ac873a0770aa1c89bb7d3b42f7918a6cbd58e701eb3225f85718fcdd49ed97aef0f8a1cc
7
+ data.tar.gz: 73741ee9f08ccfb8aaaff41993ff91bc2bfa7ba5491e8d078a037ad769e22c802bed26a2e374b079eb539fb23715cf38bf64c21801d8151099e027832bbd015c
data/README.md CHANGED
@@ -13,18 +13,17 @@ bundle add qismo
13
13
  ## Usage
14
14
 
15
15
  ```ruby
16
- client = Qismo::Client.new(app_id: "QISCUS_APP_ID", secret_key: "QISCUS_SECRET_KEY")
16
+ qismo = Qismo::Client.new(app_id: "QISCUS_APP_ID", secret_key: "QISCUS_SECRET_KEY")
17
17
 
18
18
  params = {
19
- channel: { channel_id: 12345, source: "wa" },
19
+ channel: [{ channel_id: 12345, source: "wa" }],
20
20
  status: "unresolved",
21
21
  serve_status: "served",
22
22
  is_handled_by_bot: true,
23
23
  }
24
24
 
25
- rooms = client.rooms(params)
25
+ pp qismo.list_rooms(params)
26
26
 
27
- puts rooms
28
27
  # [
29
28
  # #<Qismo::Objects::CustomerRoom
30
29
  # channel_id=126392
@@ -58,7 +57,7 @@ Qismo ruby also provide some optional configuration that you can pass, they are:
58
57
  Defaultly, Qismo ruby will use your QISCUS_OMNICHANNEL_URL env as base url. If its nil, it will use https://qismo.qiscus.com. If you need to customize URL other than that, you can pass it at client initialization
59
58
 
60
59
  ```ruby
61
- client.url = "https://qismo.qiscus.com"
60
+ qismo.url = "https://qismo.qiscus.com"
62
61
  ```
63
62
 
64
63
  **logger**
@@ -68,7 +67,7 @@ You can also log the request and response the any HTTP request you make in Qismo
68
67
  ```ruby
69
68
  require "logger"
70
69
 
71
- client.logger = Logger.new($stdout)
70
+ qismo.logger = Logger.new($stdout)
72
71
  ```
73
72
 
74
73
  **instrumentation**
@@ -76,17 +75,17 @@ client.logger = Logger.new($stdout)
76
75
  For advanced logging, you can also use laverage ActiveSupport instrumentation. If you are using Rails, you can use ActiveSupport without installing the gem by your self.
77
76
 
78
77
  ```ruby
79
- ActiveSupport::Notifications.subscribe('start_request.http') d |name, start, finish, id, payload|
80
- pp :name => name, :start => start.to_f, :finish => finish.to_f, :id => id, :payload => payload
78
+ ActiveSupport::Notifications.subscribe('start_request.http') do |name, start, finish, id, payload|
79
+ pp name: name, start: start.to_f, finish: finish.to_f, id: id, payload: payload
81
80
  end
82
81
 
83
- client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }
82
+ qismo.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }
84
83
  ```
85
84
 
86
85
  You can also customize the instrumentation's namespace by using this configuration
87
86
 
88
87
  ```ruby
89
- client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter, namespace: "qiscus.http_request" }
88
+ qismo.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter, namespace: "qiscus.http_request" }
90
89
  ```
91
90
 
92
91
  **timeout**
@@ -96,13 +95,13 @@ By default, the Qismo ruby gem does not enforce timeout on a request. You can en
96
95
  Per operation timeouts are what `Net::HTTP` and the majority of HTTP clients do:
97
96
 
98
97
  ```ruby
99
- client.timeout = { connect: 5, write: 2, read: 10 }
98
+ qismo.timeout = { connect: 5, write: 2, read: 10 }
100
99
  ```
101
100
 
102
101
  Global timeouts let you set an upper bound of how long a request can take
103
102
 
104
103
  ```ruby
105
- client.timeout = 5 # in seconds
104
+ qismo.timeout = 5 # in seconds
106
105
  ```
107
106
 
108
107
  **proxy**
@@ -110,13 +109,13 @@ client.timeout = 5 # in seconds
110
109
  Making request behind proxy is as simple as making them directly. Just specify hostname (or IP address) of your proxy server and its port, and here you go
111
110
 
112
111
  ```ruby
113
- client.proxy = ["proxy-hostname.local", 8080]
112
+ qismo.proxy = ["proxy-hostname.local", 8080]
114
113
  ```
115
114
 
116
115
  Proxy needs authentication?
117
116
 
118
117
  ```ruby
119
- client.proxy = ["proxy-hostname.local", 8080, "username", "password"]
118
+ qismo.proxy = ["proxy-hostname.local", 8080, "username", "password"]
120
119
  ```
121
120
 
122
121
  ## Handling pagination
@@ -124,12 +123,14 @@ client.proxy = ["proxy-hostname.local", 8080, "username", "password"]
124
123
  Some of the Qiscus Omnichannel API will return list of data with pagination. To handle the pagination, you can to that like this example:
125
124
 
126
125
  ```ruby
126
+
127
127
  all_rooms = []
128
- rooms = client.rooms
128
+
129
+ rooms = qismo.list_rooms
129
130
  all_rooms.append(rooms)
130
131
 
131
- while rooms.has_next_page?
132
- rooms = rooms.next_page
132
+ while rooms.next_page.present?
133
+ rooms = qismo.list_rooms(cursor_after: rooms.next_page)
133
134
  all_rooms.append(rooms)
134
135
  end
135
136
  ```
@@ -140,11 +141,35 @@ Qismo ruby raise error while getting non successful http code from Qiscus Omnich
140
141
 
141
142
  ```ruby
142
143
  begin
143
- client.rooms
144
- rescue Qismo::HTTPRequestError => e
145
- e.message
146
- e.status_code
147
- e.response_body
144
+ qismo.list_rooms
145
+ rescue Qismo::BadRequestError => e
146
+ puts e.message
147
+ puts e.status_code
148
+ puts e.response_body
149
+ rescue Qismo::UnauthorizedError => e
150
+ puts e.message
151
+ puts e.status_code
152
+ puts e.response_body
153
+ rescue Qismo::PaymentRequiredError => e
154
+ puts e.message
155
+ puts e.status_code
156
+ puts e.response_body
157
+ rescue Qismo::ForbiddenError => e
158
+ puts e.message
159
+ puts e.status_code
160
+ puts e.response_body
161
+ rescue Qismo::NotFoundError => e
162
+ puts e.message
163
+ puts e.status_code
164
+ puts e.response_body
165
+ rescue Qismo::TooManyRequestError => e
166
+ puts e.message
167
+ puts e.status_code
168
+ puts e.response_body
169
+ rescue Qismo::InternalServerError => e
170
+ puts e.message
171
+ puts e.status_code
172
+ puts e.response_body
148
173
  end
149
174
  ```
150
175
 
@@ -161,9 +186,10 @@ class QiscusWebhooksController < ApplicationController
161
186
 
162
187
  # Do any action you want using payload that has been objectified
163
188
  if webhook.candidate_agent.present?
164
- Qismo.assign_agent(
165
- webhook.room_id,
166
- webhook.candidate_agent.id
189
+ qismo = Qismo::Client.new(app_id: "", secret_key: "")
190
+ qismo.assign_agent(
191
+ room_id: webhook.room_id,
192
+ agent_id: webhook.candidate_agent.id
167
193
  )
168
194
  end
169
195
  end
@@ -199,7 +225,7 @@ class QiscusWebhooksController < ApplicationController
199
225
  # Fetch customer from room participants
200
226
  customer = webhook.payload.room.participants.find { |participant| participant.email.start_with?("twitter_customer_") }
201
227
  if customer.present?
202
- twitter_rest_client.create_direct_message(webhook.payload.rooms, webhook.payload.message.text)
228
+ twitter_rest_client.create_direct_message(customer.email, webhook.payload.message.text)
203
229
  end
204
230
  end
205
231
 
@@ -224,10 +250,13 @@ class QiscusWebhooksController < ApplicationController
224
250
  bot_message = response.query_result.fulfillment_text
225
251
 
226
252
  # Send message to Qismo room
227
- Qismo.send_bot_message(
228
- webhook.payload.room.id,
253
+ qismo = Qismo::Client.new(app_id: "", secret_key: "")
254
+ qismo.send_bot_message(
255
+ room_id: webhook.payload.room.id,
229
256
  message: bot_message
230
257
  )
231
258
  end
232
259
  end
233
260
  ```
261
+ ## Developer Experience
262
+ > TODO documentation
data/lib/qismo/api.rb CHANGED
@@ -32,7 +32,7 @@ module Qismo
32
32
  # @param is_handled_by_bot [TrueClass,FalseClass]
33
33
  # Filter rooms by chatbot activation status in room
34
34
  # @return [Qismo::Collection<Qismo::CustomerRoom>]
35
- def rooms(channels: nil, status: nil, serve_status: nil, name: nil, limit: 50, tag_ids: nil, user_ids: nil, order: "desc", cursor_after: nil, cursor_before: nil, is_handled_by_bot: nil)
35
+ def list_rooms(channels: nil, status: nil, serve_status: nil, name: nil, limit: 50, tag_ids: nil, user_ids: nil, order: "desc", cursor_after: nil, cursor_before: nil, is_handled_by_bot: nil)
36
36
  body = post("/api/v2/customer_rooms", {
37
37
  channels: channels,
38
38
  status: status,
@@ -58,7 +58,7 @@ module Qismo
58
58
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#8c803377-eea2-4879-9d66-8906d9f41275
59
59
  # @param room_id [Integer]
60
60
  # @return [Qismo::Objects::CustomerRoom]
61
- def room(room_id:)
61
+ def get_room(room_id:)
62
62
  body = get("/api/v2/customer_rooms/#{room_id}")
63
63
  if body.data.customer_room.nil?
64
64
  raise Qismo::NotFoundError.new("Room not found", status_code: 404, response_body: body.to_json)
@@ -72,7 +72,7 @@ module Qismo
72
72
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#d40b54a7-2b37-4afc-b474-62593001274e
73
73
  # @param room_id [Integer]
74
74
  # @return [Qismo::Collection<Qismo::Objects::Tag>]
75
- def room_tags(room_id:)
75
+ def list_room_tags(room_id:)
76
76
  Qismo::Collection.new(
77
77
  Qismo::Objects::Tag.from_array(
78
78
  get("/api/v2/room_tags/#{room_id}").data
@@ -109,7 +109,7 @@ module Qismo
109
109
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#88c2287b-21af-4afd-b495-aaaa2818c381
110
110
  # @param room_id [Integer]
111
111
  # @return [Array<Qismo::Objects::RoomAdditionalInfo>]
112
- def room_additional_info(room_id:)
112
+ def list_room_info(room_id:)
113
113
  Qismo::Objects::RoomAdditionalInfo.from_array(
114
114
  get("/api/v1/qiscus/room/#{room_id}/user_info").data.extras.user_properties
115
115
  )
@@ -117,8 +117,6 @@ module Qismo
117
117
  Qismo::Objects::RoomAdditionalInfo.from_array([])
118
118
  end
119
119
 
120
- alias_method :room_info, :room_additional_info
121
-
122
120
  # Set room additional info
123
121
  #
124
122
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#2b968e9e-2a76-4569-8763-f883e11dc5a7
@@ -127,7 +125,7 @@ module Qismo
127
125
  # @param info [Array<Hash>]
128
126
  # Key value pair of additional info. Ex: [{ key: "Ticket Link", value: "https://ticket.com" }]
129
127
  # @return [Array<Qismo::Objects::RoomAdditionalInfo>]
130
- def set_room_additional_info(room_id:, info:)
128
+ def create_room_info(room_id:, info:)
131
129
  Qismo::Objects::RoomAdditionalInfo.from_array(
132
130
  post(
133
131
  "/api/v1/qiscus/room/#{room_id}/user_info",
@@ -136,31 +134,25 @@ module Qismo
136
134
  )
137
135
  end
138
136
 
139
- alias_method :set_room_info, :set_room_additional_info
140
- alias_method :create_room_info, :set_room_additional_info
141
- alias_method :create_room_additional_info, :set_room_additional_info
142
-
143
137
  # Update room additional info
144
138
  #
145
139
  # @param room_id [Integer]
146
140
  # @param info [Array<Hash>]
147
141
  # Key value pair of additional info. Ex: [{ key: "Ticket Link", value: "https://ticket.com" }]
148
142
  # @return [Array<Qismo::Objects::RoomAdditionalInfo>]
149
- def update_room_additional_info(room_id:, info:)
143
+ def update_room_info(room_id:, info:)
150
144
  old_info = room_additional_info(room_id).as_json
151
145
  new_info = (info.as_json + old_info).uniq { |h| h.values_at("key") }
152
146
  set_room_additional_info(room_id: room_id, info: new_info)
153
147
  end
154
148
 
155
- alias_method :update_room_info, :update_room_additional_info
156
-
157
149
  # List broadcast history inside room
158
150
  #
159
151
  # @param room_id [Integer]
160
152
  # @param page [Integer]
161
153
  # @param limit [Integer]
162
154
  # @return [Qismo::Collection<Qismo::Objects::BroadcastLog>]
163
- def room_broadcast_history(room_id:, page: 1, limit: 25)
155
+ def list_room_broadcasts(room_id:, page: 1, limit: 25)
164
156
  body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", {
165
157
  page: page,
166
158
  limit: limit
@@ -243,8 +235,6 @@ module Qismo
243
235
  )
244
236
  end
245
237
 
246
- alias_method :resolve, :resolve_room
247
-
248
238
  # Get agent that can be assigned to room
249
239
  #
250
240
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#a62432c6-1aba-4e2b-be9a-2f7151db9119
@@ -294,7 +284,7 @@ module Qismo
294
284
  # @param cursor_after [String]
295
285
  # @param cursor_before [String]
296
286
  # @return [Qismo::Collection<Qismo::Objects::User>]
297
- def other_agents(room_id:, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
287
+ def list_other_agents(room_id:, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
298
288
  body = get("/api/v2/admin/service/other_agents", {
299
289
  room_id: room_id.to_s,
300
290
  search: search,
@@ -320,7 +310,7 @@ module Qismo
320
310
  # @param cursor_after [String]
321
311
  # @param cursor_before [String]
322
312
  # @return [Qismo::Collection<Qismo::Objects::User>]
323
- def available_agents(room_id:, is_available_in_room: true, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
313
+ def list_available_agents(room_id:, is_available_in_room: true, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
324
314
  body = get("/api/v2/admin/service/available_agents", {
325
315
  room_id: room_id.to_s,
326
316
  is_available_in_room: is_available_in_room,
@@ -340,7 +330,7 @@ module Qismo
340
330
  # Get new session webhook config
341
331
  #
342
332
  # @return [Qismo::Objects::Webhook]
343
- def new_session_webhook
333
+ def get_new_session_webhook
344
334
  config = get("/api/v2/app/config/new_session_webhook").data.configs
345
335
  Qismo::Objects::Webhook.new(
346
336
  enabled: config.is_new_session_webhook_enabled,
@@ -353,7 +343,7 @@ module Qismo
353
343
  # @param url [String]
354
344
  # @param enabled [TrueClass,FalseClass]
355
345
  # @return [Qismo::Objects::Webhook]
356
- def set_new_session_webhook(url:, enabled: true)
346
+ def create_new_session_webhook(url:, enabled: true)
357
347
  config = post("/api/v2/app/config/new_session_webhook", url: url, enabled: enabled).data.configs
358
348
  Qismo::Objects::Webhook.new(
359
349
  enabled: config.is_new_session_webhook_enabled,
@@ -364,7 +354,7 @@ module Qismo
364
354
  # Get auth webhook config
365
355
  #
366
356
  # @return [Qismo::Objects::Webhook]
367
- def auth_webhook
357
+ def get_auth_webhook
368
358
  config = get("/api/v2/app/config/auth_webhook").data.configs
369
359
  Qismo::Objects::Webhook.new(
370
360
  enabled: config.is_auth_webhook_enabled,
@@ -377,7 +367,7 @@ module Qismo
377
367
  # @param url [String]
378
368
  # @param enabled [TrueClass, FalseClass]
379
369
  # @return [Qismo::Objects::Webhook]
380
- def set_auth_webhook(url:, enabled: true)
370
+ def create_auth_webhook(url:, enabled: true)
381
371
  config = post("/api/v2/app/config/auth_webhook", url: url, enabled: enabled).data.configs
382
372
  Qismo::Objects::Webhook.new(
383
373
  enabled: config.is_auth_webhook_enabled,
@@ -388,7 +378,7 @@ module Qismo
388
378
  # Get resolve webhook config
389
379
  #
390
380
  # @return [Qismo::Objects::Webhook]
391
- def resolve_webhook
381
+ def get_resolve_webhook
392
382
  config = get("/api/v1/app/webhook/mark_as_resolved").data
393
383
  Qismo::Objects::Webhook.new(
394
384
  enabled: config.is_mark_as_resolved_webhook_enabled,
@@ -401,7 +391,7 @@ module Qismo
401
391
  # @param url [String]
402
392
  # @param options [Hash]
403
393
  # @return [Qismo::Objects::Webhook]
404
- def set_resolve_webhook(url:, enabled: true)
394
+ def create_resolve_webhook(url:, enabled: true)
405
395
  config = post("/api/v1/app/webhook/mark_as_resolved", webhook_url: url, is_webhook_enabled: enabled).data
406
396
  Qismo::Objects::Webhook.new(
407
397
  enabled: config.is_mark_as_resolved_webhook_enabled,
@@ -414,7 +404,7 @@ module Qismo
414
404
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#849205ca-00d9-4356-9fdd-f05bff777b4e
415
405
  # @param options [Hash]
416
406
  # @return [Qismo::Collection<Qismo::Objects::User>]
417
- def agents(page: 1, limit: 10, search: nil, scope: nil)
407
+ def list_agents(page: 1, limit: 10, search: nil, scope: nil)
418
408
  body = get("/api/v2/admin/agents", {
419
409
  page: page,
420
410
  limit: limit,
@@ -436,7 +426,7 @@ module Qismo
436
426
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3db6c8c8-8ffe-4a88-b630-41f9d5b62298
437
427
  # @param agent_ids [Array<Integer>]
438
428
  # @return [Qismo::Collection<Qismo::Objects::User>]
439
- def agents_by_ids(agent_ids:)
429
+ def list_agents_by_ids(agent_ids:)
440
430
  Qismo::Collection.new(
441
431
  Qismo::Objects::User.from_array(get("/api/v1/admin/agents/get_by_ids", {"ids[]": agent_ids}).data)
442
432
  )
@@ -455,7 +445,7 @@ module Qismo
455
445
  # @param sort [String]
456
446
  # Sort result by descending or ascending
457
447
  # @return [Qismo::Collection<Qismo::Objects::User>]
458
- def agents_by_divisions(division_ids, page: 1, limit: 10, is_available: nil, sort: "asc")
448
+ def list_agents_by_divisions(division_ids, page: 1, limit: 10, is_available: nil, sort: "asc")
459
449
  body = get("/api/v2/admin/agents/by_division", {
460
450
  "division_ids[]": division_ids,
461
451
  page: page,
@@ -476,7 +466,7 @@ module Qismo
476
466
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#c6184a6b-ba4d-4f3e-a4da-c6d0fa4597af
477
467
  # @param agent_id [Integer]
478
468
  # @return [Qismo::Objects::User]
479
- def agent(agent_id:)
469
+ def get_agent(agent_id:)
480
470
  Qismo::Objects::User.new(get("/api/v2/admin/agent/#{agent_id}").data.agent)
481
471
  end
482
472
 
@@ -484,7 +474,7 @@ module Qismo
484
474
  #
485
475
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#6f3f0cb0-a391-4945-b01a-95ce81138913
486
476
  # @return [Qismo::Objects::OfficeHour]
487
- def office_hours
477
+ def get_office_hours
488
478
  Qismo::Objects::OfficeHour.new(
489
479
  get("/api/v1/admin/office_hours").data
490
480
  )
@@ -500,7 +490,7 @@ module Qismo
500
490
  # @param approved [TrueClass,FalseClass]
501
491
  # Filter template by approval status
502
492
  # @return [Qismo::Collection<Qismo::Objects::HsmTemplate>]
503
- def wa_broadcast_templates(page: 1, limit: 10, approved: nil)
493
+ def list_wa_broadcast_templates(page: 1, limit: 10, approved: nil)
504
494
  body = get("/api/v3/admin/hsm", {
505
495
  page: page,
506
496
  limit: limit,
@@ -514,13 +504,10 @@ module Qismo
514
504
  )
515
505
  end
516
506
 
517
- alias_method :wa_message_templates, :wa_broadcast_templates
518
- alias_method :wa_outbound_templates, :wa_broadcast_templates
519
-
520
507
  # Get Whatsapp channel credit info
521
508
  #
522
509
  # @return [Qismo::Objects::WaCreditInfo]
523
- def wa_credit
510
+ def get_wa_credit
524
511
  Qismo::Objects::WaCreditInfo.new(
525
512
  get("/api/v2/admin/wa_pricing/balance").data
526
513
  )
@@ -632,8 +619,6 @@ module Qismo
632
619
  )
633
620
  end
634
621
 
635
- alias_method :create_wa_broadcast, :send_wa_broadcast
636
-
637
622
  # List WA broadcast jobs
638
623
  #
639
624
  # @param page [Integer]
@@ -642,7 +627,7 @@ module Qismo
642
627
  # @param cursor_before [Integer]
643
628
  # @param name [String]
644
629
  # @return [Qismo::Collection<Qismo::Objects::BroadcastJob>]
645
- def wa_broadcast_jobs(limit: 10, cursor_after: nil, cursor_before: nil, name: nil)
630
+ def list_wa_broadcast_jobs(limit: 10, cursor_after: nil, cursor_before: nil, name: nil)
646
631
  body = get("/api/v2/admin/broadcast_jobs", {
647
632
  limit: limit,
648
633
  cursor_after: cursor_after,
@@ -662,7 +647,7 @@ module Qismo
662
647
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#ed0806c8-2e4a-4ea4-8acb-45c84c63c2da
663
648
  # @param broadcast_job_id [Integer]
664
649
  # @return [Qismo::Objects::BroadcastJob]
665
- def wa_broadcast_job(broadcast_job_id:)
650
+ def get_wa_broadcast_job(broadcast_job_id:)
666
651
  Qismo::Objects::BroadcastJob.new(
667
652
  get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
668
653
  )
@@ -674,7 +659,7 @@ module Qismo
674
659
  # @param broadcast_job_id [Integer]
675
660
  # @param options [Hash]
676
661
  # @return [Qismo::Collection<Qismo::Objects::BroadcastLog>]
677
- def wa_broadcast_logs(broadcast_job_id:, page: 1, limit: 10)
662
+ def list_wa_broadcast_logs(broadcast_job_id:, page: 1, limit: 10)
678
663
  body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", {
679
664
  page: page,
680
665
  limit: limit
@@ -816,11 +801,11 @@ module Qismo
816
801
  email: email
817
802
  }.compact
818
803
 
804
+ options[:app_id] = app_id
805
+
819
806
  Qismo::Objects::CustomerRoom.new(post("/api/v2/qiscus/initiate_chat", options).data.customer_room)
820
807
  end
821
808
 
822
- alias_method :initiate_chat, :initiate_widget_chat
823
-
824
809
  # Send messsage to custom channel
825
810
  #
826
811
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#aee54b21-68f1-4d31-9d81-d3c73b3e125b
@@ -861,7 +846,7 @@ module Qismo
861
846
  #
862
847
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#aee54b21-68f1-4d31-9d81-d3c73b3e125b
863
848
  # @return [Qismo::Objects::ListChannelsResponse]
864
- def channels
849
+ def list_channels
865
850
  Qismo::Objects::ListChannelsResponse.new(
866
851
  get("/api/v2/channels").data
867
852
  )
data/lib/qismo/client.rb CHANGED
@@ -1,43 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "logger"
4
+
3
5
  module Qismo
4
6
  # Qismo ruby client
5
7
  #
6
8
  class Client
7
9
  include Qismo::Api
8
10
 
9
- # @return [String, NilClass]
11
+ # @return [String]
10
12
  DEFAULT_APP_ID = ENV["QISCUS_APP_ID"]
11
13
 
12
- # @return [String, NilClass]
14
+ # @return [String]
13
15
  DEFAULT_SECRET_KEY = ENV["QISCUS_SECRET_KEY"]
14
16
 
15
17
  # @return [String]
16
- DEFAULT_URL = ENV["QISCUS_OMNICHANNEL_URL"] || "https://qismo.qiscus.com"
18
+ DEFAULT_URL = (ENV["QISCUS_OMNICHANNEL_URL"] || "https://multichannel.qiscus.com")
17
19
 
18
- # @return [Hash]
19
- DEFAULT_OPTIONS = {
20
+ # @return [String]
21
+ attr_accessor :app_id
22
+
23
+ # @return [String]
24
+ attr_accessor :secret_key
25
+
26
+ # @return [Addressable::URI]
27
+ attr_accessor :url
28
+
29
+ # @return [Logger]
30
+ attr_accessor :logger
31
+
32
+ # @return [ActiveSupport::Notifications::Instrumenter]
33
+ attr_accessor :instrumentation
34
+
35
+ # @return [Integer,Hash]
36
+ attr_accessor :timeout
37
+
38
+ # @return [Array<String,Integer>]
39
+ attr_accessor :proxy
40
+
41
+ # @return [String,Proc]
42
+ attr_accessor :admin_email
43
+
44
+ # Initiate Qismo Ruby client
45
+ #
46
+ # @param app_id [String]
47
+ # Your account's app id. Can be checked in Qiscus Omnichannel dashboard.
48
+ # We will use ENV["QISCUS_APP_ID"] value as default value.
49
+ # @param secret_key [String]
50
+ # Your account's secret key. Can be checked in Qiscus Omnichannel dashboard.
51
+ # We will use ENV["QISCUS_SECRET_KEY"] value as default value.
52
+ # @param url [String]
53
+ # Custom base url for Qiscus Omnichannel client.
54
+ # We will use ENV["QISCUS_OMNICHANNEL_URL"] value as default value.
55
+ # If its not provided, we will use https://multichannel.qiscus.com as default value
56
+ # @param logger [Logger]
57
+ # Http client logging. Default is nil
58
+ # @param instrumentation [ActiveSupport::Notifications::Instrumenter]
59
+ # Http client instrumenter. Use ActiveSupport Instrumenter
60
+ # @param timeout [Integer, Hash]
61
+ # Http client timout. Default is 5 seconds
62
+ # @param proxy [Array<String,Integer>]
63
+ # Http client proxy
64
+ # @param admin_email [String,Proc]
65
+ # Your account's admin email. Can be checked in Qiscus Omnichannel dashboard
66
+ def initialize(
20
67
  app_id: DEFAULT_APP_ID,
21
68
  secret_key: DEFAULT_SECRET_KEY,
22
69
  url: DEFAULT_URL,
23
- logger: nil,
70
+ logger: Logger.new($stdout),
24
71
  instrumentation: nil,
25
- timeout: nil,
26
- proxy: nil
27
- }
28
-
29
- attr_accessor(*DEFAULT_OPTIONS.keys)
30
- attr_reader :admin_email
31
-
32
- # Initialize client
33
- #
34
- # @param options [Hash]
35
- def initialize(options = {})
36
- DEFAULT_OPTIONS.merge(options).each do |key, value|
37
- instance_variable_set("@#{key}", value)
38
- end
39
-
40
- @admin_email = "#{@app_id}_admin@qismo.com"
72
+ timeout: 5,
73
+ proxy: nil,
74
+ admin_email: nil
75
+ )
76
+ @app_id = app_id
77
+ @secret_key = secret_key
78
+
79
+ # @type [Addressable::URI]
80
+ @url = Addressable::URI.parse(url)
81
+
82
+ @logger = logger
83
+ @instrumentation = instrumentation
84
+ @timeout = timeout
85
+ @proxy = proxy
86
+
87
+ @admin_email = (admin_email || -> { "#{@app_id}_admin@qismo.com" })
41
88
  end
42
89
 
43
90
  # Send http request with post method
@@ -85,7 +132,7 @@ module Qismo
85
132
  # @param json [Hash]
86
133
  # @return [Qismo::ObjectifiedHash]
87
134
  def request(method, path, options = {})
88
- res = connection.request(method, @url + path, options.compact)
135
+ res = connection.request(method, @url.join(path), options.compact)
89
136
 
90
137
  if res.status.success?
91
138
  begin
@@ -124,16 +171,11 @@ module Qismo
124
171
  # @return [HTTP::Chainable]
125
172
  def connection
126
173
  http = HTTP
174
+ http = http.use(logging: @logger) if @logger.present?
175
+ http = http.use(instrumentation: @instrumentation) if @instrumentation.present?
176
+ http = http.via(*@proxy)
127
177
 
128
- unless @logger.nil?
129
- http = http.use(logging: @logger)
130
- end
131
-
132
- unless @instrumentation.nil?
133
- http = http.use(instrumentation: @instrumentation)
134
- end
135
-
136
- unless @timeout.nil?
178
+ if @timeout.present?
137
179
  http = if @timeout.is_a?(Hash)
138
180
  http.timeout(**@timeout)
139
181
  else
@@ -141,10 +183,6 @@ module Qismo
141
183
  end
142
184
  end
143
185
 
144
- unless @proxy.nil?
145
- http = http.via(*@proxy)
146
- end
147
-
148
186
  http.headers({
149
187
  "Qiscus-App-Id": @app_id,
150
188
  "Qiscus-Secret-Key": @secret_key,
data/lib/qismo/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Qismo
4
4
  # @return [String]
5
- VERSION = "0.17.10"
5
+ VERSION = "0.18.1"
6
6
  end
data/qismo.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.metadata = {
19
19
  "source_code_uri" => "https://bitbucket.org/qiscus/qismo-rb/src/v#{spec.version}",
20
- "documentation_uri" => "https://www.rubydoc.info/gems/qismo/#{spec.version}",
20
+ "documentation_uri" => "https://www.rubydoc.info/gems/qismo",
21
21
  "homepage_uri" => spec.homepage,
22
22
  "rubygems_mfa_required" => "true"
23
23
  }
@@ -45,5 +45,4 @@ Gem::Specification.new do |spec|
45
45
  spec.add_runtime_dependency("activesupport")
46
46
  spec.add_runtime_dependency("http")
47
47
  spec.add_runtime_dependency("dry-struct", "~> 1.6")
48
- spec.add_runtime_dependency("dry-validation", "~> 1.10")
49
48
  end
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "Initiate Qismo client": {
3
- "prefix": "Qismo",
3
+ "prefix": "Qismo::Client",
4
+ "scope": "ruby",
4
5
  "body": [
5
- "client = Qismo::Client.new(",
6
+ "qismo = Qismo::Client.new(",
6
7
  " app_id: \"${1:app_id}\",",
7
8
  " secret_key: \"${2:secret_key}\",",
8
9
  " url: \"https://qismo.qiscus.com\",",
@@ -14,22 +15,105 @@
14
15
  "description": "Initiate Qismo client"
15
16
  },
16
17
  "List rooms": {
17
- "prefix": "client.rooms",
18
- "body": [
19
- "rooms = client.rooms(",
20
- " channels: [{ source: \"wa\", channel_id: 716171 }],",
21
- " status: \"unresolved\",",
22
- " serve_status: \"served\",",
23
- " is_handled_by_bot: false,",
24
- " name: \"Qiscus\",",
25
- " limit: 50,",
26
- " tag_ids: [1,2,3],",
27
- " user_ids: [5,6,7],",
28
- " order: \"desc\",",
29
- " cursor_before: \"\",",
30
- " cursor_after: \"\"",
18
+ "prefix": "qismo.list_rooms",
19
+ "body": [
20
+ "rooms = qismo.list_rooms(",
21
+ " channels: [{ source: \"${1|wa,telegram,qiscus,line,fb|}\", channel_id: 716171 }],",
22
+ " status: \"${2|unresolved,resolved,almost_expired,expired|}\",",
23
+ " serve_status: \"${3|served,unserved|}\",",
24
+ " is_handled_by_bot: ${4|true,false|},",
25
+ " name: \"${5:customer_name}\",",
26
+ " limit: ${6:limit},",
27
+ " tag_ids: [${7:tag_ids}],",
28
+ " user_ids: [${8:user_ids}],",
29
+ " order: \"${9|desc,asc|}\",",
30
+ " cursor_before: \"${10:cursor_before}\",",
31
+ " cursor_after: \"${11:cursor_after}\"",
31
32
  ")"
32
33
  ],
33
34
  "description": "List rooms"
35
+ },
36
+ "Get room by id": {
37
+ "scope": "ruby",
38
+ "prefix": "qismo.get_room",
39
+ "body": [
40
+ "room = qismo.get_room(room_id: ${1:room_id})"
41
+ ],
42
+ "description": "Get room by id"
43
+ },
44
+ "List room tags": {
45
+ "prefix": "qismo.list_room_tags",
46
+ "body": [
47
+ "room_tags = qismo.list_room_tags(room_id: ${1:12345})"
48
+ ],
49
+ "description": "List room tags"
50
+ },
51
+ "Add room tag": {
52
+ "prefix": "qismo.add_room_tag",
53
+ "body": [
54
+ "room_tag = qismo.add_room_tag(room_id: ${1:12345}, tag: \"${2:tag_name}\")"
55
+ ],
56
+ "description": "Add room tag"
57
+ },
58
+ "Delete room tag": {
59
+ "prefix": "qismo.delete_room_tag",
60
+ "body": [
61
+ "qismo.delete_room_tag(room_id: ${1:12345}, tag_id: ${2:12345})"
62
+ ],
63
+ "description": "Delete room tag"
64
+ },
65
+ "List room additional info": {
66
+ "prefix": "qismo.list_room_info",
67
+ "body": [
68
+ "room_info = qismo.list_room_info(room_id: ${1:12345})",
69
+ "room_info.each do |info|",
70
+ " puts info.key",
71
+ " puts info.value",
72
+ "end"
73
+ ],
74
+ "description": "List room additional info"
75
+ },
76
+ "Create room additional info": {
77
+ "prefix": "qismo.create_room_info",
78
+ "body": [
79
+ "room_info = qismo.create_room_info(room_id: ${1:12345}, info: [{key: \"${2:key}\", value: \"${3:value}\"}])",
80
+ "room_info.each do |info|",
81
+ " puts info.key",
82
+ " puts info.value",
83
+ "end"
84
+ ],
85
+ "description": "Create room additional info"
86
+ },
87
+ "Update room additional info": {
88
+ "prefix": "qismo.update_room_info",
89
+ "body": [
90
+ "room_info = qismo.create_room_info(room_id: ${1:12345}, info: [{key: \"${2:key}\", value: \"${3:value}\"}])",
91
+ "room_info.each do |info|",
92
+ " puts info.key",
93
+ " puts info.value",
94
+ "end"
95
+ ],
96
+ "description": "Update room additional info"
97
+ },
98
+ "List wa broadcast in room": {
99
+ "prefix": "qismo.list_room_broadcasts",
100
+ "body": [
101
+ "room_broadcasts = qismo.list_room_broadcasts(room_id: ${1:12345}, page: ${2:1}, limit: ${3:25})"
102
+ ],
103
+ "description": "List wa broadcast in room"
104
+ },
105
+ "Assign an agent to a room": {
106
+ "prefix": "qismo.assign_agent",
107
+ "body": [
108
+ "qismo.assign_agent(room_id: ${1:12345}, agent_id: ${2:12345}, replace_latest_agent: ${3|false,true|}, max_agent: ${4:1})"
109
+ ],
110
+ "description": "Assign an agent to a room"
111
+ },
112
+ "Remove an agent from a room": {
113
+ "prefix": "qismo.remove_agent",
114
+ "body": [
115
+ "qismo.remove_agent(room_id: ${1:12345}, agent_id: ${2:12345})"
116
+ ],
117
+ "description": "Remove an agent from a room"
34
118
  }
35
119
  }
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.17.10
4
+ version: 0.18.1
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-23 00:00:00.000000000 Z
11
+ date: 2023-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
- - !ruby/object:Gem::Dependency
56
- name: dry-validation
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.10'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.10'
69
55
  description: Ruby wrapper for Qiscus Omnichannel public API
70
56
  email:
71
57
  - developer@qiscus.net
@@ -120,8 +106,8 @@ homepage: https://bitbucket.org/qiscus/qismo-rb
120
106
  licenses:
121
107
  - MIT
122
108
  metadata:
123
- source_code_uri: https://bitbucket.org/qiscus/qismo-rb/src/v0.17.10
124
- documentation_uri: https://www.rubydoc.info/gems/qismo/0.17.10
109
+ source_code_uri: https://bitbucket.org/qiscus/qismo-rb/src/v0.18.1
110
+ documentation_uri: https://www.rubydoc.info/gems/qismo
125
111
  homepage_uri: https://bitbucket.org/qiscus/qismo-rb
126
112
  rubygems_mfa_required: 'true'
127
113
  post_install_message: