gonebusy-ruby-client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +1963 -0
  4. data/lib/gonebusy/api_helper.rb +149 -0
  5. data/lib/gonebusy/configuration.rb +16 -0
  6. data/lib/gonebusy/controllers/base_controller.rb +45 -0
  7. data/lib/gonebusy/controllers/bookings_controller.rb +298 -0
  8. data/lib/gonebusy/controllers/categories_controller.rb +180 -0
  9. data/lib/gonebusy/controllers/pricing_models_controller.rb +241 -0
  10. data/lib/gonebusy/controllers/resources_controller.rb +355 -0
  11. data/lib/gonebusy/controllers/schedules_controller.rb +426 -0
  12. data/lib/gonebusy/controllers/search_controller.rb +64 -0
  13. data/lib/gonebusy/controllers/services_controller.rb +367 -0
  14. data/lib/gonebusy/controllers/users_controller.rb +288 -0
  15. data/lib/gonebusy/exceptions/api_exception.rb +16 -0
  16. data/lib/gonebusy/exceptions/entities_error_exception.rb +27 -0
  17. data/lib/gonebusy/gonebusy_client.rb +58 -0
  18. data/lib/gonebusy/http/auth/custom_auth.rb +16 -0
  19. data/lib/gonebusy/http/faraday_client.rb +41 -0
  20. data/lib/gonebusy/http/http_call_back.rb +17 -0
  21. data/lib/gonebusy/http/http_client.rb +82 -0
  22. data/lib/gonebusy/http/http_context.rb +15 -0
  23. data/lib/gonebusy/http/http_method_enum.rb +7 -0
  24. data/lib/gonebusy/http/http_request.rb +44 -0
  25. data/lib/gonebusy/http/http_response.rb +19 -0
  26. data/lib/gonebusy/models/base_model.rb +32 -0
  27. data/lib/gonebusy/models/cancel_booking_by_id_response.rb +35 -0
  28. data/lib/gonebusy/models/create_booking_body.rb +80 -0
  29. data/lib/gonebusy/models/create_booking_response.rb +35 -0
  30. data/lib/gonebusy/models/create_category_body.rb +71 -0
  31. data/lib/gonebusy/models/create_category_response.rb +35 -0
  32. data/lib/gonebusy/models/create_pricing_model_body.rb +80 -0
  33. data/lib/gonebusy/models/create_pricing_model_response.rb +35 -0
  34. data/lib/gonebusy/models/create_resource_body.rb +89 -0
  35. data/lib/gonebusy/models/create_resource_response.rb +35 -0
  36. data/lib/gonebusy/models/create_schedule_body.rb +144 -0
  37. data/lib/gonebusy/models/create_schedule_response.rb +35 -0
  38. data/lib/gonebusy/models/create_schedule_time_window_body.rb +117 -0
  39. data/lib/gonebusy/models/create_schedule_time_window_response.rb +35 -0
  40. data/lib/gonebusy/models/create_service_body.rb +98 -0
  41. data/lib/gonebusy/models/create_service_response.rb +35 -0
  42. data/lib/gonebusy/models/create_user_body.rb +89 -0
  43. data/lib/gonebusy/models/create_user_response.rb +35 -0
  44. data/lib/gonebusy/models/date_recurs_by_enum.rb +13 -0
  45. data/lib/gonebusy/models/delete_resource_by_id_response.rb +35 -0
  46. data/lib/gonebusy/models/delete_schedule_by_id_response.rb +35 -0
  47. data/lib/gonebusy/models/delete_schedule_time_window_by_id_response.rb +35 -0
  48. data/lib/gonebusy/models/delete_service_by_id_response.rb +35 -0
  49. data/lib/gonebusy/models/entities_address_entity.rb +116 -0
  50. data/lib/gonebusy/models/entities_availability_response.rb +58 -0
  51. data/lib/gonebusy/models/entities_booking_response.rb +71 -0
  52. data/lib/gonebusy/models/entities_category_response.rb +98 -0
  53. data/lib/gonebusy/models/entities_pricing_model_response.rb +89 -0
  54. data/lib/gonebusy/models/entities_resource_availabilities.rb +49 -0
  55. data/lib/gonebusy/models/entities_resource_response.rb +98 -0
  56. data/lib/gonebusy/models/entities_schedule_response.rb +76 -0
  57. data/lib/gonebusy/models/entities_search_response.rb +54 -0
  58. data/lib/gonebusy/models/entities_service_response.rb +116 -0
  59. data/lib/gonebusy/models/entities_slots.rb +45 -0
  60. data/lib/gonebusy/models/entities_thing_type_response.rb +44 -0
  61. data/lib/gonebusy/models/entities_time_window_response.rb +135 -0
  62. data/lib/gonebusy/models/entities_user_response.rb +152 -0
  63. data/lib/gonebusy/models/frequency_enum.rb +18 -0
  64. data/lib/gonebusy/models/gender_enum.rb +10 -0
  65. data/lib/gonebusy/models/get_booking_by_id_response.rb +35 -0
  66. data/lib/gonebusy/models/get_bookings_response.rb +40 -0
  67. data/lib/gonebusy/models/get_categories_response.rb +40 -0
  68. data/lib/gonebusy/models/get_category_by_id_response.rb +35 -0
  69. data/lib/gonebusy/models/get_pricing_model_by_id_response.rb +35 -0
  70. data/lib/gonebusy/models/get_pricing_models_response.rb +40 -0
  71. data/lib/gonebusy/models/get_resource_by_id_response.rb +35 -0
  72. data/lib/gonebusy/models/get_resource_things_response.rb +40 -0
  73. data/lib/gonebusy/models/get_resources_response.rb +40 -0
  74. data/lib/gonebusy/models/get_schedule_by_id_response.rb +35 -0
  75. data/lib/gonebusy/models/get_schedules_response.rb +40 -0
  76. data/lib/gonebusy/models/get_service_available_slots_by_id_response.rb +35 -0
  77. data/lib/gonebusy/models/get_service_by_id_response.rb +35 -0
  78. data/lib/gonebusy/models/get_services_response.rb +40 -0
  79. data/lib/gonebusy/models/get_user_by_id_response.rb +35 -0
  80. data/lib/gonebusy/models/get_users_pros_response.rb +40 -0
  81. data/lib/gonebusy/models/get_users_response.rb +40 -0
  82. data/lib/gonebusy/models/occurrence_enum.rb +22 -0
  83. data/lib/gonebusy/models/recurs_by_enum.rb +16 -0
  84. data/lib/gonebusy/models/search_query_response.rb +35 -0
  85. data/lib/gonebusy/models/update_booking_by_id_response.rb +35 -0
  86. data/lib/gonebusy/models/update_pricing_model_by_id_body.rb +62 -0
  87. data/lib/gonebusy/models/update_pricing_model_by_id_response.rb +35 -0
  88. data/lib/gonebusy/models/update_resource_by_id_body.rb +71 -0
  89. data/lib/gonebusy/models/update_resource_by_id_response.rb +35 -0
  90. data/lib/gonebusy/models/update_schedule_time_window_by_id_body.rb +117 -0
  91. data/lib/gonebusy/models/update_schedule_time_window_by_id_response.rb +35 -0
  92. data/lib/gonebusy/models/update_service_by_id_body.rb +89 -0
  93. data/lib/gonebusy/models/update_service_by_id_response.rb +35 -0
  94. data/lib/gonebusy/models/update_user_by_id_body.rb +89 -0
  95. data/lib/gonebusy/models/update_user_by_id_response.rb +35 -0
  96. data/lib/gonebusy.rb +105 -0
  97. metadata +186 -0
