slack_resources 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +66 -1
  3. data/.rubocop.yml +10 -2
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +7 -7
  6. data/lib/generate_event_api_resources.rb +8 -0
  7. data/lib/slack_resources.rb +9 -1
  8. data/lib/slack_resources/generator/event_api/examples_preparation.rb +71 -0
  9. data/lib/{event_api → slack_resources/generator/event_api}/fetch.rb +0 -0
  10. data/lib/slack_resources/generator/event_api/strong_hash.rb +25 -0
  11. data/lib/slack_resources/generator/event_api/to_schema.rb +200 -0
  12. data/lib/slack_resources/generator/event_api/type_detection.rb +272 -0
  13. data/lib/slack_resources/generator/event_api/write.rb +123 -0
  14. data/lib/slack_resources/raw_data/event_api/_added_examples/emoji_changed.add.json +7 -0
  15. data/lib/slack_resources/raw_data/event_api/_added_examples/emoji_changed.remove.json +6 -0
  16. data/lib/slack_resources/{resources → raw_data}/event_api/_added_examples/event_callback.json +0 -0
  17. data/lib/slack_resources/raw_data/event_api/examples/app_mention.json +8 -0
  18. data/lib/slack_resources/raw_data/event_api/examples/app_rate_limited.json +7 -0
  19. data/lib/slack_resources/raw_data/event_api/examples/app_uninstalled.json +11 -0
  20. data/lib/slack_resources/raw_data/event_api/examples/channel_archive.json +5 -0
  21. data/lib/slack_resources/raw_data/event_api/examples/channel_created.json +9 -0
  22. data/lib/slack_resources/raw_data/event_api/examples/channel_deleted.json +4 -0
  23. data/lib/slack_resources/raw_data/event_api/examples/channel_history_changed.json +6 -0
  24. data/lib/slack_resources/raw_data/event_api/examples/channel_left.json +4 -0
  25. data/lib/slack_resources/raw_data/event_api/examples/channel_rename.json +8 -0
  26. data/lib/slack_resources/raw_data/event_api/examples/channel_unarchive.json +5 -0
  27. data/lib/slack_resources/raw_data/event_api/examples/dnd_updated.json +11 -0
  28. data/lib/slack_resources/raw_data/event_api/examples/dnd_updated_user.json +9 -0
  29. data/lib/slack_resources/raw_data/event_api/examples/email_domain_changed.json +5 -0
  30. data/lib/slack_resources/raw_data/event_api/examples/emoji_changed.json +8 -0
  31. data/lib/slack_resources/raw_data/event_api/examples/file_change.json +7 -0
  32. data/lib/slack_resources/raw_data/event_api/examples/file_comment_added.json +9 -0
  33. data/lib/slack_resources/raw_data/event_api/examples/file_comment_deleted.json +8 -0
  34. data/lib/slack_resources/raw_data/event_api/examples/file_comment_edited.json +9 -0
  35. data/lib/slack_resources/raw_data/event_api/examples/file_created.json +7 -0
  36. data/lib/slack_resources/raw_data/event_api/examples/file_deleted.json +5 -0
  37. data/lib/slack_resources/raw_data/event_api/examples/file_public.json +7 -0
  38. data/lib/slack_resources/raw_data/event_api/examples/file_shared.json +7 -0
  39. data/lib/slack_resources/raw_data/event_api/examples/file_unshared.json +7 -0
  40. data/lib/slack_resources/raw_data/event_api/examples/grid_migration_finished.json +12 -0
  41. data/lib/slack_resources/raw_data/event_api/examples/grid_migration_started.json +12 -0
  42. data/lib/slack_resources/raw_data/event_api/examples/group_archive.json +4 -0
  43. data/lib/slack_resources/raw_data/event_api/examples/group_close.json +5 -0
  44. data/lib/slack_resources/raw_data/event_api/examples/group_deleted.json +4 -0
  45. data/lib/slack_resources/raw_data/event_api/examples/group_history_changed.json +6 -0
  46. data/lib/slack_resources/raw_data/event_api/examples/group_left.json +4 -0
  47. data/lib/slack_resources/raw_data/event_api/examples/group_open.json +5 -0
  48. data/lib/slack_resources/raw_data/event_api/examples/group_rename.json +8 -0
  49. data/lib/slack_resources/raw_data/event_api/examples/group_unarchive.json +4 -0
  50. data/lib/slack_resources/raw_data/event_api/examples/im_close.json +5 -0
  51. data/lib/slack_resources/raw_data/event_api/examples/im_created.json +6 -0
  52. data/lib/slack_resources/raw_data/event_api/examples/im_history_changed.json +6 -0
  53. data/lib/slack_resources/raw_data/event_api/examples/im_open.json +5 -0
  54. data/lib/slack_resources/raw_data/event_api/examples/link_shared.json +33 -0
  55. data/lib/slack_resources/raw_data/event_api/examples/member_joined_channel.json +8 -0
  56. data/lib/slack_resources/raw_data/event_api/examples/member_left_channel.json +7 -0
  57. data/lib/slack_resources/raw_data/event_api/examples/message.app_home.json +20 -0
  58. data/lib/slack_resources/raw_data/event_api/examples/message.channels.json +20 -0
  59. data/lib/slack_resources/raw_data/event_api/examples/message.groups.json +20 -0
  60. data/lib/slack_resources/raw_data/event_api/examples/message.im.json +20 -0
  61. data/lib/slack_resources/raw_data/event_api/examples/message.json +7 -0
  62. data/lib/slack_resources/raw_data/event_api/examples/message.mpim.json +20 -0
  63. data/lib/slack_resources/raw_data/event_api/examples/pin_added.json +8 -0
  64. data/lib/slack_resources/raw_data/event_api/examples/pin_removed.json +9 -0
  65. data/lib/slack_resources/raw_data/event_api/examples/reaction_added.json +12 -0
  66. data/lib/slack_resources/raw_data/event_api/examples/reaction_removed.json +12 -0
  67. data/lib/slack_resources/raw_data/event_api/examples/resources_added.json +31 -0
  68. data/lib/slack_resources/raw_data/event_api/examples/resources_removed.json +31 -0
  69. data/lib/slack_resources/raw_data/event_api/examples/scope_denied.json +20 -0
  70. data/lib/slack_resources/raw_data/event_api/examples/scope_granted.json +20 -0
  71. data/lib/slack_resources/raw_data/event_api/examples/star_added.json +7 -0
  72. data/lib/slack_resources/raw_data/event_api/examples/star_removed.json +7 -0
  73. data/lib/slack_resources/raw_data/event_api/examples/subteam_created.json +28 -0
  74. data/lib/slack_resources/raw_data/event_api/examples/subteam_members_changed.json +17 -0
  75. data/lib/slack_resources/raw_data/event_api/examples/subteam_self_added.json +4 -0
  76. data/lib/slack_resources/raw_data/event_api/examples/subteam_self_removed.json +4 -0
  77. data/lib/slack_resources/raw_data/event_api/examples/subteam_updated.json +34 -0
  78. data/lib/slack_resources/raw_data/event_api/examples/team_domain_change.json +5 -0
  79. data/lib/slack_resources/raw_data/event_api/examples/team_join.json +5 -0
  80. data/lib/slack_resources/raw_data/event_api/examples/team_rename.json +4 -0
  81. data/lib/slack_resources/raw_data/event_api/examples/tokens_revoked.json +19 -0
  82. data/lib/slack_resources/raw_data/event_api/examples/url_verification.json +5 -0
  83. data/lib/slack_resources/raw_data/event_api/examples/user_change.json +5 -0
  84. data/lib/slack_resources/raw_data/event_api/examples/user_resource_denied.json +20 -0
  85. data/lib/slack_resources/raw_data/event_api/examples/user_resource_granted.json +20 -0
  86. data/lib/slack_resources/raw_data/event_api/examples/user_resource_removed.json +16 -0
  87. data/lib/slack_resources/{resources → raw_data}/event_api/meta.json +0 -72
  88. data/lib/{schema.json → slack_resources/raw_data/event_api/preset_schemas.json} +7 -0
  89. data/lib/slack_resources/resources/event_api.rb +38 -0
  90. data/lib/slack_resources/resources/event_api/details/app_mention.json +67 -46
  91. data/lib/slack_resources/resources/event_api/details/app_rate_limited.json +59 -41
  92. data/lib/slack_resources/resources/event_api/details/app_uninstalled.json +22 -16
  93. data/lib/slack_resources/resources/event_api/details/channel_archive.json +42 -30
  94. data/lib/slack_resources/resources/event_api/details/channel_created.json +63 -54
  95. data/lib/slack_resources/resources/event_api/details/channel_deleted.json +32 -23
  96. data/lib/slack_resources/resources/event_api/details/channel_history_changed.json +48 -33
  97. data/lib/slack_resources/resources/event_api/details/channel_left.json +32 -23
  98. data/lib/slack_resources/resources/event_api/details/channel_rename.json +58 -49
  99. data/lib/slack_resources/resources/event_api/details/channel_unarchive.json +42 -30
  100. data/lib/slack_resources/resources/event_api/details/dnd_updated.json +66 -54
  101. data/lib/slack_resources/resources/event_api/details/dnd_updated_user.json +62 -50
  102. data/lib/slack_resources/resources/event_api/details/email_domain_changed.json +39 -27
  103. data/lib/slack_resources/resources/event_api/details/emoji_changed.add.json +78 -0
  104. data/lib/slack_resources/resources/event_api/details/emoji_changed.json +85 -44
  105. data/lib/slack_resources/resources/event_api/details/emoji_changed.remove.json +77 -0
  106. data/lib/slack_resources/resources/event_api/details/event_callback.json +102 -72
  107. data/lib/slack_resources/resources/event_api/details/file_change.json +49 -37
  108. data/lib/slack_resources/resources/event_api/details/file_comment_added.json +61 -46
  109. data/lib/slack_resources/resources/event_api/details/file_comment_deleted.json +59 -44
  110. data/lib/slack_resources/resources/event_api/details/file_comment_edited.json +61 -46
  111. data/lib/slack_resources/resources/event_api/details/file_created.json +49 -37
  112. data/lib/slack_resources/resources/event_api/details/file_deleted.json +41 -29
  113. data/lib/slack_resources/resources/event_api/details/file_public.json +49 -37
  114. data/lib/slack_resources/resources/event_api/details/file_shared.json +49 -37
  115. data/lib/slack_resources/resources/event_api/details/file_unshared.json +49 -37
  116. data/lib/slack_resources/resources/event_api/details/grid_migration_finished.json +31 -22
  117. data/lib/slack_resources/resources/event_api/details/grid_migration_started.json +31 -22
  118. data/lib/slack_resources/resources/event_api/details/group_archive.json +32 -23
  119. data/lib/slack_resources/resources/event_api/details/group_close.json +42 -30
  120. data/lib/slack_resources/resources/event_api/details/group_deleted.json +32 -23
  121. data/lib/slack_resources/resources/event_api/details/group_history_changed.json +48 -33
  122. data/lib/slack_resources/resources/event_api/details/group_left.json +32 -23
  123. data/lib/slack_resources/resources/event_api/details/group_open.json +42 -30
  124. data/lib/slack_resources/resources/event_api/details/group_rename.json +58 -49
  125. data/lib/slack_resources/resources/event_api/details/group_unarchive.json +32 -23
  126. data/lib/slack_resources/resources/event_api/details/im_close.json +42 -30
  127. data/lib/slack_resources/resources/event_api/details/im_created.json +53 -41
  128. data/lib/slack_resources/resources/event_api/details/im_history_changed.json +48 -33
  129. data/lib/slack_resources/resources/event_api/details/im_open.json +42 -30
  130. data/lib/slack_resources/resources/event_api/details/link_shared.json +107 -83
  131. data/lib/slack_resources/resources/event_api/details/member_joined_channel.json +66 -48
  132. data/lib/slack_resources/resources/event_api/details/member_left_channel.json +58 -43
  133. data/lib/slack_resources/resources/event_api/details/message.app_home.json +74 -53
  134. data/lib/slack_resources/resources/event_api/details/message.channels.json +74 -56
  135. data/lib/slack_resources/resources/event_api/details/message.groups.json +74 -56
  136. data/lib/slack_resources/resources/event_api/details/message.im.json +74 -56
  137. data/lib/slack_resources/resources/event_api/details/message.json +106 -60
  138. data/lib/slack_resources/resources/event_api/details/message.mpim.json +74 -56
  139. data/lib/slack_resources/resources/event_api/details/pin_added.json +65 -47
  140. data/lib/slack_resources/resources/event_api/details/pin_removed.json +73 -52
  141. data/lib/slack_resources/resources/event_api/details/reaction_added.json +94 -73
  142. data/lib/slack_resources/resources/event_api/details/reaction_removed.json +94 -73
  143. data/lib/slack_resources/resources/event_api/details/resources_added.json +127 -115
  144. data/lib/slack_resources/resources/event_api/details/resources_removed.json +127 -115
  145. data/lib/slack_resources/resources/event_api/details/scope_denied.json +74 -59
  146. data/lib/slack_resources/resources/event_api/details/scope_granted.json +74 -59
  147. data/lib/slack_resources/resources/event_api/details/star_added.json +56 -41
  148. data/lib/slack_resources/resources/event_api/details/star_removed.json +56 -41
  149. data/lib/slack_resources/resources/event_api/details/subteam_created.json +177 -168
  150. data/lib/slack_resources/resources/event_api/details/subteam_members_changed.json +118 -82
  151. data/lib/slack_resources/resources/event_api/details/subteam_self_added.json +31 -22
  152. data/lib/slack_resources/resources/event_api/details/subteam_self_removed.json +31 -22
  153. data/lib/slack_resources/resources/event_api/details/subteam_updated.json +189 -180
  154. data/lib/slack_resources/resources/event_api/details/team_domain_change.json +38 -26
  155. data/lib/slack_resources/resources/event_api/details/team_join.json +35 -26
  156. data/lib/slack_resources/resources/event_api/details/team_rename.json +32 -23
  157. data/lib/slack_resources/resources/event_api/details/tokens_revoked.json +58 -49
  158. data/lib/slack_resources/resources/event_api/details/url_verification.json +32 -26
  159. data/lib/slack_resources/resources/event_api/details/user_change.json +35 -26
  160. data/lib/slack_resources/resources/event_api/details/user_resource_denied.json +82 -64
  161. data/lib/slack_resources/resources/event_api/details/user_resource_granted.json +82 -64
  162. data/lib/slack_resources/resources/event_api/details/user_resource_removed.json +41 -29
  163. data/lib/slack_resources/resources/event_api/examples/app_mention.json +4 -4
  164. data/lib/slack_resources/resources/event_api/examples/app_rate_limited.json +4 -4
  165. data/lib/slack_resources/resources/event_api/examples/app_uninstalled.json +1 -9
  166. data/lib/slack_resources/resources/event_api/examples/channel_archive.json +1 -1
  167. data/lib/slack_resources/resources/event_api/examples/channel_created.json +2 -2
  168. data/lib/slack_resources/resources/event_api/examples/channel_deleted.json +2 -2
  169. data/lib/slack_resources/resources/event_api/examples/channel_history_changed.json +2 -2
  170. data/lib/slack_resources/resources/event_api/examples/channel_left.json +2 -2
  171. data/lib/slack_resources/resources/event_api/examples/channel_rename.json +2 -2
  172. data/lib/slack_resources/resources/event_api/examples/channel_unarchive.json +1 -1
  173. data/lib/slack_resources/resources/event_api/examples/dnd_updated.json +3 -3
  174. data/lib/slack_resources/resources/event_api/examples/dnd_updated_user.json +3 -3
  175. data/lib/slack_resources/resources/event_api/examples/email_domain_changed.json +2 -2
  176. data/lib/slack_resources/resources/event_api/examples/emoji_changed.add.json +7 -0
  177. data/lib/slack_resources/resources/event_api/examples/emoji_changed.json +4 -5
  178. data/lib/slack_resources/resources/event_api/examples/emoji_changed.remove.json +8 -0
  179. data/lib/slack_resources/resources/event_api/examples/event_callback.json +7 -6
  180. data/lib/slack_resources/resources/event_api/examples/file_change.json +3 -3
  181. data/lib/slack_resources/resources/event_api/examples/file_comment_added.json +3 -3
  182. data/lib/slack_resources/resources/event_api/examples/file_comment_deleted.json +3 -3
  183. data/lib/slack_resources/resources/event_api/examples/file_comment_edited.json +3 -3
  184. data/lib/slack_resources/resources/event_api/examples/file_created.json +3 -3
  185. data/lib/slack_resources/resources/event_api/examples/file_deleted.json +2 -2
  186. data/lib/slack_resources/resources/event_api/examples/file_public.json +3 -3
  187. data/lib/slack_resources/resources/event_api/examples/file_shared.json +3 -3
  188. data/lib/slack_resources/resources/event_api/examples/file_unshared.json +3 -3
  189. data/lib/slack_resources/resources/event_api/examples/grid_migration_finished.json +2 -10
  190. data/lib/slack_resources/resources/event_api/examples/grid_migration_started.json +2 -10
  191. data/lib/slack_resources/resources/event_api/examples/group_archive.json +2 -2
  192. data/lib/slack_resources/resources/event_api/examples/group_close.json +2 -2
  193. data/lib/slack_resources/resources/event_api/examples/group_deleted.json +2 -2
  194. data/lib/slack_resources/resources/event_api/examples/group_history_changed.json +2 -2
  195. data/lib/slack_resources/resources/event_api/examples/group_left.json +2 -2
  196. data/lib/slack_resources/resources/event_api/examples/group_open.json +2 -2
  197. data/lib/slack_resources/resources/event_api/examples/group_rename.json +2 -2
  198. data/lib/slack_resources/resources/event_api/examples/group_unarchive.json +2 -2
  199. data/lib/slack_resources/resources/event_api/examples/im_close.json +2 -2
  200. data/lib/slack_resources/resources/event_api/examples/im_created.json +3 -3
  201. data/lib/slack_resources/resources/event_api/examples/im_history_changed.json +2 -2
  202. data/lib/slack_resources/resources/event_api/examples/im_open.json +2 -2
  203. data/lib/slack_resources/resources/event_api/examples/link_shared.json +18 -30
  204. data/lib/slack_resources/resources/event_api/examples/member_joined_channel.json +3 -3
  205. data/lib/slack_resources/resources/event_api/examples/member_left_channel.json +3 -3
  206. data/lib/slack_resources/resources/event_api/examples/message.app_home.json +7 -18
  207. data/lib/slack_resources/resources/event_api/examples/message.channels.json +7 -18
  208. data/lib/slack_resources/resources/event_api/examples/message.groups.json +7 -18
  209. data/lib/slack_resources/resources/event_api/examples/message.im.json +7 -18
  210. data/lib/slack_resources/resources/event_api/examples/message.json +6 -4
  211. data/lib/slack_resources/resources/event_api/examples/message.mpim.json +7 -18
  212. data/lib/slack_resources/resources/event_api/examples/pin_added.json +3 -3
  213. data/lib/slack_resources/resources/event_api/examples/pin_removed.json +4 -4
  214. data/lib/slack_resources/resources/event_api/examples/reaction_added.json +5 -5
  215. data/lib/slack_resources/resources/event_api/examples/reaction_removed.json +5 -5
  216. data/lib/slack_resources/resources/event_api/examples/resources_added.json +17 -28
  217. data/lib/slack_resources/resources/event_api/examples/resources_removed.json +17 -28
  218. data/lib/slack_resources/resources/event_api/examples/scope_denied.json +6 -17
  219. data/lib/slack_resources/resources/event_api/examples/scope_granted.json +6 -17
  220. data/lib/slack_resources/resources/event_api/examples/star_added.json +3 -3
  221. data/lib/slack_resources/resources/event_api/examples/star_removed.json +3 -3
  222. data/lib/slack_resources/resources/event_api/examples/subteam_created.json +2 -2
  223. data/lib/slack_resources/resources/event_api/examples/subteam_members_changed.json +6 -6
  224. data/lib/slack_resources/resources/event_api/examples/subteam_self_added.json +2 -2
  225. data/lib/slack_resources/resources/event_api/examples/subteam_self_removed.json +2 -2
  226. data/lib/slack_resources/resources/event_api/examples/subteam_updated.json +2 -2
  227. data/lib/slack_resources/resources/event_api/examples/team_domain_change.json +2 -2
  228. data/lib/slack_resources/resources/event_api/examples/team_rename.json +2 -2
  229. data/lib/slack_resources/resources/event_api/examples/tokens_revoked.json +8 -16
  230. data/lib/slack_resources/resources/event_api/examples/url_verification.json +1 -1
  231. data/lib/slack_resources/resources/event_api/examples/user_resource_denied.json +6 -17
  232. data/lib/slack_resources/resources/event_api/examples/user_resource_granted.json +6 -17
  233. data/lib/slack_resources/resources/event_api/examples/user_resource_removed.json +3 -14
  234. data/lib/slack_resources/resources/event_api/schema.json +257 -105
  235. data/lib/slack_resources/resources/event_api/schemas/emoji_changed.add.json +42 -0
  236. data/lib/slack_resources/resources/event_api/schemas/emoji_changed.json +27 -9
  237. data/lib/slack_resources/resources/event_api/schemas/emoji_changed.remove.json +40 -0
  238. data/lib/slack_resources/resources/event_api/schemas/member_joined_channel.json +1 -4
  239. data/lib/slack_resources/resources/event_api/schemas/member_left_channel.json +1 -4
  240. data/lib/slack_resources/resources/event_api/schemas/message.app_home.json +1 -4
  241. data/lib/slack_resources/resources/event_api/schemas/message.channels.json +1 -7
  242. data/lib/slack_resources/resources/event_api/schemas/message.groups.json +1 -7
  243. data/lib/slack_resources/resources/event_api/schemas/message.im.json +1 -7
  244. data/lib/slack_resources/resources/event_api/schemas/message.json +39 -17
  245. data/lib/slack_resources/resources/event_api/schemas/message.mpim.json +1 -7
  246. data/lib/slack_resources/resources/event_api/schemas/resources_added.json +15 -15
  247. data/lib/slack_resources/resources/event_api/schemas/resources_removed.json +15 -15
  248. data/lib/slack_resources/resources/event_api/schemas/team_rename.json +2 -2
  249. data/lib/slack_resources/resources/event_api/schemas/url_verification.json +0 -6
  250. data/lib/slack_resources/resources/event_api/summary.json +4887 -3400
  251. data/slack_resources.gemspec +4 -2
  252. metadata +91 -8
  253. data/lib/event_api/write.rb +0 -364
  254. data/lib/slack_resources/version.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b727e25d899b7c234485101bcabddbb2611a577908ccc887a163a1c4b759020b
