qismo 0.12.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,170 @@
1
+ module Qismo
2
+ module WebhookRequests
3
+ # @!attribute [r] is_new_session
4
+ # @return [TrueClass,FalseClass]
5
+ # @!attribute [r] payload
6
+ # @return [Payload]
7
+ # @!attribute [r] room_log
8
+ # @return [RoomLog]
9
+ class OnNewSessionInitiated < Qismo::Object
10
+ # @!attribute [r] avatar_url
11
+ # @return [String]
12
+ # @!attribute [r] email
13
+ # @return [String]
14
+ # @!attribute [r] id
15
+ # @return [Integer]
16
+ # @!attribute [r] name
17
+ # @return [String]
18
+ class From < Qismo::Object
19
+ attribute? :avatar_url, Types::String.optional
20
+ attribute? :email, Types::String.optional
21
+ attribute? :id, Types::Int.optional
22
+ attribute? :name, Types::String.optional
23
+ end
24
+
25
+ # @!attribute [r] comment_before_id
26
+ # @return [Integer]
27
+ # @!attribute [r] created_at
28
+ # @return [String]
29
+ # @!attribute [r] id
30
+ # @return [Integer]
31
+ # @!attribute [r] payload
32
+ # @return [Hash]
33
+ # @!attribute [r] text
34
+ # @return [String]
35
+ # @!attribute [r] timestamp
36
+ # @return [String]
37
+ # @!attribute [r] type
38
+ # @return [String]
39
+ # @!attribute [r] unique_temp_id
40
+ # @return [String]
41
+ # @!attribute [r] unix_nano_timestamp
42
+ # @return [String]
43
+ # @!attribute [r] unix_timestamp
44
+ # @return [String]
45
+ class Message < Qismo::Object
46
+ attribute? :comment_before_id, Types::Int.optional
47
+ attribute? :created_at, Types::String.optional
48
+ attribute? :id, Types::Int.optional
49
+ attribute? :payload, Types::Hash.optional
50
+ attribute? :text, Types::String.optional
51
+ attribute? :timestamp, Types::String.optional
52
+ attribute? :type, Types::String.optional
53
+ attribute? :unique_temp_id, Types::String.optional
54
+ attribute? :unix_nano_timestamp, Types::String.optional
55
+ attribute? :unix_timestamp, Types::String.optional
56
+ end
57
+
58
+ # @!attribute [r] email
59
+ # @return [String]
60
+ class Participant < Qismo::Object
61
+ attribute? :email, Types::String.optional
62
+ end
63
+
64
+ # @!attribute [r] id
65
+ # @return [String]
66
+ # @!attribute [r] name
67
+ # @return [String]
68
+ # @!attribute [r] options
69
+ # @return [String]
70
+ # @!attribute [r] participants
71
+ # @return [Array<Participant>]
72
+ # @!attribute [r] room_avatar
73
+ # @return [String]
74
+ class Room < Qismo::Object
75
+ attribute? :id, Types::String.optional
76
+ attribute? :name, Types::String.optional
77
+ attribute? :options, Types::String.optional
78
+ attribute? :participants, Types.Array(Participant.optional).optional
79
+ attribute? :room_avatar, Types::String.optional
80
+ end
81
+
82
+ # @!attribute [r] from
83
+ # @return [From]
84
+ # @!attribute [r] message
85
+ # @return [Message]
86
+ # @!attribute [r] room
87
+ # @return [Room]
88
+ # @!attribute [r] type
89
+ # @return [String]
90
+ class Payload < Qismo::Object
91
+ attribute? :from, From.optional
92
+ attribute? :message, Message.optional
93
+ attribute? :room, Room.optional
94
+ end
95
+
96
+ # @!attribute [r] key
97
+ # @return [String]
98
+ # @!attribute [r] value
99
+ # @return [String,Integer,TrueClass,FalseClass]
100
+ class UserProperty < Qismo::Object
101
+ attribute? :key, Types::String.optional
102
+ attribute? :value, (Types::String.optional | Types::Int.optional | Types::Params::Bool.optional)
103
+ end
104
+
105
+ # @!attribute [r] timezone_offset
106
+ # @return [String]
107
+ class AdditionalExtras < Qismo::Object
108
+ attribute? :timezone_offset, Types::String
109
+ end
110
+
111
+ # @!attribute [r] additional_extras
112
+ # @return [AdditionalExtras]
113
+ # @!attribute [r] notes
114
+ # @return [String]
115
+ # @!attribute [r] timezone_offset
116
+ # @return [String]
117
+ # @!attribute [r] user_properties
118
+ # @return [Array<UserProperty>]
119
+ class Extras < Qismo::Object
120
+ attribute? :additional_extras, AdditionalExtras.optional
121
+ attribute? :notes, Types::String
122
+ attribute? :timezone_offset, Types::String
123
+ attribute? :user_properties, Types.Array(UserProperty.optional).optional
124
+ end
125
+
126
+ # @!attribute [r] channel_id
127
+ # @return [Integer]
128
+ # @!attribute [r] created_at
129
+ # @return [String]
130
+ # @!attribute [r] extras
131
+ # @return [String]
132
+ # @!attribute [r] has_no_message
133
+ # @return [TrueClass,FalseClass]
134
+ # @!attribute [r] is_waiting
135
+ # @return [TrueClass,FalseClass]
136
+ # @!attribute [r] name
137
+ # @return [String]
138
+ # @!attribute [r] resolved
139
+ # @return [TrueClass,FalseClass]
140
+ # @!attribute [r] room_badge
141
+ # @return [String]
142
+ # @!attribute [r] room_id
143
+ # @return [String]
144
+ # @!attribute [r] source
145
+ # @return [String]
146
+ # @!attribute [r] user_avatar_url
147
+ # @return [String]
148
+ # @!attribute [r] user_id
149
+ # @return [String]
150
+ class RoomLog < Qismo::Object
151
+ attribute? :channel_id, Types::Int
152
+ attribute? :created_at, Types::String
153
+ attribute? :extras, Extras
154
+ attribute? :has_no_message, Types::Bool
155
+ attribute? :is_waiting, Types::Nil
156
+ attribute? :name, Types::String
157
+ attribute? :resolved, Types::Bool
158
+ attribute? :room_badge, Types::String
159
+ attribute? :room_id, Types::String
160
+ attribute? :source, Types::String
161
+ attribute? :user_avatar_url, Types::String
162
+ attribute? :user_id, Types::String
163
+ end
164
+
165
+ attribute? :is_new_session, Types::Bool
166
+ attribute? :payload, Payload
167
+ attribute? :room_log, RoomLog
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,81 @@
1
+ module Qismo
2
+ module WebhookRequests
3
+ # @!attribute [r] customer
4
+ # @return [Customer]
5
+ # @!attribute [r] resolved_by
6
+ # @return [ResolvedBy]
7
+ # @!attribute [r] service
8
+ # @return [Service]
9
+ class OnRoomResolved < Qismo::Object
10
+ # @!attribute [r] key
11
+ # @return [String]
12
+ # @!attribute [r] value
13
+ # @return [String,Integer,TrueClass,FalseClass]
14
+ class AdditionalInfo < Qismo::Object
15
+ attribute? :key, Types::String.optional
16
+ attribute? :value, (Types::String.optional | Types::Int.optional | Types::Params::Bool.optional)
17
+ end
18
+
19
+ # @!attribute [r] additional_info
20
+ # @return [Array<AdditionalInfo>]
21
+ # @!attribute [r] avatar
22
+ # @return [String]
23
+ # @!attribute [r] name
24
+ # @return [String]
25
+ # @!attribute [r] user_id
26
+ # @return [String]
27
+ class Customer < Qismo::Object
28
+ attribute? :additional_info, Types.Array(AdditionalInfo.optional).optional
29
+ attribute? :avatar, Types::String.optional
30
+ attribute? :name, Types::String.optional
31
+ attribute? :user_id, Types::String.optional
32
+ end
33
+
34
+ # @!attribute [r] email
35
+ # @return [String]
36
+ # @!attribute [r] id
37
+ # @return [Integer]
38
+ # @!attribute [r] is_available
39
+ # @return [TrueClass,FalseClass]
40
+ # @!attribute [r] name
41
+ # @return [String]
42
+ # @!attribute [r] type
43
+ # @return [String]
44
+ class ResolvedBy < Qismo::Object
45
+ attribute? :email, Types::String.optional
46
+ attribute? :id, Types::Int.optional
47
+ attribute? :is_available, Types::Bool.optional
48
+ attribute? :name, Types::String.optional
49
+ attribute? :type, Types::String.optional
50
+ end
51
+
52
+ # @!attribute [r] first_comment_id
53
+ # @return [String]
54
+ # @!attribute [r] last_comment_id
55
+ # @return [String]
56
+ # @!attribute [r] id
57
+ # @return [Integer]
58
+ # @!attribute [r] is_resolved
59
+ # @return [TrueClass,FalseClass]
60
+ # @!attribute [r] notes
61
+ # @return [String]
62
+ # @!attribute [r] room_id
63
+ # @return [String]
64
+ # @!attribute [r] source
65
+ # @return [String]
66
+ class Service < Qismo::Object
67
+ attribute? :first_comment_id, Types::String.optional
68
+ attribute? :last_comment_id, Types::String.optional
69
+ attribute? :id, Types::Int.optional
70
+ attribute? :is_resolved, Types::Bool.optional
71
+ attribute? :notes, Types::String.optional
72
+ attribute? :room_id, Types::String.optional
73
+ attribute? :source, Types::String.optional
74
+ end
75
+
76
+ attribute? :customer, Customer
77
+ attribute? :resolved_by, ResolvedBy
78
+ attribute? :service, Service
79
+ end
80
+ end
81
+ end
data/lib/qismo.rb CHANGED
@@ -1,44 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/all"
4
+ require "dry-struct"
4
5
  require "http"
