qismo 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
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