4
- data.tar.gz: e7b83835d0a3aac090fae3066d63ac1488fc676f6eae4f7e4630dd83a262ba23
3
+ metadata.gz: f80ba497575cdb836330fa4d5194cf448cd1b8bc81d06710bbbe446fee45ed03
4
+ data.tar.gz: 4093cb4eb9f3d0fa85deaa49ce53f5135aeb98087dc8c8346d6e89acefa3e13a
5
5
  SHA512:
6
- metadata.gz: f39ac17a63cb4b892df164ac55bd8def3fd734d3f50a5ed0bb1d25a3f6b21498a43e6b2fe065b8fe41183eecd42a98da2ef0085f2690f2d8c22a417b7b18e6c9
7
- data.tar.gz: 41c7cefd5c596a9c2588aa38a91b334a54f6b1f340daaee32db465e04f284390352e7410ee7a0a19f7a5ce1630973e2381a8b59926a3fda089397e3b1694af88
6
+ metadata.gz: 6a72b6d58185091cc4459f140ad4f805942d970de11b09f8a7b55aec18f01e90e94e95ef0e8a695ab5b26fc312fe8a2435ef64e68ed6cc7758d2658d9cfd07ae
7
+ data.tar.gz: 13687631b5dd8823d972fa31ca1f506a88a45dbe5e1c3567ff8c3fe1600abd8a6c5dd72a70c35f9ffab71eb498d2d913ce703c543eb41ecfa8413ab5fd90f263
@@ -1,11 +1,62 @@
1
1
  version: 2