5
6
 
6
- require "qismo/util"
7
7
  require "qismo/version"
8
+ require "qismo/types"
8
9
  require "qismo/error"
9
- require "qismo/model"
10
+
11
+ require "qismo/object"
12
+ require "qismo/objectified_hash"
13
+ require "qismo/collection"
14
+
15
+ require "qismo/objects/customer_room"
16
+ require "qismo/objects/tag"
17
+ require "qismo/objects/room_additional_info"
18
+ require "qismo/objects/broadcast_log"
19
+ require "qismo/objects/user"
20
+ require "qismo/objects/agent_service"
21
+ require "qismo/objects/webhook"
22
+ require "qismo/objects/office_hour"
23
+ require "qismo/objects/hsm_template"
24
+ require "qismo/objects/wa_credit_info"
25
+ require "qismo/objects/broadcast_job"
26
+ require "qismo/objects/custom_channel_message_response"
27
+
28
+ require "qismo/webhook_requests/on_agent_allocation_needed"
29
+ require "qismo/webhook_requests/on_custom_button_clicked"
30
+ require "qismo/webhook_requests/on_custom_channel_message_sent"
31
+ require "qismo/webhook_requests/on_message_for_bot_sent"
32
+ require "qismo/webhook_requests/on_new_session_initiated"
33
+ require "qismo/webhook_requests/on_room_resolved"
34
+
10
35
  require "qismo/api"
