diff --git a/lib/socket_io.rb b/lib/socket_io.rb index 0d50eeb..74f4963 100644 --- a/lib/socket_io.rb +++ b/lib/socket_io.rb @@ -1,7 +1,7 @@ require 'socket_io/web_socket' require 'rest_client' require 'json' -require 'parser' +require 'socket_parser' module SocketIO @@ -65,7 +65,7 @@ def connect_transport def start_recieve_loop @thread = Thread.new() do while data = @transport.receive() - decoded = Parser.decode(data) + decoded = SocketParser.decode(data) case decoded[:type] when '0' @on_disconnect.call if @on_disconnect diff --git a/lib/parser.rb b/lib/socket_parser.rb similarity index 93% rename from lib/parser.rb rename to lib/socket_parser.rb index f3948b6..351c546 100644 --- a/lib/parser.rb +++ b/lib/socket_parser.rb @@ -1,4 +1,4 @@ -module Parser +module SocketParser @regexp = /([^:]+):([0-9]+)?(\+)?:([^:]+)?:?([\s\S]*)?/ # returns hash as {type: '1', id: '1', end_point: '4', data: [{key: value}]} @@ -10,4 +10,4 @@ def self.decode(string) end end -end \ No newline at end of file +end diff --git a/socketio-client.gemspec b/socketio-client.gemspec index 93ec1b3..8acf8e8 100644 --- a/socketio-client.gemspec +++ b/socketio-client.gemspec @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) Gem::Specification.new do |s| s.name = "socketio-client" - s.version = "0.1.0" + s.version = "0.1.1" s.authors = ["Lyon"] s.email = ["lyon@delorum.com"] s.homepage = "http://github.com/lyondhill/socket.io-ruby-client" diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb deleted file mode 100644 index 45ed51f..0000000 --- a/spec/parser_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'socket_io' - -describe Parser do - - it 'should be able to decode all valid messages' do - Parser.decode("0").should == {type: "0"} - Parser.decode("1::").should == {type: "1", id: nil, end_point: nil, data: ""} - Parser.decode("2::").should == {type: "2", id: nil, end_point: nil, data: ""} - Parser.decode("3:::hay you").should == {type: "3", id: nil, end_point: nil, data: "hay you"} - Parser.decode("4:::{\"can\":\"youcall\"}").should == {type: "4", id: nil, end_point: nil, data: "{\"can\":\"youcall\"}"} - Parser.decode("5:::hay you").should == {type: "5", id: nil, end_point: nil, data: "hay you"} - Parser.decode("6:::").should == {type: "6", id: nil, end_point: nil, data: ""} - Parser.decode("7:::there is an error").should == {type: "7", id: nil, end_point: nil, data: "there is an error"} - Parser.decode("8:::").should == {type: "8", id: nil, end_point: nil, data: ""} - end - - it "should give a disconnect if bad input" do - Parser.decode("hay dude").should == {type: "0"} - Parser.decode("9").should == {type: "0"} - end - -end diff --git a/spec/socket_parser_spec.rb b/spec/socket_parser_spec.rb new file mode 100644 index 0000000..3c458a5 --- /dev/null +++ b/spec/socket_parser_spec.rb @@ -0,0 +1,22 @@ +require 'socket_io' + +describe SocketParser do + + it 'should be able to decode all valid messages' do + described_class.decode("0").should == {type: "0"} + described_class.decode("1::").should == {type: "1", id: nil, end_point: nil, data: ""} + described_class.decode("2::").should == {type: "2", id: nil, end_point: nil, data: ""} + described_class.decode("3:::hay you").should == {type: "3", id: nil, end_point: nil, data: "hay you"} + described_class.decode("4:::{\"can\":\"youcall\"}").should == {type: "4", id: nil, end_point: nil, data: "{\"can\":\"youcall\"}"} + described_class.decode("5:::hay you").should == {type: "5", id: nil, end_point: nil, data: "hay you"} + described_class.decode("6:::").should == {type: "6", id: nil, end_point: nil, data: ""} + described_class.decode("7:::there is an error").should == {type: "7", id: nil, end_point: nil, data: "there is an error"} + described_class.decode("8:::").should == {type: "8", id: nil, end_point: nil, data: ""} + end + + it "should give a disconnect if bad input" do + described_class.decode("hay dude").should == {type: "0"} + described_class.decode("9").should == {type: "0"} + end + +end