Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added half-baked web client lib

  • Loading branch information...
commit d18c6ccd9d222e156244a51c6abc07347a8b242b 1 parent cb3b80f
@technomancy authored
Showing with 35 additions and 10 deletions.
  1. +12 −10 README.txt
  2. +23 −0 lib/bus_scheme/web/client.rb
View
22 README.txt
@@ -31,6 +31,18 @@ $ bus foo.scm # load a file
See http://technomancy.us/104 for a "Getting Started" tutorial.
+== Contributing
+
+If you're looking for stuff to do, try "rake todo"
+
+Patches are welcome especially if they were written while riding a
+bus. If your daily commute does not involve a bus but you want to
+submit a patch, we may be able to work something out regarding code
+written on trains, ferries, or perhaps even carpool lanes.
+
+Join the mailing list to ask questions and discuss:
+http://rubyforge.org/mail/?group_id=5094
+
== What makes Bus Scheme different?
Well, for starters it's implemented on the bus. No other Scheme
@@ -113,16 +125,6 @@ mostly) in the relevant test files.
Bus Scheme should run on (at least) Ruby 1.8, Ruby 1.9, Rubinius,
JRuby. Any support for Windows is entirely accidental.
-== Contributing
-
-Patches are welcome especially if they were written while riding a
-bus. If your daily commute does not involve a bus but you want to
-submit a patch, we may be able to work something out regarding code
-written on trains, ferries, or perhaps even carpool lanes.
-
-Join the mailing list to ask questions and discuss:
-http://rubyforge.org/mail/?group_id=5094
-
== Bonus Fact
I haven't actually used a real Scheme yet. Everything I know about it
View
23 lib/bus_scheme/web/client.rb
@@ -0,0 +1,23 @@
+require 'net/http'
+require 'uri'
+
+module BusScheme
+ define('http-get', primitive do |uri, options|
+ BusScheme['http-method'].call('get', uri, options)
+ end)
+
+ define('http-post', primitive do |uri, options|
+ options ||= {}
+ BusScheme['http-method'].call('post', uri, options)
+ end)
+
+ # TODO: should we return a hash, or just the body? How do we offer
+ # the necessary flexibility without making simple calls complicated?
+ define('http-method', primitive do |method, uri, options|
+ uri = URI.parse(uri)
+ res = Net::HTTP.start(uri.host, uri.port) {|h|
+ h.send(method, uri.path, options) }
+ { :body.sym => res.body, :code.sym => res.code,
+ :headers.sym => res.to_hash }
+ end)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.