qismo 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/qismo/api.rb +556 -324
  3. data/lib/qismo/client.rb +31 -19
  4. data/lib/qismo/collection.rb +21 -0
  5. data/lib/qismo/object.rb +21 -0
  6. data/lib/qismo/objectified_hash.rb +30 -0
  7. data/lib/qismo/objects/agent_service.rb +53 -0
  8. data/lib/qismo/objects/broadcast_job.rb +99 -0
  9. data/lib/qismo/objects/broadcast_log.rb +59 -0
  10. data/lib/qismo/objects/custom_channel.rb +35 -0
  11. data/lib/qismo/objects/custom_channel_message_response.rb +19 -0
  12. data/lib/qismo/objects/customer_room.rb +85 -0
  13. data/lib/qismo/objects/fb_channel.rb +31 -0
  14. data/lib/qismo/objects/hsm_template.rb +111 -0
  15. data/lib/qismo/objects/ig_channel.rb +43 -0
  16. data/lib/qismo/objects/line_channel.rb +27 -0
  17. data/lib/qismo/objects/list_channels_response.rb +39 -0
  18. data/lib/qismo/objects/office_hour.rb +67 -0
  19. data/lib/qismo/objects/qiscus_channel.rb +27 -0
  20. data/lib/qismo/objects/room_additional_info.rb +15 -0
  21. data/lib/qismo/objects/tag.rb +27 -0
  22. data/lib/qismo/objects/telegram_channel.rb +31 -0
  23. data/lib/qismo/objects/user.rb +99 -0
  24. data/lib/qismo/objects/wa_channel.rb +111 -0
  25. data/lib/qismo/objects/wa_credit_info.rb +71 -0
  26. data/lib/qismo/objects/waca_channel.rb +55 -0
  27. data/lib/qismo/objects/webhook.rb +15 -0
  28. data/lib/qismo/types.rb +10 -1
  29. data/lib/qismo/version.rb +1 -1
  30. data/lib/qismo/webhook_requests/on_agent_allocation_needed.rb +8 -2
  31. data/lib/qismo/webhook_requests/on_custom_button_clicked.rb +15 -7
  32. data/lib/qismo/webhook_requests/on_custom_channel_message_sent.rb +18 -6
  33. data/lib/qismo/webhook_requests/on_message_for_bot_sent.rb +18 -6
  34. data/lib/qismo/webhook_requests/on_new_session_initiated.rb +30 -10
  35. data/lib/qismo/webhook_requests/on_room_resolved.rb +15 -5
  36. data/lib/qismo.rb +28 -34
  37. data/qismo.gemspec +1 -0
  38. metadata +40 -6
  39. data/lib/qismo/model.rb +0 -102
  40. data/lib/qismo/models/base.rb +0 -13
  41. data/lib/qismo/models/customer_room.rb +0 -6
  42. data/lib/qismo/util.rb +0 -31
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
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dry-struct"
4
-
5
- module Qismo
6
- module Models
7
- include Qismo::Types
8
-
9
- class Base < Dry::Struct
10
- transform_keys(&:to_sym)
11
- end
12
- end
13
- end
@@ -1,6 +0,0 @@
1
- module Qismo
2
- module Models
3
- class CustomerRoom < Base
4
- end
5
- end
6
- 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