kinetic_sdk 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +7 -0
  2. data/GettingStarted.md +64 -0
  3. data/README.md +383 -0
  4. data/bin/console +12 -0
  5. data/bin/setup +8 -0
  6. data/gems/kontena-websocket-client-0.1.1/Gemfile +4 -0
  7. data/gems/kontena-websocket-client-0.1.1/LICENSE +190 -0
  8. data/gems/kontena-websocket-client-0.1.1/README.md +138 -0
  9. data/gems/kontena-websocket-client-0.1.1/Rakefile +6 -0
  10. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-client.rb +45 -0
  11. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-em.rb +66 -0
  12. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.rb +161 -0
  13. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.sh +17 -0
  14. data/gems/kontena-websocket-client-0.1.1/benchmark/websocket-echo-server.go +207 -0
  15. data/gems/kontena-websocket-client-0.1.1/examples/websocket-echo-client.rb +80 -0
  16. data/gems/kontena-websocket-client-0.1.1/kontena-websocket-client.gemspec +24 -0
  17. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/connection.rb +119 -0
  18. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/version.rb +13 -0
  19. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client.rb +848 -0
  20. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/error.rb +81 -0
  21. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/logging.rb +55 -0
  22. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/openssl_patch.rb +10 -0
  23. data/gems/kontena-websocket-client-0.1.1/lib/kontena-websocket-client.rb +15 -0
  24. data/gems/mime-types-3.1/Code-of-Conduct.rdoc +74 -0
  25. data/gems/mime-types-3.1/Contributing.rdoc +130 -0
  26. data/gems/mime-types-3.1/History.rdoc +658 -0
  27. data/gems/mime-types-3.1/Licence.rdoc +25 -0
  28. data/gems/mime-types-3.1/Manifest.txt +31 -0
  29. data/gems/mime-types-3.1/README.rdoc +202 -0
  30. data/gems/mime-types-3.1/Rakefile +254 -0
  31. data/gems/mime-types-3.1/lib/mime/type/columnar.rb +55 -0
  32. data/gems/mime-types-3.1/lib/mime/type.rb +573 -0
  33. data/gems/mime-types-3.1/lib/mime/types/_columnar.rb +135 -0
  34. data/gems/mime-types-3.1/lib/mime/types/cache.rb +56 -0
  35. data/gems/mime-types-3.1/lib/mime/types/columnar.rb +1 -0
  36. data/gems/mime-types-3.1/lib/mime/types/container.rb +30 -0
  37. data/gems/mime-types-3.1/lib/mime/types/deprecations.rb +32 -0
  38. data/gems/mime-types-3.1/lib/mime/types/full.rb +17 -0
  39. data/gems/mime-types-3.1/lib/mime/types/loader.rb +148 -0
  40. data/gems/mime-types-3.1/lib/mime/types/logger.rb +37 -0
  41. data/gems/mime-types-3.1/lib/mime/types/registry.rb +81 -0
  42. data/gems/mime-types-3.1/lib/mime/types.rb +228 -0
  43. data/gems/mime-types-3.1/lib/mime-types.rb +1 -0
  44. data/gems/mime-types-3.1/test/bad-fixtures/malformed +9 -0
  45. data/gems/mime-types-3.1/test/fixture/json.json +1 -0
  46. data/gems/mime-types-3.1/test/fixture/old-data +9 -0
  47. data/gems/mime-types-3.1/test/fixture/yaml.yaml +55 -0
  48. data/gems/mime-types-3.1/test/minitest_helper.rb +13 -0
  49. data/gems/mime-types-3.1/test/test_mime_type.rb +603 -0
  50. data/gems/mime-types-3.1/test/test_mime_types.rb +161 -0
  51. data/gems/mime-types-3.1/test/test_mime_types_cache.rb +109 -0
  52. data/gems/mime-types-3.1/test/test_mime_types_class.rb +155 -0
  53. data/gems/mime-types-3.1/test/test_mime_types_lazy.rb +43 -0
  54. data/gems/mime-types-3.1/test/test_mime_types_loader.rb +32 -0
  55. data/gems/mime-types-data-3.2016.0521/Code-of-Conduct.md +75 -0
  56. data/gems/mime-types-data-3.2016.0521/Contributing.md +157 -0
  57. data/gems/mime-types-data-3.2016.0521/History.md +351 -0
  58. data/gems/mime-types-data-3.2016.0521/Licence.md +25 -0
  59. data/gems/mime-types-data-3.2016.0521/Manifest.txt +18 -0
  60. data/gems/mime-types-data-3.2016.0521/README.md +61 -0
  61. data/gems/mime-types-data-3.2016.0521/Rakefile +80 -0
  62. data/gems/mime-types-data-3.2016.0521/data/mime-types.json +1 -0
  63. data/gems/mime-types-data-3.2016.0521/data/mime.content_type.column +1964 -0
  64. data/gems/mime-types-data-3.2016.0521/data/mime.docs.column +1964 -0
  65. data/gems/mime-types-data-3.2016.0521/data/mime.encoding.column +1964 -0
  66. data/gems/mime-types-data-3.2016.0521/data/mime.flags.column +1964 -0
  67. data/gems/mime-types-data-3.2016.0521/data/mime.friendly.column +1964 -0
  68. data/gems/mime-types-data-3.2016.0521/data/mime.pext.column +1964 -0
  69. data/gems/mime-types-data-3.2016.0521/data/mime.use_instead.column +1964 -0
  70. data/gems/mime-types-data-3.2016.0521/data/mime.xrefs.column +1964 -0
  71. data/gems/mime-types-data-3.2016.0521/lib/mime/types/data.rb +21 -0
  72. data/gems/mime-types-data-3.2016.0521/lib/mime-types-data.rb +3 -0
  73. data/gems/multipart-post-2.0.0/Gemfile +14 -0
  74. data/gems/multipart-post-2.0.0/History.txt +60 -0
  75. data/gems/multipart-post-2.0.0/Manifest.txt +9 -0
  76. data/gems/multipart-post-2.0.0/README.md +77 -0
  77. data/gems/multipart-post-2.0.0/Rakefile +9 -0
  78. data/gems/multipart-post-2.0.0/lib/composite_io.rb +108 -0
  79. data/gems/multipart-post-2.0.0/lib/multipart_post.rb +9 -0
  80. data/gems/multipart-post-2.0.0/lib/multipartable.rb +29 -0
  81. data/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +27 -0
  82. data/gems/multipart-post-2.0.0/lib/parts.rb +96 -0
  83. data/gems/multipart-post-2.0.0/multipart-post.gemspec +22 -0
  84. data/gems/multipart-post-2.0.0/test/multibyte.txt +1 -0
  85. data/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +110 -0
  86. data/gems/multipart-post-2.0.0/test/test_composite_io.rb +115 -0
  87. data/gems/multipart-post-2.0.0/test/test_parts.rb +86 -0
  88. data/gems/parallel-1.12.1/MIT-LICENSE.txt +20 -0
  89. data/gems/parallel-1.12.1/lib/parallel/processor_count.rb +93 -0
  90. data/gems/parallel-1.12.1/lib/parallel/version.rb +3 -0
  91. data/gems/parallel-1.12.1/lib/parallel.rb +500 -0
  92. data/gems/ruby-progressbar-1.9.0/LICENSE.txt +19 -0
  93. data/gems/ruby-progressbar-1.9.0/README.md +38 -0
  94. data/gems/ruby-progressbar-1.9.0/Rakefile +2 -0
  95. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/base.rb +183 -0
  96. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/length.rb +99 -0
  97. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/running_average.rb +9 -0
  98. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/bar.rb +96 -0
  99. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/percentage.rb +29 -0
  100. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/rate.rb +43 -0
  101. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/time.rb +107 -0
  102. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/title.rb +13 -0
  103. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components.rb +5 -0
  104. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
  105. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/formatter.rb +27 -0
  106. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/molecule.rb +59 -0
  107. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/string.rb +36 -0
  108. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format.rb +3 -0
  109. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/output.rb +68 -0
  110. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
  111. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/null.rb +33 -0
  112. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/tty.rb +32 -0
  113. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/progress.rb +118 -0
  114. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements/enumerator.rb +25 -0
  115. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements.rb +1 -0
  116. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/throttle.rb +25 -0
  117. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/time.rb +30 -0
  118. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb +72 -0
  119. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/version.rb +3 -0
  120. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar.rb +18 -0
  121. data/gems/slugify-1.0.7/README +18 -0
  122. data/gems/slugify-1.0.7/lib/slugify.rb +1012 -0
  123. data/gems/slugify-1.0.7/lib/slugify_string.rb +11 -0
  124. data/gems/slugify-1.0.7/tests/slugify_test.rb +116 -0
  125. data/gems/slugify-1.0.7/tests/string_slugify_test.rb +23 -0
  126. data/gems/websocket-driver-0.6.5/CHANGELOG.md +123 -0
  127. data/gems/websocket-driver-0.6.5/LICENSE.md +22 -0
  128. data/gems/websocket-driver-0.6.5/README.md +369 -0
  129. data/gems/websocket-driver-0.6.5/examples/tcp_server.rb +28 -0
  130. data/gems/websocket-driver-0.6.5/ext/websocket-driver/Makefile +264 -0
  131. data/gems/websocket-driver-0.6.5/ext/websocket-driver/WebsocketMaskService.java +55 -0
  132. data/gems/websocket-driver-0.6.5/ext/websocket-driver/extconf.rb +4 -0
  133. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.bundle +0 -0
  134. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.c +41 -0
  135. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.o +0 -0
  136. data/gems/websocket-driver-0.6.5/lib/websocket/driver/client.rb +140 -0
  137. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft75.rb +102 -0
  138. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft76.rb +96 -0
  139. data/gems/websocket-driver-0.6.5/lib/websocket/driver/event_emitter.rb +54 -0
  140. data/gems/websocket-driver-0.6.5/lib/websocket/driver/headers.rb +45 -0
  141. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/frame.rb +20 -0
  142. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/message.rb +31 -0
  143. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi.rb +406 -0
  144. data/gems/websocket-driver-0.6.5/lib/websocket/driver/proxy.rb +68 -0
  145. data/gems/websocket-driver-0.6.5/lib/websocket/driver/server.rb +80 -0
  146. data/gems/websocket-driver-0.6.5/lib/websocket/driver/stream_reader.rb +55 -0
  147. data/gems/websocket-driver-0.6.5/lib/websocket/driver.rb +199 -0
  148. data/gems/websocket-driver-0.6.5/lib/websocket/http/headers.rb +112 -0
  149. data/gems/websocket-driver-0.6.5/lib/websocket/http/request.rb +45 -0
  150. data/gems/websocket-driver-0.6.5/lib/websocket/http/response.rb +29 -0
  151. data/gems/websocket-driver-0.6.5/lib/websocket/http.rb +15 -0
  152. data/gems/websocket-driver-0.6.5/lib/websocket/mask.rb +14 -0
  153. data/gems/websocket-driver-0.6.5/lib/websocket/websocket_mask.rb +2 -0
  154. data/gems/websocket-driver-0.6.5/lib/websocket_mask.bundle +0 -0
  155. data/gems/websocket-driver-0.6.5-java/CHANGELOG.md +123 -0
  156. data/gems/websocket-driver-0.6.5-java/LICENSE.md +22 -0
  157. data/gems/websocket-driver-0.6.5-java/README.md +369 -0
  158. data/gems/websocket-driver-0.6.5-java/examples/tcp_server.rb +28 -0
  159. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/WebsocketMaskService.java +55 -0
  160. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/extconf.rb +4 -0
  161. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/websocket_mask.c +41 -0
  162. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/client.rb +140 -0
  163. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft75.rb +102 -0
  164. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft76.rb +96 -0
  165. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/event_emitter.rb +54 -0
  166. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/headers.rb +45 -0
  167. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/frame.rb +20 -0
  168. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/message.rb +31 -0
  169. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi.rb +406 -0
  170. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/proxy.rb +68 -0
  171. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/server.rb +80 -0
  172. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/stream_reader.rb +55 -0
  173. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver.rb +199 -0
  174. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/headers.rb +112 -0
  175. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/request.rb +45 -0
  176. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/response.rb +29 -0
  177. data/gems/websocket-driver-0.6.5-java/lib/websocket/http.rb +15 -0
  178. data/gems/websocket-driver-0.6.5-java/lib/websocket/mask.rb +14 -0
  179. data/gems/websocket-driver-0.6.5-java/lib/websocket/websocket_mask.rb +2 -0
  180. data/gems/websocket-driver-0.6.5-java/lib/websocket_mask.jar +0 -0
  181. data/gems/websocket-extensions-0.1.3/CHANGELOG.md +15 -0
  182. data/gems/websocket-extensions-0.1.3/LICENSE.md +20 -0
  183. data/gems/websocket-extensions-0.1.3/README.md +313 -0
  184. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions/parser.rb +111 -0
  185. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions.rb +181 -0
  186. data/lib/kinetic-sdk.rb +1 -0
  187. data/lib/kinetic_sdk/bridgehub/bridgehub-sdk.rb +80 -0
  188. data/lib/kinetic_sdk/bridgehub/lib/access_keys.rb +67 -0
  189. data/lib/kinetic_sdk/bridgehub/lib/bridge.rb +69 -0
  190. data/lib/kinetic_sdk/discussions/discussions-sdk.rb +165 -0
  191. data/lib/kinetic_sdk/discussions/lib/discussions.rb +107 -0
  192. data/lib/kinetic_sdk/discussions/lib/invitations.rb +120 -0
  193. data/lib/kinetic_sdk/discussions/lib/messages.rb +190 -0
  194. data/lib/kinetic_sdk/discussions/lib/meta.rb +14 -0
  195. data/lib/kinetic_sdk/discussions/lib/participants.rb +64 -0
  196. data/lib/kinetic_sdk/discussions/lib/related_items.rb +54 -0
  197. data/lib/kinetic_sdk/discussions/lib/websockets.rb +96 -0
  198. data/lib/kinetic_sdk/filehub/filehub-sdk.rb +80 -0
  199. data/lib/kinetic_sdk/filehub/lib/access_keys.rb +67 -0
  200. data/lib/kinetic_sdk/filehub/lib/filestores.rb +67 -0
  201. data/lib/kinetic_sdk/request_ce/lib/attribute_definitions.rb +153 -0
  202. data/lib/kinetic_sdk/request_ce/lib/bridges.rb +66 -0
  203. data/lib/kinetic_sdk/request_ce/lib/categories.rb +34 -0
  204. data/lib/kinetic_sdk/request_ce/lib/datastore_form.rb +110 -0
  205. data/lib/kinetic_sdk/request_ce/lib/datastore_submissions.rb +157 -0
  206. data/lib/kinetic_sdk/request_ce/lib/form.rb +99 -0
  207. data/lib/kinetic_sdk/request_ce/lib/form_types.rb +51 -0
  208. data/lib/kinetic_sdk/request_ce/lib/jwt.rb +55 -0
  209. data/lib/kinetic_sdk/request_ce/lib/kapp.rb +93 -0
  210. data/lib/kinetic_sdk/request_ce/lib/meta.rb +14 -0
  211. data/lib/kinetic_sdk/request_ce/lib/oauth.rb +37 -0
  212. data/lib/kinetic_sdk/request_ce/lib/security_policy_definitions.rb +157 -0
  213. data/lib/kinetic_sdk/request_ce/lib/space.rb +89 -0
  214. data/lib/kinetic_sdk/request_ce/lib/submissions.rb +215 -0
  215. data/lib/kinetic_sdk/request_ce/lib/system_api.rb +69 -0
  216. data/lib/kinetic_sdk/request_ce/lib/teams.rb +113 -0
  217. data/lib/kinetic_sdk/request_ce/lib/users.rb +245 -0
  218. data/lib/kinetic_sdk/request_ce/lib/webhook_jobs.rb +142 -0
  219. data/lib/kinetic_sdk/request_ce/lib/webhooks.rb +192 -0
  220. data/lib/kinetic_sdk/request_ce/request-ce-sdk.rb +153 -0
  221. data/lib/kinetic_sdk/task/lib/access_keys.rb +94 -0
  222. data/lib/kinetic_sdk/task/lib/categories.rb +190 -0
  223. data/lib/kinetic_sdk/task/lib/config.rb +202 -0
  224. data/lib/kinetic_sdk/task/lib/engine.rb +42 -0
  225. data/lib/kinetic_sdk/task/lib/environment.rb +14 -0
  226. data/lib/kinetic_sdk/task/lib/errors.rb +165 -0
  227. data/lib/kinetic_sdk/task/lib/groups.rb +112 -0
  228. data/lib/kinetic_sdk/task/lib/handlers.rb +105 -0
  229. data/lib/kinetic_sdk/task/lib/health.rb +28 -0
  230. data/lib/kinetic_sdk/task/lib/license.rb +52 -0
  231. data/lib/kinetic_sdk/task/lib/policy_rules.rb +166 -0
  232. data/lib/kinetic_sdk/task/lib/setup.rb +56 -0
  233. data/lib/kinetic_sdk/task/lib/sources.rb +134 -0
  234. data/lib/kinetic_sdk/task/lib/tasks.rb +17 -0
  235. data/lib/kinetic_sdk/task/lib/trees.rb +274 -0
  236. data/lib/kinetic_sdk/task/lib/users.rb +75 -0
  237. data/lib/kinetic_sdk/task/task-sdk.rb +92 -0
  238. data/lib/kinetic_sdk/utils/kinetic-http-headers.rb +150 -0
  239. data/lib/kinetic_sdk/utils/kinetic-http-response.rb +75 -0
  240. data/lib/kinetic_sdk/utils/kinetic-http.rb +552 -0
  241. data/lib/kinetic_sdk/utils/logger.rb +70 -0
  242. data/lib/kinetic_sdk/utils/random.rb +30 -0
  243. data/lib/kinetic_sdk/version.rb +7 -0
  244. data/lib/kinetic_sdk.rb +57 -0
  245. metadata +414 -0
