teleswagger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (368) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +69 -0
  4. data/README.md +260 -0
  5. data/Rakefile +8 -0
  6. data/config.json +5 -0
  7. data/docs/AddStickerToSetLinkBody.md +12 -0
  8. data/docs/AllowedUpdate.md +7 -0
  9. data/docs/Animation.md +12 -0
  10. data/docs/AnswerInlineQueryBody.md +14 -0
  11. data/docs/AnswerShippingQueryBody.md +11 -0
  12. data/docs/AttachmentsApi.md +1023 -0
  13. data/docs/Audio.md +13 -0
  14. data/docs/CallbackGame.md +7 -0
  15. data/docs/CallbackQuery.md +14 -0
  16. data/docs/CallbacksApi.md +70 -0
  17. data/docs/Chat.md +18 -0
  18. data/docs/ChatMember.md +23 -0
  19. data/docs/ChatPhoto.md +9 -0
  20. data/docs/ChatsApi.md +890 -0
  21. data/docs/ChosenInlineResult.md +12 -0
  22. data/docs/Contact.md +11 -0
  23. data/docs/CreateNewStickerSetLinkBody.md +14 -0
  24. data/docs/Document.md +12 -0
  25. data/docs/EditMessageCaptionBody.md +12 -0
  26. data/docs/EditMessageReplyMarkupBody.md +11 -0
  27. data/docs/EditMessageTextBody.md +14 -0
  28. data/docs/Error.md +10 -0
  29. data/docs/File.md +10 -0
  30. data/docs/ForceReply.md +9 -0
  31. data/docs/Game.md +13 -0
  32. data/docs/GameHighScore.md +10 -0
  33. data/docs/GamesApi.md +182 -0
  34. data/docs/InlineApi.md +59 -0
  35. data/docs/InlineKeyboardButton.md +14 -0
  36. data/docs/InlineKeyboardMarkup.md +8 -0
  37. data/docs/InlineQuery.md +12 -0
  38. data/docs/InlineQueryResultArticle.md +18 -0
  39. data/docs/InlineQueryResultAudio.md +16 -0
  40. data/docs/InlineQueryResultCachedAudio.md +13 -0
  41. data/docs/InlineQueryResultCachedDocument.md +14 -0
  42. data/docs/InlineQueryResultCachedGif.md +14 -0
  43. data/docs/InlineQueryResultCachedMpeg4Gif.md +14 -0
  44. data/docs/InlineQueryResultCachedPhoto.md +15 -0
  45. data/docs/InlineQueryResultCachedSticker.md +12 -0
  46. data/docs/InlineQueryResultCachedVideo.md +15 -0
  47. data/docs/InlineQueryResultCachedVoice.md +14 -0
  48. data/docs/InlineQueryResultContact.md +17 -0
  49. data/docs/InlineQueryResultDocument.md +19 -0
  50. data/docs/InlineQueryResultGame.md +11 -0
  51. data/docs/InlineQueryResultGif.md +18 -0
  52. data/docs/InlineQueryResultLocation.md +17 -0
  53. data/docs/InlineQueryResultMpeg4Gif.md +18 -0
  54. data/docs/InlineQueryResultPhoto.md +17 -0
  55. data/docs/InlineQueryResultVenue.md +19 -0
  56. data/docs/InlineQueryResultVideo.md +20 -0
  57. data/docs/InlineQueryResultVoice.md +15 -0
  58. data/docs/InlineResponse200.md +11 -0
  59. data/docs/InlineResponse2001.md +11 -0
  60. data/docs/InlineResponse2002.md +11 -0
  61. data/docs/InlineResponse2003.md +11 -0
  62. data/docs/InlineResponse2004.md +11 -0
  63. data/docs/InlineResponse2005.md +11 -0
  64. data/docs/InlineResponse2006.md +11 -0
  65. data/docs/InlineResponse2007.md +11 -0
  66. data/docs/InlineResponse2008.md +11 -0
  67. data/docs/InlineResponse2009.md +11 -0
  68. data/docs/InlineType.md +7 -0
  69. data/docs/InputContactMessageContent.md +10 -0
  70. data/docs/InputLocationMessageContent.md +9 -0
  71. data/docs/InputTextMessageContent.md +10 -0
  72. data/docs/InputVenueMessageContent.md +12 -0
  73. data/docs/Invoice.md +12 -0
  74. data/docs/KeyboardButton.md +10 -0
  75. data/docs/LabeledPrice.md +9 -0
  76. data/docs/Location.md +9 -0
  77. data/docs/MaskPosition.md +11 -0
  78. data/docs/Message.md +45 -0
  79. data/docs/MessageEntity.md +12 -0
  80. data/docs/MessagesApi.md +375 -0
  81. data/docs/OrderInfo.md +11 -0
  82. data/docs/ParseMode.md +7 -0
  83. data/docs/PaymentsApi.md +167 -0
  84. data/docs/PhotoSize.md +11 -0
  85. data/docs/PreCheckoutQuery.md +14 -0
  86. data/docs/PromoteChatMemberBody.md +17 -0
  87. data/docs/ReplyKeyboardMarkup.md +11 -0
  88. data/docs/ReplyKeyboardRemove.md +9 -0
  89. data/docs/ResponseBool.md +11 -0
  90. data/docs/ResponseMessage.md +11 -0
  91. data/docs/ResponseParameters.md +9 -0
  92. data/docs/ResponseUpdate.md +11 -0
  93. data/docs/RestrictChatMemberBody.md +14 -0
  94. data/docs/SendAudioLinkBody.md +16 -0
  95. data/docs/SendContactBody.md +14 -0
  96. data/docs/SendDocumentLinkBody.md +13 -0
  97. data/docs/SendGameBody.md +12 -0
  98. data/docs/SendInvoiceBody.md +27 -0
  99. data/docs/SendLocationBody.md +13 -0
  100. data/docs/SendMessageBody.md +14 -0
  101. data/docs/SendPhotoLinkBody.md +13 -0
  102. data/docs/SendStickerLinkBody.md +12 -0
  103. data/docs/SendVenueBody.md +16 -0
  104. data/docs/SendVideoLinkBody.md +16 -0
  105. data/docs/SendVideoNoteLinkBody.md +14 -0
  106. data/docs/SendVoiceLinkBody.md +14 -0
  107. data/docs/ShippingAddress.md +13 -0
  108. data/docs/ShippingOption.md +10 -0
  109. data/docs/ShippingQuery.md +11 -0
  110. data/docs/Sticker.md +15 -0
  111. data/docs/StickerSet.md +11 -0
  112. data/docs/StickersApi.md +498 -0
  113. data/docs/SuccessfulPayment.md +14 -0
  114. data/docs/Update.md +17 -0
  115. data/docs/UpdatesApi.md +205 -0
  116. data/docs/User.md +13 -0
  117. data/docs/UserProfilePhotos.md +9 -0
  118. data/docs/UsersApi.md +111 -0
  119. data/docs/Venue.md +11 -0
  120. data/docs/Video.md +14 -0
  121. data/docs/VideoNote.md +12 -0
  122. data/docs/Voice.md +11 -0
  123. data/docs/WebhookInfo.md +14 -0
  124. data/lib/teleswagger.rb +156 -0
  125. data/lib/teleswagger/api/attachments_api.rb +1243 -0
  126. data/lib/teleswagger/api/callbacks_api.rb +113 -0
  127. data/lib/teleswagger/api/chats_api.rb +1141 -0
  128. data/lib/teleswagger/api/games_api.rb +235 -0
  129. data/lib/teleswagger/api/inline_api.rb +80 -0
  130. data/lib/teleswagger/api/messages_api.rb +460 -0
  131. data/lib/teleswagger/api/payments_api.rb +209 -0
  132. data/lib/teleswagger/api/stickers_api.rb +658 -0
  133. data/lib/teleswagger/api/updates_api.rb +265 -0
  134. data/lib/teleswagger/api/users_api.rb +146 -0
  135. data/lib/teleswagger/api_client.rb +388 -0
  136. data/lib/teleswagger/api_error.rb +38 -0
  137. data/lib/teleswagger/configuration.rb +202 -0
  138. data/lib/teleswagger/models/add_sticker_to_set_link_body.rb +244 -0
  139. data/lib/teleswagger/models/allowed_update.rb +27 -0
  140. data/lib/teleswagger/models/animation.rb +229 -0
  141. data/lib/teleswagger/models/answer_inline_query_body.rb +254 -0
  142. data/lib/teleswagger/models/answer_shipping_query_body.rb +227 -0
  143. data/lib/teleswagger/models/audio.rb +233 -0
  144. data/lib/teleswagger/models/callback_game.rb +179 -0
  145. data/lib/teleswagger/models/callback_query.rb +242 -0
  146. data/lib/teleswagger/models/chat.rb +321 -0
  147. data/lib/teleswagger/models/chat_member.rb +366 -0
  148. data/lib/teleswagger/models/chat_photo.rb +197 -0
  149. data/lib/teleswagger/models/chosen_inline_result.rb +239 -0
  150. data/lib/teleswagger/models/contact.rb +215 -0
  151. data/lib/teleswagger/models/create_new_sticker_set_link_body.rb +267 -0
  152. data/lib/teleswagger/models/document.rb +224 -0
  153. data/lib/teleswagger/models/edit_message_caption_body.rb +224 -0
  154. data/lib/teleswagger/models/edit_message_reply_markup_body.rb +215 -0
  155. data/lib/teleswagger/models/edit_message_text_body.rb +247 -0
  156. data/lib/teleswagger/models/error.rb +206 -0
  157. data/lib/teleswagger/models/file.rb +206 -0
  158. data/lib/teleswagger/models/force_reply.rb +197 -0
  159. data/lib/teleswagger/models/game.rb +252 -0
  160. data/lib/teleswagger/models/game_high_score.rb +206 -0
  161. data/lib/teleswagger/models/inline_keyboard_button.rb +242 -0
  162. data/lib/teleswagger/models/inline_keyboard_markup.rb +190 -0
  163. data/lib/teleswagger/models/inline_query.rb +224 -0
  164. data/lib/teleswagger/models/inline_query_result_article.rb +298 -0
  165. data/lib/teleswagger/models/inline_query_result_audio.rb +280 -0
  166. data/lib/teleswagger/models/inline_query_result_cached_audio.rb +248 -0
  167. data/lib/teleswagger/models/inline_query_result_cached_document.rb +257 -0
  168. data/lib/teleswagger/models/inline_query_result_cached_gif.rb +257 -0
  169. data/lib/teleswagger/models/inline_query_result_cached_mpeg4_gif.rb +257 -0
  170. data/lib/teleswagger/models/inline_query_result_cached_photo.rb +266 -0
  171. data/lib/teleswagger/models/inline_query_result_cached_sticker.rb +239 -0
  172. data/lib/teleswagger/models/inline_query_result_cached_video.rb +266 -0
  173. data/lib/teleswagger/models/inline_query_result_cached_voice.rb +257 -0
  174. data/lib/teleswagger/models/inline_query_result_contact.rb +289 -0
  175. data/lib/teleswagger/models/inline_query_result_document.rb +312 -0
  176. data/lib/teleswagger/models/inline_query_result_game.rb +230 -0
  177. data/lib/teleswagger/models/inline_query_result_gif.rb +298 -0
  178. data/lib/teleswagger/models/inline_query_result_location.rb +294 -0
  179. data/lib/teleswagger/models/inline_query_result_mpeg4_gif.rb +298 -0
  180. data/lib/teleswagger/models/inline_query_result_photo.rb +289 -0
  181. data/lib/teleswagger/models/inline_query_result_venue.rb +317 -0
  182. data/lib/teleswagger/models/inline_query_result_video.rb +326 -0
  183. data/lib/teleswagger/models/inline_query_result_voice.rb +271 -0
  184. data/lib/teleswagger/models/inline_response_200.rb +215 -0
  185. data/lib/teleswagger/models/inline_response_200_1.rb +215 -0
  186. data/lib/teleswagger/models/inline_response_200_2.rb +215 -0
  187. data/lib/teleswagger/models/inline_response_200_3.rb +215 -0
  188. data/lib/teleswagger/models/inline_response_200_4.rb +217 -0
  189. data/lib/teleswagger/models/inline_response_200_5.rb +215 -0
  190. data/lib/teleswagger/models/inline_response_200_6.rb +215 -0
  191. data/lib/teleswagger/models/inline_response_200_7.rb +215 -0
  192. data/lib/teleswagger/models/inline_response_200_8.rb +215 -0
  193. data/lib/teleswagger/models/inline_response_200_9.rb +215 -0
  194. data/lib/teleswagger/models/inline_type.rb +33 -0
  195. data/lib/teleswagger/models/input_contact_message_content.rb +216 -0
  196. data/lib/teleswagger/models/input_location_message_content.rb +207 -0
  197. data/lib/teleswagger/models/input_text_message_content.rb +211 -0
  198. data/lib/teleswagger/models/input_venue_message_content.rb +244 -0
  199. data/lib/teleswagger/models/invoice.rb +224 -0
  200. data/lib/teleswagger/models/keyboard_button.rb +206 -0
  201. data/lib/teleswagger/models/labeled_price.rb +197 -0
  202. data/lib/teleswagger/models/location.rb +197 -0
  203. data/lib/teleswagger/models/mask_position.rb +248 -0
  204. data/lib/teleswagger/models/message.rb +529 -0
  205. data/lib/teleswagger/models/message_entity.rb +257 -0
  206. data/lib/teleswagger/models/order_info.rb +215 -0
  207. data/lib/teleswagger/models/parse_mode.rb +22 -0
  208. data/lib/teleswagger/models/photo_size.rb +215 -0
  209. data/lib/teleswagger/models/pre_checkout_query.rb +242 -0
  210. data/lib/teleswagger/models/promote_chat_member_body.rb +279 -0
  211. data/lib/teleswagger/models/reply_keyboard_markup.rb +217 -0
  212. data/lib/teleswagger/models/reply_keyboard_remove.rb +197 -0
  213. data/lib/teleswagger/models/response_bool.rb +215 -0
  214. data/lib/teleswagger/models/response_message.rb +215 -0
  215. data/lib/teleswagger/models/response_parameters.rb +197 -0
  216. data/lib/teleswagger/models/response_update.rb +217 -0
  217. data/lib/teleswagger/models/restrict_chat_member_body.rb +252 -0
  218. data/lib/teleswagger/models/send_audio_link_body.rb +270 -0
  219. data/lib/teleswagger/models/send_contact_body.rb +257 -0
  220. data/lib/teleswagger/models/send_document_link_body.rb +243 -0
  221. data/lib/teleswagger/models/send_game_body.rb +234 -0
  222. data/lib/teleswagger/models/send_invoice_body.rb +401 -0
  223. data/lib/teleswagger/models/send_location_body.rb +248 -0
  224. data/lib/teleswagger/models/send_message_body.rb +252 -0
  225. data/lib/teleswagger/models/send_photo_link_body.rb +243 -0
  226. data/lib/teleswagger/models/send_sticker_link_body.rb +234 -0
  227. data/lib/teleswagger/models/send_venue_body.rb +285 -0
  228. data/lib/teleswagger/models/send_video_link_body.rb +270 -0
  229. data/lib/teleswagger/models/send_video_note_link_body.rb +252 -0
  230. data/lib/teleswagger/models/send_voice_link_body.rb +252 -0
  231. data/lib/teleswagger/models/shipping_address.rb +233 -0
  232. data/lib/teleswagger/models/shipping_option.rb +208 -0
  233. data/lib/teleswagger/models/shipping_query.rb +215 -0
  234. data/lib/teleswagger/models/sticker.rb +251 -0
  235. data/lib/teleswagger/models/sticker_set.rb +217 -0
  236. data/lib/teleswagger/models/successful_payment.rb +242 -0
  237. data/lib/teleswagger/models/update.rb +269 -0
  238. data/lib/teleswagger/models/user.rb +233 -0
  239. data/lib/teleswagger/models/user_profile_photos.rb +199 -0
  240. data/lib/teleswagger/models/venue.rb +215 -0
  241. data/lib/teleswagger/models/video.rb +242 -0
  242. data/lib/teleswagger/models/video_note.rb +224 -0
  243. data/lib/teleswagger/models/voice.rb +215 -0
  244. data/lib/teleswagger/models/webhook_info.rb +259 -0
  245. data/lib/teleswagger/version.rb +15 -0
  246. data/spec/api/attachments_api_spec.rb +311 -0
  247. data/spec/api/callbacks_api_spec.rb +52 -0
  248. data/spec/api/chats_api_spec.rb +266 -0
  249. data/spec/api/games_api_spec.rb +83 -0
  250. data/spec/api/inline_api_spec.rb +48 -0
  251. data/spec/api/messages_api_spec.rb +130 -0
  252. data/spec/api/payments_api_spec.rb +76 -0
  253. data/spec/api/stickers_api_spec.rb +165 -0
  254. data/spec/api/updates_api_spec.rb +89 -0
  255. data/spec/api/users_api_spec.rb +62 -0
  256. data/spec/api_client_spec.rb +226 -0
  257. data/spec/configuration_spec.rb +42 -0
  258. data/spec/models/add_sticker_to_set_link_body_spec.rb +66 -0
  259. data/spec/models/allowed_update_spec.rb +36 -0
  260. data/spec/models/animation_spec.rb +66 -0
  261. data/spec/models/answer_inline_query_body_spec.rb +78 -0
  262. data/spec/models/answer_shipping_query_body_spec.rb +60 -0
  263. data/spec/models/audio_spec.rb +72 -0
  264. data/spec/models/callback_game_spec.rb +36 -0
  265. data/spec/models/callback_query_spec.rb +78 -0
  266. data/spec/models/chat_member_spec.rb +136 -0
  267. data/spec/models/chat_photo_spec.rb +48 -0
  268. data/spec/models/chat_spec.rb +106 -0
  269. data/spec/models/chosen_inline_result_spec.rb +66 -0
  270. data/spec/models/contact_spec.rb +60 -0
  271. data/spec/models/create_new_sticker_set_link_body_spec.rb +78 -0
  272. data/spec/models/document_spec.rb +66 -0
  273. data/spec/models/edit_message_caption_body_spec.rb +66 -0
  274. data/spec/models/edit_message_reply_markup_body_spec.rb +60 -0
  275. data/spec/models/edit_message_text_body_spec.rb +78 -0
  276. data/spec/models/error_spec.rb +54 -0
  277. data/spec/models/file_spec.rb +54 -0
  278. data/spec/models/force_reply_spec.rb +48 -0
  279. data/spec/models/game_high_score_spec.rb +54 -0
  280. data/spec/models/game_spec.rb +72 -0
  281. data/spec/models/inline_keyboard_button_spec.rb +78 -0
  282. data/spec/models/inline_keyboard_markup_spec.rb +42 -0
  283. data/spec/models/inline_query_result_article_spec.rb +102 -0
  284. data/spec/models/inline_query_result_audio_spec.rb +90 -0
  285. data/spec/models/inline_query_result_cached_audio_spec.rb +72 -0
  286. data/spec/models/inline_query_result_cached_document_spec.rb +78 -0
  287. data/spec/models/inline_query_result_cached_gif_spec.rb +78 -0
  288. data/spec/models/inline_query_result_cached_mpeg4_gif_spec.rb +78 -0
  289. data/spec/models/inline_query_result_cached_photo_spec.rb +84 -0
  290. data/spec/models/inline_query_result_cached_sticker_spec.rb +66 -0
  291. data/spec/models/inline_query_result_cached_video_spec.rb +84 -0
  292. data/spec/models/inline_query_result_cached_voice_spec.rb +78 -0
  293. data/spec/models/inline_query_result_contact_spec.rb +96 -0
  294. data/spec/models/inline_query_result_document_spec.rb +108 -0
  295. data/spec/models/inline_query_result_game_spec.rb +60 -0
  296. data/spec/models/inline_query_result_gif_spec.rb +102 -0
  297. data/spec/models/inline_query_result_location_spec.rb +96 -0
  298. data/spec/models/inline_query_result_mpeg4_gif_spec.rb +102 -0
  299. data/spec/models/inline_query_result_photo_spec.rb +96 -0
  300. data/spec/models/inline_query_result_venue_spec.rb +108 -0
  301. data/spec/models/inline_query_result_video_spec.rb +114 -0
  302. data/spec/models/inline_query_result_voice_spec.rb +84 -0
  303. data/spec/models/inline_query_spec.rb +66 -0
  304. data/spec/models/inline_response_200_1_spec.rb +60 -0
  305. data/spec/models/inline_response_200_2_spec.rb +60 -0
  306. data/spec/models/inline_response_200_3_spec.rb +60 -0
  307. data/spec/models/inline_response_200_4_spec.rb +60 -0
  308. data/spec/models/inline_response_200_5_spec.rb +60 -0
  309. data/spec/models/inline_response_200_6_spec.rb +60 -0
  310. data/spec/models/inline_response_200_7_spec.rb +60 -0
  311. data/spec/models/inline_response_200_8_spec.rb +60 -0
  312. data/spec/models/inline_response_200_9_spec.rb +60 -0
  313. data/spec/models/inline_response_200_spec.rb +60 -0
  314. data/spec/models/inline_type_spec.rb +36 -0
  315. data/spec/models/input_contact_message_content_spec.rb +54 -0
  316. data/spec/models/input_location_message_content_spec.rb +48 -0
  317. data/spec/models/input_text_message_content_spec.rb +54 -0
  318. data/spec/models/input_venue_message_content_spec.rb +66 -0
  319. data/spec/models/invoice_spec.rb +66 -0
  320. data/spec/models/keyboard_button_spec.rb +54 -0
  321. data/spec/models/labeled_price_spec.rb +48 -0
  322. data/spec/models/location_spec.rb +48 -0
  323. data/spec/models/mask_position_spec.rb +64 -0
  324. data/spec/models/message_entity_spec.rb +70 -0
  325. data/spec/models/message_spec.rb +264 -0
  326. data/spec/models/order_info_spec.rb +60 -0
  327. data/spec/models/parse_mode_spec.rb +36 -0
  328. data/spec/models/photo_size_spec.rb +60 -0
  329. data/spec/models/pre_checkout_query_spec.rb +78 -0
  330. data/spec/models/promote_chat_member_body_spec.rb +96 -0
  331. data/spec/models/reply_keyboard_markup_spec.rb +60 -0
  332. data/spec/models/reply_keyboard_remove_spec.rb +48 -0
  333. data/spec/models/response_bool_spec.rb +60 -0
  334. data/spec/models/response_message_spec.rb +60 -0
  335. data/spec/models/response_parameters_spec.rb +48 -0
  336. data/spec/models/response_update_spec.rb +60 -0
  337. data/spec/models/restrict_chat_member_body_spec.rb +78 -0
  338. data/spec/models/send_audio_link_body_spec.rb +90 -0
  339. data/spec/models/send_contact_body_spec.rb +78 -0
  340. data/spec/models/send_document_link_body_spec.rb +72 -0
  341. data/spec/models/send_game_body_spec.rb +66 -0
  342. data/spec/models/send_invoice_body_spec.rb +156 -0
  343. data/spec/models/send_location_body_spec.rb +72 -0
  344. data/spec/models/send_message_body_spec.rb +78 -0
  345. data/spec/models/send_photo_link_body_spec.rb +72 -0
  346. data/spec/models/send_sticker_link_body_spec.rb +66 -0
  347. data/spec/models/send_venue_body_spec.rb +90 -0
  348. data/spec/models/send_video_link_body_spec.rb +90 -0
  349. data/spec/models/send_video_note_link_body_spec.rb +78 -0
  350. data/spec/models/send_voice_link_body_spec.rb +78 -0
  351. data/spec/models/shipping_address_spec.rb +72 -0
  352. data/spec/models/shipping_option_spec.rb +54 -0
  353. data/spec/models/shipping_query_spec.rb +60 -0
  354. data/spec/models/sticker_set_spec.rb +60 -0
  355. data/spec/models/sticker_spec.rb +84 -0
  356. data/spec/models/successful_payment_spec.rb +78 -0
  357. data/spec/models/update_spec.rb +96 -0
  358. data/spec/models/user_profile_photos_spec.rb +48 -0
  359. data/spec/models/user_spec.rb +72 -0
  360. data/spec/models/venue_spec.rb +60 -0
  361. data/spec/models/video_note_spec.rb +66 -0
  362. data/spec/models/video_spec.rb +78 -0
  363. data/spec/models/voice_spec.rb +60 -0
  364. data/spec/models/webhook_info_spec.rb +78 -0
  365. data/spec/spec_helper.rb +111 -0
  366. data/swagger.yaml +5202 -0
  367. data/teleswagger.gemspec +46 -0
  368. metadata +709 -0
