stackone_hris_client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,306 @@
1
+ =begin
2
+ #StackOne Unified API
3
+
4
+ #The documentation for the StackOne Unified API
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.4.0
10
+
11
+ =end
12
+
13
+ module StackOneHrisClient
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the API Key Token used with API Key Token authentication.
63
+ #
64
+ # @return [String]
65
+ attr_accessor :api_key_token
66
+
67
+ # Defines the access token (Bearer) used with OAuth2.
68
+ attr_accessor :access_token
69
+
70
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
71
+ # Overrides the access_token if set
72
+ # @return [Proc]
73
+ attr_accessor :access_token_getter
74
+
75
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
76
+ # details will be logged with `logger.debug` (see the `logger` attribute).
77
+ # Default to false.
78
+ #
79
+ # @return [true, false]
80
+ attr_accessor :debugging
81
+
82
+ # Defines the logger used for debugging.
83
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
84
+ #
85
+ # @return [#debug]
86
+ attr_accessor :logger
87
+
88
+ # Defines the temporary folder to store downloaded files
89
+ # (for API endpoints that have file response).
90
+ # Default to use `Tempfile`.
91
+ #
92
+ # @return [String]
93
+ attr_accessor :temp_folder_path
94
+
95
+ # The time limit for HTTP request in seconds.
96
+ # Default to 0 (never times out).
97
+ attr_accessor :timeout
98
+
99
+ # Set this to false to skip client side validation in the operation.
100
+ # Default to true.
101
+ # @return [true, false]
102
+ attr_accessor :client_side_validation
103
+
104
+ ### TLS/SSL setting
105
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
106
+ # Default to true.
107
+ #
108
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
109
+ #
110
+ # @return [true, false]
111
+ attr_accessor :verify_ssl
112
+
113
+ ### TLS/SSL setting
114
+ # Set this to false to skip verifying SSL host name
115
+ # Default to true.
116
+ #
117
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
118
+ #
119
+ # @return [true, false]
120
+ attr_accessor :verify_ssl_host
121
+
122
+ ### TLS/SSL setting
123
+ # Set this to customize the certificate file to verify the peer.
124
+ #
125
+ # @return [String] the path to the certificate file
126
+ #
127
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
128
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
129
+ attr_accessor :ssl_ca_cert
130
+
131
+ ### TLS/SSL setting
132
+ # Client certificate file (for client certificate)
133
+ attr_accessor :cert_file
134
+
135
+ ### TLS/SSL setting
136
+ # Client private key file (for client certificate)
137
+ attr_accessor :key_file
138
+
139
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
140
+ # Default to nil.
141
+ #
142
+ # @see The params_encoding option of Ethon. Related source code:
143
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
144
+ attr_accessor :params_encoding
145
+
146
+ attr_accessor :inject_format
147
+
148
+ attr_accessor :force_ending_format
149
+
150
+ # Defines the region slug used to choose the API base url.
151
+ # Default to eu1.
152
+ #
153
+ # @return [String]
154
+ attr_accessor :region_slug
155
+
156
+ def initialize
157
+ @scheme = 'https'
158
+ @host = 'stackone.com'
159
+ @base_path = ''
160
+ @server_index = nil
161
+ @server_operation_index = {}
162
+ @server_variables = {}
163
+ @server_operation_variables = {}
164
+ @api_key = {}
165
+ @api_key_prefix = {}
166
+ @password = ''
167
+ @client_side_validation = true
168
+ @verify_ssl = true
169
+ @verify_ssl_host = true
170
+ @cert_file = nil
171
+ @key_file = nil
172
+ @timeout = 0
173
+ @params_encoding = nil
174
+ @debugging = false
175
+ @inject_format = false
176
+ @force_ending_format = false
177
+ @region_slug = 'eu1'
178
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
179
+
180
+ yield(self) if block_given?
181
+ end
182
+
183
+ # The default Configuration object.
184
+ def self.default
185
+ @@default ||= Configuration.new
186
+ end
187
+
188
+ def configure
189
+ yield(self) if block_given?
190
+ end
191
+
192
+ def scheme=(scheme)
193
+ # remove :// from scheme
194
+ @scheme = scheme.sub(/:\/\//, '')
195
+ end
196
+
197
+ def host=(host)
198
+ # remove http(s):// and anything after a slash
199
+ @host = host.sub(/https?:\/\//, '').split('/').first
200
+ end
201
+
202
+ def base_path=(base_path)
203
+ # Add leading and trailing slashes to base_path
204
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
205
+ @base_path = '' if @base_path == '/'
206
+ end
207
+
208
+ def region_slug_subdomain
209
+ return '' if region_slug.nil? || region_slug.empty?
210
+
211
+ "api.#{region_slug}."
212
+ end
213
+
214
+ # Returns base URL for specified operation based on server settings
215
+ def base_url(operation = nil)
216
+ index = server_operation_index.fetch(operation, server_index)
217
+ return "#{scheme}://#{region_slug_subdomain}#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
218
+
219
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
220
+ end
221
+
222
+ # Gets API key (with prefix if set).
223
+ # @param [String] param_name the parameter name of API key auth
224
+ def api_key_with_prefix(param_name, param_alias = nil)
225
+ key = @api_key[param_name]
226
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
227
+ if @api_key_prefix[param_name]
228
+ "#{@api_key_prefix[param_name]} #{key}"
229
+ else
230
+ key
231
+ end
232
+ end
233
+
234
+ # Gets access_token using access_token_getter or uses the static access_token
235
+ def access_token_with_refresh
236
+ return access_token if access_token_getter.nil?
237
+ access_token_getter.call
238
+ end
239
+
240
+ # Gets Basic Auth token string
241
+ def basic_auth_token
242
+ 'Basic ' + ["#{api_key_token}:#{password}"].pack('m').delete("\r\n")
243
+ end
244
+
245
+ # Returns Auth Settings hash for api client.
246
+ def auth_settings
247
+ {
248
+ 'basic' =>
249
+ {
250
+ type: 'basic',
251
+ in: 'header',
252
+ key: 'Authorization',
253
+ value: basic_auth_token
254
+ },
255
+ }
256
+ end
257
+
258
+ # Returns an array of Server setting
259
+ def server_settings
260
+ [
261
+ {
262
+ url: "",
263
+ description: "No description provided",
264
+ }
265
+ ]
266
+ end
267
+
268
+ def operation_server_settings
269
+ {}
270
+ end
271
+
272
+ # Returns URL based on server settings
273
+ #
274
+ # @param index array index of the server settings
275
+ # @param variables hash of variable and the corresponding value
276
+ def server_url(index, variables = {}, servers = nil)
277
+ servers = server_settings if servers == nil
278
+
279
+ # check array index out of bound
280
+ if (index < 0 || index >= servers.size)
281
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
282
+ end
283
+
284
+ server = servers[index]
285
+ url = server[:url]
286
+
287
+ return url unless server.key? :variables
288
+
289
+ # go through variable and assign a value
290
+ server[:variables].each do |name, variable|
291
+ if variables.key?(name)
292
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
293
+ url.gsub! "{" + name.to_s + "}", variables[name]
294
+ else
295
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
296
+ end
297
+ else
298
+ # use default value
299
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
300
+ end
301
+ end
302
+
303
+ url
304
+ end
305
+ end
306
+ end