supersaas-api-client 1.1.0 → 2.0.0
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 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +296 -0
- data/Gemfile +5 -3
- data/Gemfile.lock +34 -7
- data/README.md +109 -58
- 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 +37 -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 +106 -36
- 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 +52 -38
- 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
data/examples/users.rb
CHANGED
@@ -1,51 +1,59 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
+
require 'supersaas-api-client'
|
4
5
|
|
5
|
-
puts "
|
6
|
+
puts "# SuperSaaS Users Example"
|
6
7
|
|
7
8
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
8
|
-
puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g
|
9
|
-
puts "
|
9
|
+
puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
|
10
|
+
puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
|
10
11
|
return
|
11
12
|
end
|
12
13
|
|
13
14
|
puts "## Account: #{Supersaas::Client.instance.account_name}"
|
14
|
-
puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}
|
15
|
+
puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}"
|
15
16
|
|
16
17
|
Supersaas::Client.instance.verbose = true
|
17
18
|
|
18
|
-
puts
|
19
|
-
puts "
|
20
|
-
params = {full_name: 'Example', name: 'example@example.com', email: 'example@example.com', api_key: 'example'}
|
19
|
+
puts 'creating new user...'
|
20
|
+
puts "#### Supersaas::Client.instance.users.create({...})"
|
21
|
+
params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com', api_key: 'example' }
|
21
22
|
Supersaas::Client.instance.users.create(params)
|
22
23
|
new_user_id = nil
|
23
24
|
|
24
|
-
puts "
|
25
|
-
puts "
|
25
|
+
puts "listing users..."
|
26
|
+
puts "#### Supersaas::Client.instance.users.list(nil, 50)"
|
26
27
|
|
27
28
|
users = Supersaas::Client.instance.users.list(nil, 50)
|
28
29
|
users.each do |user|
|
29
|
-
new_user_id = user.id if user.name == params[:email]
|
30
|
+
new_user_id = user.id if user.name == params[:email]
|
30
31
|
end
|
31
32
|
|
32
33
|
if new_user_id
|
33
|
-
puts "
|
34
|
-
puts "
|
34
|
+
puts "getting user..."
|
35
|
+
puts "#### Supersaas::Client.instance.users.get(#{new_user_id})"
|
35
36
|
user = Supersaas::Client.instance.users.get(new_user_id)
|
36
37
|
|
37
|
-
puts "
|
38
|
-
puts "
|
39
|
-
Supersaas::Client.instance.users.update(new_user_id, {country: 'FR', address: 'Rue 1'})
|
38
|
+
puts "updating user..."
|
39
|
+
puts "#### Supersaas::Client.instance.users.update(#{new_user_id})"
|
40
|
+
Supersaas::Client.instance.users.update(new_user_id, { country: 'FR', address: 'Rue 1' })
|
40
41
|
|
41
|
-
puts "
|
42
|
-
puts "
|
42
|
+
puts "deleting user..."
|
43
|
+
puts "#### Supersaas::Client.instance.users.delete(#{user.id})"
|
43
44
|
Supersaas::Client.instance.users.delete(user.id)
|
44
45
|
else
|
45
|
-
puts "
|
46
|
+
puts "... did not find user in list"
|
46
47
|
end
|
47
48
|
|
48
|
-
puts "
|
49
|
-
puts "
|
50
|
-
|
51
|
-
|
49
|
+
puts "creating user with errors..."
|
50
|
+
puts "#### Supersaas::Client.instance.users.create"
|
51
|
+
begin
|
52
|
+
Supersaas::Client.instance.users.create({ name: 'error' })
|
53
|
+
rescue Supersaas::Exception => e
|
54
|
+
puts "This raises an error #{e.message}"
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "#### Supersaas::Client.instance.users.field_list"
|
58
|
+
Supersaas::Client.instance.users.field_list
|
59
|
+
puts
|
@@ -1,17 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Supersaas
|
2
4
|
# REF: https://www.supersaas.com/info/dev/appointment_api
|
3
5
|
class Appointments < BaseApi
|
4
|
-
def agenda(schedule_id, user_id, from_time=nil)
|
6
|
+
def agenda(schedule_id, user_id, from_time = nil, slot = false)
|
5
7
|
path = "/agenda/#{validate_id(schedule_id)}"
|
6
8
|
params = {
|
7
9
|
user: validate_present(user_id),
|
8
10
|
from: from_time && validate_datetime(from_time)
|
9
11
|
}
|
12
|
+
params.merge!(slot: true) if slot
|
10
13
|
res = client.get(path, params)
|
11
14
|
map_slots_or_bookings(res)
|
12
15
|
end
|
13
16
|
|
14
|
-
def agenda_slots(schedule_id, user_id, from_time=nil)
|
17
|
+
def agenda_slots(schedule_id, user_id, from_time = nil)
|
15
18
|
path = "/agenda/#{validate_id(schedule_id)}"
|
16
19
|
params = {
|
17
20
|
user: validate_present(user_id),
|
@@ -22,7 +25,7 @@ module Supersaas
|
|
22
25
|
map_slots_or_bookings(res, true)
|
23
26
|
end
|
24
27
|
|
25
|
-
def available(schedule_id, from_time, length_minutes=nil, resource=nil, full=nil, limit=nil)
|
28
|
+
def available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil)
|
26
29
|
path = "/free/#{validate_id(schedule_id)}"
|
27
30
|
params = {
|
28
31
|
length: length_minutes && validate_number(length_minutes),
|
@@ -35,27 +38,27 @@ module Supersaas
|
|
35
38
|
map_slots_or_bookings(res)
|
36
39
|
end
|
37
40
|
|
38
|
-
def list(schedule_id, form=nil, start_time=nil, limit=nil)
|
39
|
-
path =
|
41
|
+
def list(schedule_id, form = nil, start_time = nil, limit = nil)
|
42
|
+
path = '/bookings'
|
40
43
|
params = {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
schedule_id: validate_id(schedule_id),
|
45
|
+
form: form ? true : nil,
|
46
|
+
start: start_time ? validate_datetime(start_time) : nil,
|
47
|
+
limit: limit && validate_number(limit)
|
45
48
|
}
|
46
49
|
res = client.get(path, params)
|
47
50
|
map_slots_or_bookings(res)
|
48
51
|
end
|
49
52
|
|
50
53
|
def get(schedule_id, appointment_id)
|
51
|
-
params = {schedule_id: validate_id(schedule_id)}
|
54
|
+
params = { schedule_id: validate_id(schedule_id) }
|
52
55
|
path = "/bookings/#{validate_id(appointment_id)}"
|
53
56
|
res = client.get(path, params)
|
54
57
|
Supersaas::Appointment.new(res)
|
55
58
|
end
|
56
59
|
|
57
|
-
def create(schedule_id, user_id, attributes, form=nil, webhook=nil)
|
58
|
-
path =
|
60
|
+
def create(schedule_id, user_id, attributes, form = nil, webhook = nil)
|
61
|
+
path = '/bookings'
|
59
62
|
params = {
|
60
63
|
schedule_id: schedule_id,
|
61
64
|
webhook: webhook,
|
@@ -83,16 +86,14 @@ module Supersaas
|
|
83
86
|
client.post(path, params)
|
84
87
|
end
|
85
88
|
|
86
|
-
def update(schedule_id, appointment_id, attributes, form=nil, webhook=nil)
|
89
|
+
def update(schedule_id, appointment_id, attributes, form = nil, webhook = nil)
|
87
90
|
path = "/bookings/#{validate_id(appointment_id)}"
|
88
91
|
params = {
|
89
92
|
schedule_id: schedule_id,
|
90
|
-
webhook: webhook,
|
91
|
-
form: form,
|
92
93
|
booking: {
|
93
94
|
start: attributes[:start],
|
94
95
|
finish: attributes[:finish],
|
95
|
-
name:
|
96
|
+
name: attributes[:name],
|
96
97
|
email: attributes[:email],
|
97
98
|
full_name: attributes[:full_name],
|
98
99
|
address: attributes[:address],
|
@@ -108,33 +109,39 @@ module Supersaas
|
|
108
109
|
slot_id: attributes[:slot_id]
|
109
110
|
}
|
110
111
|
}
|
112
|
+
|
113
|
+
params.merge!(form: form) if form
|
114
|
+
params.merge!(webhook: webhook) if webhook
|
115
|
+
params[:booking].compact!
|
111
116
|
client.put(path, params)
|
112
117
|
end
|
113
118
|
|
114
119
|
def delete(schedule_id, appointment_id)
|
115
120
|
path = "/bookings/#{validate_id(appointment_id)}"
|
116
|
-
params = {schedule_id: validate_id(schedule_id)}
|
121
|
+
params = { schedule_id: validate_id(schedule_id) }
|
117
122
|
client.delete(path, nil, params)
|
118
123
|
end
|
119
124
|
|
120
|
-
def changes(schedule_id, from_time=nil, to=nil, slot=false)
|
125
|
+
def changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil)
|
121
126
|
path = "/changes/#{validate_id(schedule_id)}"
|
122
|
-
params = build_param({}, from_time, to, slot)
|
127
|
+
params = build_param({}, from_time, to, slot, user, limit, offset)
|
123
128
|
res = client.get(path, params)
|
124
129
|
map_slots_or_bookings(res)
|
125
130
|
end
|
126
131
|
|
127
|
-
def range(schedule_id, today=false, from_time=nil, to=nil, slot=false
|
132
|
+
def range(schedule_id, today = false, from_time = nil, to = nil, slot = false, user = nil, resource_id = nil, service_id = nil,
|
133
|
+
limit = nil, offset = nil)
|
128
134
|
path = "/range/#{validate_id(schedule_id)}"
|
129
|
-
params = {}
|
130
|
-
params
|
135
|
+
params = {}
|
136
|
+
params.merge!(today: true) if today
|
137
|
+
params = build_param(params, from_time, to, slot, user, limit, offset, resource_id, service_id)
|
131
138
|
res = client.get(path, params)
|
132
139
|
map_slots_or_bookings(res)
|
133
140
|
end
|
134
141
|
|
135
142
|
private
|
136
143
|
|
137
|
-
def map_slots_or_bookings(obj, slot=false)
|
144
|
+
def map_slots_or_bookings(obj, slot = false)
|
138
145
|
if obj.is_a?(Array) && slot
|
139
146
|
obj.map { |attributes| Supersaas::Slot.new(attributes) }
|
140
147
|
elsif obj.is_a?(Array)
|
@@ -148,11 +155,16 @@ module Supersaas
|
|
148
155
|
end
|
149
156
|
end
|
150
157
|
|
151
|
-
def build_param(params, from_time, to, slot)
|
158
|
+
def build_param(params, from_time, to, slot, user, limit, offset, resource_id = nil, service_id = nil)
|
152
159
|
params.merge!(from: validate_datetime(from_time)) if from_time
|
153
160
|
params.merge!(to: validate_datetime(to)) if to
|
154
161
|
params.merge!(slot: true) if slot
|
162
|
+
params.merge!(user: validate_user(user)) if user
|
163
|
+
params.merge!(limit: validate_number(limit)) if limit
|
164
|
+
params.merge!(offset: validate_number(offset)) if offset
|
165
|
+
params.merge!(resource_id: validate_id(resource_id)) if resource_id
|
166
|
+
params.merge!(service_id: validate_id(service_id)) if service_id
|
155
167
|
params
|
156
168
|
end
|
157
169
|
end
|
158
|
-
end
|
170
|
+
end
|
@@ -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
|