@@ -0,0 +1,573 @@
1
+ ##
2
+ module MIME
3
+ end
4
+
5
+ # The definition of one MIME content-type.
6
+ #
7
+ # == Usage
8
+ # require 'mime/types'
9
+ #
10
+ # plaintext = MIME::Types['text/plain'].first
11
+ # # returns [text/plain, text/plain]
12
+ # text = plaintext.first
13
+ # print text.media_type # => 'text'
14
+ # print text.sub_type # => 'plain'
15
+ #
16
+ # puts text.extensions.join(" ") # => 'asc txt c cc h hh cpp'
17
+ #
18
+ # puts text.encoding # => 8bit
19
+ # puts text.binary? # => false
20
+ # puts text.ascii? # => true
21
+ # puts text == 'text/plain' # => true
22
+ # puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
23
+ #
24
+ # puts MIME::Types.any? { |type|
25
+ # type.content_type == 'text/plain'
26
+ # } # => true
27
+ # puts MIME::Types.all?(&:registered?)
28
+ # # => false
29
+ class MIME::Type
30
+ # Reflects a MIME content-type specification that is not correctly
31
+ # formatted (it isn't +type+/+subtype+).
32
+ class InvalidContentType < ArgumentError
33
+ # :stopdoc:
34
+ def initialize(type_string)
35
+ @type_string = type_string
36
+ end
37
+
38
+ def to_s
39
+ "Invalid Content-Type #{@type_string.inspect}"
40
+ end
41
+ # :startdoc:
42
+ end
43
+
44
+ # Reflects an unsupported MIME encoding.
45
+ class InvalidEncoding < ArgumentError
46
+ # :stopdoc:
47
+ def initialize(encoding)
48
+ @encoding = encoding
49
+ end
50
+
51
+ def to_s
52
+ "Invalid Encoding #{@encoding.inspect}"
53
+ end
54
+ # :startdoc:
55
+ end
56
+
57
+ # The released version of the mime-types library.
58
+ VERSION = '3.1'
59
+
60
+ include Comparable
61
+
62
+ # :stopdoc:
63
+ # TODO verify mime-type character restrictions; I am pretty sure that this is
64
+ # too wide open.
65
+ MEDIA_TYPE_RE = %r{([-\w.+]+)/([-\w.+]*)}
66
+ I18N_RE = %r{[^[:alnum:]]}
67
+ BINARY_ENCODINGS = %w(base64 8bit)
68
+ ASCII_ENCODINGS = %w(7bit quoted-printable)
69
+ # :startdoc:
70
+
71
+ private_constant :MEDIA_TYPE_RE, :I18N_RE, :BINARY_ENCODINGS,
72
+ :ASCII_ENCODINGS
73
+
74
+ # Builds a MIME::Type object from the +content_type+, a MIME Content Type
75
+ # value (e.g., 'text/plain' or 'applicaton/x-eruby'). The constructed object
76
+ # is yielded to an optional block for additional configuration, such as
77
+ # associating extensions and encoding information.
78
+ #
79
+ # * When provided a Hash or a MIME::Type, the MIME::Type will be
80
+ # constructed with #init_with.
81
+ # * When provided an Array, the MIME::Type will be constructed using
82
+ # the first element as the content type and the remaining flattened
83
+ # elements as extensions.
84
+ # * Otherwise, the content_type will be used as a string.
85
+ #
86
+ # Yields the newly constructed +self+ object.
87
+ def initialize(content_type) # :yields self:
88
+ @friendly = {}
89
+ @obsolete = @registered = false
90
+ @preferred_extension = @docs = @use_instead = nil
91
+ self.extensions = []
92
+
93
+ case content_type
94
+ when Hash
95
+ init_with(content_type)
96
+ when Array
97
+ self.content_type = content_type.shift
98
+ self.extensions = content_type.flatten
99
+ when MIME::Type
100
+ init_with(content_type.to_h)
101
+ else
102
+ self.content_type = content_type
103
+ end
104
+
105
+ self.encoding ||= :default
106
+ self.xrefs ||= {}
107
+
108
+ yield self if block_given?
109
+ end
110
+
111
+ # Indicates that a MIME type is like another type. This differs from
112
+ # <tt>==</tt> because <tt>x-</tt> prefixes are removed for this comparison.
113
+ def like?(other)
114
+ other = if other.respond_to?(:simplified)
115
+ MIME::Type.simplified(other.simplified, remove_x_prefix: true)
116
+ else
117
+ MIME::Type.simplified(other.to_s, remove_x_prefix: true)
118
+ end
119
+ MIME::Type.simplified(simplified, remove_x_prefix: true) == other
120
+ end
121
+
122
+ # Compares the +other+ MIME::Type against the exact content type or the
123
+ # simplified type (the simplified type will be used if comparing against
124
+ # something that can be treated as a String with #to_s). In comparisons, this
125
+ # is done against the lowercase version of the MIME::Type.
126
+ def <=>(other)
127
+ if other.nil?
128
+ -1
129
+ elsif other.respond_to?(:simplified)
130
+ simplified <=> other.simplified
131
+ else
132
+ simplified <=> MIME::Type.simplified(other.to_s)
133
+ end
134
+ end
135
+
136
+ # Compares the +other+ MIME::Type based on how reliable it is before doing a
137
+ # normal <=> comparison. Used by MIME::Types#[] to sort types. The
138
+ # comparisons involved are:
139
+ #
140
+ # 1. self.simplified <=> other.simplified (ensures that we
141
+ # don't try to compare different types)
142
+ # 2. IANA-registered definitions < other definitions.
143
+ # 3. Complete definitions < incomplete definitions.
144
+ # 4. Current definitions < obsolete definitions.
145
+ # 5. Obselete with use-instead names < obsolete without.
146
+ # 6. Obsolete use-instead definitions are compared.
147
+ #
148
+ # While this method is public, its use is strongly discouraged by consumers
149
+ # of mime-types. In mime-types 3, this method is likely to see substantial
150
+ # revision and simplification to ensure current registered content types sort
151
+ # before unregistered or obsolete content types.
152
+ def priority_compare(other)
153
+ pc = simplified <=> other.simplified
154
+ if pc.zero?
155
+ pc = if (reg = registered?) != other.registered?
156
+ reg ? -1 : 1 # registered < unregistered
157
+ elsif (comp = complete?) != other.complete?
158
+ comp ? -1 : 1 # complete < incomplete
159
+ elsif (obs = obsolete?) != other.obsolete?
160
+ obs ? 1 : -1 # current < obsolete
161
+ elsif obs and ((ui = use_instead) != (oui = other.use_instead))
162
+ if ui.nil?
163
+ 1
164
+ elsif oui.nil?
165
+ -1
166
+ else
167
+ ui <=> oui
168
+ end
169
+ else
170
+ 0
171
+ end
172
+ end
173
+
174
+ pc
175
+ end
176
+
177
+ # Returns +true+ if the +other+ object is a MIME::Type and the content types
178
+ # match.
179
+ def eql?(other)
180
+ other.kind_of?(MIME::Type) and self == other
181
+ end
182
+
183
+ # Returns the whole MIME content-type string.
184
+ #
185
+ # The content type is a presentation value from the MIME type registry and
186
+ # should not be used for comparison. The case of the content type is
187
+ # preserved, and extension markers (<tt>x-</tt>) are kept.
188
+ #
189
+ # text/plain => text/plain
190
+ # x-chemical/x-pdb => x-chemical/x-pdb
191
+ # audio/QCELP => audio/QCELP
192
+ attr_reader :content_type
193
+ # A simplified form of the MIME content-type string, suitable for
194
+ # case-insensitive comparison, with any extension markers (<tt>x-</tt)
195
+ # removed and converted to lowercase.
196
+ #
197
+ # text/plain => text/plain
198
+ # x-chemical/x-pdb => x-chemical/x-pdb
199
+ # audio/QCELP => audio/qcelp
200
+ attr_reader :simplified
201
+ # Returns the media type of the simplified MIME::Type.
202
+ #
203
+ # text/plain => text
204
+ # x-chemical/x-pdb => x-chemical
205
+ # audio/QCELP => audio
206
+ attr_reader :media_type
207
+ # Returns the media type of the unmodified MIME::Type.
208
+ #
209
+ # text/plain => text
210
+ # x-chemical/x-pdb => x-chemical
211
+ # audio/QCELP => audio
212
+ attr_reader :raw_media_type
213
+ # Returns the sub-type of the simplified MIME::Type.
214
+ #
215
+ # text/plain => plain
216
+ # x-chemical/x-pdb => pdb
217
+ # audio/QCELP => QCELP
218
+ attr_reader :sub_type
219
+ # Returns the media type of the unmodified MIME::Type.
220
+ #
221
+ # text/plain => plain
222
+ # x-chemical/x-pdb => x-pdb
223
+ # audio/QCELP => qcelp
224
+ attr_reader :raw_sub_type
225
+
226
+ ##
227
+ # The list of extensions which are known to be used for this MIME::Type.
228
+ # Non-array values will be coerced into an array with #to_a. Array values
229
+ # will be flattened, +nil+ values removed, and made unique.
230
+ #
231
+ # :attr_accessor: extensions
232
+ def extensions
233
+ @extensions.to_a
234
+ end
235
+
236
+ ##
237
+ def extensions=(value) # :nodoc:
238
+ @extensions = Set[*Array(value).flatten.compact].freeze
239
+ MIME::Types.send(:reindex_extensions, self)
240
+ end
241
+
242
+ # Merge the +extensions+ provided into this MIME::Type. The extensions added
243
+ # will be merged uniquely.
244
+ def add_extensions(*extensions)
245
+ self.extensions += extensions
246
+ end
247
+
248
+ ##
249
+ # The preferred extension for this MIME type. If one is not set and there are
250
+ # exceptions defined, the first extension will be used.
251
+ #
252
+ # When setting #preferred_extensions, if #extensions does not contain this
253
+ # extension, this will be added to #xtensions.
254
+ #
255
+ # :attr_accessor: preferred_extension
256
+
257
+ ##
258
+ def preferred_extension
259
+ @preferred_extension || extensions.first
260
+ end
261
+
262
+ ##
263
+ def preferred_extension=(value) # :nodoc:
264
+ add_extensions(value) if value
265
+ @preferred_extension = value
266
+ end
267
+
268
+ ##
269
+ # The encoding (+7bit+, +8bit+, <tt>quoted-printable</tt>, or +base64+)
270
+ # required to transport the data of this content type safely across a
271
+ # network, which roughly corresponds to Content-Transfer-Encoding. A value of
272
+ # +nil+ or <tt>:default</tt> will reset the #encoding to the
273
+ # #default_encoding for the MIME::Type. Raises ArgumentError if the encoding
274
+ # provided is invalid.
275
+ #
276
+ # If the encoding is not provided on construction, this will be either
277
+ # 'quoted-printable' (for text/* media types) and 'base64' for eveything
278
+ # else.
279
+ #
280
+ # :attr_accessor: encoding
281
+
282
+ ##
283
+ attr_reader :encoding
284
+
285
+ ##
286
+ def encoding=(enc) # :nodoc:
287
+ if enc.nil? or enc == :default
288
+ @encoding = default_encoding
289
+ elsif BINARY_ENCODINGS.include?(enc) or ASCII_ENCODINGS.include?(enc)
290
+ @encoding = enc
291
+ else
292
+ fail InvalidEncoding, enc
293
+ end
294
+ end
295
+
296
+ # Returns the default encoding for the MIME::Type based on the media type.
297
+ def default_encoding
298
+ (@media_type == 'text') ? 'quoted-printable' : 'base64'
299
+ end
300
+
301
+ ##
302
+ # Returns the media type or types that should be used instead of this media
303
+ # type, if it is obsolete. If there is no replacement media type, or it is
304
+ # not obsolete, +nil+ will be returned.
305
+ #
306
+ # :attr_accessor: use_instead
307
+
308
+ ##
309
+ def use_instead
310
+ obsolete? ? @use_instead : nil
311
+ end
312
+
313
+ ##
314
+ attr_writer :use_instead
315
+
316
+ # Returns +true+ if the media type is obsolete.
317
+ attr_accessor :obsolete
318
+ alias_method :obsolete?, :obsolete
319
+
320
+ # The documentation for this MIME::Type.
321
+ attr_accessor :docs
322
+
323
+ # A friendly short description for this MIME::Type.
324
+ #
325
+ # call-seq:
326
+ # text_plain.friendly # => "Text File"
327
+ # text_plain.friendly('en') # => "Text File"
328
+ def friendly(lang = 'en'.freeze)
329
+ @friendly ||= {}
330
+
331
+ case lang
332
+ when String, Symbol
333
+ @friendly[lang.to_s]
334
+ when Array
335
+ @friendly.update(Hash[*lang])
336
+ when Hash
337
+ @friendly.update(lang)
338
+ else
339
+ fail ArgumentError,
340
+ "Expected a language or translation set, not #{lang.inspect}"
341
+ end
342
+ end
343
+
344
+ # A key suitable for use as a lookup key for translations, such as with
345
+ # the I18n library.
346
+ #
347
+ # call-seq:
348
+ # text_plain.i18n_key # => "text.plain"
349
+ # 3gpp_xml.i18n_key # => "application.vnd-3gpp-bsf-xml"
350
+ # # from application/vnd.3gpp.bsf+xml
351
+ # x_msword.i18n_key # => "application.word"
352
+ # # from application/x-msword
353
+ attr_reader :i18n_key
354
+
355
+ ##
356
+ # The cross-references list for this MIME::Type.
357
+ #
358
+ # :attr_accessor: xrefs
359
+
360
+ ##
361
+ attr_reader :xrefs
362
+
363
+ ##
364
+ def xrefs=(x) # :nodoc:
365
+ MIME::Types::Container.new.merge(x).tap do |xr|
366
+ xr.each do |k, v|
367
+ xr[k] = Set[*v] unless v.kind_of? Set
368
+ end
369
+
370
+ @xrefs = xr
371
+ end
372
+ end
373
+
374
+ # The decoded cross-reference URL list for this MIME::Type.
375
+ def xref_urls
376
+ xrefs.flat_map { |type, values|
377
+ name = :"xref_url_for_#{type.tr('-', '_')}"
378
+ respond_to?(name, true) and xref_map(values, name) or values.to_a
379
+ }
380
+ end
381
+
382
+ # Indicates whether the MIME type has been registered with IANA.
383
+ attr_accessor :registered
384
+ alias_method :registered?, :registered
385
+
386
+ # MIME types can be specified to be sent across a network in particular
387
+ # formats. This method returns +true+ when the MIME::Type encoding is set
388
+ # to <tt>base64</tt>.
389
+ def binary?
390
+ BINARY_ENCODINGS.include?(encoding)
391
+ end
392
+
393
+ # MIME types can be specified to be sent across a network in particular
394
+ # formats. This method returns +false+ when the MIME::Type encoding is
395
+ # set to <tt>base64</tt>.
396
+ def ascii?
397
+ ASCII_ENCODINGS.include?(encoding)
398
+ end
399
+
400
+ # Indicateswhether the MIME type is declared as a signature type.
401
+ attr_accessor :signature
402
+ alias_method :signature?, :signature
403
+
404
+ # Returns +true+ if the MIME::Type specifies an extension list,
405
+ # indicating that it is a complete MIME::Type.
406
+ def complete?
407
+ !@extensions.empty?
408
+ end
409
+
410
+ # Returns the MIME::Type as a string.
411
+ def to_s
412
+ content_type
413
+ end
414
+
415
+ # Returns the MIME::Type as a string for implicit conversions. This allows
416
+ # MIME::Type objects to appear on either side of a comparison.
417
+ #
418
+ # 'text/plain' == MIME::Type.new('text/plain')
419
+ def to_str
420
+ content_type
421
+ end
422
+
423
+ # Converts the MIME::Type to a JSON string.
424
+ def to_json(*args)
425
+ require 'json'
426
+ to_h.to_json(*args)
427
+ end
428
+
429
+ # Converts the MIME::Type to a hash. The output of this method can also be
430
+ # used to initialize a MIME::Type.
431
+ def to_h
432
+ encode_with({})
433
+ end
434
+
435
+ # Populates the +coder+ with attributes about this record for
436
+ # serialization. The structure of +coder+ should match the structure used
437
+ # with #init_with.
438
+ #
439
+ # This method should be considered a private implementation detail.
440
+ def encode_with(coder)
441
+ coder['content-type'] = @content_type
442
+ coder['docs'] = @docs unless @docs.nil? or @docs.empty?
443
+ unless @friendly.nil? or @friendly.empty?
444
+ coder['friendly'] = @friendly
445
+ end
446
+ coder['encoding'] = @encoding
447
+ coder['extensions'] = @extensions.to_a unless @extensions.empty?
448
+ coder['preferred-extension'] = @preferred_extension if @preferred_extension
449
+ if obsolete?
450
+ coder['obsolete'] = obsolete?
451
+ coder['use-instead'] = use_instead if use_instead
452
+ end
453
+ unless xrefs.empty?
454
+ {}.tap do |hash|
455
+ xrefs.each do |k, v|
456
+ hash[k] = v.sort.to_a
457
+ end
458
+ coder['xrefs'] = hash
459
+ end
460
+ end
461
+ coder['registered'] = registered?
462
+ coder['signature'] = signature? if signature?
463
+ coder
464
+ end
465
+
466
+ # Initialize an empty object from +coder+, which must contain the
467
+ # attributes necessary for initializing an empty object.
468
+ #
469
+ # This method should be considered a private implementation detail.
470
+ def init_with(coder)
471
+ self.content_type = coder['content-type']
472
+ self.docs = coder['docs'] || ''
473
+ self.encoding = coder['encoding']
474
+ self.extensions = coder['extensions'] || []
475
+ self.preferred_extension = coder['preferred-extension']
476
+ self.obsolete = coder['obsolete'] || false
477
+ self.registered = coder['registered'] || false
478
+ self.signature = coder['signature']
479
+ self.xrefs = coder['xrefs'] || {}
480
+ self.use_instead = coder['use-instead']
481
+
482
+ friendly(coder['friendly'] || {})
483
+ end
484
+
485
+ def inspect # :nodoc:
486
+ # We are intentionally lying here because MIME::Type::Columnar is an
487
+ # implementation detail.
488
+ "#<MIME::Type: #{self}>"
489
+ end
490
+
491
+ class << self
492
+ # MIME media types are case-insensitive, but are typically presented in a
493
+ # case-preserving format in the type registry. This method converts
494
+ # +content_type+ to lowercase.
495
+ #
496
+ # In previous versions of mime-types, this would also remove any extension
497
+ # prefix (<tt>x-</tt>). This is no longer default behaviour, but may be
498
+ # provided by providing a truth value to +remove_x_prefix+.
499
+ def simplified(content_type, remove_x_prefix: false)
500
+ simplify_matchdata(match(content_type), remove_x_prefix)
501
+ end
502
+
503
+ # Converts a provided +content_type+ into a translation key suitable for
504
+ # use with the I18n library.
505
+ def i18n_key(content_type)
506
+ simplify_matchdata(match(content_type), joiner: '.') { |e|
507
+ e.gsub!(I18N_RE, '-'.freeze)
508
+ }
509
+ end
510
+
511
+ # Return a +MatchData+ object of the +content_type+ against pattern of
512
+ # media types.
513
+ def match(content_type)
514
+ case content_type
515
+ when MatchData
516
+ content_type
517
+ else
518
+ MEDIA_TYPE_RE.match(content_type)
519
+ end
520
+ end
521
+
522
+ private
523
+
524
+ def simplify_matchdata(matchdata, remove_x = false, joiner: '/'.freeze)
525
+ return nil unless matchdata
526
+
527
+ matchdata.captures.map { |e|
528
+ e.downcase!
529
+ e.sub!(%r{^x-}, ''.freeze) if remove_x
530
+ yield e if block_given?
531
+ e
532
+ }.join(joiner)
533
+ end
534
+ end
535
+
536
+ private
537
+
538
+ def content_type=(type_string)
539
+ match = MEDIA_TYPE_RE.match(type_string)
540
+ fail InvalidContentType, type_string if match.nil?
541
+
542
+ @content_type = type_string
543
+ @raw_media_type, @raw_sub_type = match.captures
544
+ @simplified = MIME::Type.simplified(match)
545
+ @i18n_key = MIME::Type.i18n_key(match)
546
+ @media_type, @sub_type = MEDIA_TYPE_RE.match(@simplified).captures
547
+ end
548
+
549
+ def xref_map(values, helper)
550
+ values.map { |value| send(helper, value) }
551
+ end
552
+
553
+ def xref_url_for_rfc(value)
554
+ 'http://www.iana.org/go/%s'.freeze % value
555
+ end
556
+
557
+ def xref_url_for_draft(value)
558
+ 'http://www.iana.org/go/%s'.freeze % value.sub(/\ARFC/, 'draft')
559
+ end
560
+
561
+ def xref_url_for_rfc_errata(value)
562
+ 'http://www.rfc-editor.org/errata_search.php?eid=%s'.freeze % value
563
+ end
564
+
565
+ def xref_url_for_person(value)
566
+ 'http://www.iana.org/assignments/media-types/media-types.xhtml#%s'.freeze %
567
+ value
568
+ end
569
+
570
+ def xref_url_for_template(value)
571
+ 'http://www.iana.org/assignments/media-types/%s'.freeze % value
572
+ end
573
+ end
@@ -0,0 +1,135 @@
1
+ require 'mime/type/columnar'
2
+
3
+ # MIME::Types::Columnar is used to extend a MIME::Types container to load data
4
+ # by columns instead of from JSON or YAML. Column loads of MIME types loaded
5
+ # through the columnar store are synchronized with a Mutex.
6
+ #
7
+ # MIME::Types::Columnar is not intended to be used directly, but will be added
8
+ # to an instance of MIME::Types when it is loaded with
9
+ # MIME::Types::Loader#load_columnar.
10
+ module MIME::Types::Columnar
11
+ LOAD_MUTEX = Mutex.new # :nodoc:
12
+
13
+ def self.extended(obj) # :nodoc:
14
+ super
15
+ obj.instance_variable_set(:@__mime_data__, [])
16
+ obj.instance_variable_set(:@__files__, Set.new)
17
+ end
18
+
19
+ # Load the first column data file (type and extensions).
20
+ def load_base_data(path) #:nodoc:
21
+ @__root__ = path
22
+
23
+ each_file_line('content_type', false) do |line|
24
+ line = line.split
25
+ content_type = line.shift
26
+ extensions = line
27
+ # content_type, *extensions = line.split
28
+
29
+ type = MIME::Type::Columnar.new(self, content_type, extensions)
30
+ @__mime_data__ << type
31
+ add(type)
32
+ end
33
+
34
+ self
35
+ end
36
+
37
+ private
38
+
39
+ def each_file_line(name, lookup = true)
40
+ LOAD_MUTEX.synchronize do
41
+ next if @__files__.include?(name)
42
+
43
+ i = -1
44
+ column = File.join(@__root__, "mime.#{name}.column")
45
+
46
+ IO.readlines(column, encoding: 'UTF-8'.freeze).each do |line|
47
+ line.chomp!
48
+
49
+ if lookup
50
+ type = @__mime_data__[i += 1] or next
51
+ yield type, line
52
+ else
53
+ yield line
54
+ end
55
+ end
56
+
57
+ @__files__ << name
58
+ end
59
+ end
60
+
61
+ def load_encoding
62
+ each_file_line('encoding') do |type, line|
63
+ pool ||= {}
64
+ line.freeze
65
+ type.instance_variable_set(:@encoding, (pool[line] ||= line))
66
+ end
67
+ end
68
+
69
+ def load_docs
70
+ each_file_line('docs') do |type, line|
71
+ type.instance_variable_set(:@docs, opt(line))
72
+ end
73
+ end
74
+
75
+ def load_preferred_extension
76
+ each_file_line('pext') do |type, line|
77
+ type.instance_variable_set(:@preferred_extension, opt(line))
78
+ end
79
+ end
80
+
81
+ def load_flags
82
+ each_file_line('flags') do |type, line|
83
+ line = line.split
84
+ type.instance_variable_set(:@obsolete, flag(line.shift))
85
+ type.instance_variable_set(:@registered, flag(line.shift))
86
+ type.instance_variable_set(:@signature, flag(line.shift))
87
+ end
88
+ end
89
+
90
+ def load_xrefs
91
+ each_file_line('xrefs') { |type, line|
92
+ type.instance_variable_set(:@xrefs, dict(line, array: true))
93
+ }
94
+ end
95
+
96
+ def load_friendly
97
+ each_file_line('friendly') { |type, line|
98
+ type.instance_variable_set(:@friendly, dict(line))
99
+ }
100
+ end
101
+
102
+ def load_use_instead
103
+ each_file_line('use_instead') do |type, line|
104
+ type.instance_variable_set(:@use_instead, opt(line))
105
+ end
106
+ end
107
+
108
+ def dict(line, array: false)
109
+ if line == '-'.freeze
110
+ {}
111
+ else
112
+ line.split('|'.freeze).each_with_object({}) { |l, h|
113
+ k, v = l.split('^'.freeze)
114
+ v = nil if v.empty?
115
+ h[k] = array ? Array(v) : v
116
+ }
117
+ end
118
+ end
119
+
120
+ def arr(line)
121
+ if line == '-'.freeze
122
+ []
123
+ else
124
+ line.split('|'.freeze).flatten.compact.uniq
125
+ end
126
+ end
127
+
128
+ def opt(line)
129
+ line unless line == '-'.freeze
130
+ end
131
+
132
+ def flag(line)
133
+ line == '1'.freeze ? true : false
134
+ end
135
+ end