stackone_hris_client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +73 -0
- data/README.md +107 -0
- data/Rakefile +10 -0
- data/docs/Employee.md +48 -0
- data/docs/EmployeeResult.md +20 -0
- data/docs/EmployeesApi.md +169 -0
- data/docs/EmployeesPaginated.md +22 -0
- data/gem-config.yml +14 -0
- data/generate_gem.sh +1 -0
- data/git_push.sh +57 -0
- data/lib/stackone_hris_client/api/employees_api.rb +182 -0
- data/lib/stackone_hris_client/api_client.rb +392 -0
- data/lib/stackone_hris_client/api_error.rb +58 -0
- data/lib/stackone_hris_client/configuration.rb +306 -0
- data/lib/stackone_hris_client/models/employee.rb +427 -0
- data/lib/stackone_hris_client/models/employee_result.rb +231 -0
- data/lib/stackone_hris_client/models/employees_paginated.rb +247 -0
- data/lib/stackone_hris_client/version.rb +15 -0
- data/lib/stackone_hris_client.rb +42 -0
- data/spec/api/employees_api_spec.rb +68 -0
- data/spec/api_client_spec.rb +228 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/employee_result_spec.rb +40 -0
- data/spec/models/employee_spec.rb +124 -0
- data/spec/models/employees_paginated_spec.rb +46 -0
- data/spec/spec_helper.rb +111 -0
- data/stackone_hris_client.gemspec +38 -0
- metadata +118 -0
@@ -0,0 +1,182 @@
|
|
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
|
+
require 'cgi'
|
14
|
+
|
15
|
+
module StackOneHrisClient
|
16
|
+
class EmployeesApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
#
|
23
|
+
# @param id [String]
|
24
|
+
# @param x_account_id [String] The account identifier
|
25
|
+
# @param [Hash] opts the optional parameters
|
26
|
+
# @option opts [String] :page The page number of the results to fetch
|
27
|
+
# @option opts [String] :page_size The number of results per page (default to '25')
|
28
|
+
# @option opts [Boolean] :raw Indicates that the raw request result is returned (default to false)
|
29
|
+
# @option opts [Array<String>] :fields The list of fields to return in the response (if empty, all fields are returned)
|
30
|
+
# @option opts [Array<String>] :expand The list of fields that will be expanded in the response
|
31
|
+
# @return [EmployeeResult]
|
32
|
+
def employees_get(id, x_account_id, opts = {})
|
33
|
+
data, _status_code, _headers = employees_get_with_http_info(id, x_account_id, opts)
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# @param id [String]
|
39
|
+
# @param x_account_id [String] The account identifier
|
40
|
+
# @param [Hash] opts the optional parameters
|
41
|
+
# @option opts [String] :page The page number of the results to fetch
|
42
|
+
# @option opts [String] :page_size The number of results per page (default to '25')
|
43
|
+
# @option opts [Boolean] :raw Indicates that the raw request result is returned (default to false)
|
44
|
+
# @option opts [Array<String>] :fields The list of fields to return in the response (if empty, all fields are returned)
|
45
|
+
# @option opts [Array<String>] :expand The list of fields that will be expanded in the response
|
46
|
+
# @return [Array<(EmployeeResult, Integer, Hash)>] EmployeeResult data, response status code and response headers
|
47
|
+
def employees_get_with_http_info(id, x_account_id, opts = {})
|
48
|
+
if @api_client.config.debugging
|
49
|
+
@api_client.config.logger.debug 'Calling API: EmployeesApi.employees_get ...'
|
50
|
+
end
|
51
|
+
# verify the required parameter 'id' is set
|
52
|
+
if @api_client.config.client_side_validation && id.nil?
|
53
|
+
fail ArgumentError, "Missing the required parameter 'id' when calling EmployeesApi.employees_get"
|
54
|
+
end
|
55
|
+
# verify the required parameter 'x_account_id' is set
|
56
|
+
if @api_client.config.client_side_validation && x_account_id.nil?
|
57
|
+
fail ArgumentError, "Missing the required parameter 'x_account_id' when calling EmployeesApi.employees_get"
|
58
|
+
end
|
59
|
+
# resource path
|
60
|
+
local_var_path = '/unified/hris/employees/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
|
61
|
+
|
62
|
+
# query parameters
|
63
|
+
query_params = opts[:query_params] || {}
|
64
|
+
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
|
65
|
+
query_params[:'page_size'] = opts[:'page_size'] if !opts[:'page_size'].nil?
|
66
|
+
query_params[:'raw'] = opts[:'raw'] if !opts[:'raw'].nil?
|
67
|
+
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :multi) if !opts[:'fields'].nil?
|
68
|
+
query_params[:'expand'] = @api_client.build_collection_param(opts[:'expand'], :multi) if !opts[:'expand'].nil?
|
69
|
+
|
70
|
+
# header parameters
|
71
|
+
header_params = opts[:header_params] || {}
|
72
|
+
# HTTP header 'Accept' (if needed)
|
73
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
74
|
+
header_params[:'x-account-id'] = x_account_id
|
75
|
+
|
76
|
+
# form parameters
|
77
|
+
form_params = opts[:form_params] || {}
|
78
|
+
|
79
|
+
# http body (model)
|
80
|
+
post_body = opts[:debug_body]
|
81
|
+
|
82
|
+
# return_type
|
83
|
+
return_type = opts[:debug_return_type] || 'EmployeeResult'
|
84
|
+
|
85
|
+
# auth_names
|
86
|
+
auth_names = opts[:debug_auth_names] || ['basic']
|
87
|
+
|
88
|
+
new_options = opts.merge(
|
89
|
+
:operation => :"EmployeesApi.employees_get",
|
90
|
+
:header_params => header_params,
|
91
|
+
:query_params => query_params,
|
92
|
+
:form_params => form_params,
|
93
|
+
:body => post_body,
|
94
|
+
:auth_names => auth_names,
|
95
|
+
:return_type => return_type
|
96
|
+
)
|
97
|
+
|
98
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
99
|
+
if @api_client.config.debugging
|
100
|
+
@api_client.config.logger.debug "API called: EmployeesApi#employees_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
101
|
+
end
|
102
|
+
return data, status_code, headers
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# @param x_account_id [String] The account identifier
|
107
|
+
# @param [Hash] opts the optional parameters
|
108
|
+
# @option opts [String] :page The page number of the results to fetch
|
109
|
+
# @option opts [String] :page_size The number of results per page (default to '25')
|
110
|
+
# @option opts [Boolean] :raw Indicates that the raw request result is returned (default to false)
|
111
|
+
# @option opts [Array<String>] :fields The list of fields to return in the response (if empty, all fields are returned)
|
112
|
+
# @option opts [Array<String>] :expand The list of fields that will be expanded in the response
|
113
|
+
# @return [EmployeesPaginated]
|
114
|
+
def employees_list(x_account_id, opts = {})
|
115
|
+
data, _status_code, _headers = employees_list_with_http_info(x_account_id, opts)
|
116
|
+
data
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# @param x_account_id [String] The account identifier
|
121
|
+
# @param [Hash] opts the optional parameters
|
122
|
+
# @option opts [String] :page The page number of the results to fetch
|
123
|
+
# @option opts [String] :page_size The number of results per page (default to '25')
|
124
|
+
# @option opts [Boolean] :raw Indicates that the raw request result is returned (default to false)
|
125
|
+
# @option opts [Array<String>] :fields The list of fields to return in the response (if empty, all fields are returned)
|
126
|
+
# @option opts [Array<String>] :expand The list of fields that will be expanded in the response
|
127
|
+
# @return [Array<(EmployeesPaginated, Integer, Hash)>] EmployeesPaginated data, response status code and response headers
|
128
|
+
def employees_list_with_http_info(x_account_id, opts = {})
|
129
|
+
if @api_client.config.debugging
|
130
|
+
@api_client.config.logger.debug 'Calling API: EmployeesApi.employees_list ...'
|
131
|
+
end
|
132
|
+
# verify the required parameter 'x_account_id' is set
|
133
|
+
if @api_client.config.client_side_validation && x_account_id.nil?
|
134
|
+
fail ArgumentError, "Missing the required parameter 'x_account_id' when calling EmployeesApi.employees_list"
|
135
|
+
end
|
136
|
+
# resource path
|
137
|
+
local_var_path = '/unified/hris/employees'
|
138
|
+
|
139
|
+
# query parameters
|
140
|
+
query_params = opts[:query_params] || {}
|
141
|
+
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
|
142
|
+
query_params[:'page_size'] = opts[:'page_size'] if !opts[:'page_size'].nil?
|
143
|
+
query_params[:'raw'] = opts[:'raw'] if !opts[:'raw'].nil?
|
144
|
+
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :multi) if !opts[:'fields'].nil?
|
145
|
+
query_params[:'expand'] = @api_client.build_collection_param(opts[:'expand'], :multi) if !opts[:'expand'].nil?
|
146
|
+
|
147
|
+
# header parameters
|
148
|
+
header_params = opts[:header_params] || {}
|
149
|
+
# HTTP header 'Accept' (if needed)
|
150
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
151
|
+
header_params[:'x-account-id'] = x_account_id
|
152
|
+
|
153
|
+
# form parameters
|
154
|
+
form_params = opts[:form_params] || {}
|
155
|
+
|
156
|
+
# http body (model)
|
157
|
+
post_body = opts[:debug_body]
|
158
|
+
|
159
|
+
# return_type
|
160
|
+
return_type = opts[:debug_return_type] || 'EmployeesPaginated'
|
161
|
+
|
162
|
+
# auth_names
|
163
|
+
auth_names = opts[:debug_auth_names] || ['basic']
|
164
|
+
|
165
|
+
new_options = opts.merge(
|
166
|
+
:operation => :"EmployeesApi.employees_list",
|
167
|
+
:header_params => header_params,
|
168
|
+
:query_params => query_params,
|
169
|
+
:form_params => form_params,
|
170
|
+
:body => post_body,
|
171
|
+
:auth_names => auth_names,
|
172
|
+
:return_type => return_type
|
173
|
+
)
|
174
|
+
|
175
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
176
|
+
if @api_client.config.debugging
|
177
|
+
@api_client.config.logger.debug "API called: EmployeesApi#employees_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
178
|
+
end
|
179
|
+
return data, status_code, headers
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,392 @@
|
|
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
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'time'
|
18
|
+
require 'typhoeus'
|
19
|
+
|
20
|
+
module StackOneHrisClient
|
21
|
+
class ApiClient
|
22
|
+
# The Configuration object holding settings to be used in the API client.
|
23
|
+
attr_accessor :config
|
24
|
+
|
25
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
28
|
+
attr_accessor :default_headers
|
29
|
+
|
30
|
+
# Initializes the ApiClient
|
31
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
|
+
def initialize(config = Configuration.default)
|
33
|
+
@config = config
|
34
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
35
|
+
@default_headers = {
|
36
|
+
'Content-Type' => 'application/json',
|
37
|
+
'User-Agent' => @user_agent
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.default
|
42
|
+
@@default ||= ApiClient.new
|
43
|
+
end
|
44
|
+
|
45
|
+
# Call an API with given options.
|
46
|
+
#
|
47
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
48
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
49
|
+
def call_api(http_method, path, opts = {})
|
50
|
+
request = build_request(http_method, path, opts)
|
51
|
+
response = request.run
|
52
|
+
|
53
|
+
if @config.debugging
|
54
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
unless response.success?
|
58
|
+
if response.timed_out?
|
59
|
+
fail ApiError.new('Connection timed out')
|
60
|
+
elsif response.code == 0
|
61
|
+
# Errors from libcurl will be made visible here
|
62
|
+
fail ApiError.new(:code => 0,
|
63
|
+
:message => response.return_message)
|
64
|
+
else
|
65
|
+
fail ApiError.new(:code => response.code,
|
66
|
+
:response_headers => response.headers,
|
67
|
+
:response_body => response.body),
|
68
|
+
response.status_message
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if opts[:return_type]
|
73
|
+
data = deserialize(response, opts[:return_type])
|
74
|
+
else
|
75
|
+
data = nil
|
76
|
+
end
|
77
|
+
return data, response.code, response.headers
|
78
|
+
end
|
79
|
+
|
80
|
+
# Builds the HTTP request
|
81
|
+
#
|
82
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
83
|
+
# @param [String] path URL path (e.g. /account/new)
|
84
|
+
# @option opts [Hash] :header_params Header parameters
|
85
|
+
# @option opts [Hash] :query_params Query parameters
|
86
|
+
# @option opts [Hash] :form_params Query parameters
|
87
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
88
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
89
|
+
def build_request(http_method, path, opts = {})
|
90
|
+
url = build_request_url(path, opts)
|
91
|
+
http_method = http_method.to_sym.downcase
|
92
|
+
|
93
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
94
|
+
query_params = opts[:query_params] || {}
|
95
|
+
form_params = opts[:form_params] || {}
|
96
|
+
follow_location = opts[:follow_location] || true
|
97
|
+
|
98
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
99
|
+
|
100
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
101
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
102
|
+
|
103
|
+
req_opts = {
|
104
|
+
:method => http_method,
|
105
|
+
:headers => header_params,
|
106
|
+
:params => query_params,
|
107
|
+
:params_encoding => @config.params_encoding,
|
108
|
+
:timeout => @config.timeout,
|
109
|
+
:ssl_verifypeer => @config.verify_ssl,
|
110
|
+
:ssl_verifyhost => _verify_ssl_host,
|
111
|
+
:sslcert => @config.cert_file,
|
112
|
+
:sslkey => @config.key_file,
|
113
|
+
:verbose => @config.debugging,
|
114
|
+
:followlocation => follow_location
|
115
|
+
}
|
116
|
+
|
117
|
+
# set custom cert, if provided
|
118
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
119
|
+
|
120
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
121
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
122
|
+
req_opts.update :body => req_body
|
123
|
+
if @config.debugging
|
124
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
request = Typhoeus::Request.new(url, req_opts)
|
129
|
+
download_file(request) if opts[:return_type] == 'File'
|
130
|
+
request
|
131
|
+
end
|
132
|
+
|
133
|
+
# Builds the HTTP request body
|
134
|
+
#
|
135
|
+
# @param [Hash] header_params Header parameters
|
136
|
+
# @param [Hash] form_params Query parameters
|
137
|
+
# @param [Object] body HTTP body (JSON/XML)
|
138
|
+
# @return [String] HTTP body data in the form of string
|
139
|
+
def build_request_body(header_params, form_params, body)
|
140
|
+
# http form
|
141
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
142
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
143
|
+
data = {}
|
144
|
+
form_params.each do |key, value|
|
145
|
+
case value
|
146
|
+
when ::File, ::Array, nil
|
147
|
+
# let typhoeus handle File, Array and nil parameters
|
148
|
+
data[key] = value
|
149
|
+
else
|
150
|
+
data[key] = value.to_s
|
151
|
+
end
|
152
|
+
end
|
153
|
+
elsif body
|
154
|
+
data = body.is_a?(String) ? body : body.to_json
|
155
|
+
else
|
156
|
+
data = nil
|
157
|
+
end
|
158
|
+
data
|
159
|
+
end
|
160
|
+
|
161
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
162
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
163
|
+
# The response body is written to the file in chunks in order to handle files which
|
164
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
165
|
+
# process can use.
|
166
|
+
#
|
167
|
+
# @see Configuration#temp_folder_path
|
168
|
+
def download_file(request)
|
169
|
+
tempfile = nil
|
170
|
+
encoding = nil
|
171
|
+
request.on_headers do |response|
|
172
|
+
content_disposition = response.headers['Content-Disposition']
|
173
|
+
if content_disposition && content_disposition =~ /filename=/i
|
174
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
175
|
+
prefix = sanitize_filename(filename)
|
176
|
+
else
|
177
|
+
prefix = 'download-'
|
178
|
+
end
|
179
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
180
|
+
encoding = response.body.encoding
|
181
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
182
|
+
@tempfile = tempfile
|
183
|
+
end
|
184
|
+
request.on_body do |chunk|
|
185
|
+
chunk.force_encoding(encoding)
|
186
|
+
tempfile.write(chunk)
|
187
|
+
end
|
188
|
+
request.on_complete do |response|
|
189
|
+
if tempfile
|
190
|
+
tempfile.close
|
191
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
192
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
193
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
194
|
+
"explicitly with `tempfile.delete`"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Check if the given MIME is a JSON MIME.
|
200
|
+
# JSON MIME examples:
|
201
|
+
# application/json
|
202
|
+
# application/json; charset=UTF8
|
203
|
+
# APPLICATION/JSON
|
204
|
+
# */*
|
205
|
+
# @param [String] mime MIME
|
206
|
+
# @return [Boolean] True if the MIME is application/json
|
207
|
+
def json_mime?(mime)
|
208
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
209
|
+
end
|
210
|
+
|
211
|
+
# Deserialize the response to the given return type.
|
212
|
+
#
|
213
|
+
# @param [Response] response HTTP response
|
214
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
215
|
+
def deserialize(response, return_type)
|
216
|
+
body = response.body
|
217
|
+
|
218
|
+
# handle file downloading - return the File instance processed in request callbacks
|
219
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
220
|
+
return @tempfile if return_type == 'File'
|
221
|
+
|
222
|
+
return nil if body.nil? || body.empty?
|
223
|
+
|
224
|
+
# return response body directly for String return type
|
225
|
+
return body if return_type == 'String'
|
226
|
+
|
227
|
+
# ensuring a default content type
|
228
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
229
|
+
|
230
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
231
|
+
|
232
|
+
begin
|
233
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
234
|
+
rescue JSON::ParserError => e
|
235
|
+
if %w(String Date Time).include?(return_type)
|
236
|
+
data = body
|
237
|
+
else
|
238
|
+
raise e
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
convert_to_type data, return_type
|
243
|
+
end
|
244
|
+
|
245
|
+
# Convert data to the given return type.
|
246
|
+
# @param [Object] data Data to be converted
|
247
|
+
# @param [String] return_type Return type
|
248
|
+
# @return [Mixed] Data in a particular type
|
249
|
+
def convert_to_type(data, return_type)
|
250
|
+
return nil if data.nil?
|
251
|
+
case return_type
|
252
|
+
when 'String'
|
253
|
+
data.to_s
|
254
|
+
when 'Integer'
|
255
|
+
data.to_i
|
256
|
+
when 'Float'
|
257
|
+
data.to_f
|
258
|
+
when 'Boolean'
|
259
|
+
data == true
|
260
|
+
when 'Time'
|
261
|
+
# parse date time (expecting ISO 8601 format)
|
262
|
+
Time.parse data
|
263
|
+
when 'Date'
|
264
|
+
# parse date time (expecting ISO 8601 format)
|
265
|
+
Date.parse data
|
266
|
+
when 'Object'
|
267
|
+
# generic object (usually a Hash), return directly
|
268
|
+
data
|
269
|
+
when /\AArray<(.+)>\z/
|
270
|
+
# e.g. Array<Pet>
|
271
|
+
sub_type = $1
|
272
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
273
|
+
when /\AHash\<String, (.+)\>\z/
|
274
|
+
# e.g. Hash<String, Integer>
|
275
|
+
sub_type = $1
|
276
|
+
{}.tap do |hash|
|
277
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
278
|
+
end
|
279
|
+
else
|
280
|
+
# models (e.g. Pet) or oneOf
|
281
|
+
klass = StackOneHrisClient.const_get(return_type)
|
282
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
# Sanitize filename by removing path.
|
287
|
+
# e.g. ../../sun.gif becomes sun.gif
|
288
|
+
#
|
289
|
+
# @param [String] filename the filename to be sanitized
|
290
|
+
# @return [String] the sanitized filename
|
291
|
+
def sanitize_filename(filename)
|
292
|
+
filename.gsub(/.*[\/\\]/, '')
|
293
|
+
end
|
294
|
+
|
295
|
+
def build_request_url(path, opts = {})
|
296
|
+
# Add leading and trailing slashes to path
|
297
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
298
|
+
@config.base_url(opts[:operation]) + path
|
299
|
+
end
|
300
|
+
|
301
|
+
# Update header and query params based on authentication settings.
|
302
|
+
#
|
303
|
+
# @param [Hash] header_params Header parameters
|
304
|
+
# @param [Hash] query_params Query parameters
|
305
|
+
# @param [String] auth_names Authentication scheme name
|
306
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
307
|
+
Array(auth_names).each do |auth_name|
|
308
|
+
auth_setting = @config.auth_settings[auth_name]
|
309
|
+
next unless auth_setting
|
310
|
+
case auth_setting[:in]
|
311
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
312
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
313
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
# Sets user agent in HTTP header
|
319
|
+
#
|
320
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
321
|
+
def user_agent=(user_agent)
|
322
|
+
@user_agent = user_agent
|
323
|
+
@default_headers['User-Agent'] = @user_agent
|
324
|
+
end
|
325
|
+
|
326
|
+
# Return Accept header based on an array of accepts provided.
|
327
|
+
# @param [Array] accepts array for Accept
|
328
|
+
# @return [String] the Accept header (e.g. application/json)
|
329
|
+
def select_header_accept(accepts)
|
330
|
+
return nil if accepts.nil? || accepts.empty?
|
331
|
+
# use JSON when present, otherwise use all of the provided
|
332
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
333
|
+
json_accept || accepts.join(',')
|
334
|
+
end
|
335
|
+
|
336
|
+
# Return Content-Type header based on an array of content types provided.
|
337
|
+
# @param [Array] content_types array for Content-Type
|
338
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
339
|
+
def select_header_content_type(content_types)
|
340
|
+
# return nil by default
|
341
|
+
return if content_types.nil? || content_types.empty?
|
342
|
+
# use JSON when present, otherwise use the first one
|
343
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
344
|
+
json_content_type || content_types.first
|
345
|
+
end
|
346
|
+
|
347
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
348
|
+
# @param [Object] model object to be converted into JSON string
|
349
|
+
# @return [String] JSON string representation of the object
|
350
|
+
def object_to_http_body(model)
|
351
|
+
return model if model.nil? || model.is_a?(String)
|
352
|
+
local_body = nil
|
353
|
+
if model.is_a?(Array)
|
354
|
+
local_body = model.map { |m| object_to_hash(m) }
|
355
|
+
else
|
356
|
+
local_body = object_to_hash(model)
|
357
|
+
end
|
358
|
+
local_body.to_json
|
359
|
+
end
|
360
|
+
|
361
|
+
# Convert object(non-array) to hash.
|
362
|
+
# @param [Object] obj object to be converted into JSON string
|
363
|
+
# @return [String] JSON string representation of the object
|
364
|
+
def object_to_hash(obj)
|
365
|
+
if obj.respond_to?(:to_hash)
|
366
|
+
obj.to_hash
|
367
|
+
else
|
368
|
+
obj
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
# Build parameter value according to the given collection format.
|
373
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
374
|
+
def build_collection_param(param, collection_format)
|
375
|
+
case collection_format
|
376
|
+
when :csv
|
377
|
+
param.join(',')
|
378
|
+
when :ssv
|
379
|
+
param.join(' ')
|
380
|
+
when :tsv
|
381
|
+
param.join("\t")
|
382
|
+
when :pipes
|
383
|
+
param.join('|')
|
384
|
+
when :multi
|
385
|
+
# return the array directly as typhoeus will handle it as expected
|
386
|
+
param
|
387
|
+
else
|
388
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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 ApiError < StandardError
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
16
|
+
|
17
|
+
# Usage examples:
|
18
|
+
# ApiError.new
|
19
|
+
# ApiError.new("message")
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
22
|
+
def initialize(arg = nil)
|
23
|
+
if arg.is_a? Hash
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
25
|
+
super(arg[:message] || arg['message'])
|
26
|
+
else
|
27
|
+
super arg
|
28
|
+
end
|
29
|
+
|
30
|
+
arg.each do |k, v|
|
31
|
+
instance_variable_set "@#{k}", v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super arg
|
35
|
+
@message = arg
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Override to_s to display a friendly error message
|
40
|
+
def to_s
|
41
|
+
message
|
42
|
+
end
|
43
|
+
|
44
|
+
def message
|
45
|
+
if @message.nil?
|
46
|
+
msg = "Error message: the server returns an error"
|
47
|
+
else
|
48
|
+
msg = @message
|
49
|
+
end
|
50
|
+
|
51
|
+
msg += "\nHTTP status code: #{code}" if code
|
52
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
53
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
54
|
+
|
55
|
+
msg
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|