supersaas-api-client 1.1.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/actions.yaml +21 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +296 -0
- data/Gemfile +5 -3
- data/Gemfile.lock +31 -4
- data/README.md +108 -54
- data/Rakefile +8 -6
- data/bin/console +4 -3
- data/examples/appointments.rb +70 -42
- data/examples/forms.rb +20 -22
- data/examples/groups.rb +20 -0
- data/examples/promotions.rb +32 -0
- data/examples/schedules.rb +23 -11
- data/examples/users.rb +31 -23
- data/lib/supersaas-api-client/api/appointments.rb +38 -25
- data/lib/supersaas-api-client/api/base_api.rb +69 -23
- data/lib/supersaas-api-client/api/forms.rb +16 -9
- data/lib/supersaas-api-client/api/groups.rb +12 -0
- data/lib/supersaas-api-client/api/promotions.rb +29 -0
- data/lib/supersaas-api-client/api/schedules.rb +14 -4
- data/lib/supersaas-api-client/api/users.rb +28 -15
- data/lib/supersaas-api-client/client.rb +101 -35
- data/lib/supersaas-api-client/exception.rb +3 -1
- data/lib/supersaas-api-client/models/appointment.rb +9 -12
- data/lib/supersaas-api-client/models/base_model.rb +4 -1
- data/lib/supersaas-api-client/models/field_list.rb +12 -0
- data/lib/supersaas-api-client/models/form.rb +5 -2
- data/lib/supersaas-api-client/models/group.rb +7 -0
- data/lib/supersaas-api-client/models/promotion.rb +7 -0
- data/lib/supersaas-api-client/models/resource.rb +3 -1
- data/lib/supersaas-api-client/models/schedule.rb +3 -1
- data/lib/supersaas-api-client/models/slot.rb +4 -6
- data/lib/supersaas-api-client/models/super_form.rb +7 -0
- data/lib/supersaas-api-client/models/user.rb +5 -8
- data/lib/supersaas-api-client/version.rb +4 -2
- data/lib/supersaas-api-client.rb +3 -1
- data/lib/supersaas.rb +23 -15
- data/supersaas-api-client.gemspec +19 -18
- metadata +40 -26
- data/test/appointments_test.rb +0 -99
- data/test/client_test.rb +0 -46
- data/test/forms_test.rb +0 -22
- data/test/schedules_test.rb +0 -19
- data/test/test_helper.rb +0 -23
- data/test/users_test.rb +0 -68
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
class BaseApi
|
3
5
|
attr_accessor :client
|
4
6
|
|
5
|
-
INTEGER_REGEX = /\A[0-9]+\Z
|
6
|
-
DATETIME_REGEX = /\A\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}\Z
|
7
|
+
INTEGER_REGEX = /\A[0-9]+\Z/.freeze
|
8
|
+
DATETIME_REGEX = /\A\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}\Z/.freeze
|
9
|
+
PROMOTION_REGEX = /\A[0-9a-zA-Z]+\Z/.freeze
|
7
10
|
|
8
11
|
def initialize(client)
|
9
12
|
@client = client
|
@@ -17,39 +20,82 @@ module Supersaas
|
|
17
20
|
elsif value.is_a?(String) && value =~ INTEGER_REGEX
|
18
21
|
value.to_i
|
19
22
|
else
|
20
|
-
raise Supersaas::Exception
|
23
|
+
raise Supersaas::Exception, "Invalid id parameter: #{value}. Provide a integer value."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_user(value)
|
28
|
+
return if value.nil?
|
29
|
+
|
30
|
+
unless value.is_a?(Integer) || value.is_a?(String)
|
31
|
+
raise Supersaas::Exception, "Invalid user id parameter: #{value}."
|
32
|
+
end
|
33
|
+
|
34
|
+
value
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_number(value)
|
38
|
+
validate_id(value)
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_name(value)
|
42
|
+
unless value.nil? || (value.is_a?(String) && value.size)
|
43
|
+
raise Supersaas::Exception, 'Required parameter name is missing.'
|
21
44
|
end
|
45
|
+
|
46
|
+
value
|
22
47
|
end
|
23
|
-
def validate_number(value); validate_id(value); end
|
24
48
|
|
25
49
|
def validate_present(value)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
50
|
+
raise Supersaas::Exception, 'Required parameter is missing.' unless value
|
51
|
+
|
52
|
+
value
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate_notfound(value)
|
56
|
+
unless value.is_a?(String) && %w[error ignore].include?(value)
|
57
|
+
raise Supersaas::Exception, "Required parameter notfound can only be 'error' or 'ignore'."
|
30
58
|
end
|
59
|
+
|
60
|
+
value
|
31
61
|
end
|
32
62
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
elsif value.is_a?(Time) || value.is_a?(DateTime)
|
38
|
-
value.strftime("%Y-%m-%d %H:%M:%S")
|
39
|
-
else
|
40
|
-
raise ArgumentError
|
41
|
-
end
|
42
|
-
rescue ArgumentError
|
43
|
-
raise Supersaas::Exception.new("Invalid datetime parameter: #{value}. Provide a Time object or formatted 'YYYY-DD-MM HH:MM:SS' string.")
|
63
|
+
def validate_promotion(value)
|
64
|
+
unless value.is_a?(String) && value.size && value =~ PROMOTION_REGEX
|
65
|
+
raise Supersaas::Exception,
|
66
|
+
'Required parameter promotional code not found or contains other than alphanumeric characters.'
|
44
67
|
end
|
68
|
+
|
69
|
+
value
|
45
70
|
end
|
46
71
|
|
47
|
-
def
|
48
|
-
|
72
|
+
def validate_duplicate(value)
|
73
|
+
unless value.is_a?(String) && %w[ignore raise].include?(value)
|
74
|
+
raise Supersaas::Exception, "Required parameter duplicate can only be 'ignore'."
|
75
|
+
end
|
76
|
+
|
77
|
+
value
|
78
|
+
end
|
79
|
+
|
80
|
+
def validate_datetime(value)
|
81
|
+
if value.is_a?(String) && value =~ DATETIME_REGEX
|
49
82
|
value
|
83
|
+
elsif value.is_a?(Time) || value.is_a?(DateTime)
|
84
|
+
value.strftime('%Y-%m-%d %H:%M:%S')
|
50
85
|
else
|
51
|
-
raise
|
86
|
+
raise ArgumentError
|
52
87
|
end
|
88
|
+
rescue ArgumentError
|
89
|
+
raise Supersaas::Exception,
|
90
|
+
"Invalid datetime parameter: #{value}. Provide a Time object or formatted 'YYYY-DD-MM HH:MM:SS' string."
|
91
|
+
end
|
92
|
+
|
93
|
+
def validate_options(value, options)
|
94
|
+
unless options.include?(value)
|
95
|
+
raise Supersaas::Exception, "Invalid option parameter: #{value}. Must be one of #{options.join(', ')}."
|
96
|
+
end
|
97
|
+
|
98
|
+
value
|
53
99
|
end
|
54
100
|
end
|
55
|
-
end
|
101
|
+
end
|
@@ -1,21 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
# REF: https://www.supersaas.com/info/dev/form_api
|
3
5
|
class Forms < BaseApi
|
4
|
-
def list(template_form_id, from_time=nil)
|
5
|
-
path =
|
6
|
-
params = {
|
7
|
-
|
8
|
-
|
9
|
-
}
|
6
|
+
def list(template_form_id, from_time = nil, user = nil)
|
7
|
+
path = '/forms'
|
8
|
+
params = { form_id: validate_id(template_form_id) }
|
9
|
+
params.merge!(from: validate_datetime(from_time)) if from_time
|
10
|
+
params.merge!(user: validate_user(user)) if user
|
10
11
|
res = client.get(path, params)
|
11
12
|
res.map { |attributes| Supersaas::Form.new(attributes) }
|
12
13
|
end
|
13
14
|
|
14
15
|
def get(form_id)
|
15
|
-
path =
|
16
|
-
params = {id: validate_id(form_id)}
|
16
|
+
path = '/forms'
|
17
|
+
params = { id: validate_id(form_id) }
|
17
18
|
res = client.get(path, params)
|
18
19
|
Supersaas::Form.new(res)
|
19
20
|
end
|
21
|
+
|
22
|
+
def forms
|
23
|
+
path = '/super_forms'
|
24
|
+
res = client.get(path)
|
25
|
+
res.map { |attributes| Supersaas::SuperForm.new(attributes) }
|
26
|
+
end
|
20
27
|
end
|
21
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Supersaas
|
4
|
+
class Groups < BaseApi
|
5
|
+
# REF: https://www.supersaas.com/info/dev/information_api#groups
|
6
|
+
def list
|
7
|
+
path = '/groups'
|
8
|
+
res = client.get(path)
|
9
|
+
res.map { |attributes| Supersaas::Group.new(attributes) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Supersaas
|
4
|
+
class Promotions < BaseApi
|
5
|
+
# REF: https://www.supersaas.com/info/dev/promotion_api
|
6
|
+
def list(limit = nil, offset = nil)
|
7
|
+
path = '/promotions'
|
8
|
+
params = {
|
9
|
+
limit: limit && validate_number(limit),
|
10
|
+
offset: offset && validate_number(offset)
|
11
|
+
}
|
12
|
+
res = client.get(path, params)
|
13
|
+
res.map { |attributes| Supersaas::Promotion.new(attributes) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def promotion(promotion_code)
|
17
|
+
path = '/promotions'
|
18
|
+
query = { promotion_code: validate_promotion(promotion_code) }
|
19
|
+
res = client.get(path, query)
|
20
|
+
res.map { |attributes| Supersaas::Promotion.new(attributes) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def duplicate_promotion_code(promotion_code, template_code)
|
24
|
+
path = '/promotions'
|
25
|
+
query = { id: validate_promotion(promotion_code), template_code: validate_promotion(template_code) }
|
26
|
+
client.post(path, query)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,16 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
class Schedules < BaseApi
|
5
|
+
# REF: https://www.supersaas.com/info/dev/information_api
|
3
6
|
def list
|
4
|
-
path =
|
7
|
+
path = '/schedules'
|
5
8
|
res = client.get(path)
|
6
9
|
res.map { |attributes| Supersaas::Schedule.new(attributes) }
|
7
10
|
end
|
8
11
|
|
9
12
|
def resources(schedule_id)
|
10
|
-
path =
|
11
|
-
query = {schedule_id: validate_id(schedule_id)}
|
13
|
+
path = '/resources'
|
14
|
+
query = { schedule_id: validate_id(schedule_id) }
|
12
15
|
res = client.get(path, query)
|
13
16
|
res.map { |attributes| Supersaas::Resource.new(attributes) }
|
14
17
|
end
|
18
|
+
|
19
|
+
def field_list(schedule_id)
|
20
|
+
path = '/field_list'
|
21
|
+
query = { schedule_id: validate_id(schedule_id) }
|
22
|
+
res = client.get(path, query)
|
23
|
+
res.map { |attributes| Supersaas::FieldList.new(attributes) }
|
24
|
+
end
|
15
25
|
end
|
16
|
-
end
|
26
|
+
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
# REF: https://www.supersaas.com/info/dev/user_api
|
3
5
|
class Users < BaseApi
|
4
|
-
def list(form=nil, limit=nil, offset=nil)
|
6
|
+
def list(form = nil, limit = nil, offset = nil)
|
5
7
|
path = user_path(nil)
|
6
8
|
params = {
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
form: form ? true : nil,
|
10
|
+
limit: limit && validate_number(limit),
|
11
|
+
offset: offset && validate_number(offset)
|
10
12
|
}
|
11
13
|
res = client.get(path, params)
|
12
14
|
res.map { |attributes| Supersaas::User.new(attributes) }
|
@@ -18,12 +20,13 @@ module Supersaas
|
|
18
20
|
Supersaas::User.new(res)
|
19
21
|
end
|
20
22
|
|
21
|
-
def create(attributes, user_id=nil, webhook=nil)
|
23
|
+
def create(attributes, user_id = nil, webhook = nil, duplicate = nil)
|
22
24
|
path = user_path(user_id)
|
23
|
-
query = {webhook: webhook}
|
25
|
+
query = { webhook: webhook }
|
26
|
+
query.merge!(duplicate: validate_duplicate(duplicate)) if duplicate
|
24
27
|
params = {
|
25
28
|
user: {
|
26
|
-
name:
|
29
|
+
name: validate_name(attributes[:name]),
|
27
30
|
email: attributes[:email],
|
28
31
|
password: attributes[:password],
|
29
32
|
full_name: attributes[:full_name],
|
@@ -31,6 +34,7 @@ module Supersaas
|
|
31
34
|
mobile: attributes[:mobile],
|
32
35
|
phone: attributes[:phone],
|
33
36
|
country: attributes[:country],
|
37
|
+
timezone: attributes[:timezone],
|
34
38
|
field_1: attributes[:field_1],
|
35
39
|
field_2: attributes[:field_2],
|
36
40
|
super_field: attributes[:super_field],
|
@@ -41,12 +45,13 @@ module Supersaas
|
|
41
45
|
client.post(path, params, query)
|
42
46
|
end
|
43
47
|
|
44
|
-
def update(user_id, attributes, webhook=nil)
|
45
|
-
path = user_path(
|
46
|
-
query = {webhook: webhook}
|
48
|
+
def update(user_id, attributes, webhook = nil, notfound = nil)
|
49
|
+
path = user_path(user_id)
|
50
|
+
query = { webhook: webhook }
|
51
|
+
query.merge!(notfound: validate_notfound(notfound)) if notfound
|
47
52
|
params = {
|
48
53
|
user: {
|
49
|
-
name: attributes[:name],
|
54
|
+
name: validate_name(attributes[:name]),
|
50
55
|
email: attributes[:email],
|
51
56
|
password: attributes[:password],
|
52
57
|
full_name: attributes[:full_name],
|
@@ -54,6 +59,7 @@ module Supersaas
|
|
54
59
|
mobile: attributes[:mobile],
|
55
60
|
phone: attributes[:phone],
|
56
61
|
country: attributes[:country],
|
62
|
+
timezone: attributes[:timezone],
|
57
63
|
field_1: attributes[:field_1],
|
58
64
|
field_2: attributes[:field_2],
|
59
65
|
super_field: attributes[:super_field],
|
@@ -61,22 +67,29 @@ module Supersaas
|
|
61
67
|
role: attributes[:role] && validate_options(attributes[:role], User::ROLES)
|
62
68
|
}
|
63
69
|
}
|
70
|
+
params[:user].compact!
|
64
71
|
client.put(path, params, query)
|
65
72
|
end
|
66
73
|
|
67
74
|
def delete(user_id)
|
68
|
-
path = user_path(
|
75
|
+
path = user_path(user_id)
|
69
76
|
client.delete(path)
|
70
77
|
end
|
71
78
|
|
79
|
+
def field_list
|
80
|
+
path = '/field_list'
|
81
|
+
res = client.get(path)
|
82
|
+
res.map { |attributes| Supersaas::FieldList.new(attributes) }
|
83
|
+
end
|
84
|
+
|
72
85
|
private
|
73
86
|
|
74
87
|
def user_path(user_id)
|
75
88
|
if user_id.nil? || user_id == ''
|
76
|
-
|
89
|
+
'/users'
|
77
90
|
else
|
78
|
-
"/users/#{user_id}"
|
91
|
+
"/users/#{validate_user(user_id)}"
|
79
92
|
end
|
80
93
|
end
|
81
94
|
end
|
82
|
-
end
|
95
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/http'
|
2
4
|
require 'uri'
|
3
5
|
require 'json'
|
@@ -24,8 +26,8 @@ module Supersaas
|
|
24
26
|
attr_accessor :account_name, :api_key, :host, :dry_run, :verbose
|
25
27
|
attr_reader :last_request
|
26
28
|
|
27
|
-
def initialize(configuration=nil)
|
28
|
-
configuration
|
29
|
+
def initialize(configuration = nil)
|
30
|
+
configuration ||= Configuration.new
|
29
31
|
@account_name = configuration.account_name
|
30
32
|
@api_key = configuration.api_key
|
31
33
|
@host = configuration.host
|
@@ -33,32 +35,70 @@ module Supersaas
|
|
33
35
|
@verbose = configuration.verbose
|
34
36
|
end
|
35
37
|
|
36
|
-
def appointments
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def appointments
|
39
|
+
@appointments ||= Appointments.new(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def forms
|
43
|
+
@forms ||= Forms.new(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def schedules
|
47
|
+
@schedules ||= Schedules.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def users
|
51
|
+
@users ||= Users.new(self)
|
52
|
+
end
|
40
53
|
|
41
|
-
def
|
54
|
+
def promotions
|
55
|
+
@promotions ||= Promotions.new(self)
|
56
|
+
end
|
57
|
+
|
58
|
+
def groups
|
59
|
+
@groups ||= Groups.new(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get(path, query = {})
|
42
63
|
request(:get, path, {}, query)
|
43
64
|
end
|
44
65
|
|
45
|
-
def post(path, params={}, query={})
|
66
|
+
def post(path, params = {}, query = {})
|
46
67
|
request(:post, path, params, query)
|
47
68
|
end
|
48
69
|
|
49
|
-
def put(path, params={}, query={})
|
70
|
+
def put(path, params = {}, query = {})
|
50
71
|
request(:put, path, params, query)
|
51
72
|
end
|
52
73
|
|
53
|
-
def delete(path, params={}, query={})
|
74
|
+
def delete(path, params = {}, query = {})
|
54
75
|
request(:delete, path, params, query)
|
55
76
|
end
|
56
77
|
|
57
78
|
private
|
58
79
|
|
59
|
-
|
60
|
-
|
61
|
-
|
80
|
+
# The rate limiter allows a maximum of 4 requests within the specified time window
|
81
|
+
WINDOW_SIZE = 1 # seconds
|
82
|
+
MAX_PER_WINDOW = 4
|
83
|
+
def throttle
|
84
|
+
# A queue to store timestamps of requests made within the rate limiting window
|
85
|
+
@queue ||= Array.new(MAX_PER_WINDOW)
|
86
|
+
# Represents the timestamp of the oldest request within the time window
|
87
|
+
oldest_request = @queue.push(Time.now).shift
|
88
|
+
# This ensures that the client does not make requests faster than the defined rate limit
|
89
|
+
if oldest_request && (d = Time.now - oldest_request) < WINDOW_SIZE
|
90
|
+
sleep WINDOW_SIZE - d
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def request(http_method, path, params = {}, query = {})
|
95
|
+
throttle
|
96
|
+
unless account_name&.size
|
97
|
+
raise Supersaas::Exception, 'Account name not configured. Call `Supersaas::Client.configure`.'
|
98
|
+
end
|
99
|
+
unless api_key&.size
|
100
|
+
raise Supersaas::Exception, 'Account api key not configured. Call `Supersaas::Client.configure`.'
|
101
|
+
end
|
62
102
|
|
63
103
|
uri = URI.parse(host)
|
64
104
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -68,7 +108,7 @@ module Supersaas
|
|
68
108
|
query = delete_blank_values query
|
69
109
|
|
70
110
|
path = "/api#{path}.json"
|
71
|
-
path += "?#{URI.encode_www_form(query)}" if query.keys.size
|
111
|
+
path += "?#{URI.encode_www_form(query)}" if query.keys.size.positive?
|
72
112
|
|
73
113
|
case http_method
|
74
114
|
when :get
|
@@ -83,7 +123,8 @@ module Supersaas
|
|
83
123
|
req = Net::HTTP::Delete.new(path)
|
84
124
|
req.body = params.to_json
|
85
125
|
else
|
86
|
-
raise Supersaas::Exception
|
126
|
+
raise Supersaas::Exception,
|
127
|
+
"Invalid HTTP Method: #{http_method}. Only `:get`, `:post`, `:put`, `:delete` supported."
|
87
128
|
end
|
88
129
|
|
89
130
|
req.basic_auth account_name, api_key
|
@@ -93,10 +134,10 @@ module Supersaas
|
|
93
134
|
req['User-Agent'] = self.class.user_agent
|
94
135
|
|
95
136
|
if verbose
|
96
|
-
puts
|
137
|
+
puts '### SuperSaaS Client Request:'
|
97
138
|
puts "#{http_method} #{path}"
|
98
139
|
puts params.to_json
|
99
|
-
puts
|
140
|
+
puts '------------------------------'
|
100
141
|
end
|
101
142
|
|
102
143
|
@last_request = req
|
@@ -106,13 +147,14 @@ module Supersaas
|
|
106
147
|
res = http.request(req)
|
107
148
|
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
108
149
|
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
109
|
-
raise Supersaas::Exception
|
150
|
+
raise Supersaas::Exception, "HTTP Request Error (#{uri}#{path}): #{e.message}"
|
110
151
|
end
|
111
152
|
|
112
153
|
if verbose
|
113
|
-
puts
|
154
|
+
puts 'Response:'
|
155
|
+
puts res.inspect
|
114
156
|
puts res.body
|
115
|
-
puts
|
157
|
+
puts '=============================='
|
116
158
|
end
|
117
159
|
|
118
160
|
code = res.code.to_i
|
@@ -123,29 +165,53 @@ module Supersaas
|
|
123
165
|
else
|
124
166
|
json_body(res)
|
125
167
|
end
|
126
|
-
|
127
|
-
|
168
|
+
else
|
169
|
+
handle_errors(code, res)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def handle_errors(code, res)
|
174
|
+
print_errors(res)
|
175
|
+
case code
|
176
|
+
when 422
|
177
|
+
raise Supersaas::Exception, 'HTTP Request Error: Unprocessable Content'
|
178
|
+
when 400
|
179
|
+
raise Supersaas::Exception, 'HTTP Request Error: Bad Request'
|
128
180
|
when 401
|
129
|
-
raise Supersaas::Exception
|
181
|
+
raise Supersaas::Exception, 'HTTP Request Error: Unauthorised'
|
130
182
|
when 404
|
131
|
-
raise Supersaas::Exception
|
183
|
+
raise Supersaas::Exception, 'HTTP Request Error: Not Found'
|
184
|
+
when 501
|
185
|
+
raise Supersaas::Exception, 'Not yet implemented for service type schedule'
|
186
|
+
when 403
|
187
|
+
raise Supersaas::Exception, 'Unauthorized'
|
188
|
+
when 405
|
189
|
+
raise Supersaas::Exception, 'Not available for capacity type schedule'
|
132
190
|
else
|
133
|
-
{}
|
191
|
+
raise Supersaas::Exception, "HTTP Request Error: #{code}"
|
134
192
|
end
|
135
193
|
end
|
136
194
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
195
|
+
def print_errors(res)
|
196
|
+
json_body = json_body(res)
|
197
|
+
return unless json_body[:errors]
|
198
|
+
|
199
|
+
errors each do |error|
|
200
|
+
puts "Error code: #{error['code']}, #{error['title']}"
|
142
201
|
end
|
143
202
|
end
|
144
203
|
|
204
|
+
def json_body(res)
|
205
|
+
res.body&.size ? JSON.parse(res.body) : {}
|
206
|
+
rescue JSON::ParserError
|
207
|
+
{}
|
208
|
+
end
|
209
|
+
|
145
210
|
def delete_blank_values(hash)
|
146
211
|
return hash unless hash
|
147
|
-
|
148
|
-
|
212
|
+
|
213
|
+
hash.delete_if do |_k, v|
|
214
|
+
v = v.compact if v.is_a?(Hash)
|
149
215
|
v.nil? || v == ''
|
150
216
|
end
|
151
217
|
end
|
@@ -156,12 +222,12 @@ module Supersaas
|
|
156
222
|
attr_accessor :account_name, :host, :api_key, :dry_run, :verbose
|
157
223
|
|
158
224
|
def initialize
|
159
|
-
@account_name = ENV
|
160
|
-
@api_key = ENV
|
225
|
+
@account_name = ENV.fetch('SSS_API_ACCOUNT_NAME', nil)
|
226
|
+
@api_key = ENV.fetch('SSS_API_KEY', nil)
|
161
227
|
@host = DEFAULT_HOST
|
162
228
|
@dry_run = false
|
163
229
|
@verbose = false
|
164
230
|
end
|
165
231
|
end
|
166
232
|
end
|
167
|
-
end
|
233
|
+
end
|
@@ -1,22 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
class Appointment < BaseModel
|
3
|
-
attr_accessor :address, :country, :created_by, :created_on, :deleted, :description, :email, :field_1, :field_2,
|
5
|
+
attr_accessor :address, :country, :created_by, :created_on, :deleted, :description, :email, :field_1, :field_2,
|
6
|
+
:field_1_r, :field_2_r, :finish, :form_id, :full_name, :id, :mobile, :name, :phone, :price, :res_name,
|
7
|
+
:resource_id, :schedule_id, :schedule_name, :service_id, :service_name, :slot_id, :start, :status,
|
8
|
+
:super_field, :updated_by, :updated_on, :user_id, :waitlisted
|
4
9
|
attr_reader :form, :slot
|
5
10
|
|
6
11
|
def form=(value)
|
7
|
-
|
8
|
-
@form = Supersaas::Form.new(value)
|
9
|
-
else
|
10
|
-
@form = value
|
11
|
-
end
|
12
|
+
@form = value.is_a?(Hash) ? Supersaas::Form.new(value) : value
|
12
13
|
end
|
13
14
|
|
14
15
|
def slot=(value)
|
15
|
-
|
16
|
-
@slot = Supersaas::Slot.new(value)
|
17
|
-
else
|
18
|
-
@slot = value
|
19
|
-
end
|
16
|
+
@slot = value.is_a?(Hash) ? Supersaas::Slot.new(value) : value
|
20
17
|
end
|
21
18
|
end
|
22
|
-
end
|
19
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
class BaseModel
|
3
5
|
attr_accessor :errors
|
@@ -12,8 +14,9 @@ module Supersaas
|
|
12
14
|
|
13
15
|
def assign_attributes(attributes)
|
14
16
|
attributes.each do |key, value|
|
17
|
+
self.class.module_eval { attr_accessor key }
|
15
18
|
public_send("#{key}=", value) if respond_to?("#{key}=")
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
19
|
-
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Supersaas
|
4
|
+
class FieldList < BaseModel
|
5
|
+
attr_accessor :name, :type, :label, :advanced
|
6
|
+
attr_reader :spec
|
7
|
+
|
8
|
+
def spec=(value)
|
9
|
+
@spec = value.is_a?(Array) ? value.map { |attributes| JSON.parse(attributes) } : value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
class Form < BaseModel
|
3
|
-
attr_accessor :content, :created_on, :deleted, :id, :reservation_process_id, :super_form_id, :uniq, :updated_name,
|
5
|
+
attr_accessor :content, :created_on, :deleted, :id, :reservation_process_id, :super_form_id, :uniq, :updated_name,
|
6
|
+
:updated_on, :user_id
|
4
7
|
end
|
5
|
-
end
|
8
|
+
end
|