minep-request 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -13,6 +13,7 @@ test/tmp
13
13
  test/version_tmp
14
14
  tmp
15
15
  archives
16
+ *-debug.rb
16
17
 
17
18
  # YARD artifacts
18
19
  .yardoc
data/README.md CHANGED
@@ -19,6 +19,7 @@ The known commands are :
19
19
  - exit : Disconnect and quit the program
20
20
  - help : Show the list of the commands
21
21
  - insert : Send an INSERT request
22
+ - load : Send a LOAD request
22
23
  - move : Send a MOVE request
23
24
  - quit : Disconnect and quit the program
24
25
  - signup : Send a SIGNUP request
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # lib = "lib"
4
- # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
3
  require 'optparse'
7
4
  require 'socket'
8
5
  require 'WEBSocket'
@@ -23,7 +20,7 @@ $commands = {
23
20
  "move" => Proc.new { |s| Minep::Request.move s},
24
21
  "backspace" => Proc.new { |s| Minep::Request.backspace s},
25
22
  "delete" => Proc.new { |s| Minep::Request.delete s},
26
- "file" => Proc.new { |s| Minep::Request.file s},
23
+ "load" => Proc.new { |s| Minep::Request.load s, $options[:type]},
27
24
  "help" => Proc.new { |s| help s},
28
25
  "exit" => Proc.new { |s| quit s},
29
26
  "quit" => Proc.new { |s| quit s}
@@ -1,3 +1,5 @@
1
+ require 'minep-request/minep'
2
+
1
3
  module Minep
2
4
  module Request
3
5
  CommandsInfo ||= {
@@ -8,7 +10,7 @@ module Minep
8
10
  "move" => "Send a MOVE request",
9
11
  "backspace" => "Send a BACKSPACE request",
10
12
  "delete" => "Send a DELETE request",
11
- "file" => "Send a FILE request",
13
+ "load" => "Send a LOAD request",
12
14
  "help" => "Show the list of the commands",
13
15
  "exit" => "Disconnect and quit the program",
14
16
  "quit" => "Disconnect and quit the program"
@@ -18,7 +20,7 @@ module Minep
18
20
  CommandsInfo
19
21
  end
20
22
 
21
- def self.file socket
23
+ def self.load socket, type
22
24
  args = {
23
25
  :path => "",
24
26
  :size => 0,
@@ -26,14 +28,34 @@ module Minep
26
28
  :port => 0
27
29
  }
28
30
  printf "path : "
29
- args[:path] = read
31
+ args[:path] = Minep.read
30
32
  printf "line number : "
31
- args[:line] = read.to_i
33
+ args[:line] = Minep.read.to_i
34
+ printf "port : "
35
+ args[:port] = Minep.read.to_i
32
36
  if File.exist? args[:path]
33
37
  f = File.new args[:path]
34
38
  args[:size] = f.size
35
- args[:content] = f.read
36
- socket.write "FILE=#{JSON.dump args}"
39
+ f.close
40
+ Thread.start args[:port], args[:path] do |port, path|
41
+ file = File.new args[:path]
42
+ content = file.read
43
+ file.close
44
+ server = nil
45
+ if type == :tcp
46
+ server = TCPServer.new "0.0.0.0", port
47
+ elsif type == :websocket
48
+ server = WEBSocket::Server.new "0.0.0.0", port
49
+ end
50
+ socket = server.accept
51
+ socket.write content
52
+ socket.shutdown :RDWR
53
+ socket.close
54
+ server.close
55
+ Thread.stop
56
+ end
57
+ sleep 2
58
+ socket.write "LOAD=#{JSON.dump args}"
37
59
  else
38
60
  $stderr.puts "File #{args[:path]} doesn't exists"
39
61
  end
@@ -1,6 +1,6 @@
1
1
  module Minep
2
2
  module Request
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  DATE = Time.now.to_s.split[0]
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minep-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: WEBSocket
@@ -40,7 +40,7 @@ description: ! 'Binary allowing the communication with a MINE server. It support
40
40
  email:
41
41
  - ciappam@gmail.com
42
42
  executables:
43
- - mine-request
43
+ - minep-request
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
@@ -49,7 +49,7 @@ files:
49
49
  - LICENSE.txt
50
50
  - README.md
51
51
  - Rakefile
52
- - bin/mine-request
52
+ - bin/minep-request
53
53
  - lib/minep-request.rb
54
54
  - lib/minep-request/minep.rb
55
55
  - lib/minep-request/requests.rb
@@ -80,4 +80,3 @@ signing_key:
80
80
  specification_version: 3
81
81
  summary: Binary allowing the communication with a MINE server
82
82
  test_files: []
83
- has_rdoc: