supersaas-api-client 2.0.5 → 2.1.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/README.md +122 -37
- data/examples/appointments.rb +16 -22
- data/examples/forms.rb +9 -5
- data/examples/groups.rb +2 -1
- data/examples/promotions.rb +5 -4
- data/examples/schedules.rb +7 -7
- data/examples/slots.rb +42 -0
- data/examples/users.rb +1 -1
- data/lib/supersaas-api-client/api/appointments.rb +27 -36
- data/lib/supersaas-api-client/api/base_api.rb +2 -0
- data/lib/supersaas-api-client/api/groups.rb +1 -1
- data/lib/supersaas-api-client/api/hooks.rb +25 -0
- data/lib/supersaas-api-client/api/promotions.rb +1 -1
- data/lib/supersaas-api-client/api/schedules.rb +9 -1
- data/lib/supersaas-api-client/api/slots.rb +63 -0
- data/lib/supersaas-api-client/api/users.rb +30 -40
- data/lib/supersaas-api-client/client.rb +44 -30
- data/lib/supersaas-api-client/exception.rb +8 -0
- data/lib/supersaas-api-client/models/base_model.rb +18 -2
- data/lib/supersaas-api-client/models/field_list.rb +11 -2
- data/lib/supersaas-api-client/models/slot.rb +1 -1
- data/lib/supersaas-api-client/version.rb +1 -1
- data/lib/supersaas.rb +2 -0
- metadata +11 -17
- data/.github/workflows/actions.yaml +0 -21
- data/.gitignore +0 -13
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -298
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -49
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/supersaas-api-client.gemspec +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 48f5cb476c043a4a2af0c8074ca7458d742ab825ae4da26075c9451b536dd985
|
|
4
|
+
data.tar.gz: 2a0ea6698b74279c1533272a094ddd2c31ebcffcb9d8cfe33c4fcd27f0ae3f43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12fe85acf084b75321a21b1f1c91bddbcda6bc97496c9eadb89f66ed0c469bdf5e62dacf9dfd0842957a3e7b3afb73ad2516a7b76ef2a7eee752b9a93cc5270e
|
|
7
|
+
data.tar.gz: e347315a16264c7d5c3f8a06b124169aa55dfe8b0bfc44c232e5a3122ea6ee2588fa25809b15c76846fca0c040f0ae228381ef62815856f017332ff9e0e45355
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# SuperSaaS Ruby API Client
|
|
2
2
|
|
|
3
|
-
Manage appointments, users, and other
|
|
3
|
+
Manage appointments, users, and other objects on the [SuperSaaS appointment scheduling](https://www.supersaas.com/) platform in Ruby.
|
|
4
4
|
|
|
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.
|
|
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 a back-end system or to extract information to generate reports.
|
|
7
7
|
|
|
8
8
|
## Prerequisites
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ This can be useful to build an integration with back-end system or to extract in
|
|
|
12
12
|
|
|
13
13
|
### Dependencies
|
|
14
14
|
|
|
15
|
-
No external dependencies. Only the `json` and `net/http`
|
|
15
|
+
No external dependencies. Only the `json` and `net/http` libraries from the Ruby standard library are used. Requires Ruby 2.5 or later.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ Install with:
|
|
|
20
20
|
|
|
21
21
|
$ gem install supersaas-api-client
|
|
22
22
|
|
|
23
|
-
Alternatively, you can use `bundler` to install it by adding this line to
|
|
23
|
+
Alternatively, you can use `bundler` to install it by adding this line to your Gemfile.
|
|
24
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.
|
|
25
25
|
|
|
26
26
|
gem 'supersaas-api-client', '~> 2'
|
|
@@ -28,11 +28,11 @@ The supersaas-api-client may update major versions with breaking changes, so it'
|
|
|
28
28
|
## Configuration
|
|
29
29
|
|
|
30
30
|
The `Client` can be used either (1) through the singleton helper method `instance`, e.g.
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
Supersaas::Client.instance #=> <Supersaas::Client>
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
Or else by (2) simply creating a new client instance manually, e.g.
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
Supersaas::Client.new #=> <Supersaas::Client>
|
|
37
37
|
|
|
38
38
|
Initialize the SuperSaaS `Client` with authorization credentials:
|
|
@@ -41,19 +41,19 @@ Initialize the SuperSaaS `Client` with authorization credentials:
|
|
|
41
41
|
config.account_name = 'accnt'
|
|
42
42
|
config.api_key = 'xxxxxxxxxxxxxxxxxxxxxx'
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
> Note, ensure that `configure` is called before `instance` or `new`, otherwise the client will be initialized with configuration defaults.
|
|
46
46
|
|
|
47
47
|
If the client isn't configured explicitly, it will use default `ENV` variables for the account name and api key.
|
|
48
48
|
|
|
49
49
|
ENV['SSS_API_ACCOUNT_NAME'] = 'your-env-supersaas-account-name'
|
|
50
|
-
ENV['SSS_API_KEY'] = 'your-env-supersaas-
|
|
50
|
+
ENV['SSS_API_KEY'] = 'your-env-supersaas-api-key'
|
|
51
51
|
Supersaas::Client.instance.account_name #=> 'your-env-supersaas-account-name'
|
|
52
|
-
Supersaas::Client.instance.api_key #=> 'your-env-supersaas-
|
|
53
|
-
|
|
52
|
+
Supersaas::Client.instance.api_key #=> 'your-env-supersaas-api-key'
|
|
53
|
+
|
|
54
54
|
All configuration options can be individually set on the client.
|
|
55
55
|
|
|
56
|
-
Supersaas::Client.instance.api_key = 'xxxxxxxxxxxxxxxxxxxxxx'
|
|
56
|
+
Supersaas::Client.instance.api_key = 'xxxxxxxxxxxxxxxxxxxxxx'
|
|
57
57
|
Supersaas::Client.instance.verbose = true
|
|
58
58
|
...
|
|
59
59
|
|
|
@@ -69,7 +69,7 @@ Create a user with user attributes params `create(attributes, user_id = nil, web
|
|
|
69
69
|
If webhook=true is present it will trigger any webhooks connected to the account.
|
|
70
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
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
|
|
72
|
+
If validation fails for any field then error `422 Unprocessable Entity` will be raised. The server's explanation is in the exception's `errors`, see [Error Handling](#error-handling).
|
|
73
73
|
Data fields that you can supply can be found [here.](https://www.supersaas.com/info/dev/user_api)
|
|
74
74
|
|
|
75
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
|
|
@@ -83,14 +83,14 @@ If the `user_id` does not exist 404 error will be raised.
|
|
|
83
83
|
You only need to specify the attributes you wish to update:
|
|
84
84
|
|
|
85
85
|
Supersaas::Client.instance.users.update(12345, {full_name: 'New Name'}, true, "ignore") #=> nil
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
#### Delete User
|
|
88
88
|
|
|
89
89
|
Delete a single user by `user_id`, and if the user does not exist 404 error will be raised.
|
|
90
90
|
If webhook=true is present it will trigger any webhooks connected to the account.
|
|
91
91
|
|
|
92
92
|
Supersaas::Client.instance.users.delete(12345) #=> nil
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
#### Get User
|
|
95
95
|
|
|
96
96
|
Get a single user by `user_id`, and if the user does not exist 404 error will be raised, you may use optional `form`:
|
|
@@ -110,6 +110,12 @@ Get all the fields available to user object:
|
|
|
110
110
|
|
|
111
111
|
Supersaas::Client.instance.users.field_list #=> [<Supersaas::FieldList>, ...]
|
|
112
112
|
|
|
113
|
+
#### List Input Fields of User object
|
|
114
|
+
|
|
115
|
+
Get the fields that can be set when creating a user, each with a `required` flag:
|
|
116
|
+
|
|
117
|
+
Supersaas::Client.instance.users.input_field_list #=> [<Supersaas::FieldList>, ...]
|
|
118
|
+
|
|
113
119
|
#### Create Appointment/Booking
|
|
114
120
|
|
|
115
121
|
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,
|
|
@@ -117,6 +123,10 @@ Create an appointment with `schedule_id`, and `user_id(optional)` (see API docum
|
|
|
117
123
|
|
|
118
124
|
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
125
|
|
|
126
|
+
**Input attributes** are sent on create and update: `start`, `finish`, `name`, `full_name`, `email`, `address`, `mobile`, `phone`, `country`, `field_1`, `field_2`, `field_1_r`, `field_2_r`, `super_field`, `description` and `form_id`, plus what is booked: `resource_id` on a resource schedule, or `slot_id` and `quantity` (number of places) on a capacity schedule. Any other attribute is not sent. The API does not support creating bookings on service schedules.
|
|
127
|
+
|
|
128
|
+
**Read-only attributes** are returned when reading appointments but never sent: `id`, `created_on`, `updated_on`, `created_by`, `updated_by`, `user_id`, `deleted`, `res_name`, `service_id`, `service_name`, `waitlisted`, and `form` when reading with `form` set.
|
|
129
|
+
|
|
120
130
|
#### Update Appointment/Booking
|
|
121
131
|
|
|
122
132
|
Update an appointment by `schedule_id` and `appointment_id` with appointment attributes, see the above link,
|
|
@@ -138,14 +148,14 @@ Get a single appointment by `schedule_id` and `appointment_id`:
|
|
|
138
148
|
|
|
139
149
|
#### List Appointments/Bookings
|
|
140
150
|
|
|
141
|
-
List appointments by `schedule_id`, with `form`
|
|
142
|
-
`list(schedule_id, form = nil, start_time = nil, limit = nil)`:
|
|
151
|
+
List appointments by `schedule_id`, with `form`, `start_time`, `limit`, `finish` and `offset` view params,
|
|
152
|
+
`list(schedule_id, form = nil, start_time = nil, limit = nil, finish = nil, offset = nil)`:
|
|
143
153
|
|
|
144
|
-
Supersaas::Client.instance.appointments.list(12345,
|
|
154
|
+
Supersaas::Client.instance.appointments.list(12345, true, '2018-01-31 00:00:00', 25) #=> [<Supersaas::Appointment>, ...]
|
|
145
155
|
|
|
146
156
|
#### Get Agenda
|
|
147
157
|
|
|
148
|
-
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),
|
|
158
|
+
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)),
|
|
149
159
|
`agenda(schedule_id, user_id, from_time = nil, slot = false)`:
|
|
150
160
|
|
|
151
161
|
Supersaas::Client.instance.appointments.agenda(12345, 67890, '2018-01-31 00:00:00') #=> [<Supersaas::Appointment>, ...]
|
|
@@ -156,13 +166,13 @@ This method is deprecated and will be removed in the future.
|
|
|
156
166
|
Get agenda (upcoming) slots by `schedule_id` and `user_id`, with `from_time` view param,
|
|
157
167
|
`agenda_slots(schedule_id, user_id, from_time = nil)`:
|
|
158
168
|
|
|
159
|
-
Supersaas::Client.instance.appointments.agenda_slots(12345, 67890, '2018-01-31 00:00:00') #=> [<Supersaas::Slot>, ...]
|
|
169
|
+
Supersaas::Client.instance.appointments.agenda_slots(12345, 67890, '2018-01-31 00:00:00') #=> [<Supersaas::Slot>, ...]
|
|
160
170
|
|
|
161
171
|
_Note: only works for capacity type schedules._
|
|
162
172
|
|
|
163
173
|
#### Get Available Appointments/Bookings
|
|
164
174
|
|
|
165
|
-
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),
|
|
175
|
+
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)),
|
|
166
176
|
`available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil)`:
|
|
167
177
|
|
|
168
178
|
Supersaas::Client.instance.appointments.available(12345, '2018-01-31 00:00:00', 15, 'My Class') #=> [<Supersaas::Appointment>, ...]
|
|
@@ -172,7 +182,7 @@ Get available appointments by `schedule_id`, with `from` time and `length_minute
|
|
|
172
182
|
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)),
|
|
173
183
|
`changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil)`:
|
|
174
184
|
|
|
175
|
-
Supersaas::Client.instance.appointments.changes(12345, '2018-01-31 00:00:00', '2019-01-31 00:00:00',
|
|
185
|
+
Supersaas::Client.instance.appointments.changes(12345, '2018-01-31 00:00:00', '2019-01-31 00:00:00', true) #=> [<Supersaas::Appointment>, ...]
|
|
176
186
|
|
|
177
187
|
#### Get range of appointments
|
|
178
188
|
|
|
@@ -181,6 +191,41 @@ Get range of appointments by `schedule_id`, with `today`, `from` time, `to` time
|
|
|
181
191
|
|
|
182
192
|
Supersaas::Client.instance.appointments.range(12345, false, '2018-01-31 00:00:00', '2019-01-31 00:00:00', true) #=> [<Supersaas::Appointment>, ...]/[<Supersaas::Slot>, ...]
|
|
183
193
|
|
|
194
|
+
#### List Slots
|
|
195
|
+
|
|
196
|
+
List the slots of a capacity type schedule by `schedule_id`, with optional `start_time`, `finish`, `limit` (default 100, max 2500) and `offset` view params,
|
|
197
|
+
`list(schedule_id, start_time = nil, finish = nil, limit = nil, offset = nil)`:
|
|
198
|
+
|
|
199
|
+
Supersaas::Client.instance.slots.list(12345, '2018-01-31 00:00:00', '2019-01-31 00:00:00', 50) #=> [<Supersaas::Slot>, ...]
|
|
200
|
+
|
|
201
|
+
_Note: slots only work for capacity type schedules. On other schedule types the API returns 405, which raises `Supersaas::Exception` with "Not available for this schedule type"._
|
|
202
|
+
|
|
203
|
+
#### Get Slot
|
|
204
|
+
|
|
205
|
+
Get a single slot by `schedule_id` and `slot_id`:
|
|
206
|
+
|
|
207
|
+
Supersaas::Client.instance.slots.get(12345, 67890) #=> <Supersaas::Slot>
|
|
208
|
+
|
|
209
|
+
#### Create Slot
|
|
210
|
+
|
|
211
|
+
Create a slot with `schedule_id` and slot attributes (`start`, `finish`, `title`, `description`, `location`, `capacity`, `price`, `color`),
|
|
212
|
+
`create(schedule_id, attributes)`. A `capacity` of `'-'` means unlimited, `0` means no places:
|
|
213
|
+
|
|
214
|
+
Supersaas::Client.instance.slots.create(12345, {start: '2018-01-31 14:00:00', finish: '2018-01-31 15:00:00', title: 'Yoga', capacity: 10}) #=> http://www.supersaas.com/api/slots/67890.json
|
|
215
|
+
|
|
216
|
+
#### Update Slot
|
|
217
|
+
|
|
218
|
+
Update a slot by `schedule_id` and `slot_id` with slot attributes, see the above link,
|
|
219
|
+
`update(schedule_id, slot_id, attributes)`:
|
|
220
|
+
|
|
221
|
+
Supersaas::Client.instance.slots.update(12345, 67890, {title: 'Advanced Yoga', capacity: '-'}) #=> {}
|
|
222
|
+
|
|
223
|
+
#### Delete Slot
|
|
224
|
+
|
|
225
|
+
Delete a single slot by `schedule_id` and `slot_id`. Bookings on the slot are deleted as well:
|
|
226
|
+
|
|
227
|
+
Supersaas::Client.instance.slots.delete(12345, 67890) #=> {}
|
|
228
|
+
|
|
184
229
|
#### List Template Forms
|
|
185
230
|
|
|
186
231
|
Get all forms by template `superform_id`, with `from_time`, and `user` params ([see](https://www.supersaas.com/info/dev/form_api)) and `limit`/`offset` pagination params:
|
|
@@ -208,16 +253,16 @@ Get a list of promotional coupon codes with pagination parameters `limit` and `o
|
|
|
208
253
|
|
|
209
254
|
#### Get a single coupon code
|
|
210
255
|
|
|
211
|
-
Retrieve information about a single coupon code
|
|
256
|
+
Retrieve information about a single coupon code by its alphanumeric `promotion_code`:
|
|
212
257
|
|
|
213
|
-
Supersaas::Client.instance.promotions.promotion(
|
|
258
|
+
Supersaas::Client.instance.promotions.promotion('SPRING10') #=> [<Supersaas::Promotion>]
|
|
214
259
|
|
|
215
260
|
#### Duplicate promotion code
|
|
216
261
|
|
|
217
262
|
Duplicate a template promotion by giving (new) `promotion_code` and `template_code` in that order,
|
|
218
263
|
`duplicate_promotion_code(promotion_code, template_code)`:
|
|
219
264
|
|
|
220
|
-
Supersaas::Client.instance.promotions.duplicate_promotion_code(
|
|
265
|
+
Supersaas::Client.instance.promotions.duplicate_promotion_code('SPRING11', 'SPRING10') #=> nil
|
|
221
266
|
|
|
222
267
|
#### List Groups in an account
|
|
223
268
|
|
|
@@ -235,7 +280,7 @@ Get all account schedules:
|
|
|
235
280
|
|
|
236
281
|
Get all services/resources by `schedule_id`:
|
|
237
282
|
|
|
238
|
-
Supersaas::Client.instance.schedules.resources(12345) #=> [<Supersaas::Resource>, ...]
|
|
283
|
+
Supersaas::Client.instance.schedules.resources(12345) #=> [<Supersaas::Resource>, ...]
|
|
239
284
|
|
|
240
285
|
_Note: does not work for capacity type schedules._
|
|
241
286
|
|
|
@@ -245,16 +290,40 @@ Get all the available fields of a schedule by `schedule_id`:
|
|
|
245
290
|
|
|
246
291
|
Supersaas::Client.instance.schedules.field_list(12345) #=> [<Supersaas::FieldList>, ...]
|
|
247
292
|
|
|
293
|
+
#### List Input Fields of a Schedule
|
|
294
|
+
|
|
295
|
+
Get the fields that can be set when creating a booking on a schedule by `schedule_id`, each with a `required` flag:
|
|
296
|
+
|
|
297
|
+
Supersaas::Client.instance.schedules.input_field_list(12345) #=> [<Supersaas::FieldList>, ...]
|
|
298
|
+
|
|
299
|
+
#### Check Credentials
|
|
300
|
+
|
|
301
|
+
Check that the account name and API key are valid. Returns `true`, or raises `Supersaas::Exception` with status 401:
|
|
302
|
+
|
|
303
|
+
Supersaas::Client.instance.ping #=> true
|
|
304
|
+
|
|
305
|
+
#### Create Webhook
|
|
306
|
+
|
|
307
|
+
Create a webhook with `target_url`, `event` and `parent_id` ([see](https://www.supersaas.com/info/dev/webhooks)). The event is the trigger letter, e.g. `'U'` new user, `'M'` changed user, `'N'` new appointment, `'C'` changed appointment. The `parent_id` is the schedule id for appointment events, the super form id for form events, and the account id otherwise:
|
|
308
|
+
|
|
309
|
+
Supersaas::Client.instance.hooks.create('https://example.com/hook', 'N', 12345) #=> {"id"=>67, "parent_id"=>12345}
|
|
310
|
+
|
|
311
|
+
#### Delete Webhook
|
|
312
|
+
|
|
313
|
+
Delete a webhook by `hook_id` and `parent_id`:
|
|
314
|
+
|
|
315
|
+
Supersaas::Client.instance.hooks.delete(67, 12345) #=> {}
|
|
316
|
+
|
|
248
317
|
|
|
249
318
|
## Examples
|
|
250
319
|
|
|
251
320
|
The ./examples folder contains several executable Ruby scripts demonstrating how to use the API Client for common requests.
|
|
252
321
|
|
|
253
|
-
The examples
|
|
322
|
+
The examples require your account name and API key. The appointments example also needs a schedule id, and optionally takes a user id (otherwise it creates and deletes a user) and a slot id for capacity type schedules. These can be set as environment variables, e.g.
|
|
254
323
|
|
|
255
324
|
$ gem install supersaas-api-client
|
|
256
|
-
$
|
|
257
|
-
$
|
|
325
|
+
$ SSS_API_USER=myuserid SSS_API_SCHEDULE=myscheduleid SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=xxxxxxxxxxxxxxxxxxxxxx ./examples/appointments.rb
|
|
326
|
+
$ SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=xxxxxxxxxxxxxxxxxxxxxx ./examples/forms.rb
|
|
258
327
|
$ SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=xxxxxxxxxxxxxxxxxxxxxx ./examples/users.rb
|
|
259
328
|
|
|
260
329
|
## Testing
|
|
@@ -265,15 +334,15 @@ The HTTP requests can be stubbed by configuring the client with the `dry_run` op
|
|
|
265
334
|
|
|
266
335
|
Note, stubbed requests always return an empty Hash.
|
|
267
336
|
|
|
268
|
-
The `Client` also provides a `last_request` attribute containing the `Net::HTTP` object from the last performed request, e.g.
|
|
337
|
+
The `Client` also provides a `last_request` attribute containing the `Net::HTTP` object from the last performed request, e.g.
|
|
269
338
|
|
|
270
339
|
Supersaas::Client.instance.last_request #=> <Net::HTTP::Get>
|
|
271
340
|
|
|
272
341
|
The headers, body, path, etc. of the last request can be inspected for assertion in tests, or for troubleshooting failed API requests.
|
|
273
342
|
|
|
274
|
-
For additional troubleshooting, the client can be configured with the `verbose` option, which will `puts` any JSON contents in the request and response
|
|
343
|
+
For additional troubleshooting, the client can be configured with the `verbose` option, which will `puts` any JSON contents in the request and response. Password values in the request are shown as `[FILTERED]`; the request itself is sent unchanged. E.g.
|
|
275
344
|
|
|
276
|
-
Supersaas::Client.instance.verbose = true
|
|
345
|
+
Supersaas::Client.instance.verbose = true
|
|
277
346
|
|
|
278
347
|
## Error Handling
|
|
279
348
|
|
|
@@ -285,10 +354,17 @@ The API Client raises a custom exception for HTTP errors and invalid input. Resc
|
|
|
285
354
|
# Handle error
|
|
286
355
|
end
|
|
287
356
|
|
|
288
|
-
|
|
357
|
+
For HTTP errors the exception also carries the status code and the errors the server returned:
|
|
358
|
+
|
|
359
|
+
begin
|
|
360
|
+
Supersaas::Client.instance.slots.get(12345, 999)
|
|
361
|
+
rescue Supersaas::Exception => e
|
|
362
|
+
e.message #=> "HTTP Request Error: Not Found"
|
|
363
|
+
e.status #=> 404
|
|
364
|
+
e.errors #=> [{"status"=>"404", "title"=>"Not found"}]
|
|
365
|
+
end
|
|
289
366
|
|
|
290
|
-
|
|
291
|
-
"Error 400, Bad request: unknown attribute 'bad_field_name' for Booking."
|
|
367
|
+
`errors` is an empty array when the response has no JSON error body. `status` is `nil` for errors raised before a request is sent, such as invalid input.
|
|
292
368
|
|
|
293
369
|
## Additional Information
|
|
294
370
|
|
|
@@ -298,9 +374,18 @@ Some errors have more information and are printed to the log before raising the
|
|
|
298
374
|
|
|
299
375
|
Contact: [support@supersaas.com](mailto:support@supersaas.com)
|
|
300
376
|
|
|
377
|
+
## Development
|
|
378
|
+
|
|
379
|
+
The `bin/` scripts are for working on the client itself and are not included in the gem:
|
|
380
|
+
|
|
381
|
+
$ bin/setup # install the development dependencies
|
|
382
|
+
$ bin/console # IRB session with the client loaded
|
|
383
|
+
$ bundle exec rake test
|
|
384
|
+
$ bundle exec rake lint
|
|
385
|
+
|
|
301
386
|
## Releases
|
|
302
387
|
|
|
303
|
-
The package follows [semantic versioning](https://semver.org/), i.e. MAJOR.MINOR.PATCH
|
|
388
|
+
The package follows [semantic versioning](https://semver.org/), i.e. MAJOR.MINOR.PATCH.
|
|
304
389
|
|
|
305
390
|
## License
|
|
306
391
|
|
data/examples/appointments.rb
CHANGED
|
@@ -26,35 +26,29 @@ else
|
|
|
26
26
|
return
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
# give
|
|
30
29
|
user_id = ENV.fetch('SSS_API_USER', nil)
|
|
31
30
|
|
|
32
31
|
unless user_id
|
|
33
32
|
puts 'User is created and then deleted at the end'
|
|
34
|
-
params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com'
|
|
33
|
+
params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com' }
|
|
35
34
|
user = Supersaas::Client.instance.users.create(params)
|
|
36
35
|
user_id = user.match(%r{users/(\d+)\.json})[1]
|
|
37
36
|
puts "#New user created #{user_id}"
|
|
38
37
|
end
|
|
39
38
|
|
|
40
|
-
description =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if show_slot
|
|
46
|
-
params[:slot_id] = ENV.fetch('SSS_API_SLOT', nil)
|
|
47
|
-
else
|
|
48
|
-
days = rand(1..30)
|
|
49
|
-
params[:start] = Time.now + (days * 24 * 60 * 60)
|
|
50
|
-
params[:finish] = params[:start] + (60 * 60)
|
|
51
|
-
end
|
|
52
|
-
puts 'creating new appointment...'
|
|
53
|
-
puts "#### Supersaas::Client.instance.appointments.create(#{schedule_id}, #{user_id}, {...})"
|
|
54
|
-
Supersaas::Client.instance.appointments.create(schedule_id, user_id, params)
|
|
39
|
+
description = '1234567890.'
|
|
40
|
+
params = { full_name: 'Example', description: description, name: 'example@example.com', email: 'example@example.com',
|
|
41
|
+
mobile: '555-5555', phone: '555-5555', address: 'addr' }
|
|
42
|
+
if show_slot
|
|
43
|
+
params[:slot_id] = ENV.fetch('SSS_API_SLOT', nil)
|
|
55
44
|
else
|
|
56
|
-
|
|
45
|
+
days = rand(1..30)
|
|
46
|
+
params[:start] = Time.now + (days * 24 * 60 * 60)
|
|
47
|
+
params[:finish] = params[:start] + (60 * 60)
|
|
57
48
|
end
|
|
49
|
+
puts 'creating new appointment...'
|
|
50
|
+
puts "#### Supersaas::Client.instance.appointments.create(#{schedule_id}, #{user_id}, {...})"
|
|
51
|
+
Supersaas::Client.instance.appointments.create(schedule_id, user_id, params)
|
|
58
52
|
|
|
59
53
|
puts 'listing appointments...'
|
|
60
54
|
puts "#### Supersaas::Client.instance.appointments.list(#{schedule_id}, nil, nil, 25)"
|
|
@@ -64,7 +58,7 @@ appointments = Supersaas::Client.instance.appointments.list(schedule_id, nil, ni
|
|
|
64
58
|
if appointments.size.positive?
|
|
65
59
|
appointment_id = appointments.sample.id
|
|
66
60
|
puts 'getting appointment...'
|
|
67
|
-
puts "#### Supersaas::Client.instance.appointments.get(#{appointment_id})"
|
|
61
|
+
puts "#### Supersaas::Client.instance.appointments.get(#{schedule_id}, #{appointment_id})"
|
|
68
62
|
Supersaas::Client.instance.appointments.get(schedule_id, appointment_id)
|
|
69
63
|
end
|
|
70
64
|
|
|
@@ -74,7 +68,7 @@ to = DateTime.now + 360_000
|
|
|
74
68
|
puts "#### Supersaas::Client.instance.appointments.changes(#{schedule_id},
|
|
75
69
|
'#{from.strftime('%Y-%m-%d %H:%M:%S')}', '#{to.strftime('%Y-%m-%d %H:%M:%S')}', #{show_slot || 'false'})"
|
|
76
70
|
|
|
77
|
-
Supersaas::Client.instance.appointments.changes(schedule_id, from, show_slot)
|
|
71
|
+
Supersaas::Client.instance.appointments.changes(schedule_id, from, to, show_slot)
|
|
78
72
|
|
|
79
73
|
puts 'listing available...'
|
|
80
74
|
from = DateTime.now
|
|
@@ -100,10 +94,10 @@ appointments.each do |appointment|
|
|
|
100
94
|
Supersaas::Client.instance.appointments.update(schedule_id, appointment.id, { country: 'FR', address: 'Rue 1' })
|
|
101
95
|
|
|
102
96
|
puts 'deleting appointment...'
|
|
103
|
-
puts "#### Supersaas::Client.instance.appointments.delete(#{schedule_id}
|
|
97
|
+
puts "#### Supersaas::Client.instance.appointments.delete(#{schedule_id}, #{appointment.id})"
|
|
104
98
|
Supersaas::Client.instance.appointments.delete(schedule_id, appointment.id)
|
|
105
99
|
break
|
|
106
100
|
end
|
|
107
101
|
|
|
108
|
-
#
|
|
102
|
+
# Delete the user created above
|
|
109
103
|
Supersaas::Client.instance.users.delete(user_id) unless ENV.fetch('SSS_API_USER', nil)
|
data/examples/forms.rb
CHANGED
|
@@ -7,7 +7,7 @@ puts '# SuperSaaS Forms Example'
|
|
|
7
7
|
|
|
8
8
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
|
9
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/
|
|
10
|
+
puts ' SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/forms.rb'
|
|
11
11
|
return
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -29,9 +29,13 @@ if template_forms.size.positive?
|
|
|
29
29
|
|
|
30
30
|
puts 'listing forms from account'
|
|
31
31
|
puts '#### Supersaas::Client.instance.forms.list'
|
|
32
|
-
form_id = Supersaas::Client.instance.forms.list(template_form_id).sample
|
|
32
|
+
form_id = Supersaas::Client.instance.forms.list(template_form_id).sample&.id
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
puts
|
|
37
|
-
Supersaas::Client.instance.forms.get(form_id)
|
|
35
|
+
if form_id
|
|
36
|
+
puts 'getting form...'
|
|
37
|
+
puts "#### Supersaas::Client.instance.forms.get(#{form_id})"
|
|
38
|
+
Supersaas::Client.instance.forms.get(form_id)
|
|
39
|
+
else
|
|
40
|
+
puts '... no forms found'
|
|
41
|
+
end
|
data/examples/groups.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'supersaas-api-client'
|
|
@@ -6,7 +7,7 @@ puts '# SuperSaaS Groups Example'
|
|
|
6
7
|
|
|
7
8
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
|
8
9
|
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/
|
|
10
|
+
puts 'SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/groups.rb'
|
|
10
11
|
return
|
|
11
12
|
end
|
|
12
13
|
|
data/examples/promotions.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'supersaas-api-client'
|
|
@@ -6,7 +7,7 @@ puts '# SuperSaaS Promotions Example'
|
|
|
6
7
|
|
|
7
8
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
|
8
9
|
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/
|
|
10
|
+
puts 'SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/promotions.rb'
|
|
10
11
|
return
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -19,13 +20,13 @@ puts 'listing promotions...'
|
|
|
19
20
|
puts '#### Supersaas::Client.instance.promotions.list'
|
|
20
21
|
promotions = Supersaas::Client.instance.promotions.list
|
|
21
22
|
|
|
22
|
-
[10, promotions.size].min
|
|
23
|
+
[10, promotions.size].min.times do |i|
|
|
23
24
|
puts 'A promotion'
|
|
24
|
-
puts "#### Supersaas::Client.instance.promotion(#{promotions[i].
|
|
25
|
+
puts "#### Supersaas::Client.instance.promotions.promotion('#{promotions[i].code}')"
|
|
25
26
|
Supersaas::Client.instance.promotions.promotion(promotions[i].code)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
# Uncomment to try out duplicating a promotional code
|
|
29
|
+
# Uncomment to try out duplicating a promotional code (also uncomment require 'securerandom')
|
|
29
30
|
# puts "duplicate promotional code"
|
|
30
31
|
# puts "#### Supersaas::Client.instance.promotions.duplicate_promotion_code('new_id', 'id_to_duplicate')"
|
|
31
32
|
# Supersaas::Client.instance.promotions.duplicate_promotion_code("pcode#{SecureRandom.hex(4)}", promotions.first.code)
|
data/examples/schedules.rb
CHANGED
|
@@ -7,7 +7,7 @@ puts '# SuperSaaS Schedules Example'
|
|
|
7
7
|
|
|
8
8
|
unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
|
|
9
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/
|
|
10
|
+
puts 'SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/schedules.rb'
|
|
11
11
|
return
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -21,18 +21,18 @@ puts '#### Supersaas::Client.instance.schedules.list'
|
|
|
21
21
|
schedules = Supersaas::Client.instance.schedules.list
|
|
22
22
|
|
|
23
23
|
puts 'listing schedule resources...'
|
|
24
|
-
[10, schedules.size].min
|
|
24
|
+
[10, schedules.size].min.times do |i|
|
|
25
25
|
puts "#### Supersaas::Client.instance.schedules.resources(#{schedules[i].id})"
|
|
26
|
-
# Capacity schedules
|
|
26
|
+
# Capacity type schedules have no resources, the API returns an error for them
|
|
27
27
|
begin
|
|
28
28
|
Supersaas::Client.instance.schedules.resources(schedules[i].id)
|
|
29
|
-
rescue
|
|
30
|
-
|
|
29
|
+
rescue Supersaas::Exception => e
|
|
30
|
+
puts "Skipped: #{e.message}"
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
puts '
|
|
35
|
-
[10, schedules.size].min
|
|
34
|
+
puts 'listing fields...'
|
|
35
|
+
[10, schedules.size].min.times do |i|
|
|
36
36
|
puts "#### Supersaas::Client.instance.schedules.field_list(#{schedules[i].id})"
|
|
37
37
|
Supersaas::Client.instance.schedules.field_list(schedules[i].id)
|
|
38
38
|
end
|
data/examples/slots.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'supersaas-api-client'
|
|
4
|
+
|
|
5
|
+
puts '# SuperSaaS Slots 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_SCHEDULE=<capacityscheduleid> SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/slots.rb'
|
|
10
|
+
return
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
schedule_id = ENV.fetch('SSS_API_SCHEDULE', nil)
|
|
14
|
+
unless schedule_id
|
|
15
|
+
puts 'ERROR! Missing capacity type schedule id. Rerun the script with SSS_API_SCHEDULE=<scheduleid>'
|
|
16
|
+
return
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
puts "## Account: #{Supersaas::Client.instance.account_name}"
|
|
20
|
+
puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}"
|
|
21
|
+
|
|
22
|
+
Supersaas::Client.instance.verbose = true
|
|
23
|
+
|
|
24
|
+
puts 'creating slot...'
|
|
25
|
+
start = DateTime.now + 1
|
|
26
|
+
finish = start + (1.0 / 24)
|
|
27
|
+
attributes = { start: start.strftime('%Y-%m-%d %H:%M:%S'), finish: finish.strftime('%Y-%m-%d %H:%M:%S'),
|
|
28
|
+
title: 'Example slot', capacity: 5 }
|
|
29
|
+
puts "#### Supersaas::Client.instance.slots.create(#{schedule_id}, #{attributes})"
|
|
30
|
+
location = Supersaas::Client.instance.slots.create(schedule_id, attributes)
|
|
31
|
+
slot_id = location.to_s[%r{/slots/(\d+)}, 1]
|
|
32
|
+
|
|
33
|
+
puts 'listing slots...'
|
|
34
|
+
puts "#### Supersaas::Client.instance.slots.list(#{schedule_id})"
|
|
35
|
+
Supersaas::Client.instance.slots.list(schedule_id, nil, nil, 10)
|
|
36
|
+
|
|
37
|
+
if slot_id
|
|
38
|
+
puts 'getting, updating and deleting slot...'
|
|
39
|
+
Supersaas::Client.instance.slots.get(schedule_id, slot_id)
|
|
40
|
+
Supersaas::Client.instance.slots.update(schedule_id, slot_id, { title: 'Updated example slot', capacity: '-' })
|
|
41
|
+
Supersaas::Client.instance.slots.delete(schedule_id, slot_id)
|
|
42
|
+
end
|
data/examples/users.rb
CHANGED
|
@@ -18,7 +18,7 @@ Supersaas::Client.instance.verbose = true
|
|
|
18
18
|
|
|
19
19
|
puts 'creating new user...'
|
|
20
20
|
puts '#### Supersaas::Client.instance.users.create({...})'
|
|
21
|
-
params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com'
|
|
21
|
+
params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com' }
|
|
22
22
|
Supersaas::Client.instance.users.create(params)
|
|
23
23
|
new_user_id = nil
|
|
24
24
|
|