2
2
  jobs:
3
+ test:
4
+ parallelism: 1
5
+ docker:
6
+ - image: circleci/ruby:2.5.1
7
+ steps:
8
+ - checkout
9
+
10
+ - restore_cache:
11
+ keys:
12
+ - rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
13
+ - rails-demo-bundle-v2-
14
+
15
+ - run:
16
+ name: Bundle Install
17
+ command: bundle check || bundle install --path vendor/bundle
18
+
19
+ - save_cache:
20
+ key: rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
21
+ paths:
22
+ - vendor/bundle
23
+
24
+ - run:
25
+ name: Test
26
+ command: bundle exec rspec -cfd
27
+ - run:
28
+ name: Rubocop
29
+ command: bundle exec rubocop
30
+
3
31
  deploy_gem:
4
32
  parallelism: 1
5
33
  docker:
6
- - image: circleci/ruby-2.5
34
+ - image: circleci/ruby:2.5.1
7
35
  steps:
8
36
  - checkout
37
+ - run:
38
+ name: Deployment
39
+ command: ruby .circleci/gem_deployment.rb $RUBYGEMS_API_KEY
40
+
41
+ deploy_gem_minor:
42
+ parallelism: 1
43
+ docker:
44
+ - image: circleci/ruby:2.5.1
45
+ steps:
46
+ - checkout
47
+ - run:
48
+ name: Deployment
49
+ command: ruby .circleci/gem_deployment.rb $RUBYGEMS_API_KEY minor
50
+
51
+ deploy_gem_major:
52
+ parallelism: 1
53
+ docker:
54
+ - image: circleci/ruby:2.5.1
55
+ steps:
56
+ - checkout
57
+ - run:
58
+ name: Deployment
59
+ command: ruby .circleci/gem_deployment.rb $RUBYGEMS_API_KEY major
9
60
 