@@ -0,0 +1,149 @@
1
+ module Gonebusy
2
+ class APIHelper
3
+ # Replaces template parameters in the given url
4
+ # @param [String] The query string builder to replace the template parameters
5
+ # @param [Hash] The parameters to replace in the url
6
+ def self.append_url_with_template_parameters(query_builder, parameters)
7
+ # perform parameter validation
8
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
9
+
10
+ # return if there are no parameters to replace
11
+ if parameters.nil?
12
+ query_builder
13
+ else
14
+ # iterate and append parameters
15
+ parameters.each do |key, value|
16
+ replace_value = ''
17
+
18
+ if value.nil?
19
+ replace_value = ''
20
+ elsif value.instance_of? Array
21
+ value.map!{|element| CGI.escape(element.to_s)}
22
+ replace_value = value.join('/')
23
+ else
24
+ replace_value = CGI.escape(value.to_s)
25
+ end
26
+
27
+ # find the template parameter and replace it with its value
28
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
29
+ end
30
+ end
31
+ return query_builder
32
+ end
33
+
34
+ # Appends the given set of parameters to the given query string
35
+ # @param [String] The query string builder to replace the template parameters
36
+ # @param [Hash] The parameters to append
37
+ def self.append_url_with_query_parameters(query_builder, parameters)
38
+ # perform parameter validation
39
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
40
+
41
+ # return if there are no parameters to replace
42
+ if parameters.nil?
43
+ return query_builder
44
+ else
45
+ # remove any nil values
46
+ parameters = parameters.reject { |_key, value| value.nil? }
47
+
48
+ # does the query string already has parameters
49
+ has_params = query_builder.include? '?'
50
+ separator = has_params ? '&' : '?'
51
+
52
+ # append query with separator and parameters and return
53
+ return query_builder << separator << URI.encode_www_form(parameters)
54
+ end
55
+ end
56
+
57
+ # Validates and processes the given Url
58
+ # @param [String] The given Url to process
59
+ # @return [String] Pre-processed Url as string
60
+ def self.clean_url(url)
61
+ # perform parameter validation
62
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
63
+
64
+ # ensure that the urls are absolute
65
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
66
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
67
+
68
+ # get the http protocol match
69
+ protocol = matches[1]
70
+
71
+ # check if parameters exist
72
+ index = url.index('?')
73
+
74
+ # remove redundant forward slashes
75
+ query = url[protocol.length...(index != nil ? index : url.length)]
76
+ query.gsub!(%r{\/\/+}, '/')
77
+
78
+ # get the parameters
79
+ parameters = index != nil ? url[url.index('?')...url.length] : ""
80
+
81
+ # return processed url
82
+ return protocol + query + parameters
83
+ end
84
+
85
+ # Parses JSON string.
86
+ # @param [String] A JSON string.
87
+ def self.json_deserialize(json)
88
+ begin
89
+ return JSON.parse(json)
90
+ rescue
91
+ raise TypeError, "Server responded with invalid JSON."
92
+ end
93
+ end
94
+
95
+ # Form encodes a hash of parameters.
96
+ # @param [Hash] The hash of parameters to encode.
97
+ # @return [Hash] A hash with the same parameters form encoded.
98
+ def self.form_encode_parameters(form_parameters)
99
+ encoded = Hash.new
100
+ form_parameters.each do |key, value|
101
+ encoded.merge!(APIHelper.form_encode value, key)
102
+ end
103
+ return encoded
104
+ end
105
+
106
+ # Form encodes an object.
107
+ # @param [Dynamic] An object to form encode.
108
+ # @param [String] The name of the object.
109
+ # @return [Hash] A form encoded representation of the object in the form of a hash.
110
+ def self.form_encode(obj, instance_name)
111
+ retval = Hash.new
112
+
113
+ # If this is a structure, resolve it's field names.
114
+ if obj.kind_of? BaseModel
115
+ obj = obj.to_hash
116
+ end
117
+
118
+ # Create a form encoded hash for this object.
119
+ if obj == nil
120
+ nil
121
+ elsif obj.instance_of? Array
122
+ obj.each_with_index do |value, index|
123
+ retval.merge!(APIHelper.form_encode(value, instance_name + "[" + index.to_s + "]"))
124
+ end
125
+ elsif obj.instance_of? Hash
126
+ obj.each do |key, value|
127
+ retval.merge!(APIHelper.form_encode(value, instance_name + "[" + key + "]"))
128
+ end
129
+ else
130
+ retval[instance_name] = obj
131
+ end
132
+ return retval
133
+ end
134
+ end
135
+ end
136
+
137
+ # extend types to support to_bool
138
+ module ToBoolean
139
+ def to_bool
140
+ return true if self == true || self.to_s.strip =~ /^(true|yes|y|1)$/i
141
+ return false
142
+ end
143
+ end
144
+
145
+ class NilClass; include ToBoolean; end
146
+ class TrueClass; include ToBoolean; end
147
+ class FalseClass; include ToBoolean; end
148
+ class Numeric; include ToBoolean; end
149
+ class String; include ToBoolean; end
@@ -0,0 +1,16 @@
1
+ module Gonebusy
2
+ class Configuration
3
+ # The base Uri for API calls
4
+ @base_uri = 'http://beta.gonebusy.com/api/v1'
5
+
6
+ # Set Authorization to "Token <your API key>"
7
+ @authorization = 'Token <your API key>'
8
+
9
+ # The attribute accessors for public properties
10
+ class << self
11
+ attr_accessor :base_uri
12
+ attr_accessor :authorization
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ # This file was automatically generated for GoneBusy Inc. by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Gonebusy
4
+ class BaseController
5
+ attr_accessor :http_client, :http_call_back
6
+
7
+ @@http_client = FaradayClient.new(60)
8
+
9
+ @@global_headers = {
10
+ 'user-agent' => 'APIMATIC 2.0'
11
+ }
12
+
13
+ def initialize(http_client: nil, http_call_back: nil)
14
+ @http_client = http_client ||= @@http_client
15
+ @http_call_back = http_call_back
16
+ end
17
+
18
+ def validate_parameters(args)
19
+ args.each do |name, value|
20
+ if value == nil
21
+ raise ArgumentError.new "Required parameter #{name} cannot be nil."
22
+ end
23
+ end
24
+ end
25
+
26
+ def execute_request(request, binary: false)
27
+ @http_call_back.on_before_request(request) if @http_call_back
28
+
29
+ request.headers = @@global_headers.clone.merge(request.headers)
30
+
31
+ response = binary ? @http_client.execute_as_binary(request) : @http_client.execute_as_string(request)
32
+ context = HttpContext.new(request, response)
33
+
34
+ @http_call_back.on_after_response(context) if @http_call_back
35
+
36
+ return context
37
+ end
38
+
39
+ def validate_response(context)
40
+ if !context.response.status_code.between?(200, 208) #[200,208] = HTTP OK
41
+ raise APIException.new 'HTTP Response Not OK', context
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,298 @@
1
+ # This file was automatically generated for GoneBusy Inc. by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Gonebusy
4
+ class BookingsController < BaseController
5
+ @@instance = BookingsController.new
6
+ # Singleton instance of the controller class
7
+ def self.instance
8
+ @@instance
9
+ end
10
+
11
+ # Create a Booking with params
12
+ # @param [String] authorization Required parameter: A valid API key, in the format 'Token API_KEY'
13
+ # @param [CreateBookingBody] create_booking_body Required parameter: the content of the request
14
+ # @return CreateBookingResponse response from the API call
15
+ def create_booking(options = Hash.new)
16
+
17
+ # the base uri for api requests
18
+ _query_builder = Configuration.base_uri.dup
19
+
20
+ # prepare query string for API call
21
+ _query_builder << '/bookings/new'
22
+
23
+ # validate and preprocess url
24
+ _query_url = APIHelper.clean_url _query_builder
25
+
26
+ # prepare headers
27
+ _headers = {
28
+ 'accept' => 'application/json',
29
+ 'content-type' => 'application/json; charset=utf-8',
30
+ 'Authorization' => Configuration.authorization,
31
+ 'Authorization' => options['authorization']
32
+ }
33
+
34
+ # create the HttpRequest object for the call
35
+ _request = @http_client.post _query_url, headers: _headers, parameters: options['create_booking_body'].to_json
36
+
37
+ # apply authentication
38
+ CustomAuth.apply(_request)
39
+
40
+ # execute the request
41
+ _context = execute_request(_request)
42
+
43
+ # endpoint error handling using HTTP status codes.
44
+ if _context.response.status_code == 400
45
+ raise EntitiesErrorException.new '400 - Bad Request', _context
46
+ elsif _context.response.status_code == 401
47
+ raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
48
+ elsif _context.response.status_code == 403
49
+ raise EntitiesErrorException.new '403 - Forbidden', _context
50
+ elsif _context.response.status_code == 422
51
+ raise EntitiesErrorException.new '422 - Unprocessable Entity', _context
52
+ elsif _context.response.status_code == 500
53
+ raise APIException.new '500 - Unexpected error', _context
54
+ end
55
+
56
+ # global error handling using HTTP status codes.
57
+ validate_response(_context)
58
+
59
+ # return appropriate response type
60
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
61
+ return CreateBookingResponse.from_hash(decoded)
62
+ end
63
+
64
+ # Return list of Bookings.
65
+ # @param [String] authorization Required parameter: A valid API key, in the format 'Token API_KEY'
66
+ # @param [Integer] page Optional parameter: Page offset to fetch.
67
+ # @param [Integer] per_page Optional parameter: Number of results to return per page.
68
+ # @param [String] states Optional parameter: Comma-separated list of Booking states to retrieve only Bookings in those states. Leave blank to retrieve all Bookings.
69
+ # @param [Integer] user_id Optional parameter: Retrieve Bookings owned only by this User Id. You must be authorized to manage this User Id.
70
+ # @return GetBookingsResponse response from the API call
71
+ def get_bookings(options = Hash.new)
72
+
73
+ # the base uri for api requests
74
+ _query_builder = Configuration.base_uri.dup
75
+
76
+ # prepare query string for API call
77
+ _query_builder << '/bookings'
78
+
79
+ # process optional query parameters
80
+ _query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
81
+ 'page' => options['page'],
82
+ 'per_page' => options['per_page'],
83
+ 'states' => options['states'],
84
+ 'user_id' => options['user_id']
85
+ }
86
+
87
+ # validate and preprocess url
88
+ _query_url = APIHelper.clean_url _query_builder
89
+
90
+ # prepare headers
91
+ _headers = {
92
+ 'accept' => 'application/json',
93
+ 'Authorization' => Configuration.authorization,
94
+ 'Authorization' => options['authorization']
95
+ }
96
+
97
+ # create the HttpRequest object for the call
98
+ _request = @http_client.get _query_url, headers: _headers
99
+
100
+ # apply authentication
101
+ CustomAuth.apply(_request)
102
+
103
+ # execute the request
104
+ _context = execute_request(_request)
105
+
106
+ # endpoint error handling using HTTP status codes.
107
+ if _context.response.status_code == 401
108
+ raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
109
+ elsif _context.response.status_code == 403
110
+ raise EntitiesErrorException.new '403 - Forbidden', _context
111
+ elsif _context.response.status_code == 404
112
+ raise EntitiesErrorException.new '404 - Not Found', _context
113
+ elsif _context.response.status_code == 500
114
+ raise APIException.new '500 - Unexpected error', _context
115
+ end
116
+
117
+ # global error handling using HTTP status codes.
118
+ validate_response(_context)
119
+
120
+ # return appropriate response type
121
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
122
+ return GetBookingsResponse.from_hash(decoded)
123
+ end
124
+
125
+ # Cancel a Booking by id
126
+ # @param [String] authorization Required parameter: A valid API key, in the format 'Token API_KEY'
127
+ # @param [String] id Required parameter: Example:
128
+ # @return CancelBookingByIdResponse response from the API call
129
+ def cancel_booking_by_id(options = Hash.new)
130
+
131
+ # the base uri for api requests
132
+ _query_builder = Configuration.base_uri.dup
133
+
134
+ # prepare query string for API call
135
+ _query_builder << '/bookings/{id}'
136
+
137
+ # process optional query parameters
138
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
139
+ 'id' => options['id']
140
+ }
141
+
142
+ # validate and preprocess url
143
+ _query_url = APIHelper.clean_url _query_builder
144
+
145
+ # prepare headers
146
+ _headers = {
147
+ 'accept' => 'application/json',
148
+ 'Authorization' => Configuration.authorization,
149
+ 'Authorization' => options['authorization']
150
+ }
151
+
152
+ # create the HttpRequest object for the call
153
+ _request = @http_client.delete _query_url, headers: _headers
154
+
155
+ # apply authentication
156
+ CustomAuth.apply(_request)
157
+
158
+ # execute the request
159
+ _context = execute_request(_request)
160
+
161
+ # endpoint error handling using HTTP status codes.
162
+ if _context.response.status_code == 400
163
+ raise EntitiesErrorException.new '400 - Bad Request', _context
164
+ elsif _context.response.status_code == 401
165
+ raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
166
+ elsif _context.response.status_code == 403
167
+ raise EntitiesErrorException.new '403 - Forbidden', _context
168
+ elsif _context.response.status_code == 404
169
+ raise EntitiesErrorException.new '404 - Not Found', _context
170
+ elsif _context.response.status_code == 500
171
+ raise APIException.new '500 - Unexpected error', _context
172
+ end
173
+
174
+ # global error handling using HTTP status codes.
175
+ validate_response(_context)
176
+
177
+ # return appropriate response type
178
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
179
+ return CancelBookingByIdResponse.from_hash(decoded)
180
+ end
181
+
182
+ # Update a Booking by id
183
+ # @param [String] authorization Required parameter: A valid API key, in the format 'Token API_KEY'
184
+ # @param [String] id Required parameter: Example:
185
+ # @return UpdateBookingByIdResponse response from the API call
186
+ def update_booking_by_id(options = Hash.new)
187
+
188
+ # the base uri for api requests
189
+ _query_builder = Configuration.base_uri.dup
190
+
191
+ # prepare query string for API call
192
+ _query_builder << '/bookings/{id}'
193
+
194
+ # process optional query parameters
195
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
196
+ 'id' => options['id']
197
+ }
198
+
199
+ # validate and preprocess url
200
+ _query_url = APIHelper.clean_url _query_builder
201
+
202
+ # prepare headers
203
+ _headers = {
204
+ 'accept' => 'application/json',
205
+ 'Authorization' => Configuration.authorization,
206
+ 'Authorization' => options['authorization']
207
+ }
208
+
209
+ # create the HttpRequest object for the call
210
+ _request = @http_client.put _query_url, headers: _headers
211
+
212
+ # apply authentication
213
+ CustomAuth.apply(_request)
214
+
215
+ # execute the request
216
+ _context = execute_request(_request)
217
+
218
+ # endpoint error handling using HTTP status codes.
219
+ if _context.response.status_code == 400
220
+ raise EntitiesErrorException.new '400 - Bad Request', _context
221
+ elsif _context.response.status_code == 401
222
+ raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
223
+ elsif _context.response.status_code == 403
224
+ raise EntitiesErrorException.new '403 - Forbidden', _context
225
+ elsif _context.response.status_code == 404
226
+ raise EntitiesErrorException.new '404 - Not Found', _context
227
+ elsif _context.response.status_code == 422
228
+ raise EntitiesErrorException.new '422 - Unprocessable Entity', _context
229
+ elsif _context.response.status_code == 500
230
+ raise APIException.new '500 - Unexpected error', _context
231
+ end
232
+
233
+ # global error handling using HTTP status codes.
234
+ validate_response(_context)
235
+
236
+ # return appropriate response type
237
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
238
+ return UpdateBookingByIdResponse.from_hash(decoded)
239
+ end
240
+
241
+ # Return a Booking by id.
242
+ # @param [String] authorization Required parameter: A valid API key, in the format 'Token API_KEY'
243
+ # @param [String] id Required parameter: Example:
244
+ # @return GetBookingByIdResponse response from the API call
245
+ def get_booking_by_id(options = Hash.new)
246
+
247
+ # the base uri for api requests
248
+ _query_builder = Configuration.base_uri.dup
249
+
250
+ # prepare query string for API call
251
+ _query_builder << '/bookings/{id}'
252
+
253
+ # process optional query parameters
254
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
255
+ 'id' => options['id']
256
+ }
257
+
258
+ # validate and preprocess url
259
+ _query_url = APIHelper.clean_url _query_builder
260
+
261
+ # prepare headers
262
+ _headers = {
263
+ 'accept' => 'application/json',
264
+ 'Authorization' => Configuration.authorization,
265
+ 'Authorization' => options['authorization']
266
+ }
267
+
268
+ # create the HttpRequest object for the call
269
+ _request = @http_client.get _query_url, headers: _headers
270
+
271
+ # apply authentication
272
+ CustomAuth.apply(_request)
273
+
274
+ # execute the request
275
+ _context = execute_request(_request)
276
+
277
+ # endpoint error handling using HTTP status codes.
278
+ if _context.response.status_code == 400
279
+ raise EntitiesErrorException.new '400 - Bad Request', _context
280
+ elsif _context.response.status_code == 401
281
+ raise EntitiesErrorException.new '401 - Unauthorized/Missing Token', _context
282
+ elsif _context.response.status_code == 403
283
+ raise EntitiesErrorException.new '403 - Forbidden', _context
284
+ elsif _context.response.status_code == 404
285
+ raise EntitiesErrorException.new '404 - Not Found', _context
286
+ elsif _context.response.status_code == 500
287
+ raise APIException.new '500 - Unexpected error', _context
288
+ end
289
+
290
+ # global error handling using HTTP status codes.
291
+ validate_response(_context)
292
+
293
+ # return appropriate response type
294
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
295
+ return GetBookingByIdResponse.from_hash(decoded)
296
+ end
297
+ end
298
+ end