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,205 @@
1
+ require 'cgi'
2
+
3
+ module {{moduleName}}
4
+ {{#operations}}
5
+ class {{classname}}
6
+ attr_accessor :api_client
7
+
8
+ def initialize(api_client = ApiClient.default)
9
+ @api_client = api_client
10
+ end
11
+ {{#operation}}
12
+ {{#summary}}
13
+ # {{{.}}}
14
+ {{/summary}}
15
+ {{#notes}}
16
+ # {{{.}}}
17
+ {{/notes}}
18
+ {{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}}
19
+ {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
20
+ {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
21
+ {{/required}}{{/allParams}} # @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}]
22
+ def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
23
+ {{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts)
24
+ {{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}}
25
+ end
26
+
27
+ {{#summary}}
28
+ # {{.}}
29
+ {{/summary}}
30
+ {{#notes}}
31
+ # {{.}}
32
+ {{/notes}}
33
+ {{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}}
34
+ {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
35
+ {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
36
+ {{/required}}{{/allParams}} # @return [Array<({{{returnType}}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{.}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers
37
+ def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
38
+ if @api_client.config.debugging
39
+ @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...'
40
+ end
41
+ {{#allParams}}
42
+ {{^isNullable}}
43
+ {{#required}}
44
+ # verify the required parameter '{{paramName}}' is set
45
+ if @api_client.config.client_side_validation && {{{paramName}}}.nil?
46
+ fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}"
47
+ end
48
+ {{#isEnum}}
49
+ {{^isContainer}}
50
+ # verify enum value
51
+ allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
52
+ if @api_client.config.client_side_validation && !allowable_values.include?({{{paramName}}})
53
+ fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}"
54
+ end
55
+ {{/isContainer}}
56
+ {{/isEnum}}
57
+ {{/required}}
58
+ {{/isNullable}}
59
+ {{^required}}
60
+ {{#isEnum}}
61
+ {{#collectionFormat}}
62
+ allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
63
+ if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| allowable_values.include?(item) }
64
+ fail ArgumentError, "invalid value for \"{{{paramName}}}\", must include one of #{allowable_values}"
65
+ end
66
+ {{/collectionFormat}}
67
+ {{^collectionFormat}}
68
+ allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
69
+ if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !allowable_values.include?(opts[:'{{{paramName}}}'])
70
+ fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}"
71
+ end
72
+ {{/collectionFormat}}
73
+ {{/isEnum}}
74
+ {{/required}}
75
+ {{#hasValidation}}
76
+ {{#maxLength}}
77
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length > {{{maxLength}}}
78
+ fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be smaller than or equal to {{{maxLength}}}.'
79
+ end
80
+
81
+ {{/maxLength}}
82
+ {{#minLength}}
83
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length < {{{minLength}}}
84
+ fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be great than or equal to {{{minLength}}}.'
85
+ end
86
+
87
+ {{/minLength}}
88
+ {{#maximum}}
89
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}}
90
+ fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.'
91
+ end
92
+
93
+ {{/maximum}}
94
+ {{#minimum}}
95
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}}
96
+ fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.'
97
+ end
98
+
99
+ {{/minimum}}
100
+ {{#pattern}}
101
+ pattern = Regexp.new({{{pattern}}})
102
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ pattern
103
+ fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern #{pattern}."
104
+ end
105
+
106
+ {{/pattern}}
107
+ {{#maxItems}}
108
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length > {{{maxItems}}}
109
+ fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{{maxItems}}}.'
110
+ end
111
+
112
+ {{/maxItems}}
113
+ {{#minItems}}
114
+ if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length < {{{minItems}}}
115
+ fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{{minItems}}}.'
116
+ end
117
+
118
+ {{/minItems}}
119
+ {{/hasValidation}}
120
+ {{/allParams}}
121
+ # resource path
122
+ local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}}
123
+
124
+ # query parameters
125
+ query_params = opts[:query_params] || {}
126
+ {{#queryParams}}
127
+ {{#required}}
128
+ query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
129
+ {{/required}}
130
+ {{/queryParams}}
131
+ {{#queryParams}}
132
+ {{^required}}
133
+ query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil?
134
+ {{/required}}
135
+ {{/queryParams}}
136
+
137
+ # header parameters
138
+ header_params = opts[:header_params] || {}
139
+ {{#hasProduces}}
140
+ # HTTP header 'Accept' (if needed)
141
+ header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}])
142
+ {{/hasProduces}}
143
+ {{#hasConsumes}}
144
+ # HTTP header 'Content-Type'
145
+ content_type = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}])
146
+ if !content_type.nil?
147
+ header_params['Content-Type'] = content_type
148
+ end
149
+ {{/hasConsumes}}
150
+ {{#headerParams}}
151
+ {{#required}}
152
+ header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
153
+ {{/required}}
154
+ {{/headerParams}}
155
+ {{#headerParams}}
156
+ {{^required}}
157
+ header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil?
158
+ {{/required}}
159
+ {{/headerParams}}
160
+
161
+ # form parameters
162
+ form_params = opts[:form_params] || {}
163
+ {{#formParams}}
164
+ {{#required}}
165
+ form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
166
+ {{/required}}
167
+ {{/formParams}}
168
+ {{#formParams}}
169
+ {{^required}}
170
+ form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{paramName}}'].nil?
171
+ {{/required}}
172
+ {{/formParams}}
173
+
174
+ # http body (model)
175
+ post_body = opts[:debug_body]{{#bodyParam}} || @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}){{/bodyParam}}
176
+
177
+ # return_type
178
+ return_type = opts[:debug_return_type]{{#returnType}} || '{{{.}}}'{{/returnType}}
179
+
180
+ # auth_names
181
+ auth_names = opts[:debug_auth_names] || [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}]
182
+
183
+ new_options = opts.merge(
184
+ :operation => :"{{classname}}.{{operationId}}",
185
+ :header_params => header_params,
186
+ :query_params => query_params,
187
+ :form_params => form_params,
188
+ :body => post_body,
189
+ :auth_names => auth_names,
190
+ :return_type => return_type
191
+ )
192
+
193
+ data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, new_options)
194
+ if @api_client.config.debugging
195
+ @api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
196
+ end
197
+ return data, status_code, headers
198
+ end
199
+ {{^-last}}
200
+
201
+ {{/-last}}
202
+ {{/operation}}
203
+ end
204
+ {{/operations}}
205
+ end
@@ -0,0 +1,260 @@
1
+ require 'date'
2
+ require 'json'
3
+ require 'logger'
4
+ require 'tempfile'
5
+ require 'time'
6
+ {{^isFaraday}}
7
+ require 'typhoeus'
8
+ {{/isFaraday}}
9
+ {{#isFaraday}}
10
+ require 'faraday'
11
+ {{/isFaraday}}
12
+
13
+ module {{moduleName}}
14
+ class ApiClient
15
+ # The Configuration object holding settings to be used in the API client.
16
+ attr_accessor :config
17
+
18
+ # Defines the headers to be used in HTTP requests of all API calls by default.
19
+ #
20
+ # @return [Hash]
21
+ attr_accessor :default_headers
22
+
23
+ # Initializes the ApiClient
24
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
25
+ def initialize(config = Configuration.default)
26
+ @config = config
27
+ @user_agent = "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/#{VERSION}/ruby{{/httpUserAgent}}"
28
+ @default_headers = {
29
+ 'Content-Type' => 'application/json',
30
+ 'User-Agent' => @user_agent
31
+ }
32
+ end
33
+
34
+ def self.default
35
+ @@default ||= ApiClient.new
36
+ end
37
+
38
+ {{^isFaraday}}
39
+ {{> api_client_typhoeus_partial}}
40
+ {{/isFaraday}}
41
+ {{#isFaraday}}
42
+ {{> api_client_faraday_partial}}
43
+ {{/isFaraday}}
44
+ # Check if the given MIME is a JSON MIME.
45
+ # JSON MIME examples:
46
+ # application/json
47
+ # application/json; charset=UTF8
48
+ # APPLICATION/JSON
49
+ # */*
50
+ # @param [String] mime MIME
51
+ # @return [Boolean] True if the MIME is application/json
52
+ def json_mime?(mime)
53
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
54
+ end
55
+
56
+ # Deserialize the response to the given return type.
57
+ #
58
+ # @param [Response] response HTTP response
59
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
60
+ def deserialize(response, return_type)
61
+ body = response.body
62
+
63
+ # handle file downloading - return the File instance processed in request callbacks
64
+ # note that response body is empty when the file is written in chunks in request on_body callback
65
+ {{^isFaraday}}
66
+ return @tempfile if return_type == 'File'
67
+ {{/isFaraday}}
68
+ {{#isFaraday}}
69
+ if return_type == 'File'
70
+ content_disposition = response.headers['Content-Disposition']
71
+ if content_disposition && content_disposition =~ /filename=/i
72
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
73
+ prefix = sanitize_filename(filename)
74
+ else
75
+ prefix = 'download-'
76
+ end
77
+ prefix = prefix + '-' unless prefix.end_with?('-')
78
+ encoding = body.encoding
79
+ @tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
80
+ @tempfile.write(@stream.join.force_encoding(encoding))
81
+ @tempfile.close
82
+ @config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
83
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
84
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
85
+ "explicitly with `tempfile.delete`"
86
+ return @tempfile
87
+ end
88
+ {{/isFaraday}}
89
+
90
+ return nil if body.nil? || body.empty?
91
+
92
+ # return response body directly for String return type
93
+ return body if return_type == 'String'
94
+
95
+ # ensuring a default content type
96
+ content_type = response.headers['Content-Type'] || 'application/json'
97
+
98
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
99
+
100
+ begin
101
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
102
+ rescue JSON::ParserError => e
103
+ if %w(String Date Time).include?(return_type)
104
+ data = body
105
+ else
106
+ raise e
107
+ end
108
+ end
109
+
110
+ convert_to_type data, return_type
111
+ end
112
+
113
+ # Convert data to the given return type.
114
+ # @param [Object] data Data to be converted
115
+ # @param [String] return_type Return type
116
+ # @return [Mixed] Data in a particular type
117
+ def convert_to_type(data, return_type)
118
+ return nil if data.nil?
119
+ case return_type
120
+ when 'String'
121
+ data.to_s
122
+ when 'Integer'
123
+ data.to_i
124
+ when 'Float'
125
+ data.to_f
126
+ when 'Boolean'
127
+ data == true
128
+ when 'Time'
129
+ # parse date time (expecting ISO 8601 format)
130
+ Time.parse data
131
+ when 'Date'
132
+ # parse date time (expecting ISO 8601 format)
133
+ Date.parse data
134
+ when 'Object'
135
+ # generic object (usually a Hash), return directly
136
+ data
137
+ when /\AArray<(.+)>\z/
138
+ # e.g. Array<Pet>
139
+ sub_type = $1
140
+ data.map { |item| convert_to_type(item, sub_type) }
141
+ when /\AHash\<String, (.+)\>\z/
142
+ # e.g. Hash<String, Integer>
143
+ sub_type = $1
144
+ {}.tap do |hash|
145
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
146
+ end
147
+ else
148
+ # models (e.g. Pet) or oneOf
149
+ klass = {{moduleName}}.const_get(return_type)
150
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
151
+ end
152
+ end
153
+
154
+ # Sanitize filename by removing path.
155
+ # e.g. ../../sun.gif becomes sun.gif
156
+ #
157
+ # @param [String] filename the filename to be sanitized
158
+ # @return [String] the sanitized filename
159
+ def sanitize_filename(filename)
160
+ filename.gsub(/.*[\/\\]/, '')
161
+ end
162
+
163
+ def build_request_url(path, opts = {})
164
+ # Add leading and trailing slashes to path
165
+ path = "/#{path}".gsub(/\/+/, '/')
166
+ @config.base_url(opts[:operation]) + path
167
+ end
168
+
169
+ # Update header and query params based on authentication settings.
170
+ #
171
+ # @param [Hash] header_params Header parameters
172
+ # @param [Hash] query_params Query parameters
173
+ # @param [String] auth_names Authentication scheme name
174
+ def update_params_for_auth!(header_params, query_params, auth_names)
175
+ Array(auth_names).each do |auth_name|
176
+ auth_setting = @config.auth_settings[auth_name]
177
+ next unless auth_setting
178
+ case auth_setting[:in]
179
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
180
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
181
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
182
+ end
183
+ end
184
+ end
185
+
186
+ # Sets user agent in HTTP header
187
+ #
188
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
189
+ def user_agent=(user_agent)
190
+ @user_agent = user_agent
191
+ @default_headers['User-Agent'] = @user_agent
192
+ end
193
+
194
+ # Return Accept header based on an array of accepts provided.
195
+ # @param [Array] accepts array for Accept
196
+ # @return [String] the Accept header (e.g. application/json)
197
+ def select_header_accept(accepts)
198
+ return nil if accepts.nil? || accepts.empty?
199
+ # use JSON when present, otherwise use all of the provided
200
+ json_accept = accepts.find { |s| json_mime?(s) }
201
+ json_accept || accepts.join(',')
202
+ end
203
+
204
+ # Return Content-Type header based on an array of content types provided.
205
+ # @param [Array] content_types array for Content-Type
206
+ # @return [String] the Content-Type header (e.g. application/json)
207
+ def select_header_content_type(content_types)
208
+ # return nil by default
209
+ return if content_types.nil? || content_types.empty?
210
+ # use JSON when present, otherwise use the first one
211
+ json_content_type = content_types.find { |s| json_mime?(s) }
212
+ json_content_type || content_types.first
213
+ end
214
+
215
+ # Convert object (array, hash, object, etc) to JSON string.
216
+ # @param [Object] model object to be converted into JSON string
217
+ # @return [String] JSON string representation of the object
218
+ def object_to_http_body(model)
219
+ return model if model.nil? || model.is_a?(String)
220
+ local_body = nil
221
+ if model.is_a?(Array)
222
+ local_body = model.map { |m| object_to_hash(m) }
223
+ else
224
+ local_body = object_to_hash(model)
225
+ end
226
+ local_body.to_json
227
+ end
228
+
229
+ # Convert object(non-array) to hash.
230
+ # @param [Object] obj object to be converted into JSON string
231
+ # @return [String] JSON string representation of the object
232
+ def object_to_hash(obj)
233
+ if obj.respond_to?(:to_hash)
234
+ obj.to_hash
235
+ else
236
+ obj
237
+ end
238
+ end
239
+
240
+ # Build parameter value according to the given collection format.
241
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
242
+ def build_collection_param(param, collection_format)
243
+ case collection_format
244
+ when :csv
245
+ param.join(',')
246
+ when :ssv
247
+ param.join(' ')
248
+ when :tsv
249
+ param.join("\t")
250
+ when :pipes
251
+ param.join('|')
252
+ when :multi
253
+ # return the array directly as typhoeus will handle it as expected
254
+ param
255
+ else
256
+ fail "unknown collection format: #{collection_format.inspect}"
257
+ end
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,136 @@
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
+ ssl_options = {
7
+ :ca_file => @config.ssl_ca_file,
8
+ :verify => @config.ssl_verify,
9
+ :verify_mode => @config.ssl_verify_mode,
10
+ :client_cert => @config.ssl_client_cert,
11
+ :client_key => @config.ssl_client_key
12
+ }
13
+
14
+ connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
15
+ conn.request(:basic_auth, config.username, config.password)
16
+ @config.configure_middleware(conn)
17
+ if opts[:header_params]["Content-Type"] == "multipart/form-data"
18
+ conn.request :multipart
19
+ conn.request :url_encoded
20
+ end
21
+ conn.adapter(Faraday.default_adapter)
22
+ end
23
+
24
+ begin
25
+ response = connection.public_send(http_method.to_sym.downcase) do |req|
26
+ build_request(http_method, path, req, opts)
27
+ end
28
+
29
+ if @config.debugging
30
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
31
+ end
32
+
33
+ unless response.success?
34
+ if response.status == 0
35
+ # Errors from libcurl will be made visible here
36
+ fail ApiError.new(:code => 0,
37
+ :message => response.return_message)
38
+ else
39
+ fail ApiError.new(:code => response.status,
40
+ :response_headers => response.headers,
41
+ :response_body => response.body),
42
+ response.reason_phrase
43
+ end
44
+ end
45
+ rescue Faraday::TimeoutError
46
+ fail ApiError.new('Connection timed out')
47
+ end
48
+
49
+ if opts[:return_type]
50
+ data = deserialize(response, opts[:return_type])
51
+ else
52
+ data = nil
53
+ end
54
+ return data, response.status, response.headers
55
+ end
56
+
57
+ # Builds the HTTP request
58
+ #
59
+ # @param [String] http_method HTTP method/verb (e.g. POST)
60
+ # @param [String] path URL path (e.g. /account/new)
61
+ # @option opts [Hash] :header_params Header parameters
62
+ # @option opts [Hash] :query_params Query parameters
63
+ # @option opts [Hash] :form_params Query parameters
64
+ # @option opts [Object] :body HTTP body (JSON/XML)
65
+ # @return [Typhoeus::Request] A Typhoeus Request
66
+ def build_request(http_method, path, request, opts = {})
67
+ url = build_request_url(path, opts)
68
+ http_method = http_method.to_sym.downcase
69
+
70
+ header_params = @default_headers.merge(opts[:header_params] || {})
71
+ query_params = opts[:query_params] || {}
72
+ form_params = opts[:form_params] || {}
73
+
74
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
75
+
76
+ req_opts = {
77
+ :params_encoding => @config.params_encoding,
78
+ :timeout => @config.timeout,
79
+ :verbose => @config.debugging
80
+ }
81
+
82
+ if [:post, :patch, :put, :delete].include?(http_method)
83
+ req_body = build_request_body(header_params, form_params, opts[:body])
84
+ if @config.debugging
85
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
86
+ end
87
+ end
88
+ request.headers = header_params
89
+ request.body = req_body
90
+ request.options = OpenStruct.new(req_opts)
91
+ request.url url
92
+ request.params = query_params
93
+ download_file(request) if opts[:return_type] == 'File'
94
+ request
95
+ end
96
+
97
+ # Builds the HTTP request body
98
+ #
99
+ # @param [Hash] header_params Header parameters
100
+ # @param [Hash] form_params Query parameters
101
+ # @param [Object] body HTTP body (JSON/XML)
102
+ # @return [String] HTTP body data in the form of string
103
+ def build_request_body(header_params, form_params, body)
104
+ # http form
105
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
106
+ data = URI.encode_www_form(form_params)
107
+ elsif header_params['Content-Type'] == 'multipart/form-data'
108
+ data = {}
109
+ form_params.each do |key, value|
110
+ case value
111
+ when ::File, ::Tempfile
112
+ # TODO hardcode to application/octet-stream, need better way to detect content type
113
+ data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
114
+ when ::Array, nil
115
+ # let Faraday handle Array and nil parameters
116
+ data[key] = value
117
+ else
118
+ data[key] = value.to_s
119
+ end
120
+ end
121
+ elsif body
122
+ data = body.is_a?(String) ? body : body.to_json
123
+ else
124
+ data = nil
125
+ end
126
+ data
127
+ end
128
+
129
+ def download_file(request)
130
+ @stream = []
131
+
132
+ # handle streaming Responses
133
+ request.options.on_data = Proc.new do |chunk, overall_received_bytes|
134
+ @stream << chunk
135
+ end
136
+ end