rhcp 0.1.3 → 0.1.4

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.
@@ -0,0 +1,70 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'rhcp'
4
+
5
+ require 'net/http'
6
+ require 'logger'
7
+
8
+ $logger = Logger.new($stdout)
9
+
10
+ broker = RHCP::Broker.new()
11
+ broker.register_command(RHCP::Command.new("test", "just a test command", lambda { |req,res| "testing" }))
12
+ broker.register_command(
13
+ RHCP::Command.new("reverse", "reversing input strings",
14
+ lambda { |req,res| req.get_param_value("input").reverse }
15
+ ).add_param(RHCP::CommandParam.new("input", "the string to reverse", {
16
+ :lookup_method => lambda { [ "zaphod", "beeblebrox" ] }
17
+ }))
18
+ )
19
+ broker.register_command RHCP::Command.new("cook", "cook something nice out of some ingredients",
20
+ lambda { |req,res|
21
+ ingredients = req.get_param_value("ingredient").join(" ")
22
+ puts "cooking something with #{ingredients}"
23
+ ingredients
24
+ }
25
+ ).add_param(RHCP::CommandParam.new("ingredient", "something to cook with",
26
+ {
27
+ :lookup_method => lambda { [ "mascarpone", "chocolate", "eggs", "butter", "marzipan" ] },
28
+ :allows_multiple_values => true,
29
+ :mandatory => true
30
+ }
31
+ )
32
+ )
33
+ command = RHCP::Command.new("list_stuff", "this command lists stuff",
34
+ lambda { |req,res|
35
+ [ "peace", "aquaeduct", "education" ]
36
+ }
37
+ )
38
+ command.mark_as_read_only()
39
+ command.result_hints[:display_type] = "list"
40
+ broker.register_command command
41
+
42
+ command = RHCP::Command.new("build_table", "this command returns tabular data",
43
+ lambda { |req,res|
44
+ [
45
+ { :the_first_name => "Zaphod", :last_name => "Beeblebrox", :heads => 2, :character => "dangerous" },
46
+ { :the_first_name => "Arthur", :last_name => "Dent", :heads => 1, :character => "harmless (mostly)" },
47
+ { :the_first_name => "Prostetnik", :last_name => "Yoltz (?)", :heads => 1, :character => "ugly" }
48
+ ]
49
+ }
50
+ )
51
+ command.mark_as_read_only()
52
+ command.result_hints[:display_type] = "table"
53
+ command.result_hints[:overview_columns] = [ "the_first_name", "last_name" ]
54
+ command.result_hints[:column_titles] = [ "First Name", "Last Name" ]
55
+ broker.register_command command
56
+
57
+ exporter = RHCP::HttpExporter.new(broker, :port => 42000)
58
+
59
+ trap("INT") {
60
+ exporter.stop
61
+ Kernel.exit 0
62
+ }
63
+
64
+ $logger.info "launching http exporter..."
65
+ exporter.start()
66
+ while (true) do
67
+ sleep 30
68
+ puts "."
69
+ end
70
+ $logger.info "exiting"
@@ -0,0 +1,124 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'test/unit'
4
+ require 'rhcp'
5
+
6
+ require 'rubygems'
7
+ require 'json'
8
+
9
+ class RequestTest < Test::Unit::TestCase
10
+
11
+ def test_construction
12
+ command = RHCP::Command.new("test", "a test", nil)
13
+ assert_raise(RHCP::RhcpException) { RHCP::Request.new(nil, Hash.new()) }
14
+ request = RHCP::Request.new(command, Hash.new())
15
+ assert_not_nil request
16
+ end
17
+
18
+ def test_get_param_value
19
+ command = RHCP::Command.new("test", "a test", nil)
20
+ command.add_param(RHCP::CommandParam.new("first_param", "this is the first param"))
21
+ command.add_param(RHCP::CommandParam.new("second_param", "this is the second param", { :allows_multiple_values => true }))
22
+ request = RHCP::Request.new(
23
+ command,
24
+ {
25
+ "first_param" => ["foo"],
26
+ "second_param" => ["foo", "bar", "baz"]
27
+ }
28
+ )
29
+ assert_not_nil request
30
+ assert_equal "foo", request.get_param_value("first_param")
31
+ assert_equal ["foo", "bar", "baz"], request.get_param_value("second_param")
32
+ end
33
+
34
+ def test_has_param_value
35
+ command = RHCP::Command.new("test", "a test", nil)
36
+ command.add_param(RHCP::CommandParam.new("first_param", "this is the first param"))
37
+ command.add_param(RHCP::CommandParam.new("second_param", "this is the second param", { :allows_multiple_values => true }))
38
+ request = RHCP::Request.new(
39
+ command,
40
+ {
41
+ "first_param" => ["foo"],
42
+ "second_param" => ["foo", "bar", "baz"]
43
+ }
44
+ )
45
+ assert request.has_param_value("first_param")
46
+ assert ! request.has_param_value("third_param")
47
+ end
48
+
49
+ def test_invalid_param_name
50
+ command = RHCP::Command.new("test", "another test", lambda {})
51
+ command.add_param(RHCP::CommandParam.new("real_param", "this param does exist"))
52
+ assert_not_nil RHCP::Request.new(command, { "real_param" => [ "value for the real param" ] })
53
+ assert_raise(RHCP::RhcpException) { RHCP::Request.new(command, {
54
+ "does_not_exist" => [ "single value for non-existing param" ]
55
+ }) }
56
+ end
57
+
58
+ def test_invalid_param_values
59
+ command = RHCP::Command.new("test", "another test", lambda {})
60
+ command.add_param(RHCP::CommandParam.new("real_param", "this param does exist"))
61
+ assert_raise(RHCP::RhcpException) { RHCP::Request.new(command, {
62
+ "real_param" => [ "value for the real param", "another value for the real param" ]
63
+ }) }
64
+ end
65
+
66
+ def test_missing_mandatory_param
67
+ command = RHCP::Command.new("test", "another test", lambda {})
68
+ command.add_param(RHCP::CommandParam.new("first_param", "this is the first param", { :mandatory => true }))
69
+ command.add_param(RHCP::CommandParam.new("second_param", "this param is optional", { :mandatory => false }))
70
+
71
+ # test1 : we should not have to specify optional parameters
72
+ assert_not_nil RHCP::Request.new(command, { "first_param" => [ "bla" ]})
73
+
74
+ # test2 : but we need to specify mandatory params
75
+ assert_raise(RHCP::RhcpException) { RHCP::Request.new(command, {})}
76
+ end
77
+
78
+ def test_json
79
+ command = RHCP::Command.new("request_test", "a test", nil)
80
+ command.add_param(RHCP::CommandParam.new("first_param", "this is the first param"))
81
+ command.add_param(RHCP::CommandParam.new("second_param", "this is the second param", { :allows_multiple_values => true }))
82
+ broker = RHCP::Broker.new()
83
+ broker.register_command(command)
84
+ r= RHCP::Request.new(
85
+ command,
86
+ {
87
+ "first_param" => ["foo"],
88
+ "second_param" => ["foo", "bar", "baz"]
89
+ }
90
+ )
91
+ json = r.to_json
92
+ puts "request as JSON : >>#{json}<<"
93
+ assert_not_nil json
94
+ r2 = RHCP::Request.reconstruct_from_json(broker, json)
95
+ assert_instance_of RHCP::Request, r2
96
+ assert_equal r.command, r2.command
97
+ assert_equal r.param_values, r2.param_values
98
+ end
99
+
100
+ def test_execute
101
+ command = RHCP::Command.new("request_test", "a test", lambda { |req,res| "jehova" })
102
+ r= RHCP::Request.new(
103
+ command
104
+ )
105
+ res = r.execute
106
+ assert_not_nil res
107
+ assert_equal "jehova", res.data
108
+ end
109
+
110
+ def test_execute_with_params
111
+ command = RHCP::Command.new("request_test", "a test", lambda { |req,res| "***" + req.get_param_value("first_one") + "***" }
112
+ ).add_param(RHCP::CommandParam.new("first_one", "pole position"))
113
+ r= RHCP::Request.new(
114
+ command,
115
+ {
116
+ "first_one" => "lucky bastard"
117
+ }
118
+ )
119
+ res = r.execute()
120
+ assert_not_nil res
121
+ assert_equal "***lucky bastard***", res.data
122
+ end
123
+
124
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
7
+
8
+ require 'test/unit'
9
+ require 'rhcp/response'
10
+
11
+ class ResponseTest < Test::Unit::TestCase
12
+
13
+ def test_simple
14
+ response = RHCP::Response.new()
15
+ assert_not_nil response
16
+ response.mark_as_error("something went wrong")
17
+ assert_equal "something went wrong", response.error_text
18
+ assert_equal "", response.error_detail
19
+ end
20
+
21
+ def test_payload
22
+ response = RHCP::Response.new()
23
+ assert_not_nil response
24
+ response.set_payload("some data")
25
+ assert_equal "some data", response.data
26
+ end
27
+
28
+ def test_json
29
+ response = RHCP::Response.new()
30
+ response.set_payload("some data")
31
+ response.mark_as_error("something went wrong", "things got really fucked up")
32
+
33
+ json = response.to_json()
34
+ assert_not_nil json
35
+ r2 = RHCP::Response.reconstruct_from_json(json)
36
+ #r2 = JSON.parse(json)
37
+ assert_not_nil r2
38
+ assert_instance_of RHCP::Response, r2
39
+ assert_equal RHCP::Response::Status::ERROR, r2.status
40
+ assert_equal "something went wrong", r2.error_text
41
+ assert_equal "things got really fucked up", r2.error_detail
42
+ assert_equal "some data", r2.data
43
+ end
44
+
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp T.
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-18 00:00:00 +01:00
12
+ date: 2009-01-23 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,9 +20,9 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.8.2
23
+ version: 1.8.3
24
24
  version:
