Class: Gonebusy::SchedulesController

Inherits:
BaseController show all
Defined in:
lib/gonebusy/controllers/schedules_controller.rb

Constant Summary collapse

@@instance =
SchedulesController.new

Instance Attribute Summary

Attributes inherited from BaseController

#http_call_back, #http_client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from Gonebusy::BaseController

Class Method Details

.instanceObject

Singleton instance of the controller class



7
8
9
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 7

def self.instance
  @@instance
end

Instance Method Details

#create_schedule(options = Hash.new) ⇒ Object

Create a Schedule with params.

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • create_schedule_body (CreateScheduleBody)

    Required parameter: the content of the request

Returns:

  • CreateScheduleResponse response from the API call



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 251

def create_schedule(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules/new'

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.post _query_url, headers: _headers, parameters: options['create_schedule_body'].to_json

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 422
    raise EntitiesErrorException.new '422 - Unprocessable Entity', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return CreateScheduleResponse.from_hash(decoded)
end

#create_schedule_time_window(options = Hash.new) ⇒ Object

Add a TimeWindow to a Schedule.

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • create_schedule_time_window_body (CreateScheduleTimeWindowBody)

    Required parameter: the content of the request

  • id (String)

    Required parameter: Example:

Returns:

  • CreateScheduleTimeWindowResponse response from the API call



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 75

def create_schedule_time_window(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules/{id}/time_windows/new'

  # process optional query parameters
  _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
    'id' => options['id']
  }

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.post _query_url, headers: _headers, parameters: options['create_schedule_time_window_body'].to_json

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 422
    raise EntitiesErrorException.new '422 - Unprocessable Entity', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return CreateScheduleTimeWindowResponse.from_hash(decoded)
end

#delete_schedule_by_id(options = Hash.new) ⇒ Object

Delete a Schedule

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • id (String)

    Required parameter: Example:

Returns:

  • DeleteScheduleByIdResponse response from the API call



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 135

def delete_schedule_by_id(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules/{id}'

  # process optional query parameters
  _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
    'id' => options['id']
  }

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.delete _query_url, headers: _headers

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return DeleteScheduleByIdResponse.from_hash(decoded)
end

#delete_schedule_time_window_by_id(options = Hash.new) ⇒ Object

Delete a TimeWindow from a Schedule

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • id (String)

    Required parameter: Example:

  • time_window_id (String)

    Required parameter: Example:

Returns:

  • DeleteScheduleTimeWindowByIdResponse response from the API call



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 16

def delete_schedule_time_window_by_id(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules/{id}/time_windows/{time_window_id}'

  # process optional query parameters
  _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
    'id' => options['id'],
    'time_window_id' => options['time_window_id']
  }

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.delete _query_url, headers: _headers

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return DeleteScheduleTimeWindowByIdResponse.from_hash(decoded)
end

#get_schedule_by_id(options = Hash.new) ⇒ Object

Return a Schedule by id.

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • id (String)

    Required parameter: Example:

Returns:

  • GetScheduleByIdResponse response from the API call



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 192

def get_schedule_by_id(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules/{id}'

  # process optional query parameters
  _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
    'id' => options['id']
  }

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.get _query_url, headers: _headers

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 410
    raise EntitiesErrorException.new '410 - Gone', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return GetScheduleByIdResponse.from_hash(decoded)
end

#get_schedules(options = Hash.new) ⇒ Object

Return all Schedules that your account has access to. Includes Schedules for your own User as well as any Users for which you are the Account Manager.

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • page (Integer)

    Optional parameter: Page offset to fetch.

  • per_page (Integer)

    Optional parameter: Number of results to return per page.

  • resource_id (Integer)

    Optional parameter: Retrieve Schedules only for this Resource. You, or provided :user_id, must be authorized to manage this Resource.

  • service_id (Integer)

    Optional parameter: Retrieve Schedules only for this Service. You, or provided :user_id, must be authorized to manage this Service.

  • user_id (Integer)

    Optional parameter: Retrieve Schedules owned only by this User Id. You must be authorized to manage this User Id.

Returns:

  • GetSchedulesResponse response from the API call



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 373

def get_schedules(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules'

  # process optional query parameters
  _query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
    'page' => options['page'],
    'per_page' => options['per_page'],
    'resource_id' => options['resource_id'],
    'service_id' => options['service_id'],
    'user_id' => options['user_id']
  }

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.get _query_url, headers: _headers

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return GetSchedulesResponse.from_hash(decoded)
end

#update_schedule_time_window_by_id(options = Hash.new) ⇒ Object

Update a TimeWindow for a Schedule.

Parameters:

  • authorization (String)

    Required parameter: A valid API key, in the format ‘Token API_KEY’

  • id (String)

    Required parameter: Example:

  • time_window_id (String)

    Required parameter: Example:

  • update_schedule_time_window_by_id_body (UpdateScheduleTimeWindowByIdBody)

    Required parameter: the content of the request

Returns:

  • UpdateScheduleTimeWindowByIdResponse response from the API call



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/gonebusy/controllers/schedules_controller.rb', line 308

def update_schedule_time_window_by_id(options = Hash.new)

  # the base uri for api requests
  _query_builder = Configuration.base_uri.dup

  # prepare query string for API call
  _query_builder << '/schedules/{id}/time_windows/{time_window_id}'

  # process optional query parameters
  _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
    'id' => options['id'],
    'time_window_id' => options['time_window_id']
  }

  # validate and preprocess url
  _query_url = APIHelper.clean_url _query_builder

  # prepare headers
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8',
    'Authorization' => Configuration.authorization,
    'Authorization' => options['authorization']
  }

  # create the HttpRequest object for the call
  _request = @http_client.put _query_url, headers: _headers, parameters: options['update_schedule_time_window_by_id_body'].to_json

  # apply authentication
  CustomAuth.apply(_request)

  # execute the request
  _context = execute_request(_request)

  # endpoint error handling using HTTP status codes.
  if _context.response.status_code == 400
    raise EntitiesErrorException.new '400 - Bad Request', _context
  elsif _context.response.status_code == 401
    raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
  elsif _context.response.status_code == 403
    raise EntitiesErrorException.new '403 - Forbidden', _context
  elsif _context.response.status_code == 404
    raise EntitiesErrorException.new '404 - Not Found', _context
  elsif _context.response.status_code == 422
    raise EntitiesErrorException.new '422 - Unprocessable Entity', _context
  elsif _context.response.status_code == 500
    raise APIException.new '500 - Unexpected error', _context
  end

  # global error handling using HTTP status codes.
  validate_response(_context)

  # return appropriate response type
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  return UpdateScheduleTimeWindowByIdResponse.from_hash(decoded)
end