11
36
  require "qismo/client"
12
37
 
13
38
  module Qismo
14
- # @!parse extend Qismo::Api
15
-
16
- class << self
17
- def configure
18
- yield client
19
-
20
- client
21
- end
22
-
23
- private
24
-
25
- # @return [Qismo::Client]
26
- def client
27
- @client ||= Client.new
28
- end
29
-
30
- def method_missing(method, *args, &block)
31
- return super unless client.respond_to?(method)
32
-
33
- client.send(method, *args, &block)
34
- end
35
-
36
- def respond_to?(method_name, include_private = false)
37
- client.respond_to?(method_name, include_private) || super(method_name, include_private)
38
- end
39
-
40
- def respond_to_missing?(method_name, include_private = false)
41
- client.respond_to?(method_name, include_private) || super(method_name, include_private)
42
- end
43
- end
44
39
  end
data/qismo.gemspec CHANGED
@@ -43,4 +43,6 @@ Gem::Specification.new do |spec|
43
43
 
44
44
  spec.add_runtime_dependency("activesupport")
45
45
  spec.add_runtime_dependency("http")
46
+ spec.add_runtime_dependency("dry-struct", "~> 1.6")
47
+ spec.add_runtime_dependency("dry-validation", "~> 1.10")
46
48
  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.12.1
4
+ version: 0.14.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-08 00:00:00.000000000 Z
11
+ date: 2022-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
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'
41
69
  description: Ruby wrapper for Qiscus Omnichannel public API
42
70
  email:
43
71
  - developer@qiscus.net
@@ -51,10 +79,30 @@ files:
51
79
  - lib/qismo.rb
52
80
  - lib/qismo/api.rb
53
81
  - lib/qismo/client.rb
82
+ - lib/qismo/collection.rb
54
83
  - lib/qismo/error.rb
55
- - lib/qismo/model.rb
56
- - lib/qismo/util.rb
84
+ - lib/qismo/object.rb
85
+ - lib/qismo/objectified_hash.rb
86
+ - lib/qismo/objects/agent_service.rb
87
+ - lib/qismo/objects/broadcast_job.rb
88
+ - lib/qismo/objects/broadcast_log.rb
89
+ - lib/qismo/objects/custom_channel_message_response.rb
90
+ - lib/qismo/objects/customer_room.rb
91
+ - lib/qismo/objects/hsm_template.rb
92
+ - lib/qismo/objects/office_hour.rb
93
+ - lib/qismo/objects/room_additional_info.rb
94
+ - lib/qismo/objects/tag.rb
95
+ - lib/qismo/objects/user.rb
96
+ - lib/qismo/objects/wa_credit_info.rb
97
+ - lib/qismo/objects/webhook.rb
98
+ - lib/qismo/types.rb
57
99
  - lib/qismo/version.rb
