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,24 @@
|
|
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
|
+
# Pre-define base modules
|
14
|
+
'Quake::Timesheets'.split('::').reduce(Object) do |previous, mod|
|
15
|
+
if previous.const_defined?(mod.to_sym)
|
16
|
+
previous.const_get(mod.to_sym)
|
17
|
+
else
|
18
|
+
previous.const_set(mod.to_sym, Module.new)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Quake::Timesheets
|
23
|
+
VERSION = '0.1.0'
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
=begin
|
4
|
+
#TimesheetsApi (params in:formData)
|
5
|
+
|
6
|
+
# <p>Another API description</p>
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.0
|
9
|
+
|
10
|
+
Generated by: https://openapi-generator.tech
|
11
|
+
OpenAPI Generator version: 5.1.0
|
12
|
+
|
13
|
+
=end
|
14
|
+
|
15
|
+
$:.push File.expand_path("../lib", __FILE__)
|
16
|
+
require "quake_timesheets_client/version"
|
17
|
+
|
18
|
+
Gem::Specification.new do |s|
|
19
|
+
s.name = "quake_timesheets_client"
|
20
|
+
s.version = Quake::Timesheets::VERSION
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.authors = ["OpenAPI-Generator"]
|
23
|
+
s.email = [""]
|
24
|
+
s.homepage = "https://www.quake.co.uk"
|
25
|
+
s.summary = "A client for the Quake Timesheets API"
|
26
|
+
s.description = "Requires the Quake Timesheets system"
|
27
|
+
s.license = "MIT"
|
28
|
+
s.required_ruby_version = ">= 2.7"
|
29
|
+
|
30
|
+
s.add_runtime_dependency 'faraday', '~> 1.0', '>= 1.0.1'
|
31
|
+
|
32
|
+
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
33
|
+
|
34
|
+
s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
|
35
|
+
s.test_files = `find spec/*`.split("\n")
|
36
|
+
s.executables = []
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# {{gemName}}
|
2
|
+
|
3
|
+
{{moduleName}} - the Ruby gem for the {{appName}}
|
4
|
+
|
5
|
+
{{#appDescriptionWithNewLines}}
|
6
|
+
{{{appDescriptionWithNewLines}}}
|
7
|
+
{{/appDescriptionWithNewLines}}
|
8
|
+
|
9
|
+
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
10
|
+
|
11
|
+
- API version: {{appVersion}}
|
12
|
+
- Package version: {{gemVersion}}
|
13
|
+
{{^hideGenerationTimestamp}}
|
14
|
+
- Build date: {{generatedDate}}
|
15
|
+
{{/hideGenerationTimestamp}}
|
16
|
+
- Build package: {{generatorClass}}
|
17
|
+
{{#infoUrl}}
|
18
|
+
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
19
|
+
{{/infoUrl}}
|
20
|
+
|
21
|
+
## Generating
|
22
|
+
|
23
|
+
To re-generate the source for this gem, use the command:
|
24
|
+
```shell
|
25
|
+
./build.sh
|
26
|
+
```
|
27
|
+
|
28
|
+
To generate from a local timesheets installation (e.g. during development) use:
|
29
|
+
```shell
|
30
|
+
./build.sh local
|
31
|
+
```
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
### Build a gem
|
36
|
+
|
37
|
+
To build the Ruby code into a gem:
|
38
|
+
|
39
|
+
```shell
|
40
|
+
gem build {{{gemName}}}.gemspec
|
41
|
+
```
|
42
|
+
|
43
|
+
Then either install the gem locally:
|
44
|
+
|
45
|
+
```shell
|
46
|
+
gem install ./{{{gemName}}}-{{{gemVersion}}}.gem
|
47
|
+
```
|
48
|
+
|
49
|
+
(for development, run `gem install --dev ./{{{gemName}}}-{{{gemVersion}}}.gem` to install the development dependencies)
|
50
|
+
|
51
|
+
or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
|
52
|
+
|
53
|
+
Finally add this to the Gemfile:
|
54
|
+
|
55
|
+
gem '{{{gemName}}}', '~> {{{gemVersion}}}'
|
56
|
+
|
57
|
+
### Install from Git
|
58
|
+
|
59
|
+
If the Ruby gem is hosted at a git repository: https://{{gitHost}}/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}, then add the following in the Gemfile:
|
60
|
+
|
61
|
+
gem '{{{gemName}}}', :git => 'https://{{gitHost}}/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}.git'
|
62
|
+
|
63
|
+
### Include the Ruby code directly
|
64
|
+
|
65
|
+
Include the Ruby code directly using `-I` as follows:
|
66
|
+
|
67
|
+
```shell
|
68
|
+
ruby -Ilib script.rb
|
69
|
+
```
|
70
|
+
|
71
|
+
## Getting Started
|
72
|
+
|
73
|
+
Please follow the [installation](#installation) procedure and then run the following code:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
# Load the gem
|
77
|
+
require '{{{gemName}}}'
|
78
|
+
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}
|
79
|
+
# Setup authorization
|
80
|
+
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
81
|
+
# Configure HTTP basic authorization: {{{name}}}
|
82
|
+
config.username = 'YOUR_USERNAME'
|
83
|
+
config.password = 'YOUR_PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}}
|
84
|
+
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
|
85
|
+
config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
|
86
|
+
# Configure API key authorization: {{{name}}}
|
87
|
+
config.api_key['{{{name}}}'] = 'YOUR API KEY'{{/isApiKey}}{{#isOAuth}}
|
88
|
+
# Configure OAuth2 access token for authorization: {{{name}}}
|
89
|
+
config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
|
90
|
+
{{/authMethods}}end
|
91
|
+
{{/hasAuthMethods}}
|
92
|
+
|
93
|
+
# Optionally, for local development, you can override the endpoint being used with the below:
|
94
|
+
{{{moduleName}}}.configure do |config|
|
95
|
+
config.endpoint = 'http://localhost:3000'
|
96
|
+
end
|
97
|
+
|
98
|
+
api_instance = {{{moduleName}}}::{{{classname}}}.new
|
99
|
+
{{#requiredParams}}
|
100
|
+
{{{paramName}}} = {{{vendorExtensions.x-ruby-example}}} # {{{dataType}}} | {{{description}}}
|
101
|
+
{{/requiredParams}}
|
102
|
+
{{#optionalParams}}
|
103
|
+
{{#-first}}
|
104
|
+
opts = {
|
105
|
+
{{/-first}}
|
106
|
+
{{{paramName}}}: {{{vendorExtensions.x-ruby-example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}}
|
107
|
+
{{#-last}}
|
108
|
+
}
|
109
|
+
{{/-last}}
|
110
|
+
{{/optionalParams}}
|
111
|
+
|
112
|
+
begin
|
113
|
+
{{#summary}} #{{{.}}}
|
114
|
+
{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}{{#returnType}}
|
115
|
+
p result{{/returnType}}
|
116
|
+
rescue {{{moduleName}}}::ApiError => e
|
117
|
+
puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}"
|
118
|
+
end
|
119
|
+
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
|
120
|
+
```
|
121
|
+
|
122
|
+
## Documentation for API Endpoints
|
123
|
+
|
124
|
+
All URIs are relative to *{{basePath}}*
|
125
|
+
|
126
|
+
Class | Method | HTTP request | Description
|
127
|
+
------------ | ------------- | ------------- | -------------
|
128
|
+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}::{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
|
129
|
+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
130
|
+
|
131
|
+
## Documentation for Models
|
132
|
+
|
133
|
+
{{#models}}{{#model}} - [{{moduleName}}::{{classname}}]({{modelDocPath}}{{classname}}.md)
|
134
|
+
{{/model}}{{/models}}
|
135
|
+
|
136
|
+
## Documentation for Authorization
|
137
|
+
|
138
|
+
{{^authMethods}} All endpoints do not require authorization.
|
139
|
+
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
|
140
|
+
{{#authMethods}}### {{name}}
|
141
|
+
|
142
|
+
{{#isApiKey}}
|
143
|
+
|
144
|
+
- **Type**: API key
|
145
|
+
- **API key parameter name**: {{keyParamName}}
|
146
|
+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
147
|
+
{{/isApiKey}}
|
148
|
+
{{#isBasic}}
|
149
|
+
{{#isBasicBasic}}- **Type**: HTTP basic authentication
|
150
|
+
{{/isBasicBasic}}{{#isBasicBearer}}- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
|
151
|
+
{{/isBasicBearer}}
|
152
|
+
{{/isBasic}}
|
153
|
+
{{#isOAuth}}
|
154
|
+
|
155
|
+
- **Type**: OAuth
|
156
|
+
- **Flow**: {{flow}}
|
157
|
+
- **Authorization URL**: {{authorizationUrl}}
|
158
|
+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
159
|
+
{{#scopes}} - {{scope}}: {{description}}
|
160
|
+
{{/scopes}}
|
161
|
+
{{/isOAuth}}
|
162
|
+
|
163
|
+
{{/authMethods}}
|
164
|
+
|
165
|
+
## Debugging
|
166
|
+
|
167
|
+
When enabled, the additional information can be provided to the logger. To enable debug logging:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
{{{moduleName}}}.configure do |config|
|
171
|
+
config.debugging = true
|
172
|
+
end
|
173
|
+
```
|
174
|
+
|
175
|
+
## Middleware
|
176
|
+
|
177
|
+
This gem uses Faraday to manage the underlying http requests. Faraday supports middleware that can
|
178
|
+
interact with the request and response directly before and after they are sent or received. This
|
179
|
+
can be used to provide additional logic such as adding custom logging. See
|
180
|
+
[https://lostisland.github.io/faraday/middleware/] for details
|
181
|
+
|
182
|
+
To add a middleware to be used do something like below:
|
183
|
+
```ruby
|
184
|
+
{{{moduleName}}}.configure do |config|
|
185
|
+
config.faraday_middlewares.push(MyMiddleware)
|
186
|
+
end
|
187
|
+
```
|
@@ -0,0 +1,263 @@
|
|
1
|
+
=begin
|
2
|
+
{{> api_info}}
|
3
|
+
=end
|
4
|
+
|
5
|
+
require 'date'
|
6
|
+
require 'json'
|
7
|
+
require 'logger'
|
8
|
+
require 'tempfile'
|
9
|
+
require 'time'
|
10
|
+
{{^isFaraday}}
|
11
|
+
require 'typhoeus'
|
12
|
+
{{/isFaraday}}
|
13
|
+
{{#isFaraday}}
|
14
|
+
require 'faraday'
|
15
|
+
{{/isFaraday}}
|
16
|
+
|
17
|
+
module {{moduleName}}
|
18
|
+
class ApiClient
|
19
|
+
# The Configuration object holding settings to be used in the API client.
|
20
|
+
attr_accessor :config
|
21
|
+
|
22
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
23
|
+
#
|
24
|
+
# @return [Hash]
|
25
|
+
attr_accessor :default_headers
|
26
|
+
|
27
|
+
# Initializes the ApiClient
|
28
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
29
|
+
def initialize(config = Configuration.default)
|
30
|
+
@config = config
|
31
|
+
@default_headers = {
|
32
|
+
'Content-Type' => 'application/json',
|
33
|
+
'User-Agent' => config.user_agent
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.default
|
38
|
+
@@default ||= ApiClient.new
|
39
|
+
end
|
40
|
+
|
41
|
+
{{^isFaraday}}
|
42
|
+
{{> api_client_typhoeus_partial}}
|
43
|
+
{{/isFaraday}}
|
44
|
+
{{#isFaraday}}
|
45
|
+
{{> api_client_faraday_partial}}
|
46
|
+
{{/isFaraday}}
|
47
|
+
# Check if the given MIME is a JSON MIME.
|
48
|
+
# JSON MIME examples:
|
49
|
+
# application/json
|
50
|
+
# application/json; charset=UTF8
|
51
|
+
# APPLICATION/JSON
|
52
|
+
# */*
|
53
|
+
# @param [String] mime MIME
|
54
|
+
# @return [Boolean] True if the MIME is application/json
|
55
|
+
def json_mime?(mime)
|
56
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
# Deserialize the response to the given return type.
|
60
|
+
#
|
61
|
+
# @param [Response] response HTTP response
|
62
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
63
|
+
def deserialize(response, return_type)
|
64
|
+
body = response.body
|
65
|
+
|
66
|
+
# handle file downloading - return the File instance processed in request callbacks
|
67
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
68
|
+
{{^isFaraday}}
|
69
|
+
return @tempfile if return_type == 'File'
|
70
|
+
{{/isFaraday}}
|
71
|
+
{{#isFaraday}}
|
72
|
+
if return_type == 'File'
|
73
|
+
content_disposition = response.headers['Content-Disposition']
|
74
|
+
if content_disposition && content_disposition =~ /filename=/i
|
75
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
76
|
+
prefix = sanitize_filename(filename)
|
77
|
+
else
|
78
|
+
prefix = 'download-'
|
79
|
+
end
|
80
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
81
|
+
encoding = body.encoding
|
82
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
83
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
84
|
+
@tempfile.close
|
85
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
86
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
87
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
88
|
+
"explicitly with `tempfile.delete`"
|
89
|
+
return @tempfile
|
90
|
+
end
|
91
|
+
{{/isFaraday}}
|
92
|
+
|
93
|
+
return nil if body.nil? || body.empty?
|
94
|
+
|
95
|
+
# return response body directly for String return type
|
96
|
+
return body if return_type == 'String'
|
97
|
+
|
98
|
+
# ensuring a default content type
|
99
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
100
|
+
|
101
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
102
|
+
|
103
|
+
begin
|
104
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
105
|
+
rescue JSON::ParserError => e
|
106
|
+
if %w(String Date Time).include?(return_type)
|
107
|
+
data = body
|
108
|
+
else
|
109
|
+
raise e
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
convert_to_type data, return_type
|
114
|
+
end
|
115
|
+
|
116
|
+
# Convert data to the given return type.
|
117
|
+
# @param [Object] data Data to be converted
|
118
|
+
# @param [String] return_type Return type
|
119
|
+
# @return [Mixed] Data in a particular type
|
120
|
+
def convert_to_type(data, return_type)
|
121
|
+
return nil if data.nil?
|
122
|
+
case return_type
|
123
|
+
when 'String'
|
124
|
+
data.to_s
|
125
|
+
when 'Integer'
|
126
|
+
data.to_i
|
127
|
+
when 'Float'
|
128
|
+
data.to_f
|
129
|
+
when 'Boolean'
|
130
|
+
data == true
|
131
|
+
when 'Time'
|
132
|
+
# parse date time (expecting ISO 8601 format)
|
133
|
+
Time.parse data
|
134
|
+
when 'Date'
|
135
|
+
# parse date time (expecting ISO 8601 format)
|
136
|
+
Date.parse data
|
137
|
+
when 'Object'
|
138
|
+
# generic object (usually a Hash), return directly
|
139
|
+
data
|
140
|
+
when /\AArray<(.+)>\z/
|
141
|
+
# e.g. Array<Pet>
|
142
|
+
sub_type = $1
|
143
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
144
|
+
when /\AHash\<String, (.+)\>\z/
|
145
|
+
# e.g. Hash<String, Integer>
|
146
|
+
sub_type = $1
|
147
|
+
{}.tap do |hash|
|
148
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
149
|
+
end
|
150
|
+
else
|
151
|
+
# models (e.g. Pet) or oneOf
|
152
|
+
klass = {{moduleName}}.const_get(return_type)
|
153
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Sanitize filename by removing path.
|
158
|
+
# e.g. ../../sun.gif becomes sun.gif
|
159
|
+
#
|
160
|
+
# @param [String] filename the filename to be sanitized
|
161
|
+
# @return [String] the sanitized filename
|
162
|
+
def sanitize_filename(filename)
|
163
|
+
filename.gsub(/.*[\/\\]/, '')
|
164
|
+
end
|
165
|
+
|
166
|
+
def build_request_url(path, opts = {})
|
167
|
+
# Add leading and trailing slashes to path
|
168
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
169
|
+
@config.base_url(opts[:operation]) + path
|
170
|
+
end
|
171
|
+
|
172
|
+
# Update hearder and query params based on authentication settings.
|
173
|
+
#
|
174
|
+
# @param [Hash] header_params Header parameters
|
175
|
+
# @param [Hash] query_params Query parameters
|
176
|
+
# @param [String] auth_names Authentication scheme name
|
177
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
178
|
+
Array(auth_names).each do |auth_name|
|
179
|
+
auth_setting = @config.auth_settings[auth_name]
|
180
|
+
next unless auth_setting
|
181
|
+
case auth_setting[:in]
|
182
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
183
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
184
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Sets user agent in HTTP header
|
190
|
+
#
|
191
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
192
|
+
def user_agent=(user_agent)
|
193
|
+
@user_agent = user_agent
|
194
|
+
@default_headers['User-Agent'] = @user_agent
|
195
|
+
end
|
196
|
+
|
197
|
+
# Return Accept header based on an array of accepts provided.
|
198
|
+
# @param [Array] accepts array for Accept
|
199
|
+
# @return [String] the Accept header (e.g. application/json)
|
200
|
+
def select_header_accept(accepts)
|
201
|
+
return nil if accepts.nil? || accepts.empty?
|
202
|
+
# use JSON when present, otherwise use all of the provided
|
203
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
204
|
+
json_accept || accepts.join(',')
|
205
|
+
end
|
206
|
+
|
207
|
+
# Return Content-Type header based on an array of content types provided.
|
208
|
+
# @param [Array] content_types array for Content-Type
|
209
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
210
|
+
def select_header_content_type(content_types)
|
211
|
+
# use application/json by default
|
212
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
213
|
+
# use JSON when present, otherwise use the first one
|
214
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
215
|
+
json_content_type || content_types.first
|
216
|
+
end
|
217
|
+
|
218
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
219
|
+
# @param [Object] model object to be converted into JSON string
|
220
|
+
# @return [String] JSON string representation of the object
|
221
|
+
def object_to_http_body(model)
|
222
|
+
return model if model.nil? || model.is_a?(String)
|
223
|
+
local_body = nil
|
224
|
+
if model.is_a?(Array)
|
225
|
+
local_body = model.map { |m| object_to_hash(m) }
|
226
|
+
else
|
227
|
+
local_body = object_to_hash(model)
|
228
|
+
end
|
229
|
+
local_body.to_json
|
230
|
+
end
|
231
|
+
|
232
|
+
# Convert object(non-array) to hash.
|
233
|
+
# @param [Object] obj object to be converted into JSON string
|
234
|
+
# @return [String] JSON string representation of the object
|
235
|
+
def object_to_hash(obj)
|
236
|
+
if obj.respond_to?(:to_hash)
|
237
|
+
obj.to_hash
|
238
|
+
else
|
239
|
+
obj
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Build parameter value according to the given collection format.
|
244
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
245
|
+
def build_collection_param(param, collection_format)
|
246
|
+
case collection_format
|
247
|
+
when :csv
|
248
|
+
param.join(',')
|
249
|
+
when :ssv
|
250
|
+
param.join(' ')
|
251
|
+
when :tsv
|
252
|
+
param.join("\t")
|
253
|
+
when :pipes
|
254
|
+
param.join('|')
|
255
|
+
when :multi
|
256
|
+
# return the array directly as typhoeus will handle it as expected
|
257
|
+
param
|
258
|
+
else
|
259
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|