kabustation_client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +188 -0
  4. data/Rakefile +10 -0
  5. data/docs/ApiSoftLimitResponse.md +32 -0
  6. data/docs/AuthApi.md +72 -0
  7. data/docs/BoardSuccess.md +142 -0
  8. data/docs/BoardSuccessBuy1.md +24 -0
  9. data/docs/BoardSuccessBuy10.md +20 -0
  10. data/docs/BoardSuccessBuy2.md +20 -0
  11. data/docs/BoardSuccessBuy3.md +20 -0
  12. data/docs/BoardSuccessBuy4.md +20 -0
  13. data/docs/BoardSuccessBuy5.md +20 -0
  14. data/docs/BoardSuccessBuy6.md +20 -0
  15. data/docs/BoardSuccessBuy7.md +20 -0
  16. data/docs/BoardSuccessBuy8.md +20 -0
  17. data/docs/BoardSuccessBuy9.md +20 -0
  18. data/docs/BoardSuccessSell1.md +24 -0
  19. data/docs/BoardSuccessSell10.md +20 -0
  20. data/docs/BoardSuccessSell2.md +20 -0
  21. data/docs/BoardSuccessSell3.md +20 -0
  22. data/docs/BoardSuccessSell4.md +20 -0
  23. data/docs/BoardSuccessSell5.md +20 -0
  24. data/docs/BoardSuccessSell6.md +20 -0
  25. data/docs/BoardSuccessSell7.md +20 -0
  26. data/docs/BoardSuccessSell8.md +20 -0
  27. data/docs/BoardSuccessSell9.md +20 -0
  28. data/docs/ErrorResponse.md +20 -0
  29. data/docs/ExchangeResponse.md +28 -0
  30. data/docs/InfoApi.md +924 -0
  31. data/docs/MarginPremiumResponse.md +22 -0
  32. data/docs/MarginPremiumResponseDayTrade.md +26 -0
  33. data/docs/MarginPremiumResponseGeneralMargin.md +26 -0
  34. data/docs/OrderApi.md +275 -0
  35. data/docs/OrderSuccess.md +20 -0
  36. data/docs/OrdersSuccess.md +58 -0
  37. data/docs/OrdersSuccessDetailsInner.md +44 -0
  38. data/docs/Positions.md +20 -0
  39. data/docs/PositionsDeriv.md +20 -0
  40. data/docs/PositionsSuccess.md +58 -0
  41. data/docs/PrimaryExchangeResponse.md +20 -0
  42. data/docs/RankingByCategoryResponse.md +22 -0
  43. data/docs/RankingByCategoryResponseRankingInner.md +34 -0
  44. data/docs/RankingByMarginResponse.md +22 -0
  45. data/docs/RankingByMarginResponseRankingInner.md +36 -0
  46. data/docs/RankingByTickCountResponse.md +22 -0
  47. data/docs/RankingByTickCountResponseRankingInner.md +46 -0
  48. data/docs/RankingByTradeValueResponse.md +22 -0
  49. data/docs/RankingByTradeValueResponseRankingInner.md +42 -0
  50. data/docs/RankingByTradeVolumeResponse.md +22 -0
  51. data/docs/RankingByTradeVolumeResponseRankingInner.md +42 -0
  52. data/docs/RankingDefaultResponse.md +22 -0
  53. data/docs/RankingDefaultResponseRankingInner.md +42 -0
  54. data/docs/RankingGet200Response.md +57 -0
  55. data/docs/RegistSuccess.md +18 -0
  56. data/docs/RegisterApi.md +206 -0
  57. data/docs/RegulationsResponse.md +20 -0
  58. data/docs/RegulationsResponseRegulationsInfoInner.md +30 -0
  59. data/docs/RequestCancelOrder.md +20 -0
  60. data/docs/RequestRegister.md +18 -0
  61. data/docs/RequestRegisterSymbolsInner.md +20 -0
  62. data/docs/RequestSendOrder.md +52 -0
  63. data/docs/RequestSendOrderDerivFuture.md +42 -0
  64. data/docs/RequestSendOrderDerivFutureReverseLimitOrder.md +24 -0
  65. data/docs/RequestSendOrderDerivOption.md +42 -0
  66. data/docs/RequestSendOrderReverseLimitOrder.md +26 -0
  67. data/docs/RequestToken.md +18 -0
  68. data/docs/RequestUnregister.md +18 -0
  69. data/docs/SymbolNameSuccess.md +20 -0
  70. data/docs/SymbolSuccess.md +64 -0
  71. data/docs/TokenSuccess.md +20 -0
  72. data/docs/UnregisterAllSuccess.md +18 -0
  73. data/docs/WalletApi.md +535 -0
  74. data/docs/WalletCashSuccess.md +22 -0
  75. data/docs/WalletFutureSuccess.md +22 -0
  76. data/docs/WalletMarginSuccess.md +24 -0
  77. data/docs/WalletOptionSuccess.md +22 -0
  78. data/git_push.sh +57 -0
  79. data/kabustation_client.gemspec +39 -0
  80. data/lib/kabustation_client/api/auth_api.rb +90 -0
  81. data/lib/kabustation_client/api/info_api.rb +1044 -0
  82. data/lib/kabustation_client/api/order_api.rb +322 -0
  83. data/lib/kabustation_client/api/register_api.rb +236 -0
  84. data/lib/kabustation_client/api/wallet_api.rb +558 -0
  85. data/lib/kabustation_client/api_client.rb +393 -0
  86. data/lib/kabustation_client/api_error.rb +58 -0
  87. data/lib/kabustation_client/configuration.rb +295 -0
  88. data/lib/kabustation_client/models/api_soft_limit_response.rb +285 -0
  89. data/lib/kabustation_client/models/board_success.rb +816 -0
  90. data/lib/kabustation_client/models/board_success_buy1.rb +246 -0
  91. data/lib/kabustation_client/models/board_success_buy10.rb +226 -0
  92. data/lib/kabustation_client/models/board_success_buy2.rb +226 -0
  93. data/lib/kabustation_client/models/board_success_buy3.rb +226 -0
  94. data/lib/kabustation_client/models/board_success_buy4.rb +226 -0
  95. data/lib/kabustation_client/models/board_success_buy5.rb +226 -0
  96. data/lib/kabustation_client/models/board_success_buy6.rb +226 -0
  97. data/lib/kabustation_client/models/board_success_buy7.rb +226 -0
  98. data/lib/kabustation_client/models/board_success_buy8.rb +226 -0
  99. data/lib/kabustation_client/models/board_success_buy9.rb +226 -0
  100. data/lib/kabustation_client/models/board_success_sell1.rb +246 -0
  101. data/lib/kabustation_client/models/board_success_sell10.rb +226 -0
  102. data/lib/kabustation_client/models/board_success_sell2.rb +226 -0
  103. data/lib/kabustation_client/models/board_success_sell3.rb +226 -0
  104. data/lib/kabustation_client/models/board_success_sell4.rb +226 -0
  105. data/lib/kabustation_client/models/board_success_sell5.rb +226 -0
  106. data/lib/kabustation_client/models/board_success_sell6.rb +226 -0
  107. data/lib/kabustation_client/models/board_success_sell7.rb +226 -0
  108. data/lib/kabustation_client/models/board_success_sell8.rb +226 -0
  109. data/lib/kabustation_client/models/board_success_sell9.rb +226 -0
  110. data/lib/kabustation_client/models/error_response.rb +225 -0
  111. data/lib/kabustation_client/models/exchange_response.rb +265 -0
  112. data/lib/kabustation_client/models/margin_premium_response.rb +233 -0
  113. data/lib/kabustation_client/models/margin_premium_response_day_trade.rb +256 -0
  114. data/lib/kabustation_client/models/margin_premium_response_general_margin.rb +256 -0
  115. data/lib/kabustation_client/models/order_success.rb +225 -0
  116. data/lib/kabustation_client/models/orders_success.rb +417 -0
  117. data/lib/kabustation_client/models/orders_success_details_inner.rb +345 -0
  118. data/lib/kabustation_client/models/positions.rb +225 -0
  119. data/lib/kabustation_client/models/positions_deriv.rb +225 -0
  120. data/lib/kabustation_client/models/positions_success.rb +415 -0
  121. data/lib/kabustation_client/models/primary_exchange_response.rb +225 -0
  122. data/lib/kabustation_client/models/ranking_by_category_response.rb +237 -0
  123. data/lib/kabustation_client/models/ranking_by_category_response_ranking_inner.rb +295 -0
  124. data/lib/kabustation_client/models/ranking_by_margin_response.rb +237 -0
  125. data/lib/kabustation_client/models/ranking_by_margin_response_ranking_inner.rb +305 -0
  126. data/lib/kabustation_client/models/ranking_by_tick_count_response.rb +237 -0
  127. data/lib/kabustation_client/models/ranking_by_tick_count_response_ranking_inner.rb +355 -0
  128. data/lib/kabustation_client/models/ranking_by_trade_value_response.rb +237 -0
  129. data/lib/kabustation_client/models/ranking_by_trade_value_response_ranking_inner.rb +335 -0
  130. data/lib/kabustation_client/models/ranking_by_trade_volume_response.rb +237 -0
  131. data/lib/kabustation_client/models/ranking_by_trade_volume_response_ranking_inner.rb +335 -0
  132. data/lib/kabustation_client/models/ranking_default_response.rb +237 -0
  133. data/lib/kabustation_client/models/ranking_default_response_ranking_inner.rb +335 -0
  134. data/lib/kabustation_client/models/ranking_get200_response.rb +109 -0
  135. data/lib/kabustation_client/models/regist_success.rb +217 -0
  136. data/lib/kabustation_client/models/regulations_response.rb +227 -0
  137. data/lib/kabustation_client/models/regulations_response_regulations_info_inner.rb +275 -0
  138. data/lib/kabustation_client/models/request_cancel_order.rb +239 -0
  139. data/lib/kabustation_client/models/request_register.rb +216 -0
  140. data/lib/kabustation_client/models/request_register_symbols_inner.rb +225 -0
  141. data/lib/kabustation_client/models/request_send_order.rb +470 -0
  142. data/lib/kabustation_client/models/request_send_order_deriv_future.rb +406 -0
  143. data/lib/kabustation_client/models/request_send_order_deriv_future_reverse_limit_order.rb +274 -0
  144. data/lib/kabustation_client/models/request_send_order_deriv_option.rb +406 -0
  145. data/lib/kabustation_client/models/request_send_order_reverse_limit_order.rb +291 -0
  146. data/lib/kabustation_client/models/request_token.rb +222 -0
  147. data/lib/kabustation_client/models/request_unregister.rb +217 -0
  148. data/lib/kabustation_client/models/symbol_name_success.rb +225 -0
  149. data/lib/kabustation_client/models/symbol_success.rb +445 -0
  150. data/lib/kabustation_client/models/token_success.rb +225 -0
  151. data/lib/kabustation_client/models/unregister_all_success.rb +215 -0
  152. data/lib/kabustation_client/models/wallet_cash_success.rb +235 -0
  153. data/lib/kabustation_client/models/wallet_future_success.rb +235 -0
  154. data/lib/kabustation_client/models/wallet_margin_success.rb +245 -0
  155. data/lib/kabustation_client/models/wallet_option_success.rb +235 -0
  156. data/lib/kabustation_client/version.rb +15 -0
  157. data/lib/kabustation_client.rb +112 -0
  158. data/spec/api/auth_api_spec.rb +47 -0
  159. data/spec/api/info_api_spec.rb +222 -0
  160. data/spec/api/order_api_spec.rb +87 -0
  161. data/spec/api/register_api_spec.rb +73 -0
  162. data/spec/api/wallet_api_spec.rb +135 -0
  163. data/spec/models/api_soft_limit_response_spec.rb +78 -0
  164. data/spec/models/board_success_buy10_spec.rb +42 -0
  165. data/spec/models/board_success_buy1_spec.rb +54 -0
  166. data/spec/models/board_success_buy2_spec.rb +42 -0
  167. data/spec/models/board_success_buy3_spec.rb +42 -0
  168. data/spec/models/board_success_buy4_spec.rb +42 -0
  169. data/spec/models/board_success_buy5_spec.rb +42 -0
  170. data/spec/models/board_success_buy6_spec.rb +42 -0
  171. data/spec/models/board_success_buy7_spec.rb +42 -0
  172. data/spec/models/board_success_buy8_spec.rb +42 -0
  173. data/spec/models/board_success_buy9_spec.rb +42 -0
  174. data/spec/models/board_success_sell10_spec.rb +42 -0
  175. data/spec/models/board_success_sell1_spec.rb +54 -0
  176. data/spec/models/board_success_sell2_spec.rb +42 -0
  177. data/spec/models/board_success_sell3_spec.rb +42 -0
  178. data/spec/models/board_success_sell4_spec.rb +42 -0
  179. data/spec/models/board_success_sell5_spec.rb +42 -0
  180. data/spec/models/board_success_sell6_spec.rb +42 -0
  181. data/spec/models/board_success_sell7_spec.rb +42 -0
  182. data/spec/models/board_success_sell8_spec.rb +42 -0
  183. data/spec/models/board_success_sell9_spec.rb +42 -0
  184. data/spec/models/board_success_spec.rb +408 -0
  185. data/spec/models/error_response_spec.rb +42 -0
  186. data/spec/models/exchange_response_spec.rb +66 -0
  187. data/spec/models/margin_premium_response_day_trade_spec.rb +60 -0
  188. data/spec/models/margin_premium_response_general_margin_spec.rb +60 -0
  189. data/spec/models/margin_premium_response_spec.rb +48 -0
  190. data/spec/models/order_success_spec.rb +42 -0
  191. data/spec/models/orders_success_details_inner_spec.rb +114 -0
  192. data/spec/models/orders_success_spec.rb +156 -0
  193. data/spec/models/positions_deriv_spec.rb +42 -0
  194. data/spec/models/positions_spec.rb +42 -0
  195. data/spec/models/positions_success_spec.rb +156 -0
  196. data/spec/models/primary_exchange_response_spec.rb +42 -0
  197. data/spec/models/ranking_by_category_response_ranking_inner_spec.rb +84 -0
  198. data/spec/models/ranking_by_category_response_spec.rb +48 -0
  199. data/spec/models/ranking_by_margin_response_ranking_inner_spec.rb +90 -0
  200. data/spec/models/ranking_by_margin_response_spec.rb +48 -0
  201. data/spec/models/ranking_by_tick_count_response_ranking_inner_spec.rb +120 -0
  202. data/spec/models/ranking_by_tick_count_response_spec.rb +48 -0
  203. data/spec/models/ranking_by_trade_value_response_ranking_inner_spec.rb +108 -0
  204. data/spec/models/ranking_by_trade_value_response_spec.rb +48 -0
  205. data/spec/models/ranking_by_trade_volume_response_ranking_inner_spec.rb +108 -0
  206. data/spec/models/ranking_by_trade_volume_response_spec.rb +48 -0
  207. data/spec/models/ranking_default_response_ranking_inner_spec.rb +108 -0
  208. data/spec/models/ranking_default_response_spec.rb +48 -0
  209. data/spec/models/ranking_get200_response_spec.rb +32 -0
  210. data/spec/models/regist_success_spec.rb +36 -0
  211. data/spec/models/regulations_response_regulations_info_inner_spec.rb +72 -0
  212. data/spec/models/regulations_response_spec.rb +42 -0
  213. data/spec/models/request_cancel_order_spec.rb +42 -0
  214. data/spec/models/request_register_spec.rb +36 -0
  215. data/spec/models/request_register_symbols_inner_spec.rb +42 -0
  216. data/spec/models/request_send_order_deriv_future_reverse_limit_order_spec.rb +54 -0
  217. data/spec/models/request_send_order_deriv_future_spec.rb +108 -0
  218. data/spec/models/request_send_order_deriv_option_spec.rb +108 -0
  219. data/spec/models/request_send_order_reverse_limit_order_spec.rb +60 -0
  220. data/spec/models/request_send_order_spec.rb +138 -0
  221. data/spec/models/request_token_spec.rb +36 -0
  222. data/spec/models/request_unregister_spec.rb +36 -0
  223. data/spec/models/symbol_name_success_spec.rb +42 -0
  224. data/spec/models/symbol_success_spec.rb +174 -0
  225. data/spec/models/token_success_spec.rb +42 -0
  226. data/spec/models/unregister_all_success_spec.rb +36 -0
  227. data/spec/models/wallet_cash_success_spec.rb +48 -0
  228. data/spec/models/wallet_future_success_spec.rb +48 -0
  229. data/spec/models/wallet_margin_success_spec.rb +54 -0
  230. data/spec/models/wallet_option_success_spec.rb +48 -0
  231. data/spec/spec_helper.rb +111 -0
  232. metadata +387 -0
