kuapir 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +77 -0
  4. data/LICENSE +21 -0
  5. data/README.md +170 -0
  6. data/Rakefile +12 -0
  7. data/docs/BoxOffice.md +26 -0
  8. data/docs/BoxOfficeResponse.md +20 -0
  9. data/docs/Company.md +18 -0
  10. data/docs/Country.md +18 -0
  11. data/docs/DigitalReleaseItem.md +44 -0
  12. data/docs/DigitalReleaseResponse.md +22 -0
  13. data/docs/Distribution.md +28 -0
  14. data/docs/DistributionResponse.md +20 -0
  15. data/docs/Episode.md +28 -0
  16. data/docs/Fact.md +22 -0
  17. data/docs/FactResponse.md +20 -0
  18. data/docs/Film.md +100 -0
  19. data/docs/FilmSearchByFiltersResponse.md +22 -0
  20. data/docs/FilmSearchByFiltersResponseItems.md +42 -0
  21. data/docs/FilmSearchResponse.md +24 -0
  22. data/docs/FilmSearchResponseFilms.md +42 -0
  23. data/docs/FilmSequelsAndPrequelsResponse.md +30 -0
  24. data/docs/FilmTopResponse.md +20 -0
  25. data/docs/FilmTopResponseFilms.md +38 -0
  26. data/docs/FilmsApi.md +1126 -0
  27. data/docs/FiltersResponse.md +20 -0
  28. data/docs/FiltersResponseCountries.md +20 -0
  29. data/docs/FiltersResponseGenres.md +20 -0
  30. data/docs/Genre.md +18 -0
  31. data/docs/ImageResponse.md +22 -0
  32. data/docs/ImageResponseItems.md +20 -0
  33. data/docs/PersonByNameResponse.md +20 -0
  34. data/docs/PersonByNameResponseItems.md +28 -0
  35. data/docs/PersonResponse.md +50 -0
  36. data/docs/PersonResponseFilms.md +30 -0
  37. data/docs/PersonResponseSpouses.md +32 -0
  38. data/docs/PersonsApi.md +83 -0
  39. data/docs/PremiereResponse.md +20 -0
  40. data/docs/PremiereResponseItem.md +36 -0
  41. data/docs/RelatedFilmResponse.md +20 -0
  42. data/docs/RelatedFilmResponseItems.md +30 -0
  43. data/docs/ReviewDetailsResponse.md +32 -0
  44. data/docs/ReviewsApi.md +155 -0
  45. data/docs/ReviewsResponse.md +34 -0
  46. data/docs/ReviewsResponseReviews.md +32 -0
  47. data/docs/Season.md +20 -0
  48. data/docs/SeasonResponse.md +20 -0
  49. data/docs/StaffApi.md +147 -0
  50. data/docs/StaffResponse.md +30 -0
  51. data/docs/VideoResponse.md +20 -0
  52. data/docs/VideoResponseItems.md +22 -0
  53. data/kinopoiskapiunofficial-openapi.json +2918 -0
  54. data/kuapir.gemspec +42 -0
  55. data/lib/kuapir/api/films_api.rb +1193 -0
  56. data/lib/kuapir/api/persons_api.rb +89 -0
  57. data/lib/kuapir/api/reviews_api.rb +165 -0
  58. data/lib/kuapir/api/staff_api.rb +145 -0
  59. data/lib/kuapir/api_client.rb +390 -0
  60. data/lib/kuapir/api_error.rb +57 -0
  61. data/lib/kuapir/configuration.rb +287 -0
  62. data/lib/kuapir/models/box_office.rb +246 -0
  63. data/lib/kuapir/models/box_office_response.rb +224 -0
  64. data/lib/kuapir/models/company.rb +214 -0
  65. data/lib/kuapir/models/country.rb +214 -0
  66. data/lib/kuapir/models/digital_release_item.rb +334 -0
  67. data/lib/kuapir/models/digital_release_response.rb +232 -0
  68. data/lib/kuapir/models/distribution.rb +300 -0
  69. data/lib/kuapir/models/distribution_response.rb +224 -0
  70. data/lib/kuapir/models/episode.rb +249 -0
  71. data/lib/kuapir/models/fact.rb +266 -0
  72. data/lib/kuapir/models/fact_response.rb +224 -0
  73. data/lib/kuapir/models/film.rb +551 -0
  74. data/lib/kuapir/models/film_search_by_filters_response.rb +232 -0
  75. data/lib/kuapir/models/film_search_by_filters_response_items.rb +319 -0
  76. data/lib/kuapir/models/film_search_response.rb +244 -0
  77. data/lib/kuapir/models/film_search_response_films.rb +311 -0
  78. data/lib/kuapir/models/film_sequels_and_prequels_response.rb +300 -0
  79. data/lib/kuapir/models/film_top_response.rb +224 -0
  80. data/lib/kuapir/models/film_top_response_films.rb +272 -0
  81. data/lib/kuapir/models/filters_response.rb +226 -0
  82. data/lib/kuapir/models/filters_response_countries.rb +214 -0
  83. data/lib/kuapir/models/filters_response_genres.rb +214 -0
  84. data/lib/kuapir/models/genre.rb +214 -0
  85. data/lib/kuapir/models/image_response.rb +238 -0
  86. data/lib/kuapir/models/image_response_items.rb +214 -0
  87. data/lib/kuapir/models/person_by_name_response.rb +224 -0
  88. data/lib/kuapir/models/person_by_name_response_items.rb +274 -0
  89. data/lib/kuapir/models/person_response.rb +363 -0
  90. data/lib/kuapir/models/person_response_films.rb +284 -0
  91. data/lib/kuapir/models/person_response_spouses.rb +283 -0
  92. data/lib/kuapir/models/premiere_response.rb +224 -0
  93. data/lib/kuapir/models/premiere_response_item.rb +289 -0
  94. data/lib/kuapir/models/related_film_response.rb +224 -0
  95. data/lib/kuapir/models/related_film_response_items.rb +279 -0
  96. data/lib/kuapir/models/review_details_response.rb +314 -0
  97. data/lib/kuapir/models/reviews_response.rb +294 -0
  98. data/lib/kuapir/models/reviews_response_reviews.rb +282 -0
  99. data/lib/kuapir/models/season.rb +224 -0
  100. data/lib/kuapir/models/season_response.rb +224 -0
  101. data/lib/kuapir/models/staff_response.rb +301 -0
  102. data/lib/kuapir/models/video_response.rb +224 -0
  103. data/lib/kuapir/models/video_response_items.rb +255 -0
  104. data/lib/kuapir/version.rb +5 -0
  105. data/lib/kuapir.rb +83 -0
  106. data/openapi-generator-templates/Gemfile.mustache +9 -0
  107. data/openapi-generator-templates/README.mustache +148 -0
  108. data/openapi-generator-templates/Rakefile.mustache +10 -0
  109. data/openapi-generator-templates/api.mustache +205 -0
  110. data/openapi-generator-templates/api_client.mustache +260 -0
  111. data/openapi-generator-templates/api_client_faraday_partial.mustache +136 -0
  112. data/openapi-generator-templates/api_client_spec.mustache +216 -0
  113. data/openapi-generator-templates/api_client_typhoeus_partial.mustache +153 -0
  114. data/openapi-generator-templates/api_doc.mustache +118 -0
  115. data/openapi-generator-templates/api_error.mustache +45 -0
  116. data/openapi-generator-templates/api_info.mustache +12 -0
  117. data/openapi-generator-templates/api_test.mustache +43 -0
  118. data/openapi-generator-templates/base_object.mustache +120 -0
  119. data/openapi-generator-templates/configuration.mustache +381 -0
  120. data/openapi-generator-templates/configuration_spec.mustache +30 -0
  121. data/openapi-generator-templates/configuration_tls_faraday_partial.mustache +29 -0
  122. data/openapi-generator-templates/configuration_tls_typhoeus_partial.mustache +34 -0
  123. data/openapi-generator-templates/gem.mustache +50 -0
  124. data/openapi-generator-templates/gemspec.mustache +31 -0
  125. data/openapi-generator-templates/git_push.sh.mustache +57 -0
  126. data/openapi-generator-templates/gitignore.mustache +39 -0
  127. data/openapi-generator-templates/model.mustache +22 -0
  128. data/openapi-generator-templates/model_doc.mustache +12 -0
  129. data/openapi-generator-templates/model_test.mustache +73 -0
  130. data/openapi-generator-templates/partial_model_enum_class.mustache +20 -0
  131. data/openapi-generator-templates/partial_model_generic.mustache +371 -0
  132. data/openapi-generator-templates/partial_model_generic_doc.mustache +28 -0
  133. data/openapi-generator-templates/partial_oneof_module.mustache +137 -0
  134. data/openapi-generator-templates/partial_oneof_module_doc.mustache +92 -0
  135. data/openapi-generator-templates/rspec.mustache +2 -0
  136. data/openapi-generator-templates/rubocop.mustache +148 -0
  137. data/openapi-generator-templates/spec_helper.mustache +99 -0
  138. data/openapi-generator-templates/travis.mustache +14 -0
  139. data/openapi-generator-templates/version.mustache +3 -0
  140. data/openapitools.json +21 -0
  141. data/spec/api/films_api_spec.rb +227 -0
  142. data/spec/api/persons_api_spec.rb +45 -0
  143. data/spec/api/reviews_api_spec.rb +57 -0
  144. data/spec/api/staff_api_spec.rb +54 -0
  145. data/spec/api_client_spec.rb +229 -0
  146. data/spec/configuration_spec.rb +28 -0
  147. data/spec/models/box_office_response_spec.rb +37 -0
  148. data/spec/models/box_office_spec.rb +55 -0
  149. data/spec/models/company_spec.rb +31 -0
  150. data/spec/models/country_spec.rb +31 -0
  151. data/spec/models/digital_release_item_spec.rb +109 -0
  152. data/spec/models/digital_release_response_spec.rb +43 -0
  153. data/spec/models/distribution_response_spec.rb +37 -0
  154. data/spec/models/distribution_spec.rb +69 -0
  155. data/spec/models/episode_spec.rb +61 -0
  156. data/spec/models/fact_response_spec.rb +37 -0
  157. data/spec/models/fact_spec.rb +47 -0
  158. data/spec/models/film_search_by_filters_response_items_spec.rb +107 -0
  159. data/spec/models/film_search_by_filters_response_spec.rb +43 -0
  160. data/spec/models/film_search_response_films_spec.rb +107 -0
  161. data/spec/models/film_search_response_spec.rb +49 -0
  162. data/spec/models/film_sequels_and_prequels_response_spec.rb +71 -0
  163. data/spec/models/film_spec.rb +285 -0
  164. data/spec/models/film_top_response_films_spec.rb +91 -0
  165. data/spec/models/film_top_response_spec.rb +37 -0
  166. data/spec/models/filters_response_countries_spec.rb +37 -0
  167. data/spec/models/filters_response_genres_spec.rb +37 -0
  168. data/spec/models/filters_response_spec.rb +37 -0
  169. data/spec/models/genre_spec.rb +31 -0
  170. data/spec/models/image_response_items_spec.rb +37 -0
  171. data/spec/models/image_response_spec.rb +43 -0
  172. data/spec/models/person_by_name_response_items_spec.rb +65 -0
  173. data/spec/models/person_by_name_response_spec.rb +37 -0
  174. data/spec/models/person_response_films_spec.rb +71 -0
  175. data/spec/models/person_response_spec.rb +131 -0
  176. data/spec/models/person_response_spouses_spec.rb +77 -0
  177. data/spec/models/premiere_response_item_spec.rb +85 -0
  178. data/spec/models/premiere_response_spec.rb +37 -0
  179. data/spec/models/related_film_response_items_spec.rb +71 -0
  180. data/spec/models/related_film_response_spec.rb +37 -0
  181. data/spec/models/review_details_response_spec.rb +77 -0
  182. data/spec/models/reviews_response_reviews_spec.rb +77 -0
  183. data/spec/models/reviews_response_spec.rb +79 -0
  184. data/spec/models/season_response_spec.rb +37 -0
  185. data/spec/models/season_spec.rb +37 -0
  186. data/spec/models/staff_response_spec.rb +71 -0
  187. data/spec/models/video_response_items_spec.rb +47 -0
  188. data/spec/models/video_response_spec.rb +37 -0
  189. data/spec/spec_helper.rb +107 -0
  190. metadata +326 -0
