supersaas-api-client 2.0.4 → 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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +129 -43
  3. data/examples/appointments.rb +16 -22
  4. data/examples/forms.rb +9 -5
  5. data/examples/groups.rb +2 -1
  6. data/examples/promotions.rb +5 -4
  7. data/examples/schedules.rb +7 -7
  8. data/examples/slots.rb +42 -0
  9. data/examples/users.rb +1 -1
  10. data/lib/supersaas-api-client/api/appointments.rb +38 -43
  11. data/lib/supersaas-api-client/api/base_api.rb +2 -0
  12. data/lib/supersaas-api-client/api/forms.rb +3 -1
  13. data/lib/supersaas-api-client/api/groups.rb +1 -1
  14. data/lib/supersaas-api-client/api/hooks.rb +25 -0
  15. data/lib/supersaas-api-client/api/promotions.rb +1 -1
  16. data/lib/supersaas-api-client/api/schedules.rb +9 -1
  17. data/lib/supersaas-api-client/api/slots.rb +63 -0
  18. data/lib/supersaas-api-client/api/users.rb +39 -41
  19. data/lib/supersaas-api-client/client.rb +48 -32
  20. data/lib/supersaas-api-client/exception.rb +8 -0
  21. data/lib/supersaas-api-client/models/appointment.rb +5 -4
  22. data/lib/supersaas-api-client/models/base_model.rb +18 -2
  23. data/lib/supersaas-api-client/models/field_list.rb +11 -2
  24. data/lib/supersaas-api-client/models/form.rb +1 -2
  25. data/lib/supersaas-api-client/models/slot.rb +1 -1
  26. data/lib/supersaas-api-client/models/user.rb +2 -0
  27. data/lib/supersaas-api-client/version.rb +1 -1
  28. data/lib/supersaas.rb +2 -0
  29. metadata +11 -17
  30. data/.github/workflows/actions.yaml +0 -21
  31. data/.gitignore +0 -13
  32. data/.rubocop.yml +0 -1
  33. data/.rubocop_todo.yml +0 -296
  34. data/Gemfile +0 -5
  35. data/Gemfile.lock +0 -49
  36. data/Rakefile +0 -12
  37. data/bin/console +0 -15
  38. data/bin/setup +0 -8
  39. data/supersaas-api-client.gemspec +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a76aa1e660d7f1f2a1dc6e1dd18481c2e7c7e9379415bc0b51ca22b7dcb956b
4
- data.tar.gz: f9a223e22689e31728453603e78f5b7dcfe5985f1e6008ffb6e30c7a93cef536
3
+ metadata.gz: 48f5cb476c043a4a2af0c8074ca7458d742ab825ae4da26075c9451b536dd985
4
+ data.tar.gz: 2a0ea6698b74279c1533272a094ddd2c31ebcffcb9d8cfe33c4fcd27f0ae3f43
5
5
  SHA512:
6
- metadata.gz: 849d3cf00e778f134a828bbeb12d446039471b50e858372c6838e99c8c5726f1f8d83700f43821e7249658608cc2159c979ec3a265f0846eff8bc3ff64f503ad
7
- data.tar.gz: c7c203d37fc281821226b6d06da70abde33e3535a4111b2eb2149a8751f2b42abb9620777bc3f223f0a05c726d7f33b1c5ffc2299c01f785f3cfe8977c7abcad
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 object on the [SuperSaaS appointment scheduling](https://www.supersaas.com/) platform in Ruby.
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` gems from the ruby standard library are used.
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 you Gemfile.
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-account-name'
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-account-name'
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 and any additional information will be printed to your log.
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,16 +83,17 @@ 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
+ If webhook=true is present it will trigger any webhooks connected to the account.
90
91
 
91
92
  Supersaas::Client.instance.users.delete(12345) #=> nil
92
-
93
+
93
94
  #### Get User
94
95
 
95
- Get a single user by `user_id`, and if the user does not exist 404 error will be raised:
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`:
96
97
 
97
98
  Supersaas::Client.instance.users.get(12345) #=> <Supersaas::User>
98
99
 
@@ -109,6 +110,12 @@ Get all the fields available to user object:
109
110
 
110
111
  Supersaas::Client.instance.users.field_list #=> [<Supersaas::FieldList>, ...]
111
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
+
112
119
  #### Create Appointment/Booking
113
120
 
114
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,
@@ -116,6 +123,10 @@ Create an appointment with `schedule_id`, and `user_id(optional)` (see API docum
116
123
 
117
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
118
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
+
119
130
  #### Update Appointment/Booking
120
131
 
121
132
  Update an appointment by `schedule_id` and `appointment_id` with appointment attributes, see the above link,
@@ -125,7 +136,7 @@ Update an appointment by `schedule_id` and `appointment_id` with appointment att
125
136
 
126
137
  #### Delete Appointment/Booking
127
138
 
128
- Delete a single appointment by `schedule_id` and `appointment_id`:
139
+ Delete a single appointment by `schedule_id` and `appointment_id` with optional `webhook`:
129
140
 
130
141
  Supersaas::Client.instance.appointments.delete(12345, 67890) #=> nil
131
142
 
@@ -137,30 +148,31 @@ Get a single appointment by `schedule_id` and `appointment_id`:
137
148
 
138
149
  #### List Appointments/Bookings
139
150
 
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)`:
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)`:
142
153
 
143
- Supersaas::Client.instance.appointments.list(12345, 67890, true, true) #=> [<Supersaas::Appointment>, ...]
154
+ Supersaas::Client.instance.appointments.list(12345, true, '2018-01-31 00:00:00', 25) #=> [<Supersaas::Appointment>, ...]
144
155
 
145
156
  #### Get Agenda
146
157
 
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),
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)),
148
159
  `agenda(schedule_id, user_id, from_time = nil, slot = false)`:
149
160
 
150
161
  Supersaas::Client.instance.appointments.agenda(12345, 67890, '2018-01-31 00:00:00') #=> [<Supersaas::Appointment>, ...]
151
162
 
152
163
  #### Get Agenda Slots
153
164
 
165
+ This method is deprecated and will be removed in the future.
154
166
  Get agenda (upcoming) slots by `schedule_id` and `user_id`, with `from_time` view param,
155
167
  `agenda_slots(schedule_id, user_id, from_time = nil)`:
156
168
 
157
- 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>, ...]
158
170
 
159
171
  _Note: only works for capacity type schedules._
160
172
 
161
173
  #### Get Available Appointments/Bookings
162
174
 
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),
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)),
164
176
  `available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil)`:
165
177
 
166
178
  Supersaas::Client.instance.appointments.available(12345, '2018-01-31 00:00:00', 15, 'My Class') #=> [<Supersaas::Appointment>, ...]
@@ -170,7 +182,7 @@ Get available appointments by `schedule_id`, with `from` time and `length_minute
170
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)),
171
183
  `changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil)`:
172
184
 
173
- Supersaas::Client.instance.appointments.changes(12345, '2018-01-31 00:00:00', '2019-01-31 00:00:00', true) #=> [<Supersaas::Appointment>, ...]
185
+ Supersaas::Client.instance.appointments.changes(12345, '2018-01-31 00:00:00', '2019-01-31 00:00:00', true) #=> [<Supersaas::Appointment>, ...]
174
186
 
175
187
  #### Get range of appointments
176
188
 
@@ -179,9 +191,44 @@ Get range of appointments by `schedule_id`, with `today`, `from` time, `to` time
179
191
 
180
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>, ...]
181
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
+
182
229
  #### List Template Forms
183
230
 
184
- Get all forms by template `superform_id`, with `from_time`, and `user` params ([see](https://www.supersaas.com/info/dev/form_api)):
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:
185
232
 
186
233
  Supersaas::Client.instance.forms.list(12345, '2018-01-31 00:00:00') #=> [<Supersaas::Form>, ...]
187
234
 
@@ -200,23 +247,22 @@ Get a list of Form templates (SuperForms):
200
247
  #### List Promotions
201
248
 
202
249
  Get a list of promotional coupon codes with pagination parameters `limit` and `offset` (see [docs](https://www.supersaas.com/info/dev/promotion_api)),
203
- `list(from_time = nil, user = nil)`:
250
+ `list(limit = nil, offset = nil)`:
204
251
 
205
252
  Supersaas::Client.instance.promotions.list #=> [<Supersaas::Promotion>, ...]
206
253
 
207
254
  #### Get a single coupon code
208
255
 
209
- Retrieve information about a single coupon code use with `promotion_code`:
256
+ Retrieve information about a single coupon code by its alphanumeric `promotion_code`:
210
257
 
211
- Supersaas::Client.instance.promotions.promotion(12345) #=> <Supersaas::Promotion>
258
+ Supersaas::Client.instance.promotions.promotion('SPRING10') #=> [<Supersaas::Promotion>]
212
259
 
213
260
  #### Duplicate promotion code
214
261
 
215
262
  Duplicate a template promotion by giving (new) `promotion_code` and `template_code` in that order,
216
- duplicate_promotion_code(promotion_code, template_code):
263
+ `duplicate_promotion_code(promotion_code, template_code)`:
217
264
 
218
-
219
- Supersaas::Client.instance.promotions.duplicate_promotion_code(12345, 94832838) #=> nil
265
+ Supersaas::Client.instance.promotions.duplicate_promotion_code('SPRING11', 'SPRING10') #=> nil
220
266
 
221
267
  #### List Groups in an account
222
268
 
@@ -234,7 +280,7 @@ Get all account schedules:
234
280
 
235
281
  Get all services/resources by `schedule_id`:
236
282
 
237
- Supersaas::Client.instance.schedules.resources(12345) #=> [<Supersaas::Resource>, ...]
283
+ Supersaas::Client.instance.schedules.resources(12345) #=> [<Supersaas::Resource>, ...]
238
284
 
239
285
  _Note: does not work for capacity type schedules._
240
286
 
@@ -244,16 +290,40 @@ Get all the available fields of a schedule by `schedule_id`:
244
290
 
245
291
  Supersaas::Client.instance.schedules.field_list(12345) #=> [<Supersaas::FieldList>, ...]
246
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
+
247
317
 
248
318
  ## Examples
249
319
 
250
320
  The ./examples folder contains several executable Ruby scripts demonstrating how to use the API Client for common requests.
251
321
 
252
- The examples will require your account name, api key, and some of the examples a schedule id and/or user id and/or form id. These can be set as environment variables. e.g.
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.
253
323
 
254
324
  $ gem install supersaas-api-client
255
- $ SSS_API_UID=myuserid SSS_API_SCHEDULE=myscheduleid SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=xxxxxxxxxxxxxxxxxxxxxx ./examples/appointments.rb
256
- $ SSS_API_FORM=myuserid SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=xxxxxxxxxxxxxxxxxxxxxx ./examples/forms.rb
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
257
327
  $ SSS_API_ACCOUNT_NAME=myaccountname SSS_API_KEY=xxxxxxxxxxxxxxxxxxxxxx ./examples/users.rb
258
328
 
259
329
  ## Testing
@@ -264,15 +334,15 @@ The HTTP requests can be stubbed by configuring the client with the `dry_run` op
264
334
 
265
335
  Note, stubbed requests always return an empty Hash.
266
336
 
267
- 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.
268
338
 
269
339
  Supersaas::Client.instance.last_request #=> <Net::HTTP::Get>
270
340
 
271
341
  The headers, body, path, etc. of the last request can be inspected for assertion in tests, or for troubleshooting failed API requests.
272
342
 
273
- For additional troubleshooting, the client can be configured with the `verbose` option, which will `puts` any JSON contents in the request and response, e.g.
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.
274
344
 
275
- Supersaas::Client.instance.verbose = true
345
+ Supersaas::Client.instance.verbose = true
276
346
 
277
347
  ## Error Handling
278
348
 
@@ -284,10 +354,17 @@ The API Client raises a custom exception for HTTP errors and invalid input. Resc
284
354
  # Handle error
285
355
  end
286
356
 
287
- Some errors have more information and are printed to the log before raising the error e.g.
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
288
366
 
289
- appointment = Supersaas::Client.instance.appointments.create(12345, {bad_field_name: ''})
290
- "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.
291
368
 
292
369
  ## Additional Information
293
370
 
@@ -297,9 +374,18 @@ Some errors have more information and are printed to the log before raising the
297
374
 
298
375
  Contact: [support@supersaas.com](mailto:support@supersaas.com)
299
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
+
300
386
  ## Releases
301
387
 
302
- 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.
303
389
 
304
390
  ## License
305
391
 
@@ -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', api_key: 'example' }
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 = nil
41
- if user_id
42
- description = '1234567890.'
43
- params = { full_name: 'Example', description: description, name: 'example@example.com', email: 'example@example.com',
44
- mobile: '555-5555', phone: '555-5555', address: 'addr' }
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
- puts 'skipping create/update/delete (NO DESTRUCTIVE ACTIONS FOR SCHEDULE DATA)...'
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}. #{appointment.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
- # Puts delete user
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/appointments.rb'
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.id
32
+ form_id = Supersaas::Client.instance.forms.list(template_form_id).sample&.id
33
33
  end
34
34
 
35
- puts 'getting form...'
36
- puts "#### Supersaas::Client.instance.forms.get(#{form_id})"
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/users.rb'
10
+ puts 'SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/groups.rb'
10
11
  return
11
12
  end
12
13
 
@@ -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/users.rb'
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&.times do |i|
23
+ [10, promotions.size].min.times do |i|
23
24
  puts 'A promotion'
24
- puts "#### Supersaas::Client.instance.promotion(#{promotions[i].id})"
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)
@@ -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/users.rb'
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&.times do |i|
24
+ [10, schedules.size].min.times do |i|
25
25
  puts "#### Supersaas::Client.instance.schedules.resources(#{schedules[i].id})"
26
- # Capacity schedules bomb
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 StandardError
30
- next
29
+ rescue Supersaas::Exception => e
30
+ puts "Skipped: #{e.message}"
31
31
  end
32
32
  end
33
33
 
34
- puts 'puts listing fields...'
35
- [10, schedules.size].min&.times do |i|
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', api_key: 'example' }
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