@@ -0,0 +1,393 @@
1
+ =begin
2
+ #kabuステーションAPI
3
+
4
+ ## 定義情報 REST APIのコード一覧、エンドポイントは下記リンク参照 - [REST APIコード一覧](../ptal/error.html)
5
+
6
+ The version of the OpenAPI document: 1.5
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+
21
+ module KabustationClient
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ # Initializes the ApiClient
32
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
+ def initialize(config = Configuration.default)
34
+ @config = config
35
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
36
+ @default_headers = {
37
+ 'Content-Type' => 'application/json',
38
+ 'User-Agent' => @user_agent
39
+ }
40
+ end
41
+
42
+ def self.default
43
+ @@default ||= ApiClient.new
44
+ end
45
+
46
+ # Call an API with given options.
47
+ #
48
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
49
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
50
+ def call_api(http_method, path, opts = {})
51
+ request = build_request(http_method, path, opts)
52
+ tempfile = download_file(request) if opts[:return_type] == 'File'
53
+ response = request.run
54
+
55
+ if @config.debugging
56
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
57
+ end
58
+
59
+ unless response.success?
60
+ if response.timed_out?
61
+ fail ApiError.new('Connection timed out')
62
+ elsif response.code == 0
63
+ # Errors from libcurl will be made visible here
64
+ fail ApiError.new(:code => 0,
65
+ :message => response.return_message)
66
+ else
67
+ fail ApiError.new(:code => response.code,
68
+ :response_headers => response.headers,
69
+ :response_body => response.body),
70
+ response.status_message
71
+ end
72
+ end
73
+
74
+ if opts[:return_type] == 'File'
75
+ data = tempfile
76
+ elsif opts[:return_type]
77
+ data = deserialize(response, opts[:return_type])
78
+ else
79
+ data = nil
80
+ end
81
+ return data, response.code, response.headers
82
+ end
83
+
84
+ # Builds the HTTP request
85
+ #
86
+ # @param [String] http_method HTTP method/verb (e.g. POST)
87
+ # @param [String] path URL path (e.g. /account/new)
88
+ # @option opts [Hash] :header_params Header parameters
89
+ # @option opts [Hash] :query_params Query parameters
90
+ # @option opts [Hash] :form_params Query parameters
91
+ # @option opts [Object] :body HTTP body (JSON/XML)
92
+ # @return [Typhoeus::Request] A Typhoeus Request
93
+ def build_request(http_method, path, opts = {})
94
+ url = build_request_url(path, opts)
95
+ http_method = http_method.to_sym.downcase
96
+
97
+ header_params = @default_headers.merge(opts[:header_params] || {})
98
+ query_params = opts[:query_params] || {}
99
+ form_params = opts[:form_params] || {}
100
+ follow_location = opts[:follow_location] || true
101
+
102
+
103
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
104
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
105
+
106
+ req_opts = {
107
+ :method => http_method,
108
+ :headers => header_params,
109
+ :params => query_params,
110
+ :params_encoding => @config.params_encoding,
111
+ :timeout => @config.timeout,
112
+ :ssl_verifypeer => @config.verify_ssl,
113
+ :ssl_verifyhost => _verify_ssl_host,
114
+ :sslcert => @config.cert_file,
115
+ :sslkey => @config.key_file,
116
+ :verbose => @config.debugging,
117
+ :followlocation => follow_location
118
+ }
119
+
120
+ # set custom cert, if provided
121
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
122
+
123
+ if [:post, :patch, :put, :delete].include?(http_method)
124
+ req_body = build_request_body(header_params, form_params, opts[:body])
125
+ req_opts.update :body => req_body
126
+ if @config.debugging
127
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
128
+ end
129
+ end
130
+
131
+ Typhoeus::Request.new(url, req_opts)
132
+ end
133
+
134
+ # Builds the HTTP request body
135
+ #
136
+ # @param [Hash] header_params Header parameters
137
+ # @param [Hash] form_params Query parameters
138
+ # @param [Object] body HTTP body (JSON/XML)
139
+ # @return [String] HTTP body data in the form of string
140
+ def build_request_body(header_params, form_params, body)
141
+ # http form
142
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
143
+ header_params['Content-Type'] == 'multipart/form-data'
144
+ data = {}
145
+ form_params.each do |key, value|
146
+ case value
147
+ when ::File, ::Array, nil
148
+ # let typhoeus handle File, Array and nil parameters
149
+ data[key] = value
150
+ else
151
+ data[key] = value.to_s
152
+ end
153
+ end
154
+ elsif body
155
+ data = body.is_a?(String) ? body : body.to_json
156
+ else
157
+ data = nil
158
+ end
159
+ data
160
+ end
161
+
162
+ # Save response body into a file in (the defined) temporary folder, using the filename
163
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
164
+ # The response body is written to the file in chunks in order to handle files which
165
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
166
+ # process can use.
167
+ #
168
+ # @see Configuration#temp_folder_path
169
+ #
170
+ # @return [Tempfile] the tempfile generated
171
+ def download_file(request)
172
+ tempfile = nil
173
+ encoding = nil
174
+ request.on_headers do |response|
175
+ content_disposition = response.headers['Content-Disposition']
176
+ if content_disposition && content_disposition =~ /filename=/i
177
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
178
+ prefix = sanitize_filename(filename)
179
+ else
180
+ prefix = 'download-'
181
+ end
182
+ prefix = prefix + '-' unless prefix.end_with?('-')
183
+ encoding = response.body.encoding
184
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
185
+ end
186
+ request.on_body do |chunk|
187
+ chunk.force_encoding(encoding)
188
+ tempfile.write(chunk)
189
+ end
190
+ # run the request to ensure the tempfile is created successfully before returning it
191
+ request.run
192
+ if tempfile
193
+ tempfile.close
194
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
195
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
196
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
197
+ "explicitly with `tempfile.delete`"
198
+ else
199
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
200
+ end
201
+
202
+ tempfile
203
+ end
204
+
205
+ # Check if the given MIME is a JSON MIME.
206
+ # JSON MIME examples:
207
+ # application/json
208
+ # application/json; charset=UTF8
209
+ # APPLICATION/JSON
210
+ # */*
211
+ # @param [String] mime MIME
212
+ # @return [Boolean] True if the MIME is application/json
213
+ def json_mime?(mime)
214
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
215
+ end
216
+
217
+ # Deserialize the response to the given return type.
218
+ #
219
+ # @param [Response] response HTTP response
220
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
221
+ def deserialize(response, return_type)
222
+ body = response.body
223
+ return nil if body.nil? || body.empty?
224
+
225
+ # return response body directly for String return type
226
+ return body.to_s if return_type == 'String'
227
+
228
+ # ensuring a default content type
229
+ content_type = response.headers['Content-Type'] || 'application/json'
230
+
231
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
232
+
233
+ begin
234
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
235
+ rescue JSON::ParserError => e
236
+ if %w(String Date Time).include?(return_type)
237
+ data = body
238
+ else
239
+ raise e
240
+ end
241
+ end
242
+
243
+ convert_to_type data, return_type
244
+ end
245
+
246
+ # Convert data to the given return type.
247
+ # @param [Object] data Data to be converted
248
+ # @param [String] return_type Return type
249
+ # @return [Mixed] Data in a particular type
250
+ def convert_to_type(data, return_type)
251
+ return nil if data.nil?
252
+ case return_type
253
+ when 'String'
254
+ data.to_s
255
+ when 'Integer'
256
+ data.to_i
257
+ when 'Float'
258
+ data.to_f
259
+ when 'Boolean'
260
+ data == true
261
+ when 'Time'
262
+ # parse date time (expecting ISO 8601 format)
263
+ Time.parse data
264
+ when 'Date'
265
+ # parse date time (expecting ISO 8601 format)
266
+ Date.parse data
267
+ when 'Object'
268
+ # generic object (usually a Hash), return directly
269
+ data
270
+ when /\AArray<(.+)>\z/
271
+ # e.g. Array<Pet>
272
+ sub_type = $1
273
+ data.map { |item| convert_to_type(item, sub_type) }
274
+ when /\AHash\<String, (.+)\>\z/
275
+ # e.g. Hash<String, Integer>
276
+ sub_type = $1
277
+ {}.tap do |hash|
278
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
279
+ end
280
+ else
281
+ # models (e.g. Pet) or oneOf
282
+ klass = KabustationClient.const_get(return_type)
283
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
284
+ end
285
+ end
286
+
287
+ # Sanitize filename by removing path.
288
+ # e.g. ../../sun.gif becomes sun.gif
289
+ #
290
+ # @param [String] filename the filename to be sanitized
291
+ # @return [String] the sanitized filename
292
+ def sanitize_filename(filename)
293
+ filename.gsub(/.*[\/\\]/, '')
294
+ end
295
+
296
+ def build_request_url(path, opts = {})
297
+ # Add leading and trailing slashes to path
298
+ path = "/#{path}".gsub(/\/+/, '/')
299
+ @config.base_url(opts[:operation]) + path
300
+ end
301
+
302
+ # Update header and query params based on authentication settings.
303
+ #
304
+ # @param [Hash] header_params Header parameters
305
+ # @param [Hash] query_params Query parameters
306
+ # @param [String] auth_names Authentication scheme name
307
+ def update_params_for_auth!(header_params, query_params, auth_names)
308
+ Array(auth_names).each do |auth_name|
309
+ auth_setting = @config.auth_settings[auth_name]
310
+ next unless auth_setting
311
+ case auth_setting[:in]
312
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
313
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
314
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
315
+ end
316
+ end
317
+ end
318
+
319
+ # Sets user agent in HTTP header
320
+ #
321
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
322
+ def user_agent=(user_agent)
323
+ @user_agent = user_agent
324
+ @default_headers['User-Agent'] = @user_agent
325
+ end
326
+
327
+ # Return Accept header based on an array of accepts provided.
328
+ # @param [Array] accepts array for Accept
329
+ # @return [String] the Accept header (e.g. application/json)
330
+ def select_header_accept(accepts)
331
+ return nil if accepts.nil? || accepts.empty?
332
+ # use JSON when present, otherwise use all of the provided
333
+ json_accept = accepts.find { |s| json_mime?(s) }
334
+ json_accept || accepts.join(',')
335
+ end
336
+
337
+ # Return Content-Type header based on an array of content types provided.
338
+ # @param [Array] content_types array for Content-Type
339
+ # @return [String] the Content-Type header (e.g. application/json)
340
+ def select_header_content_type(content_types)
341
+ # return nil by default
342
+ return if content_types.nil? || content_types.empty?
343
+ # use JSON when present, otherwise use the first one
344
+ json_content_type = content_types.find { |s| json_mime?(s) }
345
+ json_content_type || content_types.first
346
+ end
347
+
348
+ # Convert object (array, hash, object, etc) to JSON string.
349
+ # @param [Object] model object to be converted into JSON string
350
+ # @return [String] JSON string representation of the object
351
+ def object_to_http_body(model)
352
+ return model if model.nil? || model.is_a?(String)
353
+ local_body = nil
354
+ if model.is_a?(Array)
355
+ local_body = model.map { |m| object_to_hash(m) }
356
+ else
357
+ local_body = object_to_hash(model)
358
+ end
359
+ local_body.to_json
360
+ end
361
+
362
+ # Convert object(non-array) to hash.
363
+ # @param [Object] obj object to be converted into JSON string
364
+ # @return [String] JSON string representation of the object
365
+ def object_to_hash(obj)
366
+ if obj.respond_to?(:to_hash)
367
+ obj.to_hash
368
+ else
369
+ obj
370
+ end
371
+ end
372
+
373
+ # Build parameter value according to the given collection format.
374
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
375
+ def build_collection_param(param, collection_format)
376
+ case collection_format
377
+ when :csv
378
+ param.join(',')
379
+ when :ssv
380
+ param.join(' ')
381
+ when :tsv
382
+ param.join("\t")
383
+ when :pipes
384
+ param.join('|')
385
+ when :multi
386
+ # return the array directly as typhoeus will handle it as expected
387
+ param
388
+ else
389
+ fail "unknown collection format: #{collection_format.inspect}"
390
+ end
391
+ end
392
+ end
393
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+ #kabuステーションAPI
3
+
4
+ ## 定義情報 REST APIのコード一覧、エンドポイントは下記リンク参照 - [REST APIコード一覧](../ptal/error.html)
5
+
6
+ The version of the OpenAPI document: 1.5
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.4.0
10
+
11
+ =end
12
+
13
+ module KabustationClient
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ @message = arg
36
+ end
37
+ end
38
+
39
+ # Override to_s to display a friendly error message
40
+ def to_s
41
+ message
42
+ end
43
+
44
+ def message
45
+ if @message.nil?
46
+ msg = "Error message: the server returns an error"
47
+ else
48
+ msg = @message
49
+ end
50
+
51
+ msg += "\nHTTP status code: #{code}" if code
52
+ msg += "\nResponse headers: #{response_headers}" if response_headers
53
+ msg += "\nResponse body: #{response_body}" if response_body
54
+
55
+ msg
56
+ end
57
+ end
58
+ end