25
- description: RHCP is a protocol designed for building up a command-metadata-based communication infrastructure making it easier for application developers to export commands in applications to generic clients.
25
+ description: FIX (describe your package)
26
26
  email:
27
27
  - philipp@hitchhackers.net
28
28
  executables: []
@@ -38,8 +38,43 @@ files:
38
38
  - Manifest.txt
39
39
  - README.txt
40
40
  - Rakefile
41
+ - build_gem.sh
42
+ - docroot/builder.js
43
+ - docroot/controls.js
44
+ - docroot/dragdrop.js
45
+ - docroot/effects.js
46
+ - docroot/index.html
47
+ - docroot/prototype.js
48
+ - docroot/scriptaculous.js
49
+ - docroot/slider.js
50
+ - docroot/sound.js
51
+ - docroot/unittest.js
52
+ - lib/rhcp.rb
53
+ - lib/rhcp/broker.rb
54
+ - lib/rhcp/client/command_param_stub.rb
55
+ - lib/rhcp/client/command_stub.rb
56
+ - lib/rhcp/client/http_broker.rb
57
+ - lib/rhcp/command.rb
58
+ - lib/rhcp/command_param.rb
59
+ - lib/rhcp/dispatching_broker.rb
60
+ - lib/rhcp/http_exporter.rb
61
+ - lib/rhcp/request.rb
62
+ - lib/rhcp/response.rb
63
+ - lib/rhcp/rhcp_exception.rb
64
+ - start_test_server.sh
65
+ - test/rhcp/broker_test.rb
66
+ - test/rhcp/client/command_param_stub_test.rb
67
+ - test/rhcp/client/command_stub_test.rb
68
+ - test/rhcp/command_param_test.rb
69
+ - test/rhcp/command_test.rb
70
+ - test/rhcp/dispatching_broker_test.rb
71
+ - test/rhcp/http_exporter_test.rb
72
+ - test/rhcp/http_registry_test.rb
73
+ - test/rhcp/http_test_server.rb
74
+ - test/rhcp/request_test.rb
75
+ - test/rhcp/response_test.rb
41
76
  has_rdoc: true
42
- homepage: http://rhcp.rubyforge.org
77
+ homepage: FIX (url)
43
78
  post_install_message:
44
79
  rdoc_options:
45
80
  - --main
@@ -64,6 +99,6 @@ rubyforge_project: rhcp
64
99
  rubygems_version: 1.3.1
65
100
  signing_key:
66
101
  specification_version: 2
67
- summary: RHCP is a protocol designed for building up a command-metadata-based communication infrastructure making it easier for application developers to export commands in applications to generic clients.
102
+ summary: FIX (describe your package)
68
103
  test_files: []
69
104