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,12 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ require "moneta/memory"
4
+
5
+ describe "Moneta::Memory" do
6
+ before(:each) do
7
+ @cache = Moneta::Memory.new
8
+ @cache.clear
9
+ end
10
+
11
+ it_should_behave_like "a read/write Moneta cache"
12
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require "moneta/mongodb"
5
+
6
+ describe "Moneta::MongoDB" do
7
+ before(:each) do
8
+ @native_expires = true
9
+ @cache = Moneta::MongoDB.new
10
+ @cache.clear
11
+ end
12
+
13
+ it_should_behave_like "a read/write Moneta cache"
14
+ end
15
+ rescue SystemExit
16
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require "moneta/redis"
5
+
6
+ describe "Moneta::Redis" do
7
+ before(:each) do
8
+ @native_expires = true
9
+ @cache = Moneta::Redis.new
10
+ @cache.clear
11
+ end
12
+
13
+ it_should_behave_like "a read/write Moneta cache"
14
+ end
15
+ rescue SystemExit
16
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require "moneta/rufus"
5
+
6
+ describe "Moneta::Rufus" do
7
+ before(:each) do
8
+ @cache = Moneta::Rufus.new(:file => "cache")
9
+ @cache.clear
10
+ end
11
+
12
+ it_should_behave_like "a read/write Moneta cache"
13
+ end
14
+ rescue SystemExit
15
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require 'moneta/s3'
5
+
6
+ describe "Moneta::S3" do
7
+ before(:each) do
8
+ @cache = Moneta::S3.new(
9
+ :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
10
+ :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
11
+ :bucket => 'moneta_test'
12
+ )
13
+ @cache.clear
14
+ end
15
+
16
+ it_should_behave_like "a read/write Moneta cache"
17
+ end
18
+ rescue SystemExit
19
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require "moneta/sdbm"
5
+
6
+ describe "Moneta::SDBM" do
7
+ before(:each) do
8
+ @cache = Moneta::SDBM.new(:file => File.join(File.dirname(__FILE__), "sdbm_cache"))
9
+ @cache.clear
10
+ end
11
+
12
+ after(:all) do
13
+ FileUtils.rm_rf(Dir.glob(File.join(File.dirname(__FILE__), "sdbm_cache*")))
14
+ end
15
+
16
+ if ENV['MONETA_TEST'].nil? || ENV['MONETA_TEST'] == 'sdbm'
17
+ it_should_behave_like "a read/write Moneta cache"
18
+ end
19
+ end
20
+ rescue SystemExit
21
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require "moneta/tyrant"
5
+
6
+ describe "Moneta::Tyrant" do
7
+ before(:each) do
8
+ @cache = Moneta::Tyrant.new(:host => "localhost", :port => 1978)
9
+ @cache.clear
10
+ end
11
+
12
+ it_should_behave_like "a read/write Moneta cache"
13
+ end
14
+ rescue SystemExit
15
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ begin
4
+ require "moneta/xattr"
5
+
6
+ describe "Moneta::Xattrs" do
7
+ before(:each) do
8
+ @cache = Moneta::Xattr.new(:file => File.join(File.dirname(__FILE__), "file_cache", "xattr_cache"))
9
+ @cache.clear
10
+ end
11
+
12
+ after(:all) do
13
+ FileUtils.rm_rf(File.join(File.dirname(__FILE__), "file_cache"))
14
+ end
15
+
16
+ if ENV['MONETA_TEST'].nil? || ENV['MONETA_TEST'] == 'xattrs'
17
+ it_should_behave_like "a read/write Moneta cache"
18
+ end
19
+ end
20
+ rescue SystemExit
21
+ end
@@ -0,0 +1,122 @@
1
+ shared_examples_for "a read/write Moneta cache" do
2
+ it "reads from keys like a Hash" do
3
+ @cache["key"].should == nil
4
+ end
5
+
6
+ it "writes to a key like a Hash" do
7
+ @cache["key"] = "value"
8
+ @cache["key"].should == "value"
9
+ end
10
+
11
+ it "specifies that it is writable via frozen?" do
12
+ @cache.should_not be_frozen
13
+ end
14
+
15
+ it "if a key is not available, returns false from key?" do
16
+ @cache.key?("key").should be_false
17
+ end
18
+
19
+ it "if a key is available, returns true from key?" do
20
+ @cache["key"] = "value"
21
+ @cache.key?("key").should be_true
22
+ end
23
+
24
+ it "if it exists, removes and return an element from the backing store via delete" do
25
+ @cache["key"] = "value"
26
+ @cache.delete("key").should == "value"
27
+ @cache.key?("key").should be_false
28
+ end
29
+
30
+ it "if it does not exists, returns nil from delete" do
31
+ @cache.delete("key").should be_nil
32
+ end
33
+
34
+ it "removes all keys from the store with clear" do
35
+ @cache["key"] = "value"
36
+ @cache["key2"] = "value2"
37
+ @cache.clear
38
+ @cache.key?("key").should_not be_true
39
+ @cache.key?("key2").should_not be_true
40
+ end
41
+
42
+ it "fetches a key with a default value with fetch, if the key is not available" do
43
+ @cache.fetch("key", "value").should == "value"
44
+ end
45
+
46
+ it "fetches a key with a block with fetch, if the key is not available" do
47
+ @cache.fetch("key") { |key| "value" }.should == "value"
48
+ end
49
+
50
+ it "fetches a key with a default value with fetch, if the key is available" do
51
+ @cache["key"] = "value2"
52
+ @cache.fetch("key", "value").should == "value2"
53
+ end
54
+
55
+ it "stores values with #store" do
56
+ @cache.store("key", "value")
57
+ @cache["key"].should == "value"
58
+ end
59
+
60
+ describe "when storing values with #store, and providing an expiration" do
61
+ before(:each) do
62
+ @cache.store("key", "value", :expires_in => 1)
63
+ end
64
+
65
+ shared_examples_for "not expired" do
66
+ it "still has the key" do
67
+ @cache.key?("key").should be_true
68
+ end
69
+
70
+ it "returns the value when indexed" do
71
+ @cache["key"].should == "value"
72
+ end
73
+
74
+ it "returns the value when fetched" do
75
+ @cache.fetch("key", "value2").should == "value"
76
+ end
77
+
78
+ it "returns the value when deleted" do
79
+ @cache.delete("key").should == "value"
80
+ end
81
+ end
82
+
83
+ describe "when expired" do
84
+ before(:each) do
85
+ if @native_expires
86
+ sleep 2
87
+ else
88
+ time = Time.now
89
+ Time.stub!(:now).and_return { time + 2 }
90
+ end
91
+ end
92
+
93
+ it "no longer has the key" do
94
+ @cache.key?("key").should be_false
95
+ end
96
+
97
+ it "returns nil when indexed" do
98
+ @cache["key"].should == nil
99
+ end
100
+
101
+ it "returns the default value when fetched" do
102
+ @cache.fetch("key", "value2").should == "value2"
103
+ end
104
+
105
+ it "returns nil when deleting the expired key" do
106
+ @cache.delete("key").should == nil
107
+ end
108
+ end
109
+
110
+ describe "when not expired" do
111
+ it_should_behave_like "not expired"
112
+ end
113
+
114
+ describe "after updating the expiry with update_key, and waiting for the initial expiry to pass" do
115
+ before(:each) do
116
+ @cache.update_key("key", :expires_in => 2)
117
+ end
118
+
119
+ it_should_behave_like "not expired"
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,7 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require "rubygems"
5
+ require "moneta"
6
+
7
+ require File.expand_path(File.join(File.dirname(__FILE__), "shared"))
@@ -0,0 +1,151 @@
1
+ = REST Client -- simple DSL for accessing REST resources
2
+
3
+ A simple REST client for Ruby, inspired by the Sinatra's microframework style
4
+ of specifying actions: get, put, post, delete.
5
+
6
+ == Usage: Raw URL
7
+
8
+ require 'rest_client'
9
+
10
+ RestClient.get 'http://example.com/resource'
11
+ RestClient.get 'https://user:password@example.com/private/resource'
12
+
13
+ RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
14
+
15
+ RestClient.delete 'http://example.com/resource'
16
+
17
+ See RestClient module docs for details.
18
+
19
+ == Usage: ActiveResource-Style
20
+
21
+ resource = RestClient::Resource.new 'http://example.com/resource'
22
+ resource.get
23
+
24
+ private_resource = RestClient::Resource.new 'https://example.com/private/resource', :user => 'adam', :password => 'secret', :timeout => 20, :open_timeout => 5
25
+ private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
26
+
27
+ See RestClient::Resource module docs for details.
28
+
29
+ == Usage: Resource Nesting
30
+
31
+ site = RestClient::Resource.new('http://example.com')
32
+ site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
33
+
34
+ See RestClient::Resource docs for details.
35
+
36
+ == Shell
37
+
38
+ The restclient shell command gives an IRB session with RestClient already loaded:
39
+
40
+ $ restclient
41
+ >> RestClient.get 'http://example.com'
42
+
43
+ Specify a URL argument for get/post/put/delete on that resource:
44
+
45
+ $ restclient http://example.com
46
+ >> put '/resource', 'data'
47
+
48
+ Add a user and password for authenticated resources:
49
+
50
+ $ restclient https://example.com user pass
51
+ >> delete '/private/resource'
52
+
53
+ Create ~/.restclient for named sessions:
54
+
55
+ sinatra:
56
+ url: http://localhost:4567
57
+ rack:
58
+ url: http://localhost:9292
59
+ private_site:
60
+ url: http://example.com
61
+ username: user
62
+ password: pass
63
+
64
+ Then invoke:
65
+
66
+ $ restclient private_site
67
+
68
+ Use as a one-off, curl-style:
69
+
70
+ $ restclient get http://example.com/resource > output_body
71
+
72
+ $ restclient put http://example.com/resource < input_body
73
+
74
+ == Logging
75
+
76
+ Write calls to a log filename (can also be "stdout" or "stderr"):
77
+
78
+ RestClient.log = '/tmp/restclient.log'
79
+
80
+ Or set an environment variable to avoid modifying the code:
81
+
82
+ $ RESTCLIENT_LOG=stdout path/to/my/program
83
+
84
+ Either produces logs like this:
85
+
86
+ RestClient.get "http://some/resource"
87
+ # => 200 OK | text/html 250 bytes
88
+ RestClient.put "http://some/resource", "payload"
89
+ # => 401 Unauthorized | application/xml 340 bytes
90
+
91
+ Note that these logs are valid Ruby, so you can paste them into the restclient
92
+ shell or a script to replay your sequence of rest calls.
93
+
94
+ == Proxy
95
+
96
+ All calls to RestClient, including Resources, will use the proxy specified by
97
+ RestClient.proxy:
98
+
99
+ RestClient.proxy = "http://proxy.example.com/"
100
+ RestClient.get "http://some/resource"
101
+ # => response from some/resource as proxied through proxy.example.com
102
+
103
+ Often the proxy url is set in an environment variable, so you can do this to
104
+ use whatever proxy the system is configured to use:
105
+
106
+ RestClient.proxy = ENV['http_proxy']
107
+
108
+ == Cookies
109
+
110
+ Request and Response objects know about HTTP cookies, and will automatically
111
+ extract and set headers for them as needed:
112
+
113
+ response = RestClient.get 'http://example.com/action_which_sets_session_id'
114
+ response.cookies
115
+ # => {"_applicatioN_session_id" => "1234"}
116
+
117
+ response2 = RestClient.post(
118
+ 'http://localhost:3000/',
119
+ {:param1 => "foo"},
120
+ {:cookies => {:session_id => "1234"}}
121
+ )
122
+ # ...response body
123
+
124
+ == SSL Client Certificates
125
+
126
+ RestClient::Resource.new(
127
+ 'https://example.com',
128
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
129
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
130
+ :ssl_ca_file => "ca_certificate.pem",
131
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
132
+ ).get
133
+
134
+ Self-signed certificates can be generated with the openssl command-line tool.
135
+
136
+ == Meta
137
+
138
+ Written by Adam Wiggins (adam at heroku dot com)
139
+
140
+ Patches contributed by: Chris Anderson, Greg Borenstein, Ardekantur, Pedro
141
+ Belo, Rafael Souza, Rick Olson, Aman Gupta, Blake Mizerany, Brian Donovan, Ivan
142
+ Makfinsky, Marc-André Cournoyer, Coda Hale, Tetsuo Watanabe, Dusty Doris,
143
+ Lennon Day-Reynolds, James Edward Gray II, Cyril Rohr, Juan Alvarez, and Adam
144
+ Jacob, Paul Dlug, and Brad Ediger
145
+
146
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
147
+
148
+ http://rest-client.heroku.com
149
+
150
+ http://github.com/adamwiggins/rest-client
151
+
@@ -0,0 +1,58 @@
1
+ require 'rake'
2
+
3
+ require 'jeweler'
4
+
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "rest-client"
7
+ s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
8
+ s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
9
+ s.author = "Adam Wiggins"
10
+ s.email = "adam@heroku.com"
11
+ s.homepage = "http://rest-client.heroku.com/"
12
+ s.rubyforge_project = "rest-client"
13
+ s.has_rdoc = true
14
+ s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
15
+ s.executables = %w(restclient)
16
+ end
17
+
18
+ Jeweler::RubyforgeTasks.new
19
+
20
+ ############################
21
+
22
+ require 'spec/rake/spectask'
23
+
24
+ desc "Run all specs"
25
+ Spec::Rake::SpecTask.new('spec') do |t|
26
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
27
+ t.spec_files = FileList['spec/*_spec.rb']
28
+ end
29
+
30
+ desc "Print specdocs"
31
+ Spec::Rake::SpecTask.new(:doc) do |t|
32
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
33
+ t.spec_files = FileList['spec/*_spec.rb']
34
+ end
35
+
36
+ desc "Run all examples with RCov"
37
+ Spec::Rake::SpecTask.new('rcov') do |t|
38
+ t.spec_files = FileList['spec/*_spec.rb']
39
+ t.rcov = true
40
+ t.rcov_opts = ['--exclude', 'examples']
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ ############################
46
+
47
+ require 'rake/rdoctask'
48
+
49
+ Rake::RDocTask.new do |t|
50
+ t.rdoc_dir = 'rdoc'
51
+ t.title = "rest-client, fetch RESTful resources effortlessly"
52
+ t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
53
+ t.options << '--charset' << 'utf-8'
54
+ t.rdoc_files.include('README.rdoc')
55
+ t.rdoc_files.include('lib/restclient.rb')
56
+ t.rdoc_files.include('lib/restclient/*.rb')
57
+ end
58
+
@@ -0,0 +1 @@
1
+ 1.0.4
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + "/../lib"
4
+ require 'restclient'
5
+
6
+ require "yaml"
7
+
8
+ def usage(why = nil)
9
+ puts "failed for reason: #{why}" if why
10
+ puts "usage: restclient [get|put|post|delete] url|name [username] [password]"
11
+ puts " The verb is optional, if you leave it off you'll get an interactive shell."
12
+ puts " put and post both take the input body on stdin."
13
+ exit(1)
14
+ end
15
+
16
+ if %w(get put post delete).include? ARGV.first
17
+ @verb = ARGV.shift
18
+ else
19
+ @verb = nil
20
+ end
21
+
22
+ @url = ARGV.shift || 'http://localhost:4567'
23
+
24
+ config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
25
+
26
+ @url, @username, @password = if c = config[@url]
27
+ [c['url'], c['username'], c['password']]
28
+ else
29
+ [@url, *ARGV]
30
+ end
31
+
32
+ usage("invalid url '#{@url}") unless @url =~ /^https?/
33
+ usage("too few args") unless ARGV.size < 3
34
+
35
+ def r
36
+ @r ||= RestClient::Resource.new(@url, @username, @password)
37
+ end
38
+
39
+ r # force rc to load
40
+
41
+ if @verb
42
+ begin
43
+ if %w(put post).include? @verb
44
+ puts r.send(@verb, STDIN.read)
45
+ else
46
+ puts r.send(@verb)
47
+ end
48
+ exit 0
49
+ rescue RestClient::Exception => e
50
+ puts e.response.body if e.respond_to? :response
51
+ raise
52
+ end
53
+ end
54
+
55
+ %w(get post put delete).each do |m|
56
+ eval <<-end_eval
57
+ def #{m}(path, *args, &b)
58
+ r[path].#{m}(*args, &b)
59
+ end
60
+ end_eval
61
+ end
62
+
63
+ def method_missing(s, *args, &b)
64
+ super unless r.respond_to?(s)
65
+ begin
66
+ r.send(s, *args, &b)
67
+ rescue RestClient::RequestFailed => e
68
+ print STDERR, e.response.body
69
+ raise e
70
+ end
71
+ end
72
+
73
+ require 'irb'
74
+ require 'irb/completion'
75
+
76
+ if File.exists? ".irbrc"
77
+ ENV['IRBRC'] = ".irbrc"
78
+ end
79
+
80
+ if File.exists?(rcfile = "~/.restclientrc")
81
+ load(rcfile)
82
+ end
83
+
84
+ ARGV.clear
85
+
86
+ IRB.start
87
+ exit!
@@ -0,0 +1,2 @@
1
+ # This file exists for backward compatbility with require 'rest_client'
2
+ require File.dirname(__FILE__) + '/restclient'
@@ -0,0 +1,88 @@
1
+ module RestClient
2
+ # This is the base RestClient exception class. Rescue it if you want to
3
+ # catch any exception that your request might raise
4
+ class Exception < RuntimeError
5
+ def message(default=nil)
6
+ self.class::ErrorMessage
7
+ end
8
+ end
9
+
10
+ # Base RestClient exception when there's a response available
11
+ class ExceptionWithResponse < Exception
12
+ attr_accessor :response
13
+
14
+ def initialize(response=nil)
15
+ @response = response
16
+ end
17
+
18
+ def http_code
19
+ @response.code.to_i if @response
20
+ end
21
+
22
+ def http_body
23
+ RestClient::Request.decode(@response['content-encoding'], @response.body) if @response
24
+ end
25
+ end
26
+
27
+ # A redirect was encountered; caught by execute to retry with the new url.
28
+ class Redirect < Exception
29
+ ErrorMessage = "Redirect"
30
+
31
+ attr_accessor :url
32
+ def initialize(url)
33
+ @url = url
34
+ end
35
+ end
36
+
37
+ class NotModified < ExceptionWithResponse
38
+ ErrorMessage = 'NotModified'
39
+ end
40
+
41
+ # Authorization is required to access the resource specified.
42
+ class Unauthorized < ExceptionWithResponse
43
+ ErrorMessage = 'Unauthorized'
44
+ end
45
+
46
+ # No resource was found at the given URL.
47
+ class ResourceNotFound < ExceptionWithResponse
48
+ ErrorMessage = 'Resource not found'
49
+ end
50
+
51
+ # The server broke the connection prior to the request completing. Usually
52
+ # this means it crashed, or sometimes that your network connection was
53
+ # severed before it could complete.
54
+ class ServerBrokeConnection < Exception
55
+ ErrorMessage = 'Server broke connection'
56
+ end
57
+
58
+ # The server took too long to respond.
59
+ class RequestTimeout < Exception
60
+ ErrorMessage = 'Request timed out'
61
+ end
62
+
63
+ # The request failed, meaning the remote HTTP server returned a code other
64
+ # than success, unauthorized, or redirect.
65
+ #
66
+ # The exception message attempts to extract the error from the XML, using
67
+ # format returned by Rails: <errors><error>some message</error></errors>
68
+ #
69
+ # You can get the status code by e.http_code, or see anything about the
70
+ # response via e.response. For example, the entire result body (which is
71
+ # probably an HTML error page) is e.response.body.
72
+ class RequestFailed < ExceptionWithResponse
73
+ def message
74
+ "HTTP status code #{http_code}"
75
+ end
76
+
77
+ def to_s
78
+ message
79
+ end
80
+ end
81
+ end
82
+
83
+ # backwards compatibility
84
+ class RestClient::Request
85
+ Redirect = RestClient::Redirect
86
+ Unauthorized = RestClient::Unauthorized
87
+ RequestFailed = RestClient::RequestFailed
88
+ end