@@ -0,0 +1,265 @@
1
+ =begin
2
+ #Telegram bot API
3
+
4
+ #This is a swagger defenition for [Telegram bot API](https://core.telegram.org/bots/api).
5
+
6
+ OpenAPI spec version: 3.3
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.2.3
10
+
11
+ =end
12
+
13
+ require "uri"
14
+
15
+ module Teleswagger
16
+ class UpdatesApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+
23
+ #
24
+ #
25
+ # @param [Hash] opts the optional parameters
26
+ # @return [ResponseBool]
27
+ def delete_webhook(opts = {})
28
+ data, _status_code, _headers = delete_webhook_with_http_info(opts)
29
+ return data
30
+ end
31
+
32
+ #
33
+ #
34
+ # @param [Hash] opts the optional parameters
35
+ # @return [Array<(ResponseBool, Fixnum, Hash)>] ResponseBool data, response status code and response headers
36
+ def delete_webhook_with_http_info(opts = {})
37
+ if @api_client.config.debugging
38
+ @api_client.config.logger.debug "Calling API: UpdatesApi.delete_webhook ..."
39
+ end
40
+ # resource path
41
+ local_var_path = "/bot{token}/deleteWebhook"
42
+
43
+ # query parameters
44
+ query_params = {}
45
+
46
+ # header parameters
47
+ header_params = {}
48
+ # HTTP header 'Accept' (if needed)
49
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
50
+ # HTTP header 'Content-Type'
51
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
52
+
53
+ # form parameters
54
+ form_params = {}
55
+
56
+ # http body (model)
57
+ post_body = nil
58
+ auth_names = []
59
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
60
+ :header_params => header_params,
61
+ :query_params => query_params,
62
+ :form_params => form_params,
63
+ :body => post_body,
64
+ :auth_names => auth_names,
65
+ :return_type => 'ResponseBool')
66
+ if @api_client.config.debugging
67
+ @api_client.config.logger.debug "API called: UpdatesApi#delete_webhook\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
68
+ end
69
+ return data, status_code, headers
70
+ end
71
+
72
+ #
73
+ #
74
+ # @param token bot&#39;s token to authorize the request
75
+ # @param [Hash] opts the optional parameters
76
+ # @option opts [Integer] :offset
77
+ # @option opts [Integer] :limit
78
+ # @option opts [Integer] :timeout
79
+ # @option opts [Array<String>] :allowed_updates
80
+ # @return [ResponseUpdate]
81
+ def get_updates(token, opts = {})
82
+ data, _status_code, _headers = get_updates_with_http_info(token, opts)
83
+ return data
84
+ end
85
+
86
+ #
87
+ #
88
+ # @param token bot&#39;s token to authorize the request
89
+ # @param [Hash] opts the optional parameters
90
+ # @option opts [Integer] :offset
91
+ # @option opts [Integer] :limit
92
+ # @option opts [Integer] :timeout
93
+ # @option opts [Array<String>] :allowed_updates
94
+ # @return [Array<(ResponseUpdate, Fixnum, Hash)>] ResponseUpdate data, response status code and response headers
95
+ def get_updates_with_http_info(token, opts = {})
96
+ if @api_client.config.debugging
97
+ @api_client.config.logger.debug "Calling API: UpdatesApi.get_updates ..."
98
+ end
99
+ # verify the required parameter 'token' is set
100
+ if @api_client.config.client_side_validation && token.nil?
101
+ fail ArgumentError, "Missing the required parameter 'token' when calling UpdatesApi.get_updates"
102
+ end
103
+ if @api_client.config.client_side_validation && opts[:'allowed_updates'] && !opts[:'allowed_updates'].all?{|item| ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'inline_query', 'chosen_inline_result', 'callback_query'].include?(item)}
104
+ fail ArgumentError, 'invalid value for "allowed_updates", must include one of message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query'
105
+ end
106
+ # resource path
107
+ local_var_path = "/bot{token}/getUpdates".sub('{' + 'token' + '}', token.to_s)
108
+
109
+ # query parameters
110
+ query_params = {}
111
+ query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
112
+ query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
113
+ query_params[:'timeout'] = opts[:'timeout'] if !opts[:'timeout'].nil?
114
+ query_params[:'allowed_updates'] = @api_client.build_collection_param(opts[:'allowed_updates'], :multi) if !opts[:'allowed_updates'].nil?
115
+
116
+ # header parameters
117
+ header_params = {}
118
+ # HTTP header 'Accept' (if needed)
119
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
120
+ # HTTP header 'Content-Type'
121
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
122
+
123
+ # form parameters
124
+ form_params = {}
125
+
126
+ # http body (model)
127
+ post_body = nil
128
+ auth_names = []
129
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
130
+ :header_params => header_params,
131
+ :query_params => query_params,
132
+ :form_params => form_params,
133
+ :body => post_body,
134
+ :auth_names => auth_names,
135
+ :return_type => 'ResponseUpdate')
136
+ if @api_client.config.debugging
137
+ @api_client.config.logger.debug "API called: UpdatesApi#get_updates\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
138
+ end
139
+ return data, status_code, headers
140
+ end
141
+
142
+ #
143
+ #
144
+ # @param [Hash] opts the optional parameters
145
+ # @return [WebhookInfo]
146
+ def get_webhook_info(opts = {})
147
+ data, _status_code, _headers = get_webhook_info_with_http_info(opts)
148
+ return data
149
+ end
150
+
151
+ #
152
+ #
153
+ # @param [Hash] opts the optional parameters
154
+ # @return [Array<(WebhookInfo, Fixnum, Hash)>] WebhookInfo data, response status code and response headers
155
+ def get_webhook_info_with_http_info(opts = {})
156
+ if @api_client.config.debugging
157
+ @api_client.config.logger.debug "Calling API: UpdatesApi.get_webhook_info ..."
158
+ end
159
+ # resource path
160
+ local_var_path = "/bot{token}/getWebhookInfo"
161
+
162
+ # query parameters
163
+ query_params = {}
164
+
165
+ # header parameters
166
+ header_params = {}
167
+ # HTTP header 'Accept' (if needed)
168
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
169
+ # HTTP header 'Content-Type'
170
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
171
+
172
+ # form parameters
173
+ form_params = {}
174
+
175
+ # http body (model)
176
+ post_body = nil
177
+ auth_names = []
178
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
179
+ :header_params => header_params,
180
+ :query_params => query_params,
181
+ :form_params => form_params,
182
+ :body => post_body,
183
+ :auth_names => auth_names,
184
+ :return_type => 'WebhookInfo')
185
+ if @api_client.config.debugging
186
+ @api_client.config.logger.debug "API called: UpdatesApi#get_webhook_info\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
187
+ end
188
+ return data, status_code, headers
189
+ end
190
+
191
+ #
192
+ #
193
+ # @param token bot&#39;s token to authorize the request
194
+ # @param url
195
+ # @param [Hash] opts the optional parameters
196
+ # @option opts [File] :certificate
197
+ # @option opts [Integer] :max_connections
198
+ # @option opts [Array<String>] :allowed_updates
199
+ # @return [ResponseBool]
200
+ def set_webhook(token, url, opts = {})
201
+ data, _status_code, _headers = set_webhook_with_http_info(token, url, opts)
202
+ return data
203
+ end
204
+
205
+ #
206
+ #
207
+ # @param token bot&#39;s token to authorize the request
208
+ # @param url
209
+ # @param [Hash] opts the optional parameters
210
+ # @option opts [File] :certificate
211
+ # @option opts [Integer] :max_connections
212
+ # @option opts [Array<String>] :allowed_updates
213
+ # @return [Array<(ResponseBool, Fixnum, Hash)>] ResponseBool data, response status code and response headers
214
+ def set_webhook_with_http_info(token, url, opts = {})
215
+ if @api_client.config.debugging
216
+ @api_client.config.logger.debug "Calling API: UpdatesApi.set_webhook ..."
217
+ end
218
+ # verify the required parameter 'token' is set
219
+ if @api_client.config.client_side_validation && token.nil?
220
+ fail ArgumentError, "Missing the required parameter 'token' when calling UpdatesApi.set_webhook"
221
+ end
222
+ # verify the required parameter 'url' is set
223
+ if @api_client.config.client_side_validation && url.nil?
224
+ fail ArgumentError, "Missing the required parameter 'url' when calling UpdatesApi.set_webhook"
225
+ end
226
+ if @api_client.config.client_side_validation && opts[:'allowed_updates'] && !opts[:'allowed_updates'].all?{|item| ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'inline_query', 'chosen_inline_result', 'callback_query'].include?(item)}
227
+ fail ArgumentError, 'invalid value for "allowed_updates", must include one of message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query'
228
+ end
229
+ # resource path
230
+ local_var_path = "/bot{token}/setWebhook".sub('{' + 'token' + '}', token.to_s)
231
+
232
+ # query parameters
233
+ query_params = {}
234
+
235
+ # header parameters
236
+ header_params = {}
237
+ # HTTP header 'Accept' (if needed)
238
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
239
+ # HTTP header 'Content-Type'
240
+ header_params['Content-Type'] = @api_client.select_header_content_type(['multipart/form-data'])
241
+
242
+ # form parameters
243
+ form_params = {}
244
+ form_params["url"] = url
245
+ form_params["certificate"] = opts[:'certificate'] if !opts[:'certificate'].nil?
246
+ form_params["max_connections"] = opts[:'max_connections'] if !opts[:'max_connections'].nil?
247
+ form_params["allowed_updates"] = @api_client.build_collection_param(opts[:'allowed_updates'], :multi) if !opts[:'allowed_updates'].nil?
248
+
249
+ # http body (model)
250
+ post_body = nil
251
+ auth_names = []
252
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path,
253
+ :header_params => header_params,
254
+ :query_params => query_params,
255
+ :form_params => form_params,
256
+ :body => post_body,
257
+ :auth_names => auth_names,
258
+ :return_type => 'ResponseBool')
259
+ if @api_client.config.debugging
260
+ @api_client.config.logger.debug "API called: UpdatesApi#set_webhook\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
261
+ end
262
+ return data, status_code, headers
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,146 @@
1
+ =begin
2
+ #Telegram bot API
3
+
4
+ #This is a swagger defenition for [Telegram bot API](https://core.telegram.org/bots/api).
5
+
6
+ OpenAPI spec version: 3.3
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.2.3
10
+
11
+ =end
12
+
13
+ require "uri"
14
+
15
+ module Teleswagger
16
+ class UsersApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+
23
+ #
24
+ #
25
+ # @param token bot&#39;s token to authorize the request
26
+ # @param [Hash] opts the optional parameters
27
+ # @return [InlineResponse200]
28
+ def get_me(token, opts = {})
29
+ data, _status_code, _headers = get_me_with_http_info(token, opts)
30
+ return data
31
+ end
32
+
33
+ #
34
+ #
35
+ # @param token bot&#39;s token to authorize the request
36
+ # @param [Hash] opts the optional parameters
37
+ # @return [Array<(InlineResponse200, Fixnum, Hash)>] InlineResponse200 data, response status code and response headers
38
+ def get_me_with_http_info(token, opts = {})
39
+ if @api_client.config.debugging
40
+ @api_client.config.logger.debug "Calling API: UsersApi.get_me ..."
41
+ end
42
+ # verify the required parameter 'token' is set
43
+ if @api_client.config.client_side_validation && token.nil?
44
+ fail ArgumentError, "Missing the required parameter 'token' when calling UsersApi.get_me"
45
+ end
46
+ # resource path
47
+ local_var_path = "/bot{token}/getMe".sub('{' + 'token' + '}', token.to_s)
48
+
49
+ # query parameters
50
+ query_params = {}
51
+
52
+ # header parameters
53
+ header_params = {}
54
+ # HTTP header 'Accept' (if needed)
55
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
56
+ # HTTP header 'Content-Type'
57
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
58
+
59
+ # form parameters
60
+ form_params = {}
61
+
62
+ # http body (model)
63
+ post_body = nil
64
+ auth_names = []
65
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
66
+ :header_params => header_params,
67
+ :query_params => query_params,
68
+ :form_params => form_params,
69
+ :body => post_body,
70
+ :auth_names => auth_names,
71
+ :return_type => 'InlineResponse200')
72
+ if @api_client.config.debugging
73
+ @api_client.config.logger.debug "API called: UsersApi#get_me\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
74
+ end
75
+ return data, status_code, headers
76
+ end
77
+
78
+ #
79
+ #
80
+ # @param token bot&#39;s token to authorize the request
81
+ # @param user_id
82
+ # @param [Hash] opts the optional parameters
83
+ # @option opts [Integer] :offset
84
+ # @option opts [Integer] :limit
85
+ # @return [InlineResponse2001]
86
+ def get_user_profile_photos(token, user_id, opts = {})
87
+ data, _status_code, _headers = get_user_profile_photos_with_http_info(token, user_id, opts)
88
+ return data
89
+ end
90
+
91
+ #
92
+ #
93
+ # @param token bot&#39;s token to authorize the request
94
+ # @param user_id
95
+ # @param [Hash] opts the optional parameters
96
+ # @option opts [Integer] :offset
97
+ # @option opts [Integer] :limit
98
+ # @return [Array<(InlineResponse2001, Fixnum, Hash)>] InlineResponse2001 data, response status code and response headers
99
+ def get_user_profile_photos_with_http_info(token, user_id, opts = {})
100
+ if @api_client.config.debugging
101
+ @api_client.config.logger.debug "Calling API: UsersApi.get_user_profile_photos ..."
102
+ end
103
+ # verify the required parameter 'token' is set
104
+ if @api_client.config.client_side_validation && token.nil?
105
+ fail ArgumentError, "Missing the required parameter 'token' when calling UsersApi.get_user_profile_photos"
106
+ end
107
+ # verify the required parameter 'user_id' is set
108
+ if @api_client.config.client_side_validation && user_id.nil?
109
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling UsersApi.get_user_profile_photos"
110
+ end
111
+ # resource path
112
+ local_var_path = "/bot{token}/getUserProfilePhotos".sub('{' + 'token' + '}', token.to_s)
113
+
114
+ # query parameters
115
+ query_params = {}
116
+ query_params[:'user_id'] = user_id
117
+ query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
118
+ query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
119
+
120
+ # header parameters
121
+ header_params = {}
122
+ # HTTP header 'Accept' (if needed)
123
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
124
+ # HTTP header 'Content-Type'
125
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
126
+
127
+ # form parameters
128
+ form_params = {}
129
+
130
+ # http body (model)
131
+ post_body = nil
132
+ auth_names = []
133
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
134
+ :header_params => header_params,
135
+ :query_params => query_params,
136
+ :form_params => form_params,
137
+ :body => post_body,
138
+ :auth_names => auth_names,
139
+ :return_type => 'InlineResponse2001')
140
+ if @api_client.config.debugging
141
+ @api_client.config.logger.debug "API called: UsersApi#get_user_profile_photos\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
142
+ end
143
+ return data, status_code, headers
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,388 @@
1
+ =begin
2
+ #Telegram bot API
3
+
4
+ #This is a swagger defenition for [Telegram bot API](https://core.telegram.org/bots/api).
5
+
6
+ OpenAPI spec version: 3.3
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.2.3
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'typhoeus'
18
+ require 'uri'
19
+
20
+ module Teleswagger
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # Defines the headers to be used in HTTP requests of all API calls by default.
26
+ #
27
+ # @return [Hash]
28
+ attr_accessor :default_headers
29
+
30
+ # Initializes the ApiClient
31
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
35
+ @default_headers = {
36
+ 'Content-Type' => "application/json",
37
+ 'User-Agent' => @user_agent
38
+ }
39
+ end
40
+
41
+ def self.default
42
+ @@default ||= ApiClient.new
43
+ end
44
+
45
+ # Call an API with given options.
46
+ #
47
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (could be nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ response = request.run
52
+
53
+ if @config.debugging
54
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
55
+ end
56
+
57
+ unless response.success?
58
+ if response.timed_out?
59
+ fail ApiError.new('Connection timed out')
60
+ elsif response.code == 0
61
+ # Errors from libcurl will be made visible here
62
+ fail ApiError.new(:code => 0,
63
+ :message => response.return_message)
64
+ else
65
+ fail ApiError.new(:code => response.code,
66
+ :response_headers => response.headers,
67
+ :response_body => response.body),
68
+ response.status_message
69
+ end
70
+ end
71
+
72
+ if opts[:return_type]
73
+ data = deserialize(response, opts[:return_type])
74
+ else
75
+ data = nil
76
+ end
77
+ return data, response.code, response.headers
78
+ end
79
+
80
+ # Builds the HTTP request
81
+ #
82
+ # @param [String] http_method HTTP method/verb (e.g. POST)
83
+ # @param [String] path URL path (e.g. /account/new)
84
+ # @option opts [Hash] :header_params Header parameters
85
+ # @option opts [Hash] :query_params Query parameters
86
+ # @option opts [Hash] :form_params Query parameters
87
+ # @option opts [Object] :body HTTP body (JSON/XML)
88
+ # @return [Typhoeus::Request] A Typhoeus Request
89
+ def build_request(http_method, path, opts = {})
90
+ url = build_request_url(path)
91
+ http_method = http_method.to_sym.downcase
92
+
93
+ header_params = @default_headers.merge(opts[:header_params] || {})
94
+ query_params = opts[:query_params] || {}
95
+ form_params = opts[:form_params] || {}
96
+
97
+
98
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
99
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
100
+
101
+ req_opts = {
102
+ :method => http_method,
103
+ :headers => header_params,
104
+ :params => query_params,
105
+ :params_encoding => @config.params_encoding,
106
+ :timeout => @config.timeout,
107
+ :ssl_verifypeer => @config.verify_ssl,
108
+ :ssl_verifyhost => _verify_ssl_host,
109
+ :sslcert => @config.cert_file,
110
+ :sslkey => @config.key_file,
111
+ :verbose => @config.debugging
112
+ }
113
+
114
+ # set custom cert, if provided
115
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
116
+
117
+ if [:post, :patch, :put, :delete].include?(http_method)
118
+ req_body = build_request_body(header_params, form_params, opts[:body])
119
+ req_opts.update :body => req_body
120
+ if @config.debugging
121
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
122
+ end
123
+ end
124
+
125
+ request = Typhoeus::Request.new(url, req_opts)
126
+ download_file(request) if opts[:return_type] == 'File'
127
+ request
128
+ end
129
+
130
+ # Check if the given MIME is a JSON MIME.
131
+ # JSON MIME examples:
132
+ # application/json
133
+ # application/json; charset=UTF8
134
+ # APPLICATION/JSON
135
+ # */*
136
+ # @param [String] mime MIME
137
+ # @return [Boolean] True if the MIME is application/json
138
+ def json_mime?(mime)
139
+ (mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
140
+ end
141
+
142
+ # Deserialize the response to the given return type.
143
+ #
144
+ # @param [Response] response HTTP response
145
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
146
+ def deserialize(response, return_type)
147
+ body = response.body
148
+
149
+ # handle file downloading - return the File instance processed in request callbacks
150
+ # note that response body is empty when the file is written in chunks in request on_body callback
151
+ return @tempfile if return_type == 'File'
152
+
153
+ return nil if body.nil? || body.empty?
154
+
155
+ # return response body directly for String return type
156
+ return body if return_type == 'String'
157
+
158
+ # ensuring a default content type
159
+ content_type = response.headers['Content-Type'] || 'application/json'
160
+
161
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
162
+
163
+ begin
164
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
165
+ rescue JSON::ParserError => e
166
+ if %w(String Date DateTime).include?(return_type)
167
+ data = body
168
+ else
169
+ raise e
170
+ end
171
+ end
172
+
173
+ convert_to_type data, return_type
174
+ end
175
+
176
+ # Convert data to the given return type.
177
+ # @param [Object] data Data to be converted
178
+ # @param [String] return_type Return type
179
+ # @return [Mixed] Data in a particular type
180
+ def convert_to_type(data, return_type)
181
+ return nil if data.nil?
182
+ case return_type
183
+ when 'String'
184
+ data.to_s
185
+ when 'Integer'
186
+ data.to_i
187
+ when 'Float'
188
+ data.to_f
189
+ when 'BOOLEAN'
190
+ data == true
191
+ when 'DateTime'
192
+ # parse date time (expecting ISO 8601 format)
193
+ DateTime.parse data
194
+ when 'Date'
195
+ # parse date time (expecting ISO 8601 format)
196
+ Date.parse data
197
+ when 'Object'
198
+ # generic object (usually a Hash), return directly
199
+ data
200
+ when /\AArray<(.+)>\z/
201
+ # e.g. Array<Pet>
202
+ sub_type = $1
203
+ data.map {|item| convert_to_type(item, sub_type) }
204
+ when /\AHash\<String, (.+)\>\z/
205
+ # e.g. Hash<String, Integer>
206
+ sub_type = $1
207
+ {}.tap do |hash|
208
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
209
+ end
210
+ else
211
+ # models, e.g. Pet
212
+ Teleswagger.const_get(return_type).new.tap do |model|
213
+ model.build_from_hash data
214
+ end
215
+ end
216
+ end
217
+
218
+ # Save response body into a file in (the defined) temporary folder, using the filename
219
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
220
+ # The response body is written to the file in chunks in order to handle files which
221
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
222
+ # process can use.
223
+ #
224
+ # @see Configuration#temp_folder_path
225
+ def download_file(request)
226
+ tempfile = nil
227
+ encoding = nil
228
+ request.on_headers do |response|
229
+ content_disposition = response.headers['Content-Disposition']
230
+ if content_disposition and content_disposition =~ /filename=/i
231
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
232
+ prefix = sanitize_filename(filename)
233
+ else
234
+ prefix = 'download-'
235
+ end
236
+ prefix = prefix + '-' unless prefix.end_with?('-')
237
+ encoding = response.body.encoding
238
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
239
+ @tempfile = tempfile
240
+ end
241
+ request.on_body do |chunk|
242
+ chunk.force_encoding(encoding)
243
+ tempfile.write(chunk)
244
+ end
245
+ request.on_complete do |response|
246
+ tempfile.close
247
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
248
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
249
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
250
+ "explicitly with `tempfile.delete`"
251
+ end
252
+ end
253
+
254
+ # Sanitize filename by removing path.
255
+ # e.g. ../../sun.gif becomes sun.gif
256
+ #
257
+ # @param [String] filename the filename to be sanitized
258
+ # @return [String] the sanitized filename
259
+ def sanitize_filename(filename)
260
+ filename.gsub(/.*[\/\\]/, '')
261
+ end
262
+
263
+ def build_request_url(path)
264
+ # Add leading and trailing slashes to path
265
+ path = "/#{path}".gsub(/\/+/, '/')
266
+ URI.encode(@config.base_url + path)
267
+ end
268
+
269
+ # Builds the HTTP request body
270
+ #
271
+ # @param [Hash] header_params Header parameters
272
+ # @param [Hash] form_params Query parameters
273
+ # @param [Object] body HTTP body (JSON/XML)
274
+ # @return [String] HTTP body data in the form of string
275
+ def build_request_body(header_params, form_params, body)
276
+ # http form
277
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
278
+ header_params['Content-Type'] == 'multipart/form-data'
279
+ data = {}
280
+ form_params.each do |key, value|
281
+ case value
282
+ when File, Array, nil
283
+ # let typhoeus handle File, Array and nil parameters
284
+ data[key] = value
285
+ else
286
+ data[key] = value.to_s
287
+ end
288
+ end
289
+ elsif body
290
+ data = body.is_a?(String) ? body : body.to_json
291
+ else
292
+ data = nil
293
+ end
294
+ data
295
+ end
296
+
297
+ # Update hearder and query params based on authentication settings.
298
+ #
299
+ # @param [Hash] header_params Header parameters
300
+ # @param [Hash] query_params Query parameters
301
+ # @param [String] auth_names Authentication scheme name
302
+ def update_params_for_auth!(header_params, query_params, auth_names)
303
+ Array(auth_names).each do |auth_name|
304
+ auth_setting = @config.auth_settings[auth_name]
305
+ next unless auth_setting
306
+ case auth_setting[:in]
307
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
308
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
309
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
310
+ end
311
+ end
312
+ end
313
+
314
+ # Sets user agent in HTTP header
315
+ #
316
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
317
+ def user_agent=(user_agent)
318
+ @user_agent = user_agent
319
+ @default_headers['User-Agent'] = @user_agent
320
+ end
321
+
322
+ # Return Accept header based on an array of accepts provided.
323
+ # @param [Array] accepts array for Accept
324
+ # @return [String] the Accept header (e.g. application/json)
325
+ def select_header_accept(accepts)
326
+ return nil if accepts.nil? || accepts.empty?
327
+ # use JSON when present, otherwise use all of the provided
328
+ json_accept = accepts.find { |s| json_mime?(s) }
329
+ return json_accept || accepts.join(',')
330
+ end
331
+
332
+ # Return Content-Type header based on an array of content types provided.
333
+ # @param [Array] content_types array for Content-Type
334
+ # @return [String] the Content-Type header (e.g. application/json)
335
+ def select_header_content_type(content_types)
336
+ # use application/json by default
337
+ return 'application/json' if content_types.nil? || content_types.empty?
338
+ # use JSON when present, otherwise use the first one
339
+ json_content_type = content_types.find { |s| json_mime?(s) }
340
+ return json_content_type || content_types.first
341
+ end
342
+
343
+ # Convert object (array, hash, object, etc) to JSON string.
344
+ # @param [Object] model object to be converted into JSON string
345
+ # @return [String] JSON string representation of the object
346
+ def object_to_http_body(model)
347
+ return model if model.nil? || model.is_a?(String)
348
+ local_body = nil
349
+ if model.is_a?(Array)
350
+ local_body = model.map{|m| object_to_hash(m) }
351
+ else
352
+ local_body = object_to_hash(model)
353
+ end
354
+ local_body.to_json
355
+ end
356
+
357
+ # Convert object(non-array) to hash.
358
+ # @param [Object] obj object to be converted into JSON string
359
+ # @return [String] JSON string representation of the object
360
+ def object_to_hash(obj)
361
+ if obj.respond_to?(:to_hash)
362
+ obj.to_hash
363
+ else
364
+ obj
365
+ end
366
+ end
367
+
368
+ # Build parameter value according to the given collection format.
369
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
370
+ def build_collection_param(param, collection_format)
371
+ case collection_format
372
+ when :csv
373
+ param.join(',')
374
+ when :ssv
375
+ param.join(' ')
376
+ when :tsv
377
+ param.join("\t")
378
+ when :pipes
379
+ param.join('|')
380
+ when :multi
381
+ # return the array directly as typhoeus will handle it as expected
382
+ param
383
+ else
384
+ fail "unknown collection format: #{collection_format.inspect}"
385
+ end
386
+ end
387
+ end
388
+ end