benschwarz-smoke 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/Rakefile +47 -0
  2. data/VERSION.yml +2 -2
  3. data/lib/core_ext/string.rb +6 -0
  4. data/lib/smoke/cache.rb +38 -23
  5. data/lib/smoke/request.rb +4 -8
  6. data/lib/smoke.rb +7 -2
  7. data/rdoc/classes/Smoke/Origin.html +340 -0
  8. data/rdoc/classes/Smoke/Source/Data.html +126 -0
  9. data/rdoc/classes/Smoke/Source/Feed.html +117 -0
  10. data/rdoc/classes/Smoke/Source/YQL.html +223 -0
  11. data/rdoc/classes/Smoke.html +260 -0
  12. data/rdoc/created.rid +1 -0
  13. data/rdoc/files/README_markdown.html +180 -0
  14. data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
  15. data/rdoc/files/lib/smoke/origin_rb.html +49 -0
  16. data/rdoc/files/lib/smoke/request_rb.html +49 -0
  17. data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
  18. data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
  19. data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
  20. data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
  21. data/rdoc/files/lib/smoke_rb.html +65 -0
  22. data/rdoc/fr_class_index.html +21 -0
  23. data/rdoc/fr_file_index.html +28 -0
  24. data/rdoc/fr_method_index.html +4459 -0
  25. data/rdoc/index.html +15 -0
  26. data/rdoc/rdoc-style.css +319 -0
  27. data/spec/smoke/cache_spec.rb +28 -6
  28. data/vendor/crack/History +15 -0
  29. data/vendor/crack/LICENSE +20 -0
  30. data/vendor/crack/README.rdoc +42 -0
  31. data/vendor/crack/Rakefile +49 -0
  32. data/vendor/crack/VERSION.yml +4 -0
  33. data/vendor/crack/crack.gemspec +61 -0
  34. data/vendor/crack/lib/crack/core_extensions.rb +128 -0
  35. data/vendor/crack/lib/crack/json.rb +68 -0
  36. data/vendor/crack/lib/crack/xml.rb +214 -0
  37. data/vendor/crack/lib/crack.rb +7 -0
  38. data/vendor/crack/test/crack_test.rb +4 -0
  39. data/vendor/crack/test/data/twittersearch-firefox.json +1 -0
  40. data/vendor/crack/test/data/twittersearch-ie.json +1 -0
  41. data/vendor/crack/test/hash_test.rb +56 -0
  42. data/vendor/crack/test/json_test.rb +66 -0
  43. data/vendor/crack/test/string_test.rb +31 -0
  44. data/vendor/crack/test/test_helper.rb +12 -0
  45. data/vendor/crack/test/xml_test.rb +489 -0
  46. data/vendor/dependencies/README.markdown +113 -0
  47. data/vendor/dependencies/Rakefile +5 -0
  48. data/vendor/dependencies/bin/dep +83 -0
  49. data/vendor/dependencies/dependencies.gemspec +15 -0
  50. data/vendor/dependencies/dependencies.gemspec.erb +27 -0
  51. data/vendor/dependencies/lib/dependencies/dep.rb +99 -0
  52. data/vendor/dependencies/lib/dependencies.rb +5 -0
  53. data/vendor/dependencies/test/dependencies_test.rb +228 -0
  54. data/vendor/dependencies/test/foobaz-0.3.gem +0 -0
  55. data/vendor/fakeweb/CHANGELOG +163 -0
  56. data/vendor/fakeweb/LICENSE.txt +281 -0
  57. data/vendor/fakeweb/README.rdoc +193 -0
  58. data/vendor/fakeweb/Rakefile +76 -0
  59. data/vendor/fakeweb/fakeweb.gemspec +21 -0
  60. data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +71 -0
  61. data/vendor/fakeweb/lib/fake_web/registry.rb +103 -0
  62. data/vendor/fakeweb/lib/fake_web/responder.rb +113 -0
  63. data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
  64. data/vendor/fakeweb/lib/fake_web/stub_socket.rb +15 -0
  65. data/vendor/fakeweb/lib/fake_web/utility.rb +22 -0
  66. data/vendor/fakeweb/lib/fake_web.rb +172 -0
  67. data/vendor/fakeweb/lib/fakeweb.rb +2 -0
  68. data/vendor/fakeweb/test/fixtures/google_response_from_curl +12 -0
  69. data/vendor/fakeweb/test/fixtures/google_response_with_transfer_encoding +17 -0
  70. data/vendor/fakeweb/test/fixtures/google_response_without_transfer_encoding +11 -0
  71. data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
  72. data/vendor/fakeweb/test/fixtures/test_txt_file +3 -0
  73. data/vendor/fakeweb/test/test_allow_net_connect.rb +85 -0
  74. data/vendor/fakeweb/test/test_deprecations.rb +54 -0
  75. data/vendor/fakeweb/test/test_fake_authentication.rb +92 -0
  76. data/vendor/fakeweb/test/test_fake_web.rb +535 -0
  77. data/vendor/fakeweb/test/test_fake_web_open_uri.rb +58 -0
  78. data/vendor/fakeweb/test/test_helper.rb +74 -0
  79. data/vendor/fakeweb/test/test_missing_open_uri.rb +25 -0
  80. data/vendor/fakeweb/test/test_precedence.rb +51 -0
  81. data/vendor/fakeweb/test/test_query_string.rb +45 -0
  82. data/vendor/fakeweb/test/test_regexes.rb +103 -0
  83. data/vendor/fakeweb/test/test_response_headers.rb +73 -0
  84. data/vendor/fakeweb/test/test_trailing_slashes.rb +53 -0
  85. data/vendor/fakeweb/test/test_utility.rb +70 -0
  86. data/vendor/json-1.1.3/CHANGES +93 -0
  87. data/vendor/json-1.1.3/GPL +340 -0
  88. data/vendor/json-1.1.3/README +78 -0
  89. data/vendor/json-1.1.3/RUBY +58 -0
  90. data/vendor/json-1.1.3/Rakefile +309 -0
  91. data/vendor/json-1.1.3/TODO +1 -0
  92. data/vendor/json-1.1.3/VERSION +1 -0
  93. data/vendor/json-1.1.3/benchmarks/benchmark.txt +133 -0
  94. data/vendor/json-1.1.3/benchmarks/benchmark_generator.rb +48 -0
  95. data/vendor/json-1.1.3/benchmarks/benchmark_parser.rb +26 -0
  96. data/vendor/json-1.1.3/benchmarks/benchmark_rails.rb +26 -0
  97. data/vendor/json-1.1.3/bin/edit_json.rb +10 -0
  98. data/vendor/json-1.1.3/bin/prettify_json.rb +76 -0
  99. data/vendor/json-1.1.3/data/example.json +1 -0
  100. data/vendor/json-1.1.3/data/index.html +38 -0
  101. data/vendor/json-1.1.3/data/prototype.js +4184 -0
  102. data/vendor/json-1.1.3/ext/json/ext/generator/extconf.rb +9 -0
  103. data/vendor/json-1.1.3/ext/json/ext/generator/generator.c +875 -0
  104. data/vendor/json-1.1.3/ext/json/ext/generator/unicode.c +182 -0
  105. data/vendor/json-1.1.3/ext/json/ext/generator/unicode.h +53 -0
  106. data/vendor/json-1.1.3/ext/json/ext/parser/extconf.rb +9 -0
  107. data/vendor/json-1.1.3/ext/json/ext/parser/parser.c +1758 -0
  108. data/vendor/json-1.1.3/ext/json/ext/parser/parser.rl +638 -0
  109. data/vendor/json-1.1.3/ext/json/ext/parser/unicode.c +154 -0
  110. data/vendor/json-1.1.3/ext/json/ext/parser/unicode.h +58 -0
  111. data/vendor/json-1.1.3/install.rb +26 -0
  112. data/vendor/json-1.1.3/lib/json/Array.xpm +21 -0
  113. data/vendor/json-1.1.3/lib/json/FalseClass.xpm +21 -0
  114. data/vendor/json-1.1.3/lib/json/Hash.xpm +21 -0
  115. data/vendor/json-1.1.3/lib/json/Key.xpm +73 -0
  116. data/vendor/json-1.1.3/lib/json/NilClass.xpm +21 -0
  117. data/vendor/json-1.1.3/lib/json/Numeric.xpm +28 -0
  118. data/vendor/json-1.1.3/lib/json/String.xpm +96 -0
  119. data/vendor/json-1.1.3/lib/json/TrueClass.xpm +21 -0
  120. data/vendor/json-1.1.3/lib/json/add/core.rb +135 -0
  121. data/vendor/json-1.1.3/lib/json/add/rails.rb +58 -0
  122. data/vendor/json-1.1.3/lib/json/common.rb +354 -0
  123. data/vendor/json-1.1.3/lib/json/editor.rb +1362 -0
  124. data/vendor/json-1.1.3/lib/json/ext.rb +13 -0
  125. data/vendor/json-1.1.3/lib/json/json.xpm +1499 -0
  126. data/vendor/json-1.1.3/lib/json/pure/generator.rb +394 -0
  127. data/vendor/json-1.1.3/lib/json/pure/parser.rb +259 -0
  128. data/vendor/json-1.1.3/lib/json/pure.rb +75 -0
  129. data/vendor/json-1.1.3/lib/json/version.rb +9 -0
  130. data/vendor/json-1.1.3/lib/json.rb +235 -0
  131. data/vendor/json-1.1.3/tests/fixtures/fail1.json +1 -0
  132. data/vendor/json-1.1.3/tests/fixtures/fail10.json +1 -0
  133. data/vendor/json-1.1.3/tests/fixtures/fail11.json +1 -0
  134. data/vendor/json-1.1.3/tests/fixtures/fail12.json +1 -0
  135. data/vendor/json-1.1.3/tests/fixtures/fail13.json +1 -0
  136. data/vendor/json-1.1.3/tests/fixtures/fail14.json +1 -0
  137. data/vendor/json-1.1.3/tests/fixtures/fail18.json +1 -0
  138. data/vendor/json-1.1.3/tests/fixtures/fail19.json +1 -0
  139. data/vendor/json-1.1.3/tests/fixtures/fail2.json +1 -0
  140. data/vendor/json-1.1.3/tests/fixtures/fail20.json +1 -0
  141. data/vendor/json-1.1.3/tests/fixtures/fail21.json +1 -0
  142. data/vendor/json-1.1.3/tests/fixtures/fail22.json +1 -0
  143. data/vendor/json-1.1.3/tests/fixtures/fail23.json +1 -0
  144. data/vendor/json-1.1.3/tests/fixtures/fail24.json +1 -0
  145. data/vendor/json-1.1.3/tests/fixtures/fail25.json +1 -0
  146. data/vendor/json-1.1.3/tests/fixtures/fail27.json +2 -0
  147. data/vendor/json-1.1.3/tests/fixtures/fail28.json +2 -0
  148. data/vendor/json-1.1.3/tests/fixtures/fail3.json +1 -0
  149. data/vendor/json-1.1.3/tests/fixtures/fail4.json +1 -0
  150. data/vendor/json-1.1.3/tests/fixtures/fail5.json +1 -0
  151. data/vendor/json-1.1.3/tests/fixtures/fail6.json +1 -0
  152. data/vendor/json-1.1.3/tests/fixtures/fail7.json +1 -0
  153. data/vendor/json-1.1.3/tests/fixtures/fail8.json +1 -0
  154. data/vendor/json-1.1.3/tests/fixtures/fail9.json +1 -0
  155. data/vendor/json-1.1.3/tests/fixtures/pass1.json +56 -0
  156. data/vendor/json-1.1.3/tests/fixtures/pass15.json +1 -0
  157. data/vendor/json-1.1.3/tests/fixtures/pass16.json +1 -0
  158. data/vendor/json-1.1.3/tests/fixtures/pass17.json +1 -0
  159. data/vendor/json-1.1.3/tests/fixtures/pass2.json +1 -0
  160. data/vendor/json-1.1.3/tests/fixtures/pass26.json +1 -0
  161. data/vendor/json-1.1.3/tests/fixtures/pass3.json +6 -0
  162. data/vendor/json-1.1.3/tests/runner.rb +25 -0
  163. data/vendor/json-1.1.3/tests/test_json.rb +293 -0
  164. data/vendor/json-1.1.3/tests/test_json_addition.rb +161 -0
  165. data/vendor/json-1.1.3/tests/test_json_fixtures.rb +30 -0
  166. data/vendor/json-1.1.3/tests/test_json_generate.rb +100 -0
  167. data/vendor/json-1.1.3/tests/test_json_rails.rb +118 -0
  168. data/vendor/json-1.1.3/tests/test_json_unicode.rb +61 -0
  169. data/vendor/json-1.1.3/tools/fuzz.rb +140 -0
  170. data/vendor/json-1.1.3/tools/server.rb +62 -0
  171. data/vendor/moneta/LICENSE +20 -0
  172. data/vendor/moneta/README +51 -0
  173. data/vendor/moneta/Rakefile +60 -0
  174. data/vendor/moneta/TODO +4 -0
  175. data/vendor/moneta/benchmarks/various.rb +234 -0
  176. data/vendor/moneta/lib/moneta/basic_file.rb +111 -0
  177. data/vendor/moneta/lib/moneta/berkeley.rb +53 -0
  178. data/vendor/moneta/lib/moneta/couch.rb +63 -0
  179. data/vendor/moneta/lib/moneta/datamapper.rb +117 -0
  180. data/vendor/moneta/lib/moneta/file.rb +91 -0
  181. data/vendor/moneta/lib/moneta/lmc.rb +52 -0
  182. data/vendor/moneta/lib/moneta/memcache.rb +53 -0
  183. data/vendor/moneta/lib/moneta/memory.rb +11 -0
  184. data/vendor/moneta/lib/moneta/mongodb.rb +58 -0
  185. data/vendor/moneta/lib/moneta/redis.rb +49 -0
  186. data/vendor/moneta/lib/moneta/rufus.rb +41 -0
  187. data/vendor/moneta/lib/moneta/s3.rb +162 -0
  188. data/vendor/moneta/lib/moneta/sdbm.rb +33 -0
  189. data/vendor/moneta/lib/moneta/tyrant.rb +58 -0
  190. data/vendor/moneta/lib/moneta/xattr.rb +58 -0
  191. data/vendor/moneta/lib/moneta.rb +76 -0
  192. data/vendor/moneta/moneta.gemspec +32 -0
  193. data/vendor/moneta/script/destroy +14 -0
  194. data/vendor/moneta/script/generate +14 -0
  195. data/vendor/moneta/spec/moneta_basic_file_spec.rb +50 -0
  196. data/vendor/moneta/spec/moneta_berkeley_spec.rb +20 -0
  197. data/vendor/moneta/spec/moneta_couch_spec.rb +22 -0
  198. data/vendor/moneta/spec/moneta_datamapper_spec.rb +79 -0
  199. data/vendor/moneta/spec/moneta_file_spec.rb +21 -0
  200. data/vendor/moneta/spec/moneta_lmc_spec.rb +24 -0
  201. data/vendor/moneta/spec/moneta_memcache_spec.rb +16 -0
  202. data/vendor/moneta/spec/moneta_memory_spec.rb +12 -0
  203. data/vendor/moneta/spec/moneta_mongodb_spec.rb +16 -0
  204. data/vendor/moneta/spec/moneta_redis_spec.rb +16 -0
  205. data/vendor/moneta/spec/moneta_rufus_spec.rb +15 -0
  206. data/vendor/moneta/spec/moneta_s3_spec.rb +19 -0
  207. data/vendor/moneta/spec/moneta_sdbm_spec.rb +21 -0
  208. data/vendor/moneta/spec/moneta_tyrant_spec.rb +15 -0
  209. data/vendor/moneta/spec/moneta_xattr_spec.rb +21 -0
  210. data/vendor/moneta/spec/shared.rb +122 -0
  211. data/vendor/moneta/spec/spec_helper.rb +7 -0
  212. data/vendor/rest-client/README.rdoc +151 -0
  213. data/vendor/rest-client/Rakefile +58 -0
  214. data/vendor/rest-client/VERSION +1 -0
  215. data/vendor/rest-client/bin/restclient +87 -0
  216. data/vendor/rest-client/lib/rest_client.rb +2 -0
  217. data/vendor/rest-client/lib/restclient/exceptions.rb +88 -0
  218. data/vendor/rest-client/lib/restclient/mixin/response.rb +43 -0
  219. data/vendor/rest-client/lib/restclient/raw_response.rb +30 -0
  220. data/vendor/rest-client/lib/restclient/request.rb +238 -0
  221. data/vendor/rest-client/lib/restclient/resource.rb +146 -0
  222. data/vendor/rest-client/lib/restclient/response.rb +20 -0
  223. data/vendor/rest-client/lib/restclient.rb +99 -0
  224. data/vendor/rest-client/rest-client.gemspec +66 -0
  225. data/vendor/rest-client/spec/base.rb +4 -0
  226. data/vendor/rest-client/spec/exceptions_spec.rb +65 -0
  227. data/vendor/rest-client/spec/mixin/response_spec.rb +46 -0
  228. data/vendor/rest-client/spec/raw_response_spec.rb +17 -0
  229. data/vendor/rest-client/spec/request_spec.rb +476 -0
  230. data/vendor/rest-client/spec/resource_spec.rb +75 -0
  231. data/vendor/rest-client/spec/response_spec.rb +16 -0
  232. data/vendor/rest-client/spec/restclient_spec.rb +53 -0
  233. data/vendor/simple-rss/LICENSE +429 -0
  234. data/vendor/simple-rss/README +43 -0
  235. data/vendor/simple-rss/Rakefile +212 -0
  236. data/vendor/simple-rss/install.rb +40 -0
  237. data/vendor/simple-rss/lib/simple-rss.rb +150 -0
  238. data/vendor/simple-rss/simple-rss.gemspec +12 -0
  239. data/vendor/simple-rss/test/base/base_test.rb +51 -0
  240. data/vendor/simple-rss/test/data/atom.xml +45 -0
  241. data/vendor/simple-rss/test/data/not-rss.xml +8 -0
  242. data/vendor/simple-rss/test/data/rss09.rdf +79 -0
  243. data/vendor/simple-rss/test/data/rss20.xml +818 -0
  244. data/vendor/simple-rss/test/test_helper.rb +4 -0
  245. metadata +314 -40