100
+ - lib/qismo/webhook_requests/on_agent_allocation_needed.rb
101
+ - lib/qismo/webhook_requests/on_custom_button_clicked.rb
102
+ - lib/qismo/webhook_requests/on_custom_channel_message_sent.rb
103
+ - lib/qismo/webhook_requests/on_message_for_bot_sent.rb
104
+ - lib/qismo/webhook_requests/on_new_session_initiated.rb
105
+ - lib/qismo/webhook_requests/on_room_resolved.rb
58
106
  - qismo.gemspec
59
107
  homepage: https://bitbucket.org/qiscus/qismo-rb
60
108
  licenses:
data/lib/qismo/model.rb DELETED
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Qismo
4
- # Class to handle http response body
5
- #
6
- class SingleObject
7
- # Initiate data object
8
- #
9
- # @param options [Hash]
10
- def initialize(options = {})
11
- options.each do |key, value|
12
- value = if value.is_a?(Array)
13
- CollectionObject.new(handle_array(value))
14
- elsif value.is_a?(Hash)
15
- self.class.new(value)
16
- elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
17
- self.class.define_method("#{key.to_s.delete_prefix("is_")}?".to_sym) { value }
18
- value
19
- else
20
- value
21
- end
22
-
23
- self.class.attr_reader(key.to_sym)
24
- instance_variable_set("@#{key}", value)
25
- end
26
- end
27
-
28
- def inspect
29
- inspected_func ||= -> do
30
- attributes = instance_variables.map do |iv|
31
- "#{iv.to_s.delete_prefix("@")}=#{instance_variable_get(iv).inspect}"
32
- end
33
-
34
- "#<#{self.class.name} #{attributes.join(", ")}>"
35
- end
36
-
37
- inspected_func.call
38
- end
39
-
40
- alias_method :to_s, :inspect
41
-
42
- private
43
-
44
- def handle_array(values)
45
- values.map do |value|
46
- if value.is_a?(Hash)
47
- self.class.new(value)
48
- else
49
- value
50
- end
51
- end
52
- end
53
- end
54
-
55
- # Class to handle response body that contain pagination
56
- #
57
- class CollectionObject < Array
58
- # Initiate collection
59
- #
60
- # @param data [Qismo::SingleObject]
61
- # @param prev_page [String, Integer]
62
- # @param next_page [String, Integer]
63
- # @param prev_func [Proc, NilClass]
64
- # @param next_func [Proc, NilClass]
65
- def initialize(data = [], prev_page: nil, next_page: nil, prev_func: -> {}, next_func: -> {})
66
- super(data)
67
-
68
- @prev_page = prev_page
69
- @next_page = next_page
70
- @prev_func = prev_func
71
- @next_func = next_func
72
- end
73
-
74
- # @return [TrueClass, FalseClass]
75
- def has_next_page?
76
- @next_page != nil
77
- end
78
-
79
- alias_method :next_page?, :has_next_page?
80
-
81
- # @return [TrueClass, FalseClass]
82
- def has_prev_page?
83
- @prev_page != nil
84
- end
85
-
86
- alias_method :prev_page?, :has_prev_page?
87
-
88
- # Call api request for next page
89
- #
90
- # @return [Qismo::SingleObject, Qismo::CollectionObject]
91
- def next_page
92
- @next_func.call if has_next_page?
93
- end
94
-
95
- # Call api request for previous page
96
- #
97
- # @return [Qismo::SingleObject, Qismo::CollectionObject]
98
- def prev_page
99
- @prev_func.call if has_prev_page?
100
- end
101
- end
102
- end
data/lib/qismo/util.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Qismo
4
- class Util
5
- class << self
6
- # Check if now is in office hour or not
7
- #
8
- # @param data [Qismo::SingleObject]
9
- # @return [TrueClass, FalseClass]
10
- def in_office_hour?(data)
11
- return false if data.timezone.blank?
12
-
13
- offset = Time.zone_offset(data.timezone)
14
- tz_current = Time.current.getlocal(offset)
15
-
16
- today_office_hour = data.office_hours.find { |oh| oh.day == tz_current.strftime("%u").to_i }
17
- return false if today_office_hour.nil?
18
-
19
- start_hour = today_office_hour.starttime
20
- end_hour = today_office_hour.endtime
21
-
22
- # rubocop:disable Layout/LineLength
23
- start_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{start_hour} #{data.timezone}")
24
- end_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{end_hour} #{data.timezone}")
25
- # rubocop:enable Layout/LineLength
26
-
27
- tz_current.between?(start_time, end_time)
28
- end
29
- end
30
- end
31
- end