@@ -0,0 +1,216 @@
1
+ require 'spec_helper'
2
+
3
+ describe {{moduleName}}::ApiClient do
4
+ context 'initialization' do
5
+ context 'URL stuff' do
6
+ context 'host' do
7
+ it 'removes http from host' do
8
+ {{moduleName}}.configure { |c| c.host = 'http://example.com' }
9
+ expect({{moduleName}}::Configuration.default.host).to eq('example.com')
10
+ end
11
+
12
+ it 'removes https from host' do
13
+ {{moduleName}}.configure { |c| c.host = 'https://wookiee.com' }
14
+ expect({{moduleName}}::ApiClient.default.config.host).to eq('wookiee.com')
15
+ end
16
+
17
+ it 'removes trailing path from host' do
18
+ {{moduleName}}.configure { |c| c.host = 'hobo.com/v4' }
19
+ expect({{moduleName}}::Configuration.default.host).to eq('hobo.com')
20
+ end
21
+ end
22
+
23
+ context 'base_path' do
24
+ it "prepends a slash to base_path" do
25
+ {{moduleName}}.configure { |c| c.base_path = 'v4/dog' }
26
+ expect({{moduleName}}::Configuration.default.base_path).to eq('/v4/dog')
27
+ end
28
+
29
+ it "doesn't prepend a slash if one is already there" do
30
+ {{moduleName}}.configure { |c| c.base_path = '/v4/dog' }
31
+ expect({{moduleName}}::Configuration.default.base_path).to eq('/v4/dog')
32
+ end
33
+
34
+ it "ends up as a blank string if nil" do
35
+ {{moduleName}}.configure { |c| c.base_path = nil }
36
+ expect({{moduleName}}::Configuration.default.base_path).to eq('')
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ {{^isFaraday}}
43
+ describe 'params_encoding in #build_request' do
44
+ let(:config) { {{moduleName}}::Configuration.new }
45
+ let(:api_client) { {{moduleName}}::ApiClient.new(config) }
46
+
47
+ it 'defaults to nil' do
48
+ expect({{moduleName}}::Configuration.default.params_encoding).to eq(nil)
49
+ expect(config.params_encoding).to eq(nil)
50
+
51
+ request = api_client.build_request(:get, '/test')
52
+ expect(request.options[:params_encoding]).to eq(nil)
53
+ end
54
+
55
+ it 'can be customized' do
56
+ config.params_encoding = :multi
57
+ request = api_client.build_request(:get, '/test')
58
+ expect(request.options[:params_encoding]).to eq(:multi)
59
+ end
60
+ end
61
+
62
+ describe 'timeout in #build_request' do
63
+ let(:config) { {{moduleName}}::Configuration.new }
64
+ let(:api_client) { {{moduleName}}::ApiClient.new(config) }
65
+
66
+ it 'defaults to 0' do
67
+ expect({{moduleName}}::Configuration.default.timeout).to eq(0)
68
+ expect(config.timeout).to eq(0)
69
+
70
+ request = api_client.build_request(:get, '/test')
71
+ expect(request.options[:timeout]).to eq(0)
72
+ end
73
+
74
+ it 'can be customized' do
75
+ config.timeout = 100
76
+ request = api_client.build_request(:get, '/test')
77
+ expect(request.options[:timeout]).to eq(100)
78
+ end
79
+ end
80
+
81
+ {{/isFaraday}}
82
+ describe '#deserialize' do
83
+ it "handles Array<Integer>" do
84
+ api_client = {{moduleName}}::ApiClient.new
85
+ headers = { 'Content-Type' => 'application/json' }
86
+ response = double('response', headers: headers, body: '[12, 34]')
87
+ data = api_client.deserialize(response, 'Array<Integer>')
88
+ expect(data).to be_instance_of(Array)
89
+ expect(data).to eq([12, 34])
90
+ end
91
+
92
+ it 'handles Array<Array<Integer>>' do
93
+ api_client = {{moduleName}}::ApiClient.new
94
+ headers = { 'Content-Type' => 'application/json' }
95
+ response = double('response', headers: headers, body: '[[12, 34], [56]]')
96
+ data = api_client.deserialize(response, 'Array<Array<Integer>>')
97
+ expect(data).to be_instance_of(Array)
98
+ expect(data).to eq([[12, 34], [56]])
99
+ end
100
+
101
+ it 'handles Hash<String, String>' do
102
+ api_client = {{moduleName}}::ApiClient.new
103
+ headers = { 'Content-Type' => 'application/json' }
104
+ response = double('response', headers: headers, body: '{"message": "Hello"}')
105
+ data = api_client.deserialize(response, 'Hash<String, String>')
106
+ expect(data).to be_instance_of(Hash)
107
+ expect(data).to eq(:message => 'Hello')
108
+ end
109
+ end
110
+
111
+ describe "#object_to_hash" do
112
+ it 'ignores nils and includes empty arrays' do
113
+ # uncomment below to test object_to_hash for model
114
+ # api_client = {{moduleName}}::ApiClient.new
115
+ # _model = {{moduleName}}::ModelName.new
116
+ # update the model attribute below
117
+ # _model.id = 1
118
+ # update the expected value (hash) below
119
+ # expected = {id: 1, name: '', tags: []}
120
+ # expect(api_client.object_to_hash(_model)).to eq(expected)
121
+ end
122
+ end
123
+
124
+ describe '#build_collection_param' do
125
+ let(:param) { ['aa', 'bb', 'cc'] }
126
+ let(:api_client) { {{moduleName}}::ApiClient.new }
127
+
128
+ it 'works for csv' do
129
+ expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
130
+ end
131
+
132
+ it 'works for ssv' do
133
+ expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
134
+ end
135
+
136
+ it 'works for tsv' do
137
+ expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
138
+ end
139
+
140
+ it 'works for pipes' do
141
+ expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
142
+ end
143
+
144
+ it 'works for multi' do
145
+ expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
146
+ end
147
+
148
+ it 'fails for invalid collection format' do
149
+ expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID')
150
+ end
151
+ end
152
+
153
+ describe '#json_mime?' do
154
+ let(:api_client) { {{moduleName}}::ApiClient.new }
155
+
156
+ it 'works' do
157
+ expect(api_client.json_mime?(nil)).to eq false
158
+ expect(api_client.json_mime?('')).to eq false
159
+
160
+ expect(api_client.json_mime?('application/json')).to eq true
161
+ expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
162
+ expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
163
+
164
+ expect(api_client.json_mime?('application/xml')).to eq false
165
+ expect(api_client.json_mime?('text/plain')).to eq false
166
+ expect(api_client.json_mime?('application/jsonp')).to eq false
167
+ end
168
+ end
169
+
170
+ describe '#select_header_accept' do
171
+ let(:api_client) { {{moduleName}}::ApiClient.new }
172
+
173
+ it 'works' do
174
+ expect(api_client.select_header_accept(nil)).to be_nil
175
+ expect(api_client.select_header_accept([])).to be_nil
176
+
177
+ expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
178
+ expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
179
+ expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
180
+
181
+ expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
182
+ expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
183
+ end
184
+ end
185
+
186
+ describe '#select_header_content_type' do
187
+ let(:api_client) { {{moduleName}}::ApiClient.new }
188
+
189
+ it 'works' do
190
+ expect(api_client.select_header_content_type(nil)).to be_nil
191
+ expect(api_client.select_header_content_type([])).to be_nil
192
+
193
+ expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
194
+ expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
195
+ expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
196
+ expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
197
+ expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
198
+ end
199
+ end
200
+
201
+ describe '#sanitize_filename' do
202
+ let(:api_client) { {{moduleName}}::ApiClient.new }
203
+
204
+ it 'works' do
205
+ expect(api_client.sanitize_filename('sun')).to eq('sun')
206
+ expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
207
+ expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
208
+ expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
209
+ expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
210
+ expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
211
+ expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
212
+ expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
213
+ expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,153 @@
1
+ # Call an API with given options.
2
+ #
3
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
4
+ # the data deserialized from response body (could be nil), response status code and response headers.
5
+ def call_api(http_method, path, opts = {})
6
+ request = build_request(http_method, path, opts)
7
+ response = request.run
8
+
9
+ if @config.debugging
10
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
11
+ end
12
+
13
+ unless response.success?
14
+ if response.timed_out?
15
+ fail ApiError.new('Connection timed out')
16
+ elsif response.code == 0
17
+ # Errors from libcurl will be made visible here
18
+ fail ApiError.new(:code => 0,
19
+ :message => response.return_message)
20
+ else
21
+ fail ApiError.new(:code => response.code,
22
+ :response_headers => response.headers,
23
+ :response_body => response.body),
24
+ response.status_message
25
+ end
26
+ end
27
+
28
+ if opts[:return_type]
29
+ data = deserialize(response, opts[:return_type])
30
+ else
31
+ data = nil
32
+ end
33
+ return data, response.code, response.headers
34
+ end
35
+
36
+ # Builds the HTTP request
37
+ #
38
+ # @param [String] http_method HTTP method/verb (e.g. POST)
39
+ # @param [String] path URL path (e.g. /account/new)
40
+ # @option opts [Hash] :header_params Header parameters
41
+ # @option opts [Hash] :query_params Query parameters
42
+ # @option opts [Hash] :form_params Query parameters
43
+ # @option opts [Object] :body HTTP body (JSON/XML)
44
+ # @return [Typhoeus::Request] A Typhoeus Request
45
+ def build_request(http_method, path, opts = {})
46
+ url = build_request_url(path, opts)
47
+ http_method = http_method.to_sym.downcase
48
+
49
+ header_params = @default_headers.merge(opts[:header_params] || {})
50
+ query_params = opts[:query_params] || {}
51
+ form_params = opts[:form_params] || {}
52
+
53
+ {{#hasAuthMethods}}
54
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
55
+ {{/hasAuthMethods}}
56
+
57
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
58
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
59
+
60
+ req_opts = {
61
+ :method => http_method,
62
+ :headers => header_params,
63
+ :params => query_params,
64
+ :params_encoding => @config.params_encoding,
65
+ :timeout => @config.timeout,
66
+ :ssl_verifypeer => @config.verify_ssl,
67
+ :ssl_verifyhost => _verify_ssl_host,
68
+ :sslcert => @config.cert_file,
69
+ :sslkey => @config.key_file,
70
+ :verbose => @config.debugging
71
+ }
72
+
73
+ # set custom cert, if provided
74
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
75
+
76
+ if [:post, :patch, :put, :delete].include?(http_method)
77
+ req_body = build_request_body(header_params, form_params, opts[:body])
78
+ req_opts.update :body => req_body
79
+ if @config.debugging
80
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
81
+ end
82
+ end
83
+
84
+ request = Typhoeus::Request.new(url, req_opts)
85
+ download_file(request) if opts[:return_type] == 'File'
86
+ request
87
+ end
88
+
89
+ # Builds the HTTP request body
90
+ #
91
+ # @param [Hash] header_params Header parameters
92
+ # @param [Hash] form_params Query parameters
93
+ # @param [Object] body HTTP body (JSON/XML)
94
+ # @return [String] HTTP body data in the form of string
95
+ def build_request_body(header_params, form_params, body)
96
+ # http form
97
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
98
+ header_params['Content-Type'] == 'multipart/form-data'
99
+ data = {}
100
+ form_params.each do |key, value|
101
+ case value
102
+ when ::File, ::Array, nil
103
+ # let typhoeus handle File, Array and nil parameters
104
+ data[key] = value
105
+ else
106
+ data[key] = value.to_s
107
+ end
108
+ end
109
+ elsif body
110
+ data = body.is_a?(String) ? body : body.to_json
111
+ else
112
+ data = nil
113
+ end
114
+ data
115
+ end
116
+
117
+ # Save response body into a file in (the defined) temporary folder, using the filename
118
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
119
+ # The response body is written to the file in chunks in order to handle files which
120
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
121
+ # process can use.
122
+ #
123
+ # @see Configuration#temp_folder_path
124
+ def download_file(request)
125
+ tempfile = nil
126
+ encoding = nil
127
+ request.on_headers do |response|
128
+ content_disposition = response.headers['Content-Disposition']
129
+ if content_disposition && content_disposition =~ /filename=/i
130
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
131
+ prefix = sanitize_filename(filename)
132
+ else
133
+ prefix = 'download-'
134
+ end
135
+ prefix = prefix + '-' unless prefix.end_with?('-')
136
+ encoding = response.body.encoding
137
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
138
+ @tempfile = tempfile
139
+ end
140
+ request.on_body do |chunk|
141
+ chunk.force_encoding(encoding)
142
+ tempfile.write(chunk)
143
+ end
144
+ request.on_complete do |response|
145
+ if tempfile
146
+ tempfile.close
147
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
148
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
149
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
150
+ "explicitly with `tempfile.delete`"
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,118 @@
1
+ # {{moduleName}}::{{classname}}{{#description}}
2
+
3
+ {{.}}{{/description}}
4
+
5
+ All URIs are relative to *{{basePath}}*
6
+
7
+ | Method | HTTP request | Description |
8
+ | ------ | ------------ | ----------- |
9
+ {{#operations}}
10
+ {{#operation}}
11
+ | [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}} |
12
+ {{/operation}}
13
+ {{/operations}}
14
+
15
+ {{#operations}}
16
+ {{#operation}}
17
+
18
+ ## {{operationId}}
19
+
20
+ > {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
21
+
22
+ {{{summary}}}{{#notes}}
23
+
24
+ {{{.}}}{{/notes}}
25
+
26
+ ### Examples
27
+
28
+ ```ruby
29
+ require 'time'
30
+ require '{{{gemName}}}'
31
+ {{#hasAuthMethods}}
32
+ # setup authorization
33
+ {{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
34
+ # Configure HTTP basic authorization: {{{name}}}
35
+ config.username = 'YOUR USERNAME'
36
+ config.password = 'YOUR PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}}
37
+ # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
38
+ config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
39
+ # Configure API key authorization: {{{name}}}
40
+ config.api_key['{{{name}}}'] = 'YOUR API KEY'
41
+ # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
42
+ # config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
43
+ # Configure OAuth2 access token for authorization: {{{name}}}
44
+ config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
45
+ {{/authMethods}}end
46
+ {{/hasAuthMethods}}
47
+
48
+ api_instance = {{{moduleName}}}::{{{classname}}}.new
49
+ {{#requiredParams}}
50
+ {{{paramName}}} = {{{vendorExtensions.x-ruby-example}}} # {{{dataType}}} | {{{description}}}
51
+ {{/requiredParams}}
52
+ {{#optionalParams}}
53
+ {{#-first}}
54
+ opts = {
55
+ {{/-first}}
56
+ {{{paramName}}}: {{{vendorExtensions.x-ruby-example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}}
57
+ {{#-last}}
58
+ }
59
+ {{/-last}}
60
+ {{/optionalParams}}
61
+
62
+ begin
63
+ {{#summary}}# {{{.}}}{{/summary}}
64
+ {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
65
+ {{#returnType}}
66
+ p result
67
+ {{/returnType}}
68
+ rescue {{{moduleName}}}::ApiError => e
69
+ puts "Error when calling {{classname}}->{{{operationId}}}: #{e}"
70
+ end
71
+ ```
72
+
73
+ #### Using the {{operationId}}_with_http_info variant
74
+
75
+ This returns an Array which contains the response data{{^returnType}} (`nil` in this case){{/returnType}}, status code and headers.
76
+
77
+ > <Array({{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Integer, Hash)> {{operationId}}_with_http_info{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
78
+
79
+ ```ruby
80
+ begin
81
+ {{#summary}}# {{{.}}}{{/summary}}
82
+ data, status_code, headers = api_instance.{{{operationId}}}_with_http_info{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
83
+ p status_code # => 2xx
84
+ p headers # => { ... }
85
+ p data # => {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil{{/returnType}}
86
+ rescue {{{moduleName}}}::ApiError => e
87
+ puts "Error when calling {{classname}}->{{{operationId}}}_with_http_info: #{e}"
88
+ end
89
+ ```
90
+
91
+ ### Parameters
92
+
93
+ {{^allParams}}
94
+ This endpoint does not need any parameter.
95
+ {{/allParams}}
96
+ {{#allParams}}
97
+ {{#-first}}
98
+ | Name | Type | Description | Notes |
99
+ | ---- | ---- | ----------- | ----- |
100
+ {{/-first}}
101
+ | **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}} |
102
+ {{/allParams}}
103
+
104
+ ### Return type
105
+
106
+ {{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil (empty response body){{/returnType}}
107
+
108
+ ### Authorization
109
+
110
+ {{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
111
+
112
+ ### HTTP request headers
113
+
114
+ - **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
115
+ - **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
116
+
117
+ {{/operation}}
118
+ {{/operations}}
@@ -0,0 +1,45 @@
1
+ module {{moduleName}}
2
+ class ApiError < StandardError
3
+ attr_reader :code, :response_headers, :response_body
4
+
5
+ # Usage examples:
6
+ # ApiError.new
7
+ # ApiError.new("message")
8
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
9
+ # ApiError.new(:code => 404, :message => "Not Found")
10
+ def initialize(arg = nil)
11
+ if arg.is_a? Hash
12
+ if arg.key?(:message) || arg.key?('message')
13
+ super(arg[:message] || arg['message'])
14
+ else
15
+ super arg
16
+ end
17
+
18
+ arg.each do |k, v|
19
+ instance_variable_set "@#{k}", v
20
+ end
21
+ else
22
+ super arg
23
+ end
24
+ end
25
+
26
+ # Override to_s to display a friendly error message
27
+ def to_s
28
+ message
29
+ end
30
+
31
+ def message
32
+ if @message.nil?
33
+ msg = "Error message: the server returns an error"
34
+ else
35
+ msg = @message
36
+ end
37
+
38
+ msg += "\nHTTP status code: #{code}" if code
39
+ msg += "\nResponse headers: #{response_headers}" if response_headers
40
+ msg += "\nResponse body: #{response_body}" if response_body
41
+
42
+ msg
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ {{#appName}}
2
+ #{{{.}}}
3
+
4
+ {{/appName}}
5
+ {{#appDescription}}
6
+ #{{{.}}}
7
+
8
+ {{/appDescription}}
9
+ {{#version}}The version of the OpenAPI document: {{.}}{{/version}}
10
+ {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
11
+ Generated by: https://openapi-generator.tech
12
+ OpenAPI Generator version: {{{generatorVersion}}}
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ # Unit tests for {{moduleName}}::{{classname}}
5
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
6
+ # Please update as you see appropriate
7
+ {{#operations}}describe '{{classname}}' do
8
+ before do
9
+ # run before each test
10
+ @api_instance = {{moduleName}}::{{classname}}.new
11
+ end
12
+
13
+ after do
14
+ # run after each test
15
+ end
16
+
17
+ describe 'test an instance of {{classname}}' do
18
+ it 'should create an instance of {{classname}}' do
19
+ expect(@api_instance).to be_instance_of({{moduleName}}::{{classname}})
20
+ end
21
+ end
22
+
23
+ {{#operation}}
24
+ # unit tests for {{operationId}}
25
+ {{#summary}}
26
+ # {{.}}
27
+ {{/summary}}
28
+ {{#notes}}
29
+ # {{.}}
30
+ {{/notes}}
31
+ {{#allParams}}{{#required}} # @param {{paramName}} {{description}}
32
+ {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
33
+ {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
34
+ {{/required}}{{/allParams}} # @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}]
35
+ describe '{{operationId}} test' do
36
+ it 'should work' do
37
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
38
+ end
39
+ end
40
+
41
+ {{/operation}}
42
+ end
43
+ {{/operations}}