quake_timesheets_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/GENERATING_README.md +17 -0
- data/Gemfile +9 -0
- data/README.md +161 -0
- data/Rakefile +10 -0
- data/build.sh +10 -0
- data/commands +13 -0
- data/docs/Approval.md +34 -0
- data/docs/ApprovalType.md +24 -0
- data/docs/ApprovalTypesApi.md +153 -0
- data/docs/ApprovalsApi.md +153 -0
- data/docs/Dataset.md +24 -0
- data/docs/DatasetsApi.md +214 -0
- data/docs/EntriesApi.md +251 -0
- data/docs/Entry.md +36 -0
- data/docs/PeopleApi.md +151 -0
- data/docs/Person.md +22 -0
- data/git_push.sh +58 -0
- data/lib/quake_timesheets_client.rb +58 -0
- data/lib/quake_timesheets_client/api/approval_types_api.rb +158 -0
- data/lib/quake_timesheets_client/api/approvals_api.rb +174 -0
- data/lib/quake_timesheets_client/api/datasets_api.rb +202 -0
- data/lib/quake_timesheets_client/api/entries_api.rb +253 -0
- data/lib/quake_timesheets_client/api/people_api.rb +151 -0
- data/lib/quake_timesheets_client/api_client.rb +396 -0
- data/lib/quake_timesheets_client/api_error.rb +57 -0
- data/lib/quake_timesheets_client/configuration.rb +302 -0
- data/lib/quake_timesheets_client/models/approval.rb +378 -0
- data/lib/quake_timesheets_client/models/approval_type.rb +269 -0
- data/lib/quake_timesheets_client/models/dataset.rb +268 -0
- data/lib/quake_timesheets_client/models/entry.rb +361 -0
- data/lib/quake_timesheets_client/models/person.rb +254 -0
- data/lib/quake_timesheets_client/version.rb +24 -0
- data/quake_timesheets_client.gemspec +38 -0
- data/ruby-templates/README.mustache +187 -0
- data/ruby-templates/api_client.mustache +263 -0
- data/ruby-templates/api_client_faraday_partial.mustache +140 -0
- data/ruby-templates/configuration.mustache +379 -0
- data/ruby-templates/gem.mustache +59 -0
- data/ruby-templates/version.mustache +16 -0
- data/ruby.config.yaml +10 -0
- data/spec/api/approval_types_api_spec.rb +59 -0
- data/spec/api/approvals_api_spec.rb +60 -0
- data/spec/api/datasets_api_spec.rb +67 -0
- data/spec/api/entries_api_spec.rb +82 -0
- data/spec/api/people_api_spec.rb +58 -0
- data/spec/api_client_spec.rb +188 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/approval_spec.rb +86 -0
- data/spec/models/approval_type_spec.rb +52 -0
- data/spec/models/dataset_spec.rb +52 -0
- data/spec/models/entry_spec.rb +92 -0
- data/spec/models/person_spec.rb +46 -0
- data/spec/spec_helper.rb +111 -0
- metadata +149 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
=begin
|
2
|
+
#TimesheetsApi (params in:formData)
|
3
|
+
|
4
|
+
# <p>Another API description</p>
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.1.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'cgi'
|
14
|
+
|
15
|
+
module Quake::Timesheets
|
16
|
+
class PeopleApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
# Search for people matching filters
|
23
|
+
# @param [Hash] opts the optional parameters
|
24
|
+
# @option opts [String] :dataset_id Filter to the people belonging to one of the identified datasets
|
25
|
+
# @return [Array<Person>]
|
26
|
+
def get_api_v1_people(opts = {})
|
27
|
+
data, _status_code, _headers = get_api_v1_people_with_http_info(opts)
|
28
|
+
data
|
29
|
+
end
|
30
|
+
|
31
|
+
# Search for people matching filters
|
32
|
+
# @param [Hash] opts the optional parameters
|
33
|
+
# @option opts [String] :dataset_id Filter to the people belonging to one of the identified datasets
|
34
|
+
# @return [Array<(Array<Person>, Integer, Hash)>] Array<Person> data, response status code and response headers
|
35
|
+
def get_api_v1_people_with_http_info(opts = {})
|
36
|
+
if @api_client.config.debugging
|
37
|
+
@api_client.config.logger.debug 'Calling API: PeopleApi.get_api_v1_people ...'
|
38
|
+
end
|
39
|
+
# resource path
|
40
|
+
local_var_path = '/api/v1/people'
|
41
|
+
|
42
|
+
# query parameters
|
43
|
+
query_params = opts[:query_params] || {}
|
44
|
+
query_params[:'dataset_id'] = opts[:'dataset_id'] if !opts[:'dataset_id'].nil?
|
45
|
+
|
46
|
+
# header parameters
|
47
|
+
header_params = opts[:header_params] || {}
|
48
|
+
# HTTP header 'Accept' (if needed)
|
49
|
+
header_params['Accept'] = @api_client.select_header_accept(['*/*'])
|
50
|
+
|
51
|
+
# form parameters
|
52
|
+
form_params = opts[:form_params] || {}
|
53
|
+
|
54
|
+
# http body (model)
|
55
|
+
post_body = opts[:debug_body]
|
56
|
+
|
57
|
+
# return_type
|
58
|
+
return_type = opts[:debug_return_type] || 'Array<Person>'
|
59
|
+
|
60
|
+
# auth_names
|
61
|
+
auth_names = opts[:debug_auth_names] || ['authToken']
|
62
|
+
|
63
|
+
new_options = opts.merge(
|
64
|
+
:operation => :"PeopleApi.get_api_v1_people",
|
65
|
+
:header_params => header_params,
|
66
|
+
:query_params => query_params,
|
67
|
+
:form_params => form_params,
|
68
|
+
:body => post_body,
|
69
|
+
:auth_names => auth_names,
|
70
|
+
:return_type => return_type
|
71
|
+
)
|
72
|
+
|
73
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
74
|
+
if @api_client.config.debugging
|
75
|
+
@api_client.config.logger.debug "API called: PeopleApi#get_api_v1_people\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
76
|
+
end
|
77
|
+
return data, status_code, headers
|
78
|
+
end
|
79
|
+
|
80
|
+
# Create a new Person record
|
81
|
+
# @param name [String] Human readable name for the Person object (usually the subject's real name)
|
82
|
+
# @param dataset_id [String] Dataset to which the Person object should belong
|
83
|
+
# @param [Hash] opts the optional parameters
|
84
|
+
# @return [Person]
|
85
|
+
def post_api_v1_people(name, dataset_id, opts = {})
|
86
|
+
data, _status_code, _headers = post_api_v1_people_with_http_info(name, dataset_id, opts)
|
87
|
+
data
|
88
|
+
end
|
89
|
+
|
90
|
+
# Create a new Person record
|
91
|
+
# @param name [String] Human readable name for the Person object (usually the subject's real name)
|
92
|
+
# @param dataset_id [String] Dataset to which the Person object should belong
|
93
|
+
# @param [Hash] opts the optional parameters
|
94
|
+
# @return [Array<(Person, Integer, Hash)>] Person data, response status code and response headers
|
95
|
+
def post_api_v1_people_with_http_info(name, dataset_id, opts = {})
|
96
|
+
if @api_client.config.debugging
|
97
|
+
@api_client.config.logger.debug 'Calling API: PeopleApi.post_api_v1_people ...'
|
98
|
+
end
|
99
|
+
# verify the required parameter 'name' is set
|
100
|
+
if @api_client.config.client_side_validation && name.nil?
|
101
|
+
fail ArgumentError, "Missing the required parameter 'name' when calling PeopleApi.post_api_v1_people"
|
102
|
+
end
|
103
|
+
# verify the required parameter 'dataset_id' is set
|
104
|
+
if @api_client.config.client_side_validation && dataset_id.nil?
|
105
|
+
fail ArgumentError, "Missing the required parameter 'dataset_id' when calling PeopleApi.post_api_v1_people"
|
106
|
+
end
|
107
|
+
# resource path
|
108
|
+
local_var_path = '/api/v1/people'
|
109
|
+
|
110
|
+
# query parameters
|
111
|
+
query_params = opts[:query_params] || {}
|
112
|
+
|
113
|
+
# header parameters
|
114
|
+
header_params = opts[:header_params] || {}
|
115
|
+
# HTTP header 'Accept' (if needed)
|
116
|
+
header_params['Accept'] = @api_client.select_header_accept(['*/*'])
|
117
|
+
# HTTP header 'Content-Type'
|
118
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/x-www-form-urlencoded', 'multipart/form-data'])
|
119
|
+
|
120
|
+
# form parameters
|
121
|
+
form_params = opts[:form_params] || {}
|
122
|
+
form_params['name'] = name
|
123
|
+
form_params['dataset_id'] = dataset_id
|
124
|
+
|
125
|
+
# http body (model)
|
126
|
+
post_body = opts[:debug_body]
|
127
|
+
|
128
|
+
# return_type
|
129
|
+
return_type = opts[:debug_return_type] || 'Person'
|
130
|
+
|
131
|
+
# auth_names
|
132
|
+
auth_names = opts[:debug_auth_names] || ['authToken']
|
133
|
+
|
134
|
+
new_options = opts.merge(
|
135
|
+
:operation => :"PeopleApi.post_api_v1_people",
|
136
|
+
:header_params => header_params,
|
137
|
+
:query_params => query_params,
|
138
|
+
:form_params => form_params,
|
139
|
+
:body => post_body,
|
140
|
+
:auth_names => auth_names,
|
141
|
+
:return_type => return_type
|
142
|
+
)
|
143
|
+
|
144
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
145
|
+
if @api_client.config.debugging
|
146
|
+
@api_client.config.logger.debug "API called: PeopleApi#post_api_v1_people\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
147
|
+
end
|
148
|
+
return data, status_code, headers
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,396 @@
|
|
1
|
+
=begin
|
2
|
+
#TimesheetsApi (params in:formData)
|
3
|
+
|
4
|
+
# <p>Another API description</p>
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.1.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'time'
|
18
|
+
require 'faraday'
|
19
|
+
|
20
|
+
module Quake::Timesheets
|
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
|
+
@default_headers = {
|
35
|
+
'Content-Type' => 'application/json',
|
36
|
+
'User-Agent' => config.user_agent
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default
|
41
|
+
@@default ||= ApiClient.new
|
42
|
+
end
|
43
|
+
|
44
|
+
# Call an API with given options.
|
45
|
+
#
|
46
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
47
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
48
|
+
def call_api(http_method, path, opts = {})
|
49
|
+
ssl_options = {
|
50
|
+
:ca_file => @config.ssl_ca_file,
|
51
|
+
:verify => @config.ssl_verify,
|
52
|
+
:verify_mode => @config.ssl_verify_mode,
|
53
|
+
:client_cert => @config.ssl_client_cert,
|
54
|
+
:client_key => @config.ssl_client_key
|
55
|
+
}
|
56
|
+
|
57
|
+
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
|
58
|
+
if opts[:header_params]["Content-Type"] == "multipart/form-data"
|
59
|
+
conn.request :multipart
|
60
|
+
conn.request :url_encoded
|
61
|
+
end
|
62
|
+
|
63
|
+
config.faraday_middlewares.each { |middleware| conn.use middleware }
|
64
|
+
|
65
|
+
conn.adapter(Faraday.default_adapter)
|
66
|
+
end
|
67
|
+
|
68
|
+
begin
|
69
|
+
response = connection.public_send(http_method.to_sym.downcase) do |req|
|
70
|
+
build_request(http_method, path, req, opts)
|
71
|
+
end
|
72
|
+
|
73
|
+
if @config.debugging
|
74
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
unless response.success?
|
78
|
+
if response.status == 0
|
79
|
+
# Errors from libcurl will be made visible here
|
80
|
+
fail ApiError.new(:code => 0,
|
81
|
+
:message => response.return_message)
|
82
|
+
else
|
83
|
+
fail ApiError.new(:code => response.status,
|
84
|
+
:response_headers => response.headers,
|
85
|
+
:response_body => response.body),
|
86
|
+
response.reason_phrase
|
87
|
+
end
|
88
|
+
end
|
89
|
+
rescue Faraday::TimeoutError
|
90
|
+
fail ApiError.new('Connection timed out')
|
91
|
+
end
|
92
|
+
|
93
|
+
if opts[:return_type]
|
94
|
+
data = deserialize(response, opts[:return_type])
|
95
|
+
else
|
96
|
+
data = nil
|
97
|
+
end
|
98
|
+
return data, response.status, response.headers
|
99
|
+
end
|
100
|
+
|
101
|
+
# Builds the HTTP request
|
102
|
+
#
|
103
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
104
|
+
# @param [String] path URL path (e.g. /account/new)
|
105
|
+
# @option opts [Hash] :header_params Header parameters
|
106
|
+
# @option opts [Hash] :query_params Query parameters
|
107
|
+
# @option opts [Hash] :form_params Query parameters
|
108
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
109
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
110
|
+
def build_request(http_method, path, request, opts = {})
|
111
|
+
url = build_request_url(path, opts)
|
112
|
+
http_method = http_method.to_sym.downcase
|
113
|
+
|
114
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
115
|
+
query_params = opts[:query_params] || {}
|
116
|
+
form_params = opts[:form_params] || {}
|
117
|
+
|
118
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
119
|
+
|
120
|
+
req_opts = {
|
121
|
+
:method => http_method,
|
122
|
+
:headers => header_params,
|
123
|
+
:params => query_params,
|
124
|
+
:params_encoding => @config.params_encoding,
|
125
|
+
:timeout => @config.timeout,
|
126
|
+
:verbose => @config.debugging
|
127
|
+
}
|
128
|
+
|
129
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
130
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
131
|
+
req_opts.update :body => req_body
|
132
|
+
if @config.debugging
|
133
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
request.headers = header_params
|
137
|
+
request.body = req_body
|
138
|
+
request.url url
|
139
|
+
request.params = query_params
|
140
|
+
download_file(request) if opts[:return_type] == 'File'
|
141
|
+
request
|
142
|
+
end
|
143
|
+
|
144
|
+
# Builds the HTTP request body
|
145
|
+
#
|
146
|
+
# @param [Hash] header_params Header parameters
|
147
|
+
# @param [Hash] form_params Query parameters
|
148
|
+
# @param [Object] body HTTP body (JSON/XML)
|
149
|
+
# @return [String] HTTP body data in the form of string
|
150
|
+
def build_request_body(header_params, form_params, body)
|
151
|
+
# http form
|
152
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
153
|
+
data = URI.encode_www_form(form_params)
|
154
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
155
|
+
data = {}
|
156
|
+
form_params.each do |key, value|
|
157
|
+
case value
|
158
|
+
when ::File, ::Tempfile
|
159
|
+
# TODO hardcode to application/octet-stream, need better way to detect content type
|
160
|
+
data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
|
161
|
+
when ::Array, nil
|
162
|
+
# let Faraday handle Array and nil parameters
|
163
|
+
data[key] = value
|
164
|
+
else
|
165
|
+
data[key] = value.to_s
|
166
|
+
end
|
167
|
+
end
|
168
|
+
elsif body
|
169
|
+
data = body.is_a?(String) ? body : body.to_json
|
170
|
+
else
|
171
|
+
data = nil
|
172
|
+
end
|
173
|
+
data
|
174
|
+
end
|
175
|
+
|
176
|
+
def download_file(request)
|
177
|
+
@stream = []
|
178
|
+
|
179
|
+
# handle streaming Responses
|
180
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
181
|
+
@stream << chunk
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Check if the given MIME is a JSON MIME.
|
186
|
+
# JSON MIME examples:
|
187
|
+
# application/json
|
188
|
+
# application/json; charset=UTF8
|
189
|
+
# APPLICATION/JSON
|
190
|
+
# */*
|
191
|
+
# @param [String] mime MIME
|
192
|
+
# @return [Boolean] True if the MIME is application/json
|
193
|
+
def json_mime?(mime)
|
194
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
195
|
+
end
|
196
|
+
|
197
|
+
# Deserialize the response to the given return type.
|
198
|
+
#
|
199
|
+
# @param [Response] response HTTP response
|
200
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
201
|
+
def deserialize(response, return_type)
|
202
|
+
body = response.body
|
203
|
+
|
204
|
+
# handle file downloading - return the File instance processed in request callbacks
|
205
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
206
|
+
if return_type == 'File'
|
207
|
+
content_disposition = response.headers['Content-Disposition']
|
208
|
+
if content_disposition && content_disposition =~ /filename=/i
|
209
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
210
|
+
prefix = sanitize_filename(filename)
|
211
|
+
else
|
212
|
+
prefix = 'download-'
|
213
|
+
end
|
214
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
215
|
+
encoding = body.encoding
|
216
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
217
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
218
|
+
@tempfile.close
|
219
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
220
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
221
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
222
|
+
"explicitly with `tempfile.delete`"
|
223
|
+
return @tempfile
|
224
|
+
end
|
225
|
+
|
226
|
+
return nil if body.nil? || body.empty?
|
227
|
+
|
228
|
+
# return response body directly for String return type
|
229
|
+
return body if return_type == 'String'
|
230
|
+
|
231
|
+
# ensuring a default content type
|
232
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
233
|
+
|
234
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
235
|
+
|
236
|
+
begin
|
237
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
238
|
+
rescue JSON::ParserError => e
|
239
|
+
if %w(String Date Time).include?(return_type)
|
240
|
+
data = body
|
241
|
+
else
|
242
|
+
raise e
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
convert_to_type data, return_type
|
247
|
+
end
|
248
|
+
|
249
|
+
# Convert data to the given return type.
|
250
|
+
# @param [Object] data Data to be converted
|
251
|
+
# @param [String] return_type Return type
|
252
|
+
# @return [Mixed] Data in a particular type
|
253
|
+
def convert_to_type(data, return_type)
|
254
|
+
return nil if data.nil?
|
255
|
+
case return_type
|
256
|
+
when 'String'
|
257
|
+
data.to_s
|
258
|
+
when 'Integer'
|
259
|
+
data.to_i
|
260
|
+
when 'Float'
|
261
|
+
data.to_f
|
262
|
+
when 'Boolean'
|
263
|
+
data == true
|
264
|
+
when 'Time'
|
265
|
+
# parse date time (expecting ISO 8601 format)
|
266
|
+
Time.parse data
|
267
|
+
when 'Date'
|
268
|
+
# parse date time (expecting ISO 8601 format)
|
269
|
+
Date.parse data
|
270
|
+
when 'Object'
|
271
|
+
# generic object (usually a Hash), return directly
|
272
|
+
data
|
273
|
+
when /\AArray<(.+)>\z/
|
274
|
+
# e.g. Array<Pet>
|
275
|
+
sub_type = $1
|
276
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
277
|
+
when /\AHash\<String, (.+)\>\z/
|
278
|
+
# e.g. Hash<String, Integer>
|
279
|
+
sub_type = $1
|
280
|
+
{}.tap do |hash|
|
281
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
282
|
+
end
|
283
|
+
else
|
284
|
+
# models (e.g. Pet) or oneOf
|
285
|
+
klass = Quake::Timesheets.const_get(return_type)
|
286
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# Sanitize filename by removing path.
|
291
|
+
# e.g. ../../sun.gif becomes sun.gif
|
292
|
+
#
|
293
|
+
# @param [String] filename the filename to be sanitized
|
294
|
+
# @return [String] the sanitized filename
|
295
|
+
def sanitize_filename(filename)
|
296
|
+
filename.gsub(/.*[\/\\]/, '')
|
297
|
+
end
|
298
|
+
|
299
|
+
def build_request_url(path, opts = {})
|
300
|
+
# Add leading and trailing slashes to path
|
301
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
302
|
+
@config.base_url(opts[:operation]) + path
|
303
|
+
end
|
304
|
+
|
305
|
+
# Update hearder and query params based on authentication settings.
|
306
|
+
#
|
307
|
+
# @param [Hash] header_params Header parameters
|
308
|
+
# @param [Hash] query_params Query parameters
|
309
|
+
# @param [String] auth_names Authentication scheme name
|
310
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
311
|
+
Array(auth_names).each do |auth_name|
|
312
|
+
auth_setting = @config.auth_settings[auth_name]
|
313
|
+
next unless auth_setting
|
314
|
+
case auth_setting[:in]
|
315
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
316
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
317
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
# Sets user agent in HTTP header
|
323
|
+
#
|
324
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
325
|
+
def user_agent=(user_agent)
|
326
|
+
@user_agent = user_agent
|
327
|
+
@default_headers['User-Agent'] = @user_agent
|
328
|
+
end
|
329
|
+
|
330
|
+
# Return Accept header based on an array of accepts provided.
|
331
|
+
# @param [Array] accepts array for Accept
|
332
|
+
# @return [String] the Accept header (e.g. application/json)
|
333
|
+
def select_header_accept(accepts)
|
334
|
+
return nil if accepts.nil? || accepts.empty?
|
335
|
+
# use JSON when present, otherwise use all of the provided
|
336
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
337
|
+
json_accept || accepts.join(',')
|
338
|
+
end
|
339
|
+
|
340
|
+
# Return Content-Type header based on an array of content types provided.
|
341
|
+
# @param [Array] content_types array for Content-Type
|
342
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
343
|
+
def select_header_content_type(content_types)
|
344
|
+
# use application/json by default
|
345
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
346
|
+
# use JSON when present, otherwise use the first one
|
347
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
348
|
+
json_content_type || content_types.first
|
349
|
+
end
|
350
|
+
|
351
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
352
|
+
# @param [Object] model object to be converted into JSON string
|
353
|
+
# @return [String] JSON string representation of the object
|
354
|
+
def object_to_http_body(model)
|
355
|
+
return model if model.nil? || model.is_a?(String)
|
356
|
+
local_body = nil
|
357
|
+
if model.is_a?(Array)
|
358
|
+
local_body = model.map { |m| object_to_hash(m) }
|
359
|
+
else
|
360
|
+
local_body = object_to_hash(model)
|
361
|
+
end
|
362
|
+
local_body.to_json
|
363
|
+
end
|
364
|
+
|
365
|
+
# Convert object(non-array) to hash.
|
366
|
+
# @param [Object] obj object to be converted into JSON string
|
367
|
+
# @return [String] JSON string representation of the object
|
368
|
+
def object_to_hash(obj)
|
369
|
+
if obj.respond_to?(:to_hash)
|
370
|
+
obj.to_hash
|
371
|
+
else
|
372
|
+
obj
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
# Build parameter value according to the given collection format.
|
377
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
378
|
+
def build_collection_param(param, collection_format)
|
379
|
+
case collection_format
|
380
|
+
when :csv
|
381
|
+
param.join(',')
|
382
|
+
when :ssv
|
383
|
+
param.join(' ')
|
384
|
+
when :tsv
|
385
|
+
param.join("\t")
|
386
|
+
when :pipes
|
387
|
+
param.join('|')
|
388
|
+
when :multi
|
389
|
+
# return the array directly as typhoeus will handle it as expected
|
390
|
+
param
|
391
|
+
else
|
392
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|