qismo 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/qismo/api.rb +5 -1
- data/lib/qismo/client.rb +4 -3
- data/lib/qismo/model.rb +60 -28
- data/lib/qismo/util.rb +25 -0
- data/lib/qismo/version.rb +1 -1
- data/lib/qismo.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be7d855a466237baededa8d61cbf42a88a52ff245c82b3a3ee2ecce2dd5ded47
|
4
|
+
data.tar.gz: 190f309eed38161f7718ce842e02a6e1e3d2c0e961096263b2ac003ca7216a29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ac3a4baa95ae52792801be684cac5d6d9de3c6bc271e50d2788fab62f243dafe9c8e05721d04d1004a02de22f89406b67e1bed8414315506d331a900738e95
|
7
|
+
data.tar.gz: 7ec9a32d43b4025809ada7d61af3e7dedcb9439c5ef074961e31e7714d1122c1a854e45126b8171af9d45c2b77ca364b4cd1032cd71ed1bfd43fc323b1d764ac
|
data/Gemfile.lock
CHANGED
data/lib/qismo/api.rb
CHANGED
@@ -167,7 +167,11 @@ module Qismo
|
|
167
167
|
end
|
168
168
|
|
169
169
|
def office_hours
|
170
|
-
get("/api/v1/admin/office_hours").data
|
170
|
+
data = get("/api/v1/admin/office_hours").data
|
171
|
+
data_hash = data.as_json
|
172
|
+
data_hash["is_in_office_hour"] = Util.in_office_hour?(data)
|
173
|
+
|
174
|
+
DataObject.new(data_hash)
|
171
175
|
end
|
172
176
|
|
173
177
|
def wa_broadcast_templates(**opt)
|
data/lib/qismo/client.rb
CHANGED
@@ -34,7 +34,7 @@ module Qismo
|
|
34
34
|
def request(method, path, **opt)
|
35
35
|
res = connection.request(method, @url + path, opt.compact)
|
36
36
|
if res.status.success?
|
37
|
-
return JSON.parse(res.to_s
|
37
|
+
return DataObject.new(JSON.parse(res.to_s))
|
38
38
|
end
|
39
39
|
|
40
40
|
if res.status.server_error?
|
@@ -42,9 +42,10 @@ module Qismo
|
|
42
42
|
end
|
43
43
|
|
44
44
|
if res.status.client_error?
|
45
|
-
body = JSON.parse(res.to_s
|
45
|
+
body = DataObject.new(JSON.parse(res.to_s))
|
46
|
+
|
46
47
|
error = body.errors
|
47
|
-
error = error.message if error.is_a?(
|
48
|
+
error = error.message if error.is_a?(DataObject)
|
48
49
|
|
49
50
|
error_klass_map = {
|
50
51
|
400 => BadRequestError,
|
data/lib/qismo/model.rb
CHANGED
@@ -1,48 +1,80 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Qismo
|
4
|
-
|
5
|
-
|
4
|
+
class DataObject
|
5
|
+
def initialize(opt = {})
|
6
|
+
opt.each do |key, value|
|
7
|
+
value = if value.is_a?(Array)
|
8
|
+
handle_array(value)
|
9
|
+
# instance_variable_set("@#{key}", handle_array(value))
|
10
|
+
elsif value.is_a?(Hash)
|
11
|
+
self.class.new(value)
|
12
|
+
# instance_variable_set("@#{key}", self.class.new(value))
|
13
|
+
else
|
14
|
+
value
|
15
|
+
# instance_variable_set("@#{key}", value)
|
16
|
+
end
|
17
|
+
|
18
|
+
self.class.attr_reader(key.to_sym)
|
19
|
+
instance_variable_set("@#{key}", value)
|
20
|
+
end
|
6
21
|
end
|
7
22
|
|
8
|
-
|
9
|
-
|
10
|
-
|
23
|
+
def inspect
|
24
|
+
inspected_func ||= -> do
|
25
|
+
attributes = instance_variables.map do |iv|
|
26
|
+
"#{iv.to_s.delete_prefix("@")}=#{instance_variable_get(iv).inspect}"
|
27
|
+
end
|
11
28
|
|
12
|
-
|
13
|
-
@next_page = next_page
|
14
|
-
@prev_func = prev_func
|
15
|
-
@next_func = next_func
|
29
|
+
"#<#{self.class.name} #{attributes.join(", ")}>"
|
16
30
|
end
|
17
31
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
32
|
+
inspected_func.call
|
33
|
+
end
|
21
34
|
|
22
|
-
|
35
|
+
alias_method :to_s, :inspect
|
23
36
|
|
24
|
-
|
25
|
-
|
37
|
+
private
|
38
|
+
|
39
|
+
def handle_array(values)
|
40
|
+
values.map do |value|
|
41
|
+
if value.is_a?(Hash)
|
42
|
+
self.class.new(value)
|
43
|
+
else
|
44
|
+
value
|
45
|
+
end
|
26
46
|
end
|
47
|
+
end
|
48
|
+
end
|
27
49
|
|
28
|
-
|
50
|
+
class Collection < Array
|
51
|
+
def initialize(data, prev_page: nil, next_page: nil, prev_func: -> { nil }, next_func: -> { nil })
|
52
|
+
super(data)
|
29
53
|
|
30
|
-
|
31
|
-
|
32
|
-
|
54
|
+
@prev_page = prev_page
|
55
|
+
@next_page = next_page
|
56
|
+
@prev_func = prev_func
|
57
|
+
@next_func = next_func
|
58
|
+
end
|
33
59
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
60
|
+
def has_next_page?
|
61
|
+
@next_page != nil
|
37
62
|
end
|
38
63
|
|
39
|
-
|
40
|
-
attr_reader :data, :meta
|
64
|
+
alias_method :next_page?, :has_next_page?
|
41
65
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
66
|
+
def has_prev_page?
|
67
|
+
@prev_page != nil
|
68
|
+
end
|
69
|
+
|
70
|
+
alias_method :prev_page?, :has_prev_page?
|
71
|
+
|
72
|
+
def next_page
|
73
|
+
@next_func.call if has_next_page?
|
74
|
+
end
|
75
|
+
|
76
|
+
def prev_page
|
77
|
+
@prev_func.call if has_prev_page?
|
46
78
|
end
|
47
79
|
end
|
48
80
|
end
|
data/lib/qismo/util.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qismo
|
4
|
+
class Util
|
5
|
+
class << self
|
6
|
+
def in_office_hour?(data)
|
7
|
+
return false if data.timezone.blank?
|
8
|
+
|
9
|
+
offset = Time.zone_offset(data.timezone)
|
10
|
+
tz_current = Time.current.getlocal(offset)
|
11
|
+
|
12
|
+
today_office_hour = data.office_hours.find { |oh| oh.day == tz_current.strftime("%u").to_i }
|
13
|
+
return false if today_office_hour.nil?
|
14
|
+
|
15
|
+
start_hour = today_office_hour.starttime
|
16
|
+
end_hour = today_office_hour.endtime
|
17
|
+
|
18
|
+
start_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{start_hour} #{data.timezone}")
|
19
|
+
end_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{end_hour} #{data.timezone}")
|
20
|
+
|
21
|
+
tz_current.between?(start_time, end_time)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/qismo/version.rb
CHANGED
data/lib/qismo.rb
CHANGED
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/qismo/client.rb
|
128
128
|
- lib/qismo/error.rb
|
129
129
|
- lib/qismo/model.rb
|
130
|
+
- lib/qismo/util.rb
|
130
131
|
- lib/qismo/version.rb
|
131
132
|
homepage: https://qiscus.com
|
132
133
|
licenses:
|