@@ -0,0 +1,75 @@
1
+ require 'json/common'
2
+ require 'json/pure/parser'
3
+ require 'json/pure/generator'
4
+
5
+ module JSON
6
+ begin
7
+ require 'iconv'
8
+ # An iconv instance to convert from UTF8 to UTF16 Big Endian.
9
+ UTF16toUTF8 = Iconv.new('utf-8', 'utf-16be') # :nodoc:
10
+ # An iconv instance to convert from UTF16 Big Endian to UTF8.
11
+ UTF8toUTF16 = Iconv.new('utf-16be', 'utf-8') # :nodoc:
12
+ UTF8toUTF16.iconv('no bom')
13
+ rescue Errno::EINVAL, Iconv::InvalidEncoding
14
+ # Iconv doesn't support big endian utf-16. Let's try to hack this manually
15
+ # into the converters.
16
+ begin
17
+ old_verbose, $VERBSOSE = $VERBOSE, nil
18
+ # An iconv instance to convert from UTF8 to UTF16 Big Endian.
19
+ UTF16toUTF8 = Iconv.new('utf-8', 'utf-16') # :nodoc:
20
+ # An iconv instance to convert from UTF16 Big Endian to UTF8.
21
+ UTF8toUTF16 = Iconv.new('utf-16', 'utf-8') # :nodoc:
22
+ UTF8toUTF16.iconv('no bom')
23
+ if UTF8toUTF16.iconv("\xe2\x82\xac") == "\xac\x20"
24
+ swapper = Class.new do
25
+ def initialize(iconv) # :nodoc:
26
+ @iconv = iconv
27
+ end
28
+
29
+ def iconv(string) # :nodoc:
30
+ result = @iconv.iconv(string)
31
+ JSON.swap!(result)
32
+ end
33
+ end
34
+ UTF8toUTF16 = swapper.new(UTF8toUTF16) # :nodoc:
35
+ end
36
+ if UTF16toUTF8.iconv("\xac\x20") == "\xe2\x82\xac"
37
+ swapper = Class.new do
38
+ def initialize(iconv) # :nodoc:
39
+ @iconv = iconv
40
+ end
41
+
42
+ def iconv(string) # :nodoc:
43
+ string = JSON.swap!(string.dup)
44
+ @iconv.iconv(string)
45
+ end
46
+ end
47
+ UTF16toUTF8 = swapper.new(UTF16toUTF8) # :nodoc:
48
+ end
49
+ rescue Errno::EINVAL, Iconv::InvalidEncoding
50
+ raise MissingUnicodeSupport, "iconv doesn't seem to support UTF-8/UTF-16 conversions"
51
+ ensure
52
+ $VERBOSE = old_verbose
53
+ end
54
+ rescue LoadError
55
+ raise MissingUnicodeSupport,
56
+ "iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions"
57
+ end
58
+
59
+ # Swap consecutive bytes of _string_ in place.
60
+ def self.swap!(string) # :nodoc:
61
+ 0.upto(string.size / 2) do |i|
62
+ break unless string[2 * i + 1]
63
+ string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
64
+ end
65
+ string
66
+ end
67
+
68
+ # This module holds all the modules/classes that implement JSON's
69
+ # functionality in pure ruby.
70
+ module Pure
71
+ $DEBUG and warn "Using pure library for JSON."
72
+ JSON.parser = Parser
73
+ JSON.generator = Generator
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ module JSON
2
+ # JSON version
3
+ VERSION = '1.1.3'
4
+ VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
8
+ VARIANT_BINARY = false
9
+ end
@@ -0,0 +1,235 @@
1
+ require 'json/common'
2
+ # = json - JSON for Ruby
3
+ #
4
+ # == Description
5
+ #
6
+ # This is a implementation of the JSON specification according to RFC 4627
7
+ # (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
8
+ # will be two variants available:
9
+ #
10
+ # * A pure ruby variant, that relies on the iconv and the stringscan
11
+ # extensions, which are both part of the ruby standard library.
12
+ # * The quite a bit faster C extension variant, which is in parts implemented
13
+ # in C and comes with its own unicode conversion functions and a parser
14
+ # generated by the ragel state machine compiler
15
+ # (http://www.cs.queensu.ca/~thurston/ragel).
16
+ #
17
+ # Both variants of the JSON generator escape all non-ASCII an control
18
+ # characters with \uXXXX escape sequences, and support UTF-16 surrogate pairs
19
+ # in order to be able to generate the whole range of unicode code points. This
20
+ # means that generated JSON text is encoded as UTF-8 (because ASCII is a subset
21
+ # of UTF-8) and at the same time avoids decoding problems for receiving
22
+ # endpoints, that don't expect UTF-8 encoded texts. On the negative side this
23
+ # may lead to a bit longer strings than necessarry.
24
+ #
25
+ # All strings, that are to be encoded as JSON strings, should be UTF-8 byte
26
+ # sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
27
+ # encoded, please use the to_json_raw_object method of String (which produces
28
+ # an object, that contains a byte array) and decode the result on the receiving
29
+ # endpoint.
30
+ #
31
+ # == Author
32
+ #
33
+ # Florian Frank <mailto:flori@ping.de>
34
+ #
35
+ # == License
36
+ #
37
+ # This software is distributed under the same license as Ruby itself, see
38
+ # http://www.ruby-lang.org/en/LICENSE.txt.
39
+ #
40
+ # == Download
41
+ #
42
+ # The latest version of this library can be downloaded at
43
+ #
44
+ # * http://rubyforge.org/frs?group_id=953
45
+ #
46
+ # Online Documentation should be located at
47
+ #
48
+ # * http://json.rubyforge.org
49
+ #
50
+ # == Usage
51
+ #
52
+ # To use JSON you can
53
+ # require 'json'
54
+ # to load the installed variant (either the extension 'json' or the pure
55
+ # variant 'json_pure'). If you have installed the extension variant, you can
56
+ # pick either the extension variant or the pure variant by typing
57
+ # require 'json/ext'
58
+ # or
59
+ # require 'json/pure'
60
+ #
61
+ # You can choose to load a set of common additions to ruby core's objects if
62
+ # you
63
+ # require 'json/add/core'
64
+ #
65
+ # After requiring this you can, e. g., serialise/deserialise Ruby ranges:
66
+ #
67
+ # JSON JSON(1..10) # => 1..10
68
+ #
69
+ # To find out how to add JSON support to other or your own classes, read the
70
+ # Examples section below.
71
+ #
72
+ # To get the best compatibility to rails' JSON implementation, you can
73
+ # require 'json/add/rails'
74
+ #
75
+ # Both of the additions attempt to require 'json' (like above) first, if it has
76
+ # not been required yet.
77
+ #
78
+ # == Speed Comparisons
79
+ #
80
+ # I have created some benchmark results (see the benchmarks subdir of the
81
+ # package) for the JSON-Parser to estimate the speed up in the C extension:
82
+ #
83
+ # JSON::Pure::Parser:: 28.90 calls/second
84
+ # JSON::Ext::Parser:: 505.50 calls/second
85
+ #
86
+ # This is ca. <b>17.5</b> times the speed of the pure Ruby implementation.
87
+ #
88
+ # I have benchmarked the JSON-Generator as well. This generates a few more
89
+ # values, because there are different modes, that also influence the achieved
90
+ # speed:
91
+ #
92
+ # * JSON::Pure::Generator:
93
+ # generate:: 35.06 calls/second
94
+ # pretty_generate:: 34.00 calls/second
95
+ # fast_generate:: 41.06 calls/second
96
+ #
97
+ # * JSON::Ext::Generator:
98
+ # generate:: 492.11 calls/second
99
+ # pretty_generate:: 348.85 calls/second
100
+ # fast_generate:: 541.60 calls/second
101
+ #
102
+ # * Speedup Ext/Pure:
103
+ # generate safe:: 14.0 times
104
+ # generate pretty:: 10.3 times
105
+ # generate fast:: 13.2 times
106
+ #
107
+ # The rails framework includes a generator as well, also it seems to be rather
108
+ # slow: I measured only 23.87 calls/second which is slower than any of my pure
109
+ # generator results. Here a comparison of the different speedups with the Rails
110
+ # measurement as the divisor:
111
+ #
112
+ # * Speedup Pure/Rails:
113
+ # generate safe:: 1.5 times
114
+ # generate pretty:: 1.4 times
115
+ # generate fast:: 1.7 times
116
+ #
117
+ # * Speedup Ext/Rails:
118
+ # generate safe:: 20.6 times
119
+ # generate pretty:: 14.6 times
120
+ # generate fast:: 22.7 times
121
+ #
122
+ # To achieve the fastest JSON text output, you can use the
123
+ # fast_generate/fast_unparse methods. Beware, that this will disable the
124
+ # checking for circular Ruby data structures, which may cause JSON to go into
125
+ # an infinite loop.
126
+ #
127
+ # == Examples
128
+ #
129
+ # To create a JSON text from a ruby data structure, you
130
+ # can call JSON.generate (or JSON.unparse) like that:
131
+ #
132
+ # json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
133
+ # # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
134
+ #
135
+ # To create a valid JSON text you have to make sure, that the output is
136
+ # embedded in either a JSON array [] or a JSON object {}. The easiest way to do
137
+ # this, is by putting your values in a Ruby Array or Hash instance.
138
+ #
139
+ # To get back a ruby data structure from a JSON text, you have to call
140
+ # JSON.parse on it:
141
+ #
142
+ # JSON.parse json
143
+ # # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
144
+ #
145
+ # Note, that the range from the original data structure is a simple
146
+ # string now. The reason for this is, that JSON doesn't support ranges
147
+ # or arbitrary classes. In this case the json library falls back to call
148
+ # Object#to_json, which is the same as #to_s.to_json.
149
+ #
150
+ # It's possible to add JSON support serialization to arbitrary classes by
151
+ # simply implementing a more specialized version of the #to_json method, that
152
+ # should return a JSON object (a hash converted to JSON with #to_json) like
153
+ # this (don't forget the *a for all the arguments):
154
+ #
155
+ # class Range
156
+ # def to_json(*a)
157
+ # {
158
+ # 'json_class' => self.class.name, # = 'Range'
159
+ # 'data' => [ first, last, exclude_end? ]
160
+ # }.to_json(*a)
161
+ # end
162
+ # end
163
+ #
164
+ # The hash key 'json_class' is the class, that will be asked to deserialise the
165
+ # JSON representation later. In this case it's 'Range', but any namespace of
166
+ # the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
167
+ # used to store the necessary data to configure the object to be deserialised.
168
+ #
169
+ # If a the key 'json_class' is found in a JSON object, the JSON parser checks
170
+ # if the given class responds to the json_create class method. If so, it is
171
+ # called with the JSON object converted to a Ruby hash. So a range can
172
+ # be deserialised by implementing Range.json_create like this:
173
+ #
174
+ # class Range
175
+ # def self.json_create(o)
176
+ # new(*o['data'])
177
+ # end
178
+ # end
179
+ #
180
+ # Now it possible to serialise/deserialise ranges as well:
181
+ #
182
+ # json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
183
+ # # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
184
+ # JSON.parse json
185
+ # # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
186
+ #
187
+ # JSON.generate always creates the shortest possible string representation of a
188
+ # ruby data structure in one line. This good for data storage or network
189
+ # protocols, but not so good for humans to read. Fortunately there's also
190
+ # JSON.pretty_generate (or JSON.pretty_generate) that creates a more
191
+ # readable output:
192
+ #
193
+ # puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
194
+ # [
195
+ # 1,
196
+ # 2,
197
+ # {
198
+ # "a": 3.141
199
+ # },
200
+ # false,
201
+ # true,
202
+ # null,
203
+ # {
204
+ # "json_class": "Range",
205
+ # "data": [
206
+ # 4,
207
+ # 10,
208
+ # false
209
+ # ]
210
+ # }
211
+ # ]
212
+ #
213
+ # There are also the methods Kernel#j for unparse, and Kernel#jj for
214
+ # pretty_unparse output to the console, that work analogous to Core Ruby's p
215
+ # and the pp library's pp methods.
216
+ #
217
+ # The script tools/server.rb contains a small example if you want to test, how
218
+ # receiving a JSON object from a webrick server in your browser with the
219
+ # javasript prototype library (http://www.prototypejs.org) works.
220
+ #
221
+ module JSON
222
+ require 'json/version'
223
+
224
+ if VARIANT_BINARY
225
+ require 'json/ext'
226
+ else
227
+ begin
228
+ require 'json/ext'
229
+ rescue LoadError
230
+ require 'json/pure'
231
+ end
232
+ end
233
+
234
+ JSON_LOADED = true
235
+ end
@@ -0,0 +1 @@
1
+ "A JSON payload should be an object or array, not a string."
@@ -0,0 +1 @@
1
+ {"Extra value after close": true} "misplaced quoted value"
@@ -0,0 +1 @@
1
+ {"Illegal expression": 1 + 2}
@@ -0,0 +1 @@
1
+ {"Illegal invocation": alert()}
@@ -0,0 +1 @@
1
+ {"Numbers cannot have leading zeroes": 013}
@@ -0,0 +1 @@
1
+ {"Numbers cannot be hex": 0x14}
@@ -0,0 +1 @@
1
+ [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
@@ -0,0 +1 @@
1
+ {"Missing colon" null}
@@ -0,0 +1 @@
1
+ ["Unclosed array"
@@ -0,0 +1 @@
1
+ {"Double colon":: null}
@@ -0,0 +1 @@
1
+ {"Comma instead of colon", null}
@@ -0,0 +1 @@
1
+ ["Colon instead of comma": false]
@@ -0,0 +1 @@
1
+ ["Bad value", truth]
@@ -0,0 +1 @@
1
+ ['single quote']
@@ -0,0 +1 @@
1
+ ["tab character in string "]
@@ -0,0 +1,2 @@
1
+ ["line
2
+ break"]
@@ -0,0 +1,2 @@
1
+ ["line\
2
+ break"]
@@ -0,0 +1 @@
1
+ {unquoted_key: "keys must be quoted"}
@@ -0,0 +1 @@
1
+ ["extra comma",]
@@ -0,0 +1 @@
1
+ ["double extra comma",,]
@@ -0,0 +1 @@
1
+ [ , "<-- missing value"]
@@ -0,0 +1 @@
1
+ ["Comma after the close"],
@@ -0,0 +1 @@
1
+ ["Extra close"]]
@@ -0,0 +1 @@
1
+ {"Extra comma": true,}
@@ -0,0 +1,56 @@
1
+ [
2
+ "JSON Test Pattern pass1",
3
+ {"object with 1 member":["array with 1 element"]},
4
+ {},
5
+ [],
6
+ -42,
7
+ true,
8
+ false,
9
+ null,
10
+ {
11
+ "integer": 1234567890,
12
+ "real": -9876.543210,
13
+ "e": 0.123456789e-12,
14
+ "E": 1.234567890E+34,
15
+ "": 23456789012E666,
16
+ "zero": 0,
17
+ "one": 1,
18
+ "space": " ",
19
+ "quote": "\"",
20
+ "backslash": "\\",
21
+ "controls": "\b\f\n\r\t",
22
+ "slash": "/ & \/",
23
+ "alpha": "abcdefghijklmnopqrstuvwyz",
24
+ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
25
+ "digit": "0123456789",
26
+ "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
27
+ "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
28
+ "true": true,
29
+ "false": false,
30
+ "null": null,
31
+ "array":[ ],
32
+ "object":{ },
33
+ "address": "50 St. James Street",
34
+ "url": "http://www.JSON.org/",
35
+ "comment": "// /* <!-- --",
36
+ "# -- --> */": " ",
37
+ " s p a c e d " :[1,2 , 3
38
+
39
+ ,
40
+
41
+ 4 , 5 , 6 ,7 ],
42
+ "compact": [1,2,3,4,5,6,7],
43
+ "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
44
+ "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
45
+ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
46
+ : "A key can be any string"
47
+ },
48
+ 0.5 ,98.6
49
+ ,
50
+ 99.44
51
+ ,
52
+
53
+ 1066
54
+
55
+
56
+ ,"rosebud"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \x15"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \'"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \017"]
@@ -0,0 +1 @@
1
+ [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
@@ -0,0 +1 @@
1
+ ["tab\ character\ in\ string\ "]
@@ -0,0 +1,6 @@
1
+ {
2
+ "JSON Test Pattern pass3": {
3
+ "The outermost value": "must be an object or array.",
4
+ "In this test": "It is an object."
5
+ }
6
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit/ui/console/testrunner'
4
+ require 'test/unit/testsuite'
5
+ $:.unshift File.expand_path(File.dirname($0))
6
+ $:.unshift 'tests'
7
+ require 'test_json'
8
+ require 'test_json_generate'
9
+ require 'test_json_unicode'
10
+ require 'test_json_addition'
11
+ require 'test_json_rails'
12
+ require 'test_json_fixtures'
13
+
14
+ class TS_AllTests
15
+ def self.suite
16
+ suite = Test::Unit::TestSuite.new name
17
+ suite << TC_JSONGenerate.suite
18
+ suite << TC_JSON.suite
19
+ suite << TC_JSONUnicode.suite
20
+ suite << TC_JSONAddition.suite
21
+ suite << TC_JSONRails.suite
22
+ suite << TC_JSONFixtures.suite
23
+ end
24
+ end
25
+ Test::Unit::UI::Console::TestRunner.run(TS_AllTests)