10
61
 
11
62
  workflows:
@@ -20,3 +71,17 @@ workflows:
20
71
  - deployment/gem
21
72
  requires:
22
73
  - test
74
+ - deploy_gem_minor:
75
+ filters:
76
+ branches:
77
+ only:
78
+ - deployment/gem_minor
79
+ requires:
80
+ - test
81
+ - deploy_gem_major:
82
+ filters:
83
+ branches:
84
+ only:
85
+ - deployment/gem_major
86
+ requires:
87
+ - test
@@ -2,6 +2,8 @@ AllCops:
2
2
  TargetRubyVersion: 2.5
3
3
  Exclude:
4
4
  - tmp
5
+ - lib/slack_resources/generator/event_api/fetch.rb
6
+ - vendor/**/*
5
7
 
6
8
  Rails:
7
9
  Enabled: true
@@ -27,7 +29,7 @@ Metrics/BlockLength:
27
29
  - 'spec/**/*'
28
30
 
29
31
  Metrics/MethodLength:
30
- Max: 40
32
+ Max: 200
31
33
  Exclude:
32
34
  - db/migrate/*.rb
33
35
 
@@ -35,7 +37,7 @@ Metrics/ModuleLength:
35
37
  Max: 150
36
38
 
37
39
  Metrics/ClassLength:
38
- Max: 150
40
+ Max: 300
39
41
  Exclude:
40
42
  - db/migrate/*.rb
41
43
 
@@ -94,3 +96,9 @@ Naming/UncommunicativeMethodParamName:
94
96
 
95
97
  Layout/IndentArray:
96
98
  EnforcedStyle: consistent
99
+
100
+ Metrics/ParameterLists:
101
+ Max: 20
102
+
103
+ Style/RescueModifier:
104
+ Enabled: false
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- # Specify your gem's dependencies in slack_app_request_handler.gemspec
6
5
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack_resources (0.1.1)
4
+ slack_resources (0.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,24 +12,24 @@ GEM
12
12
  minitest (~> 5.1)
13
13
  tzinfo (~> 1.1)
14
14
  ast (2.4.0)
15
- concurrent-ruby (1.1.3)
15
+ concurrent-ruby (1.1.4)
16
16
  diff-lcs (1.3)
17
17
  domain_name (0.5.20180417)
18
18
  unf (>= 0.0.5, < 1.0.0)
19
19
  dotenv (2.5.0)
20
20
  http-cookie (1.0.3)
21
21
  domain_name (~> 0.5)
22
- i18n (1.2.0)
22
+ i18n (1.3.0)
23
23
  concurrent-ruby (~> 1.0)
24
24
  jaro_winkler (1.5.1)
25
25
  mime-types (3.2.2)
26
26
  mime-types-data (~> 3.2015)
27
27
  mime-types-data (3.2018.0812)
28
- mini_portile2 (2.3.0)
28
+ mini_portile2 (2.4.0)
29
29
  minitest (5.11.3)
30
30
  netrc (0.11.0)
31
- nokogiri (1.8.5)
32
- mini_portile2 (~> 2.3.0)
31
+ nokogiri (1.9.1)
32
+ mini_portile2 (~> 2.4.0)
33
33
  onkcop (0.53.0.2)
34
34
  rubocop (>= 0.53.0)
35
35
  rubocop-rspec (>= 1.24.0)
@@ -73,7 +73,7 @@ GEM
73
73
  unf (0.1.4)
74
74
  unf_ext
75
75
  unf_ext (0.0.7.5)
76
- unicode-display_width (1.4.0)
76
+ unicode-display_width (1.4.1)
77
77
 
78
78
  PLATFORMS
79
79
  ruby
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ require 'slack_resources'
3
+
4
+ FileUtils.rm_r('./lib/slack_resources/resources/event_api')
5
+ SlackResources::Generator::Writer.new(
6
+ output_dir: './lib/slack_resources/resources/event_api',
7
+ data_dir: './lib/slack_resources/raw_data/event_api'
8
+ ).execute!
@@ -1,3 +1,11 @@
1
1
  module SlackResources
2
- require 'slack_resources/version'
2
+ require 'slack_resources/version' if File.exist?('./lib/slack_resources/version')
3
+
4
+ require 'slack_resources/generator/event_api/strong_hash'
5
+ require 'slack_resources/generator/event_api/examples_preparation'
6
+ require 'slack_resources/generator/event_api/to_schema'
7
+ require 'slack_resources/generator/event_api/type_detection'
8
+ require 'slack_resources/generator/event_api/write'
9
+
10
+ require 'slack_resources/resources/event_api'
3
11
  end
@@ -0,0 +1,71 @@
1
+ module SlackResources
2
+ module Generator
3
+ class ExamplePreparation
4
+ using StrongHash
5
+
6
+ def initialize(examples_dir:, added_examples_dir:)
7
+ @added_examples_dir = added_examples_dir
8
+ @examples_dir = examples_dir
9
+ end
10
+
11
+ def execute! # rubocop:disable Metrics/AbcSize
12
+ single_events = Set.new(raw_examples.map(&:first))
13
+
14
+ defined = Set.new
15
+ event_typed_examples = {}
16
+ alt_typed_examples = {}
17
+
18
+ raw_examples.each do |alt_event_type, event_type, example|
19
+ example['_raw_example'] = JSON.parse(example.to_json)
20
+ event_typed_examples.protect_merge!(event_type => example)
21
+ alt_typed_examples[alt_event_type] = JSON.parse(example.to_json)
22
+
23
+ next if defined.add?(event_type)
24
+
25
+ single_events.delete(event_type)
26
+ defined_example = event_typed_examples[event_type]
27
+
28
+ Set.new(defined_example.keys + example.keys).each do |k|
29
+ next if k == '_raw_example'
30
+
31
+ defined_value = defined_example[k]
32
+ additional_value = example[k]
33
+
34
+ next if defined_value == additional_value
35
+
36
+ if defined_value.is_a?(Hash) && defined_value[TypeDetection::SPECIAL_TYPE] == TypeDetection::MULTIPLE_EXAMPLES
37
+ (defined_value['items'] << additional_value).sort! { |a, b| a.to_s <=> b.to_s }
38
+ else
39
+ defined_example.merge!(
40
+ k => {
41
+ TypeDetection::SPECIAL_TYPE => TypeDetection::MULTIPLE_EXAMPLES,
42
+ 'target' => k,
43
+ 'items' => [defined_value, additional_value].sort! { |a, b| a.to_s <=> b.to_s },
44
+ }
45
+ )
46
+ end
47
+ end
48
+ end
49
+
50
+ alt_typed_examples.select { |k, _| single_events.include?(k) }.protect_merge!(event_typed_examples)
51
+ end
52
+
53
+ private
54
+
55
+ def all_files
56
+ Dir.glob(@added_examples_dir.join('**/*.json')) + Dir.glob(@examples_dir.join('**/*.json'))
57
+ end
58
+
59
+ def raw_examples
60
+ @raw_examples ||= all_files.map do |f|
61
+ example = JSON.parse(File.read(f))
62
+ alt_event_type = File.basename(f, '.json')
63
+ event_body = example['event'].presence || example
64
+ event_type = event_body['type']
65
+
66
+ [alt_event_type, event_type, event_body.key_ordered]
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,25 @@
1
+ module SlackResources
2
+ module Generator
3
+ module StrongHash
4
+ refine Hash do
5
+ def protect_merge!(b)
6
+ b.keys.map do |new_key|
7
+ if self[new_key]
8
+ self[new_key] = b[new_key] if b[new_key].is_a?(Hash) && b[new_key]['type'].is_a?(Array)
9
+ else
10
+ self[new_key] = b[new_key]
11
+ end
12
+ end
13
+
14
+ self
15
+ end
16
+
17
+ def key_ordered
18
+ keys.sort.inject({}) do |a, k|
19
+ a.merge!(k => self[k])
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,200 @@
1
+ require 'json'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'active_support/core_ext/hash/keys'
4
+
5
+ module SlackResources
6
+ module Generator
7
+ class ToSchema
8
+ using StrongHash
9
+
10
+ def initialize(example:, url:, preset:, key: 'root', defined: {}, defined_used: Set.new, parent: {}, root: nil)
11
+ @example = JSON.parse(example.to_json).key_ordered
12
+ @url = url
13
+ @preset = preset
14
+ @key = key
15
+ @defined = defined
16
+ @defined_used = defined_used
17
+ @parent = parent
18
+ @root = root || @example
19
+ end
20
+
21
+ def execute!
22
+ properties = @example.inject({}) do |a, (prop_name, value)|
23
+ type = TypeDetection.new(
24
+ parent_key: @key,
25
+ to_schema_instance: self,
26
+ prop_name: prop_name,
27
+ value: value,
28
+ container: @example,
29
+ preset: @preset
30
+ ).execute!
31
+
32
+ @defined_used << type if type.is_a?(String)
33
+
34
+ definition =
35
+ case
36
+ when TypeDetection.default_type?(type)
37
+ { 'type' => type }
38
+ when detail?(type)
39
+ type
40
+ when array_type?(type)
41
+ define_as_array(type, value)
42
+ else
43
+ ref_to(type)
44
+ end
45
+
46
+ a.merge(prop_name => definition)
47
+ end
48
+
49
+ [
50
+ {
51
+ 'type' => 'object',
52
+ 'description' => properties.blank? ? "definition snipped. learn more: #{@url}" : '(defined by script)',
53
+ 'properties' => properties,
54
+ },
55
+ @defined,
56
+ @defined_used,
57
+ ]
58
+ end
59
+
60
+ def root_schema?
61
+ @root == @example
62
+ end
63
+
64
+ def root_type
65
+ @root['type']
66
+ end
67
+
68
+ def root_type_prefix
69
+ @root_type_prefix ||= root_type.split('_').shift
70
+ end
71
+
72
+ def array_type?(type)
73
+ type.to_s[0..1] == '[]'
74
+ end
75
+
76
+ def detail?(type)
77
+ type.is_a?(Hash)
78
+ end
79
+
80
+ def define_as_array(array_type, values)
81
+ type = array_type[2..-1]
82
+
83
+ if TypeDetection.default_type?(type)
84
+ return {
85
+ 'type' => 'array',
86
+ 'items' => {
87
+ 'type' => type,
88
+ },
89
+ }
90
+ end
91
+
92
+ if values.first.is_a?(Hash)
93
+ to_child_schema(
94
+ prop_name: type,
95
+ example: values.first,
96
+ key: type,
97
+ parent: @example
98
+ )
99
+ elsif values.first.is_a?(String)
100
+ define_string(type)
101
+ end
102
+
103
+ {
104
+ 'type' => 'array',
105
+ 'items' => ref_to(type),
106
+ }
107
+ end
108
+
109
+ def define_object(k, v, types)
110
+ ref_key = k == 'item' ? "#{root_type_prefix}_item" : k
111
+
112
+ to_child_schema(
113
+ prop_name: ref_key,
114
+ example: v,
115
+ key: k,
116
+ parent: types
117
+ )
118
+
119
+ ref_key
120
+ end
121
+
122
+ def define_special_type(prop_name, value, container, const)
123
+ @defined_used << prop_name
124
+
125
+ return prop_name if @parent[prop_name]
126
+
127
+ types = value['items'].map { |v| detect_default_type(prop_name, v, container) }.uniq
128
+
129
+ @defined[prop_name] =
130
+ if const
131
+ { 'type' => normalize_type(types), enum: value['items'].uniq }
132
+ else
133
+ { 'type' => normalize_type(types) }
134
+ end
135
+
136
+ prop_name
137
+ end
138
+
139
+ def normalize_type(types)
140
+ types.size == 1 ? types[0] : types
141
+ end
142
+
143
+ def define_string(prop_name)
144
+ define_default_type(prop_name, 'string', nil)
145
+ end
146
+
147
+ def define_default_type(prop_name, value, container, const = false)
148
+ @defined.protect_merge!(
149
+ prop_name => {
150
+ 'type' => detect_default_type(prop_name, value, container, const),
151
+ }
152
+ )
153
+ @defined_used << prop_name
154
+
155
+ ref_to(prop_name)
156
+ end
157
+
158
+ def detect_default_type(prop_name, value, container, const = false)
159
+ return define_special_type(prop_name, value, container, const) if value.is_a?(Hash) && value[TypeDetection::SPECIAL_TYPE] == TypeDetection::MULTIPLE_EXAMPLES
160
+
161
+ case value
162
+ when Integer
163
+ 'number'
164
+ when Array
165
+ 'array'
166
+ when Hash
167
+ define_object(prop_name, value, container)
168
+ when true, false
169
+ 'boolean'
170
+ when nil
171
+ 'null'
172
+ else
173
+ 'string'
174
+ end
175
+ end
176
+
177
+ def ref_to(type)
178
+ { '$ref' => "#/definitions/#{type}" }
179
+ end
180
+
181
+ def to_child_schema(params)
182
+ prop_name = params.delete(:prop_name)
183
+ SlackResources::Generator::ToSchema.new(
184
+ example: @example,
185
+ url: @url,
186
+ preset: @preset,
187
+ key: @key,
188
+ defined: @defined,
189
+ defined_used: @defined_used,
190
+ parent: @parent,
191
+ root: @root,
192
+ **params
193
+ ).execute!.tap do |schema,|
194
+ @defined_used << prop_name
195
+ @defined[prop_name] = schema
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end