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/README.md
CHANGED
@@ -1,33 +1,29 @@
|
|
1
1
|
# SuperSaaS Ruby API Client
|
2
2
|
|
3
|
-
|
3
|
+
Manage appointments, users, and other object on the [SuperSaaS appointment scheduling](https://www.supersaas.com/) platform in Ruby.
|
4
4
|
|
5
|
-
The SuperSaaS API provides
|
5
|
+
The SuperSaaS API provides endpoints that can be used to read or update information from your SuperSaaS account.
|
6
|
+
This can be useful to build an integration with back-end system or to extract information to generate reports.
|
6
7
|
|
7
8
|
## Prerequisites
|
8
9
|
|
9
10
|
1. [Register for a (free) SuperSaaS account](https://www.supersaas.com/accounts/new), and
|
10
|
-
2.
|
11
|
+
2. Get your account name and API key on the [Account Info](https://www.supersaas.com/accounts/edit) page.
|
11
12
|
|
12
|
-
|
13
|
+
### Dependencies
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
No external libraries. Only the native `json` and `net/http` standard libs are used.
|
15
|
+
No external dependencies. Only the `json` and `net/http` gems from the ruby standard library are used.
|
17
16
|
|
18
17
|
## Installation
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
The SuperSaaS Ruby API Client is available from RubyGems and can be included in your project GemFile. Note, the supersaas-api-client may update major versions with breaking changes, so it's recommended to use a major version when expressing the gem dependency. e.g.
|
19
|
+
Install with:
|
23
20
|
|
24
|
-
gem
|
21
|
+
$ gem install supersaas-api-client
|
25
22
|
|
26
|
-
|
23
|
+
Alternatively, you can use `bundler` to install it by adding this line to you Gemfile.
|
24
|
+
The supersaas-api-client may update major versions with breaking changes, so it's recommended to use a major version when expressing the gem dependency. e.g.
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
$ gem install supersaas-api-client
|
26
|
+
gem 'supersaas-api-client', '~> 2'
|
31
27
|
|
32
28
|
## Configuration
|
33
29
|
|
@@ -67,59 +63,63 @@ Details of the data structures, parameters, and values can be found on the devel
|
|
67
63
|
|
68
64
|
https://www.supersaas.com/info/dev
|
69
65
|
|
70
|
-
#### List Schedules
|
71
|
-
|
72
|
-
Get all account schedules:
|
73
|
-
|
74
|
-
Supersaas::Client.instance.schedules.list #=> [<Supersaas::Schedule>, ...]
|
75
|
-
|
76
|
-
#### List Resource
|
77
|
-
|
78
|
-
Get all services/resources by `schedule_id`:
|
79
|
-
|
80
|
-
Supersaas::Client.instance.schedules.resources(12345) #=> [<Supersaas::Resource>, ...]
|
81
|
-
|
82
|
-
_Note: does not work for capacity type schedules._
|
83
|
-
|
84
66
|
#### Create User
|
85
67
|
|
86
|
-
Create a user with user attributes params
|
68
|
+
Create a user with user attributes params `create(attributes, user_id = nil, webhook = nil, duplicate = nil)`.
|
69
|
+
If webhook=true is present it will trigger any webhooks connected to the account.
|
70
|
+
To avoid a ‘create’ action from being automatically interpreted as an ‘update’, you can add the parameter duplicate=raise, then error `422 Unprocessable Entity` will be raised.
|
71
|
+
If in your database your user has id 1234 then you can supply a foreign key in format 1234fk in `user_id` (optional) which you can use to identify user:
|
72
|
+
If validation fails for any field then error `422 Unprocessable Entity` will be raised and any additional information will be printed to your log.
|
73
|
+
Data fields that you can supply can be found [here.](https://www.supersaas.com/info/dev/user_api)
|
87
74
|
|
88
|
-
Supersaas::Client.instance.users.create({full_name: 'Example Name', email: 'example@example.com'}) #=>
|
75
|
+
Supersaas::Client.instance.users.create({name: 'name@name.com', full_name: 'Example Name', email: 'example@example.com'}, '1234fk', true, 'raise') #=> http://www.supersaas.com/api/users/1234.json
|
89
76
|
|
90
77
|
#### Update User
|
91
78
|
|
92
|
-
Update a user by `user_id` with user attributes params
|
79
|
+
Update a user by `user_id` with user attributes params `update(user_id, attributes, webhook = nil, notfound = nil)`.
|
80
|
+
If webhook=true is present it will trigger any webhooks connected to the account.
|
81
|
+
To avoid automatically creating a new record, you can add the parameter notfound=error or notfound=ignore to return a 404 Not Found or 200 OK respectively.
|
82
|
+
If the `user_id` does not exist 404 error will be raised.
|
83
|
+
You only need to specify the attributes you wish to update:
|
93
84
|
|
94
|
-
Supersaas::Client.instance.users.update(12345, {full_name: 'New Name'}) #=> nil
|
85
|
+
Supersaas::Client.instance.users.update(12345, {full_name: 'New Name'}, true, "ignore") #=> nil
|
95
86
|
|
96
87
|
#### Delete User
|
97
88
|
|
98
|
-
Delete a single user by `user_id
|
89
|
+
Delete a single user by `user_id`, and if the user does not exist 404 error will be raised.
|
99
90
|
|
100
91
|
Supersaas::Client.instance.users.delete(12345) #=> nil
|
101
92
|
|
102
93
|
#### Get User
|
103
94
|
|
104
|
-
Get a single user by `user_id
|
95
|
+
Get a single user by `user_id`, and if the user does not exist 404 error will be raised:
|
105
96
|
|
106
97
|
Supersaas::Client.instance.users.get(12345) #=> <Supersaas::User>
|
107
98
|
|
108
99
|
#### List Users
|
109
100
|
|
110
|
-
Get all users with optional `form` and `limit`/`offset` pagination params
|
101
|
+
Get all users with optional `form` and `limit`/`offset` pagination params, `list(form = nil, limit = nil, offset = nil)`.
|
102
|
+
User can have a form attached, and setting `form=true` shows the data:
|
111
103
|
|
112
104
|
Supersaas::Client.instance.users.list(false, 25, 0) #=> [<Supersaas::User>, ...]
|
113
105
|
|
106
|
+
#### List Fields of User object
|
107
|
+
|
108
|
+
Get all the fields available to user object:
|
109
|
+
|
110
|
+
Supersaas::Client.instance.users.field_list #=> [<Supersaas::FieldList>, ...]
|
111
|
+
|
114
112
|
#### Create Appointment/Booking
|
115
113
|
|
116
|
-
Create an appointment
|
114
|
+
Create an appointment with `schedule_id`, and `user_id(optional)` (see API documentation on [create new](https://www.supersaas.com/info/dev/appointment_api#bookings_api)) appointment attributes and optional `form` and `webhook` params,
|
115
|
+
`create(schedule_id, user_id, attributes, form = nil, webhook = nil)`:
|
117
116
|
|
118
|
-
Supersaas::Client.instance.appointments.create(12345, 67890, {full_name: 'Example Name', email: 'example@example.com', slot_id: 12345}, true, true) #=>
|
117
|
+
Supersaas::Client.instance.appointments.create(12345, 67890, {full_name: 'Example Name', email: 'example@example.com', slot_id: 12345}, true, true) #=> http://www.supersaas.com/api/bookings/12345.json
|
119
118
|
|
120
119
|
#### Update Appointment/Booking
|
121
120
|
|
122
|
-
Update an appointment by `schedule_id` and `appointment_id` with appointment attributes
|
121
|
+
Update an appointment by `schedule_id` and `appointment_id` with appointment attributes, see the above link,
|
122
|
+
`update(schedule_id, appointment_id, attributes, form = nil, webhook = nil)`:
|
123
123
|
|
124
124
|
Supersaas::Client.instance.appointments.update(12345, 67890, {full_name: 'New Name'}) #=> nil
|
125
125
|
|
@@ -137,56 +137,113 @@ Get a single appointment by `schedule_id` and `appointment_id`:
|
|
137
137
|
|
138
138
|
#### List Appointments/Bookings
|
139
139
|
|
140
|
-
List appointments by `schedule_id`, with `form` and `start_time` and `limit` view params
|
140
|
+
List appointments by `schedule_id`, with `form` and `start_time` and `limit` view params,
|
141
|
+
`list(schedule_id, form = nil, start_time = nil, limit = nil)`:
|
141
142
|
|
142
143
|
Supersaas::Client.instance.appointments.list(12345, 67890, true, true) #=> [<Supersaas::Appointment>, ...]
|
143
144
|
|
144
145
|
#### Get Agenda
|
145
146
|
|
146
|
-
Get agenda (upcoming) appointments by `schedule_id` and `user_id`, with `from_time` view param
|
147
|
+
Get agenda (upcoming) appointments by `schedule_id` and `user_id`, with `from_time` view param ([see](https://www.supersaas.com/info/dev/appointment_api#agenda),
|
148
|
+
`agenda(schedule_id, user_id, from_time = nil, slot = false)`:
|
147
149
|
|
148
150
|
Supersaas::Client.instance.appointments.agenda(12345, 67890, '2018-01-31 00:00:00') #=> [<Supersaas::Appointment>, ...]
|
149
151
|
|
150
152
|
#### Get Agenda Slots
|
151
153
|
|
152
|
-
Get agenda (upcoming) slots by `schedule_id` and `user_id`, with `from_time` view param
|
154
|
+
Get agenda (upcoming) slots by `schedule_id` and `user_id`, with `from_time` view param,
|
155
|
+
`agenda_slots(schedule_id, user_id, from_time = nil)`:
|
153
156
|
|
154
157
|
Supersaas::Client.instance.appointments.agenda_slots(12345, 67890, '2018-01-31 00:00:00') #=> [<Supersaas::Slot>, ...]
|
155
158
|
|
156
|
-
_Note: works
|
159
|
+
_Note: only works for capacity type schedules._
|
157
160
|
|
158
161
|
#### Get Available Appointments/Bookings
|
159
162
|
|
160
|
-
Get available appointments by `schedule_id`, with `from` time and `length_minutes` and `resource` params
|
163
|
+
Get available appointments by `schedule_id`, with `from` time and `length_minutes` and `resource` params ([see](https://www.supersaas.com/info/dev/appointment_api#availability_api),
|
164
|
+
`available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil)`:
|
161
165
|
|
162
166
|
Supersaas::Client.instance.appointments.available(12345, '2018-01-31 00:00:00', 15, 'My Class') #=> [<Supersaas::Appointment>, ...]
|
163
167
|
|
164
168
|
#### Get Recent Changes
|
165
169
|
|
166
|
-
Get recently changed appointments by `schedule_id`, with `from` time, `to` time
|
170
|
+
Get recently changed appointments by `schedule_id`, with `from` time, `to` time, `user` user, `slot` view params (see [docs](https://www.supersaas.com/info/dev/appointment_api#recent_changes)),
|
171
|
+
`changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil)`:
|
167
172
|
|
168
173
|
Supersaas::Client.instance.appointments.changes(12345, '2018-01-31 00:00:00', '2019-01-31 00:00:00', true) #=> [<Supersaas::Appointment>, ...]
|
169
174
|
|
170
175
|
|
171
176
|
#### Get list of appointments
|
172
177
|
|
173
|
-
Get list of appointments by `schedule_id`, with `today`,`from` time, `to` time and `slot` view
|
178
|
+
Get list of appointments by `schedule_id`, with `today`,`from` time, `to` time and `slot` view params (see [docs](https://www.supersaas.com/info/dev/appointment_api#range)),
|
179
|
+
`range(schedule_id, today = false, from_time = nil, to = nil, slot = false, user = nil, resource_id = nil, service_id = nil, limit = nil, offset = nil)`:
|
174
180
|
|
175
181
|
Supersaas::Client.instance.appointments.range(12345, false, '2018-01-31 00:00:00', '2019-01-31 00:00:00', true) #=> [<Supersaas::Appointment>, ...]/[<Supersaas::Slot>, ...]
|
176
182
|
|
183
|
+
#### List Forms
|
177
184
|
|
178
|
-
|
179
|
-
|
180
|
-
Get all forms by template `superform_id`, with `from_time` param:
|
185
|
+
Get all forms by template `superform_id`, with `from_time`, and `user` params ([see](https://www.supersaas.com/info/dev/form_api)):
|
181
186
|
|
182
187
|
Supersaas::Client.instance.forms.list(12345, '2018-01-31 00:00:00') #=> [<Supersaas::Form>, ...]
|
183
188
|
|
184
189
|
#### Get Form
|
185
190
|
|
186
|
-
Get a single form by `form_id
|
191
|
+
Get a single form by `form_id`, will raise 404 error if not found:
|
187
192
|
|
188
193
|
Supersaas::Client.instance.forms.get(12345) #=> <Supersaas::Form>
|
189
194
|
|
195
|
+
#### Get a list of SuperForms
|
196
|
+
|
197
|
+
Get a list of Form templates (SuperForms):
|
198
|
+
|
199
|
+
Supersaas::Client.instance.forms.forms #=> [<Supersaas::SuperForm>, ...]
|
200
|
+
|
201
|
+
#### List Promotions
|
202
|
+
|
203
|
+
Get a list of promotional coupon codes with paging parameters `limit` and `offset` (see [docs](https://www.supersaas.com/info/dev/promotion_api)),
|
204
|
+
`list(template_form_id, from_time = nil, user = nil)`:
|
205
|
+
|
206
|
+
Supersaas::Client.instance.promotions.list #=> [<Supersaas::Promotion>, ...]
|
207
|
+
|
208
|
+
#### Get a single coupon code
|
209
|
+
|
210
|
+
Retrieve information about a single coupon code use with `promotion_code`:
|
211
|
+
|
212
|
+
Supersaas::Client.instance.promotions.promotion(12345) #=> <Supersaas::Promotion>
|
213
|
+
|
214
|
+
#### Duplicate promotion code
|
215
|
+
|
216
|
+
Duplicate a template promotion by giving (new) `id` and `template_code` in that order:
|
217
|
+
|
218
|
+
Supersaas::Client.instance.promotions.duplicate_promotion_code(12345) #=> nil
|
219
|
+
|
220
|
+
#### List Groups in an account
|
221
|
+
|
222
|
+
List Groups in an account ([see](https://www.supersaas.com/info/dev/information_api)):
|
223
|
+
|
224
|
+
Supersaas::Client.instance.groups.list #=> [<Supersaas::Group>, ...]
|
225
|
+
|
226
|
+
#### List Schedules
|
227
|
+
|
228
|
+
Get all account schedules:
|
229
|
+
|
230
|
+
Supersaas::Client.instance.schedules.list #=> [<Supersaas::Schedule>, ...]
|
231
|
+
|
232
|
+
#### List Services / Resources
|
233
|
+
|
234
|
+
Get all services/resources by `schedule_id`:
|
235
|
+
|
236
|
+
Supersaas::Client.instance.schedules.resources(12345) #=> [<Supersaas::Resource>, ...]
|
237
|
+
|
238
|
+
_Note: does not work for capacity type schedules._
|
239
|
+
|
240
|
+
#### List Fields of a Schedule
|
241
|
+
|
242
|
+
Get all the available fields of a schedule by `schedule_id`:
|
243
|
+
|
244
|
+
Supersaas::Client.instance.schedules.field_list(12345) #=> [<Supersaas::FieldList>, ...]
|
245
|
+
|
246
|
+
|
190
247
|
## Examples
|
191
248
|
|
192
249
|
The ./examples folder contains several executable Ruby scripts demonstrating how to use the API Client for common requests.
|
@@ -226,22 +283,16 @@ The API Client raises a custom exception for HTTP errors and invalid input. Resc
|
|
226
283
|
# Handle error
|
227
284
|
end
|
228
285
|
|
229
|
-
|
286
|
+
Some errors have more information and are printed to the log before raising the error e.g.
|
230
287
|
|
231
288
|
appointment = Supersaas::Client.instance.appointments.create(12345, {bad_field_name: ''})
|
232
|
-
|
289
|
+
"Error 400, Bad request: unknown attribute 'bad_field_name' for Booking."
|
233
290
|
|
234
291
|
## Additional Information
|
235
292
|
|
236
293
|
+ [SuperSaaS Registration](https://www.supersaas.com/accounts/new)
|
237
294
|
+ [Product Documentation](https://www.supersaas.com/info/support)
|
238
295
|
+ [Developer Documentation](https://www.supersaas.com/info/dev)
|
239
|
-
+ [Python API Client](https://github.com/SuperSaaS/supersaas-python-api-client)
|
240
|
-
+ [PHP API Client](https://github.com/SuperSaaS/supersaas-php-api-client)
|
241
|
-
+ [NodeJS API Client](https://github.com/SuperSaaS/supersaas-nodejs-api-client)
|
242
|
-
+ [C# API Client](https://github.com/SuperSaaS/supersaas-csharp-api-client)
|
243
|
-
+ [Objective-C API Client](https://github.com/SuperSaaS/supersaas-objc-api-client)
|
244
|
-
+ [Go API Client](https://github.com/SuperSaaS/supersaas-go-api-client)
|
245
296
|
|
246
297
|
Contact: [support@supersaas.com](mailto:support@supersaas.com)
|
247
298
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
12
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'supersaas-api-client'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "supersaas-api-client"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/examples/appointments.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require "supersaas-api-client"
|
4
|
+
require 'date'
|
5
|
+
require 'supersaas-api-client'
|
6
6
|
|
7
|
-
puts "
|
7
|
+
puts "# SuperSaaS Appointments Example"
|
8
8
|
|
9
9
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
10
|
-
puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g
|
11
|
-
puts "
|
10
|
+
puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
|
11
|
+
puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<api_key> ./examples/appointments.rb"
|
12
12
|
return
|
13
13
|
end
|
14
14
|
|
15
15
|
puts "## Account: #{Supersaas::Client.instance.account_name}"
|
16
|
-
puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}
|
16
|
+
puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}"
|
17
17
|
|
18
18
|
Supersaas::Client.instance.verbose = true
|
19
19
|
|
@@ -21,64 +21,92 @@ if ENV['SSS_API_SCHEDULE']
|
|
21
21
|
schedule_id = ENV['SSS_API_SCHEDULE']
|
22
22
|
show_slot = ENV['SSS_API_SLOT'] ? true : false
|
23
23
|
else
|
24
|
-
puts "ERROR! Missing schedule id. Rerun the script with your schedule id, e.g
|
25
|
-
puts " SSS_API_SCHEDULE=<scheduleid> ./examples/appointments.rb
|
24
|
+
puts "ERROR! Missing schedule id. Rerun the script with your schedule id, e.g."
|
25
|
+
puts " SSS_API_SCHEDULE=<scheduleid> ./examples/appointments.rb"
|
26
26
|
return
|
27
27
|
end
|
28
28
|
|
29
|
+
# give
|
30
|
+
user_id = ENV.fetch('SSS_API_USER', nil)
|
31
|
+
|
32
|
+
unless user_id
|
33
|
+
puts "User is created and then deleted at the end"
|
34
|
+
params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com', api_key: 'example' }
|
35
|
+
user = Supersaas::Client.instance.users.create(params)
|
36
|
+
user_id = user.match(/users\/(\d+)\.json/)[1]
|
37
|
+
puts "#New user created #{user_id}"
|
38
|
+
end
|
39
|
+
|
40
|
+
|
29
41
|
description = nil
|
30
|
-
|
31
|
-
user = ENV['SSS_API_USER']
|
32
|
-
if user
|
42
|
+
if user_id
|
33
43
|
description = '1234567890.'
|
34
|
-
params = {full_name: 'Example', description: description, name: 'example@example.com', email: 'example@example.com',
|
44
|
+
params = { full_name: 'Example', description: description, name: 'example@example.com', email: 'example@example.com',
|
45
|
+
mobile: '555-5555', phone: '555-5555', address: 'addr' }
|
35
46
|
if show_slot
|
36
|
-
params[:slot_id] = ENV
|
47
|
+
params[:slot_id] = ENV.fetch('SSS_API_SLOT', nil)
|
37
48
|
else
|
38
|
-
days =
|
49
|
+
days = rand(1..30)
|
39
50
|
params[:start] = Time.now + (days * 24 * 60 * 60)
|
40
51
|
params[:finish] = params[:start] + (60 * 60)
|
41
52
|
end
|
42
|
-
puts "
|
43
|
-
puts "
|
44
|
-
Supersaas::Client.instance.appointments.create(schedule_id,
|
53
|
+
puts "creating new appointment..."
|
54
|
+
puts "#### Supersaas::Client.instance.appointments.create(#{schedule_id}, #{user_id}, {...})"
|
55
|
+
Supersaas::Client.instance.appointments.create(schedule_id, user_id, params)
|
45
56
|
else
|
46
|
-
puts "
|
57
|
+
puts "skipping create/update/delete (NO DESTRUCTIVE ACTIONS FOR SCHEDULE DATA)..."
|
47
58
|
end
|
48
59
|
|
49
|
-
puts "
|
50
|
-
puts "
|
60
|
+
puts "listing appointments..."
|
61
|
+
puts "#### Supersaas::Client.instance.appointments.list(#{schedule_id}, nil, nil, 25)"
|
51
62
|
|
52
63
|
appointments = Supersaas::Client.instance.appointments.list(schedule_id, nil, nil, 25)
|
53
|
-
appointments.each do |appointment|
|
54
|
-
puts "#{description} == #{appointment.description}"
|
55
|
-
if description == appointment.description
|
56
|
-
puts "\n\rupdating appointment..."
|
57
|
-
puts "\n\r#### Supersaas::Client.instance.appointments.update(#{schedule_id}, #{new_appointment_id}, {...})\n\r"
|
58
|
-
Supersaas::Client.instance.appointments.update(schedule_id, new_appointment_id, {country: 'FR', address: 'Rue 1'})
|
59
|
-
|
60
|
-
puts "\n\rdeleting appointment..."
|
61
|
-
puts "\n\r#### Supersaas::Client.instance.appointments.delete(#{schedule_id}. #{new_appointment_id})\n\r"
|
62
|
-
Supersaas::Client.instance.appointments.delete(schedule_id, new_appointment_id)
|
63
|
-
break
|
64
|
-
end
|
65
|
-
end
|
66
64
|
|
67
|
-
if appointments.size
|
65
|
+
if appointments.size.positive?
|
68
66
|
appointment_id = appointments.sample.id
|
69
|
-
puts "
|
70
|
-
puts "
|
67
|
+
puts "getting appointment..."
|
68
|
+
puts "#### Supersaas::Client.instance.appointments.get(#{appointment_id})"
|
71
69
|
Supersaas::Client.instance.appointments.get(schedule_id, appointment_id)
|
72
70
|
end
|
73
71
|
|
74
|
-
puts "
|
72
|
+
puts "listing changes..."
|
75
73
|
from = DateTime.now - 120
|
76
|
-
|
74
|
+
to = DateTime.now + 360_000
|
75
|
+
puts "#### Supersaas::Client.instance.appointments.changes(#{schedule_id},
|
76
|
+
'#{from.strftime('%Y-%m-%d %H:%M:%S')}', '#{to.strftime('%Y-%m-%d %H:%M:%S')}', #{show_slot || 'false'})"
|
77
77
|
|
78
78
|
Supersaas::Client.instance.appointments.changes(schedule_id, from, show_slot)
|
79
79
|
|
80
|
-
puts "
|
80
|
+
puts "listing available..."
|
81
81
|
from = DateTime.now
|
82
|
-
puts "
|
82
|
+
puts "#### Supersaas::Client.instance.appointments.available(#{schedule_id},
|
83
|
+
'#{from.strftime('%Y-%m-%d %H:%M:%S')}')"
|
84
|
+
|
85
|
+
Supersaas::Client.instance.appointments.available(schedule_id, from)
|
86
|
+
|
87
|
+
puts "Appointments for a single user..."
|
88
|
+
user = Supersaas::Client.instance.users.list(nil, 1).first
|
89
|
+
from = DateTime.now
|
90
|
+
puts "#### Supersaas::Client.instance.appointments.agenda(#{schedule_id}, user.id,
|
91
|
+
'#{from.strftime('%Y-%m-%d %H:%M:%S')}')"
|
92
|
+
Supersaas::Client.instance.appointments.agenda(schedule_id, user.id, from.strftime('%Y-%m-%d %H:%M:%S'))
|
93
|
+
|
94
|
+
# Update and delete appointments
|
95
|
+
appointments.each do |appointment|
|
96
|
+
puts "#{description} == #{appointment.description}"
|
97
|
+
next unless description == appointment.description
|
98
|
+
|
99
|
+
puts "updating appointment..."
|
100
|
+
puts "#### Supersaas::Client.instance.appointments.update(#{schedule_id}, #{appointment.id}, {...})"
|
101
|
+
Supersaas::Client.instance.appointments.update(schedule_id, appointment.id, { country: 'FR', address: 'Rue 1' })
|
102
|
+
|
103
|
+
puts "deleting appointment..."
|
104
|
+
puts "#### Supersaas::Client.instance.appointments.delete(#{schedule_id}. #{appointment.id})"
|
105
|
+
Supersaas::Client.instance.appointments.delete(schedule_id, appointment.id)
|
106
|
+
break
|
107
|
+
end
|
83
108
|
|
84
|
-
|
109
|
+
# Puts delete user
|
110
|
+
unless ENV.fetch('SSS_API_USER', nil)
|
111
|
+
Supersaas::Client.instance.users.delete(user_id)
|
112
|
+
end
|
data/examples/forms.rb
CHANGED
@@ -1,39 +1,37 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require "supersaas-api-client"
|
4
|
+
require 'supersaas-api-client'
|
5
5
|
|
6
|
-
puts "
|
6
|
+
puts "# SuperSaaS Forms Example"
|
7
7
|
|
8
8
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
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/appointments.rb
|
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/appointments.rb"
|
11
11
|
return
|
12
12
|
end
|
13
13
|
|
14
14
|
puts "## Account: #{Supersaas::Client.instance.account_name}"
|
15
|
-
puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}
|
15
|
+
puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}"
|
16
16
|
|
17
17
|
Supersaas::Client.instance.verbose = true
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
return
|
25
|
-
end
|
19
|
+
puts "You will need to create a form, and also attach the form to a booking, see documentation on how to do that"
|
20
|
+
puts "The below example will take a form in random, and if it is not attached to something then 404 error will be raised"
|
21
|
+
|
22
|
+
puts "listing forms..."
|
23
|
+
puts "#### Supersaas::Client.instance.forms.forms"
|
26
24
|
|
27
|
-
|
28
|
-
puts "\n\r#### Supersaas::Client.instance.forms.list(#{form_id})\n\r"
|
25
|
+
template_forms = Supersaas::Client.instance.forms.forms
|
29
26
|
|
30
|
-
|
27
|
+
if template_forms.size.positive?
|
28
|
+
template_form_id = template_forms.sample.id
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
puts "\n\r#### Supersaas::Client.instance.forms.get(#{form_id})\n\r"
|
36
|
-
form = Supersaas::Client.instance.forms.get(form_id)
|
30
|
+
puts "listing forms from account"
|
31
|
+
puts "#### Supersaas::Client.instance.forms.list"
|
32
|
+
form_id = Supersaas::Client.instance.forms.list(template_form_id).sample.id
|
37
33
|
end
|
38
34
|
|
39
|
-
puts
|
35
|
+
puts "getting form..."
|
36
|
+
puts "#### Supersaas::Client.instance.forms.get(#{form_id})"
|
37
|
+
Supersaas::Client.instance.forms.get(form_id)
|
data/examples/groups.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'supersaas-api-client'
|
4
|
+
|
5
|
+
puts "# SuperSaaS Groups Example"
|
6
|
+
|
7
|
+
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 "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
puts "## Account: #{Supersaas::Client.instance.account_name}"
|
14
|
+
puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}"
|
15
|
+
|
16
|
+
Supersaas::Client.instance.verbose = true
|
17
|
+
|
18
|
+
puts "listing groups..."
|
19
|
+
puts "#### Supersaas::Client.instance.groups.list"
|
20
|
+
Supersaas::Client.instance.groups.list
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'supersaas-api-client'
|
4
|
+
|
5
|
+
puts "# SuperSaaS Promotions Example"
|
6
|
+
|
7
|
+
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 "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
puts "## Account: #{Supersaas::Client.instance.account_name}"
|
14
|
+
puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}"
|
15
|
+
|
16
|
+
Supersaas::Client.instance.verbose = true
|
17
|
+
|
18
|
+
puts "listing promotions..."
|
19
|
+
puts "#### Supersaas::Client.instance.promotions.list"
|
20
|
+
promotions = Supersaas::Client.instance.promotions.list
|
21
|
+
|
22
|
+
[10, promotions.size].min&.times do |i|
|
23
|
+
puts "A promotion"
|
24
|
+
puts "#### Supersaas::Client.instance.promotion(#{promotions[i].id})"
|
25
|
+
Supersaas::Client.instance.promotions.promotion(promotions[i].code)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Uncomment to try out duplicating a promotional code
|
29
|
+
# puts "duplicate promotional code"
|
30
|
+
# puts "#### Supersaas::Client.instance.promotions.duplicate_promotion_code('new_id', 'id_to_duplicate')"
|
31
|
+
# Supersaas::Client.instance.promotions.duplicate_promotion_code("pcode#{SecureRandom.hex(4)}", promotions.first.code)
|
32
|
+
# puts
|
data/examples/schedules.rb
CHANGED
@@ -1,27 +1,39 @@
|
|
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 Schedules 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 "
|
19
|
+
puts "listing schedules..."
|
20
|
+
puts "#### Supersaas::Client.instance.schedules.list"
|
20
21
|
schedules = Supersaas::Client.instance.schedules.list
|
21
22
|
|
22
|
-
puts "
|
23
|
-
[10, schedules.size].min
|
24
|
-
puts "
|
23
|
+
puts "listing schedule resources..."
|
24
|
+
[10, schedules.size].min&.times do |i|
|
25
|
+
puts "#### Supersaas::Client.instance.schedules.resources(#{schedules[i].id})"
|
26
|
+
# Capacity schedules bomb
|
27
|
+
begin
|
25
28
|
Supersaas::Client.instance.schedules.resources(schedules[i].id)
|
29
|
+
rescue
|
30
|
+
next
|
31
|
+
end
|
26
32
|
end
|
27
|
-
|
33
|
+
|
34
|
+
puts "puts listing fields..."
|
35
|
+
[10, schedules.size].min&.times do |i|
|
36
|
+
puts "#### Supersaas::Client.instance.schedules.field_list(#{schedules[i].id})"
|
37
|
+
Supersaas::Client.instance.schedules.field_list(schedules[i].id)
|
38
|
+
end
|
39
|
+
puts
|