qismo 0.18.0 → 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: ee4468cc8899fd8ff50f46e1a3b03a486d9535c58e450474624dfa46c9d7888d
4
- data.tar.gz: 15d203e201451848742fdbfa7e67e26b2efb434f8ebeb64fc8af48c4dbeda486
3
+ metadata.gz: 4b5821ce5a3af4f9c2c0b8b2ff1436ee77c8395a4b98f06b3c64c45afc188cbf
4
+ data.tar.gz: ece73a2396b03a38acbb7e64352d4121988f2e5850018bab9d95c10ba88bc3ce
5
5
  SHA512:
6
- metadata.gz: 47a01de9e692e3bc0836653702f553049bacada7fb955a9888425dc09dcee79fd99d0f4c3e79da4e32c9c0f8f50919e12ed8b1d2646599a8368cc86bf56e766e
7
- data.tar.gz: 856f96e582d66c263c4caef6c71a27d48a894acfa8b51eed4e3279f09bab6c94a9a33219a3c58143359c7009a189bdea9d07f588010b3b162d8f19d9ab8ff9ae
6
+ metadata.gz: 4c605b2d1f6dd5ba69ff9dab9927dbeb63f9678f2b953364448893d2ac873a0770aa1c89bb7d3b42f7918a6cbd58e701eb3225f85718fcdd49ed97aef0f8a1cc
7
+ data.tar.gz: 73741ee9f08ccfb8aaaff41993ff91bc2bfa7ba5491e8d078a037ad769e22c802bed26a2e374b079eb539fb23715cf38bf64c21801d8151099e027832bbd015c
data/README.md CHANGED
@@ -13,7 +13,7 @@ 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
19
  channel: [{ channel_id: 12345, source: "wa" }],
@@ -22,7 +22,7 @@ params = {
22
22
  is_handled_by_bot: true,
23
23
  }
24
24
 
25
- pp client.list_rooms(params)
25
+ pp qismo.list_rooms(params)
26
26
 
27
27
  # [
28
28
  # #<Qismo::Objects::CustomerRoom
@@ -57,7 +57,7 @@ Qismo ruby also provide some optional configuration that you can pass, they are:
57
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
58
58
 
59
59
  ```ruby
60
- client.url = "https://qismo.qiscus.com"
60
+ qismo.url = "https://qismo.qiscus.com"
61
61
  ```
62
62
 
63
63
  **logger**
@@ -67,7 +67,7 @@ You can also log the request and response the any HTTP request you make in Qismo
67
67
  ```ruby
68
68
  require "logger"
69
69
 
70
- client.logger = Logger.new($stdout)
70
+ qismo.logger = Logger.new($stdout)
71
71
  ```
72
72
 
73
73
  **instrumentation**
@@ -79,13 +79,13 @@ ActiveSupport::Notifications.subscribe('start_request.http') do |name, start, fi
79
79
  pp name: name, start: start.to_f, finish: finish.to_f, id: id, payload: payload
80
80
  end
81
81
 
82
- client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }
82
+ qismo.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }
83
83
  ```
84
84
 
85
85
  You can also customize the instrumentation's namespace by using this configuration
86
86
 
87
87
  ```ruby
88
- client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter, namespace: "qiscus.http_request" }
88
+ qismo.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter, namespace: "qiscus.http_request" }
89
89
  ```
90
90
 
91
91
  **timeout**
@@ -95,13 +95,13 @@ By default, the Qismo ruby gem does not enforce timeout on a request. You can en
95
95
  Per operation timeouts are what `Net::HTTP` and the majority of HTTP clients do:
96
96
 
97
97
  ```ruby
98
- client.timeout = { connect: 5, write: 2, read: 10 }
98
+ qismo.timeout = { connect: 5, write: 2, read: 10 }
99
99
  ```
100
100
 
101
101
  Global timeouts let you set an upper bound of how long a request can take
102
102
 
103
103
  ```ruby
104
- client.timeout = 5 # in seconds
104
+ qismo.timeout = 5 # in seconds
105
105
  ```
106
106
 
107
107
  **proxy**
@@ -109,13 +109,13 @@ client.timeout = 5 # in seconds
109
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
110
110
 
111
111
  ```ruby
112
- client.proxy = ["proxy-hostname.local", 8080]
112
+ qismo.proxy = ["proxy-hostname.local", 8080]
113
113
  ```
114
114
 
115
115
  Proxy needs authentication?
116
116
 
117
117
  ```ruby
118
- client.proxy = ["proxy-hostname.local", 8080, "username", "password"]
118
+ qismo.proxy = ["proxy-hostname.local", 8080, "username", "password"]
119
119
  ```
120
120
 
121
121
  ## Handling pagination
@@ -126,11 +126,11 @@ Some of the Qiscus Omnichannel API will return list of data with pagination. To
126
126
 
127
127
  all_rooms = []
128
128
 
129
- rooms = client.list_rooms
129
+ rooms = qismo.list_rooms
130
130
  all_rooms.append(rooms)
131
131
 
132
132
  while rooms.next_page.present?
133
- rooms = client.list_rooms(cursor_after: rooms.next_page)
133
+ rooms = qismo.list_rooms(cursor_after: rooms.next_page)
134
134
  all_rooms.append(rooms)
135
135
  end
136
136
  ```
@@ -141,7 +141,7 @@ Qismo ruby raise error while getting non successful http code from Qiscus Omnich
141
141
 
142
142
  ```ruby
143
143
  begin
144
- client.list_rooms
144
+ qismo.list_rooms
145
145
  rescue Qismo::BadRequestError => e
146
146
  puts e.message
147
147
  puts e.status_code
@@ -186,8 +186,8 @@ class QiscusWebhooksController < ApplicationController
186
186
 
187
187
  # Do any action you want using payload that has been objectified
188
188
  if webhook.candidate_agent.present?
189
- client = Qismo::Client.new(app_id: "", secret_key: "")
190
- client.assign_agent(
189
+ qismo = Qismo::Client.new(app_id: "", secret_key: "")
190
+ qismo.assign_agent(
191
191
  room_id: webhook.room_id,
192
192
  agent_id: webhook.candidate_agent.id
193
193
  )
@@ -250,11 +250,13 @@ class QiscusWebhooksController < ApplicationController
250
250
  bot_message = response.query_result.fulfillment_text
251
251
 
252
252
  # Send message to Qismo room
253
- client = Qismo::Client.new(app_id: "", secret_key: "")
254
- client.send_bot_message(
253
+ qismo = Qismo::Client.new(app_id: "", secret_key: "")
254
+ qismo.send_bot_message(
255
255
  room_id: webhook.payload.room.id,
256
256
  message: bot_message
257
257
  )
258
258
  end
259
259
  end
260
260
  ```
261
+ ## Developer Experience
262
+ > TODO documentation
data/lib/qismo/api.rb CHANGED
@@ -801,6 +801,8 @@ module Qismo
801
801
  email: email
802
802
  }.compact
803
803
 
804
+ options[:app_id] = app_id
805
+
804
806
  Qismo::Objects::CustomerRoom.new(post("/api/v2/qiscus/initiate_chat", options).data.customer_room)
805
807
  end
806
808
 
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.18.0"
5
+ VERSION = "0.18.1"
6
6
  end
data/qismo.gemspec CHANGED
@@ -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.18.0
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-25 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,7 +106,7 @@ 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.18.0
109
+ source_code_uri: https://bitbucket.org/qiscus/qismo-rb/src/v0.18.1
124
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'