From bd250ab5efd2edf2f63ca3b8a53656c7acb46702 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Wed, 18 Jul 2012 23:27:30 +0530 Subject: [PATCH] removed messagepack dependency. --- Gemfile | 1 - example/web_scraper.rb | 20 ++++++++++++++++++++ lib/transport.rb | 7 +++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 example/web_scraper.rb diff --git a/Gemfile b/Gemfile index 628b1cd..5062c3d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source :rubygems gem 'rspec' -gem 'msgpack' gem 'sinatra' diff --git a/example/web_scraper.rb b/example/web_scraper.rb new file mode 100644 index 0000000..929c2d7 --- /dev/null +++ b/example/web_scraper.rb @@ -0,0 +1,20 @@ +require_relative '../lib/stormy-cloud' +require 'net/http' + +StormyCloud.new("web_scraper", "localhost") do |c| + c.split { (2..5).to_a } + + c.map do |roll_number| + uri = URI('http://results.herokuapp.com/result') + res = Net::HTTP.post_form(uri, 'rno' => roll_number.to_s) + res.body.split('')[0..1].map {|x| x.split('')[1] } * ' ' + end + + c.reduce do |roll_number, result| + puts "#{roll_number} #{result}" + end + + c.finally do + "done" + end +end diff --git a/lib/transport.rb b/lib/transport.rb index 3138da9..a761903 100644 --- a/lib/transport.rb +++ b/lib/transport.rb @@ -1,4 +1,3 @@ -require 'base64' require 'digest' require 'msgpack' require 'securerandom' @@ -148,7 +147,7 @@ def complete? def handle(string) valid_commands = ["HELLO", "GET", "PUT"] command = unserialize(string) - + if not (command.kind_of?(Array) and valid_commands.include? command[0]) # The command is invalid. return serialize("INVALID COMMAND") @@ -214,13 +213,13 @@ def raw_send_message(string) # This can be overridden by the specific transport if the protocol used is # such that this mode of serialization is disadvantageous. def serialize(object) - Base64::encode64(object.to_msgpack) + Marshal.dump(object) end # Unserialize an object which has been serialized using the `serialize` # method. def unserialize(string) - MessagePack.unpack(Base64::decode64(string)) + Marshal.load(string) end # Return all variables relevant to the job status.