rhcp 0.1.2 → 0.1.3

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/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 0.1.2 / 2008-12-07
2
+
3
+ * initial version
4
+
5
+ * nothing to snothing to see here....
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,4 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ = RHCP
2
+
3
+ * http://rhcp.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ 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.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Rake::TestTask.new() { |t|
20
20
  t.libs << "lib"
21
21
  t.libs << "test"
22
22
  t.libs << "test/rhcp"
23
- t.test_files = FileList['test/rhcp/*_test.rb']
23
+ t.test_files = FileList['test/rhcp/**/*_test.rb']
24
24
  t.verbose = true
25
25
  }
26
26
 
@@ -114,3 +114,12 @@ Rake::GemPackageTask.new(spec) do |p|
114
114
  p.need_tar = true
115
115
  p.need_zip = true
116
116
  end
117
+
118
+ require 'rubygems'
119
+ require 'hoe'
120
+
121
+ Hoe.new('rhcp', PKG_VERSION) do |p|
122
+ # p.rubyforge_name = 'rhcp' # if different than lowercase project name
123
+ p.developer('Philipp T.', 'philipp@hitchhackers.net')
124
+ end
125
+
metadata CHANGED
@@ -1,87 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rhcp
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2008-12-07 00:00:00 +01:00
8
- summary: Library for exporting parts of your application using the rhcp protocol
9
- require_paths:
10
- - lib
11
- email: philipp@hitchhackers.net
12
- homepage: http://hitchhackers.net/projects/rhcp
13
- rubyforge_project: rhcp
14
- description: The rhcp protocol allows you to register commands along with their parameter descriptions and some metadata that can then be executed by rhcp clients.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.1.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message: |+
29
-
30
- This is the initial release of rhcp - hope you'll like it.
31
- Feel free to send me feedback to rhcp at hitchhackers dot net.
32
-
33
6
  authors:
34
- - Philipp Traeder
35
- files:
36
- - Rakefile
37
- - lib/rhcp
38
- - lib/rhcp/client
39
- - lib/rhcp/client/http_broker.rb
40
- - lib/rhcp/client/command_param_stub.rb
41
- - lib/rhcp/client/command_stub.rb
42
- - lib/rhcp/command.rb
43
- - lib/rhcp/command_param.rb
44
- - lib/rhcp/response.rb
45
- - lib/rhcp/dispatching_broker.rb
46
- - lib/rhcp/broker.rb
47
- - lib/rhcp/http_exporter.rb
48
- - lib/rhcp/request.rb
49
- - lib/rhcp/rhcp_exception.rb
50
- - lib/rhcp.rb
51
- - test/rhcp
52
- - test/rhcp/client
53
- - test/rhcp/client/command_param_stub_test.rb
54
- - test/rhcp/client/command_stub_test.rb
55
- - test/rhcp/command_param_test.rb
56
- - test/rhcp/command_test.rb
57
- - test/rhcp/response_test.rb
58
- - test/rhcp/dispatching_broker_test.rb
59
- - test/rhcp/broker_test.rb
60
- - test/rhcp/http_test_server.rb
61
- - test/rhcp/http_exporter_test.rb
62
- - test/rhcp/http_registry_test.rb
63
- - test/rhcp/request_test.rb
64
- test_files:
65
- - test/rhcp/client/command_param_stub_test.rb
66
- - test/rhcp/client/command_stub_test.rb
67
- - test/rhcp/command_param_test.rb
68
- - test/rhcp/command_test.rb
69
- - test/rhcp/response_test.rb
70
- - test/rhcp/dispatching_broker_test.rb
71
- - test/rhcp/broker_test.rb
72
- - test/rhcp/http_test_server.rb
73
- - test/rhcp/http_exporter_test.rb
74
- - test/rhcp/http_registry_test.rb
75
- - test/rhcp/request_test.rb
76
- rdoc_options: []
77
-
78
- extra_rdoc_files: []
7
+ - Philipp T.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
79
11
 
12
+ date: 2009-01-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
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.
26
+ email:
27
+ - philipp@hitchhackers.net
80
28
  executables: []
81
29
 
82
30
  extensions: []
83
31
 
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ has_rdoc: true
42
+ homepage: http://rhcp.rubyforge.org
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --main
46
+ - README.txt
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
84
61
  requirements: []
85
62
 
86
- dependencies: []
63
+ rubyforge_project: rhcp
64
+ rubygems_version: 1.3.1
65
+ signing_key:
66
+ 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.
68
+ test_files: []
87
69
 
data/lib/rhcp.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'singleton'
2
- require 'logger'
3
-
4
- require 'rhcp/broker'
5
- require 'rhcp/command'
6
- require 'rhcp/command_param'
7
- require 'rhcp/dispatching_broker'
8
- require 'rhcp/http_exporter'
9
- require 'rhcp/request'
10
- require 'rhcp/response'
11
- require 'rhcp/rhcp_exception'
12
- require 'rhcp/client/http_broker'
13
- require 'rhcp/client/command_stub'
14
- require 'rhcp/client/command_param_stub'
15
-
16
- module RHCP #:nodoc:
17
-
18
- class Version
19
-
20
- include Singleton
21
-
22
- MAJOR = 0
23
- MINOR = 1
24
- TINY = 2
25
-
26
- def Version.to_s
27
- [ MAJOR, MINOR, TINY ].join(".")
28
- end
29
-
30
- end
31
-
32
- class ModuleHelper
33
-
34
- include Singleton
35
-
36
- attr_accessor :logger
37
-
38
- def initialize()
39
- # TODO do we really want to log to STDOUT per default?
40
- # TODO check the whole package for correct usage of loggers
41
- @logger = Logger.new(STDOUT)
42
- end
43
-
44
-
45
- end
46
-
47
- end
data/lib/rhcp/broker.rb DELETED
@@ -1,37 +0,0 @@
1
- module RHCP
2
-
3
- # Applications register the commands they are implementing at a broker.
4
- # The broker holds the list of commands and is the central entry point for
5
- # all code that wants to export/publish these commands
6
- class Broker
7
-
8
- def initialize
9
- # command_name => command
10
- @known_commands = Hash.new()
11
- end
12
-
13
- # returns a list of all known commands
14
- def get_command_list()
15
- @known_commands
16
- end
17
-
18
- # returns the specified command object
19
- def get_command(command_name)
20
- raise RHCP::RhcpException.new("no such command : #{command_name}") unless @known_commands.has_key?(command_name)
21
- get_command_list[command_name]
22
- end
23
-
24
- # registers a new command - this method should be called by the application
25
- # providing the command
26
- def register_command(command)
27
- raise RHCP::RhcpException.new("duplicate command name : #{command.name}") if @known_commands.has_key?(command.name)
28
- @known_commands[command.name] = command
29
- end
30
-
31
- # removes all commands that have been registered previously
32
- def clear
33
- @known_commands = Hash.new()
34
- end
35
-
36
- end
37
- end
@@ -1,51 +0,0 @@
1
- require 'rhcp/command_param'
2
-
3
- module RHCP
4
-
5
- module Client
6
-
7
- # This is a proxy representing a remote CommandParam - see
8
- # RHCP::CommandParam for details
9
- class CommandParamStub < RHCP::CommandParam
10
-
11
- # the block that should be executed when +get_lookup_values()+ is called
12
- # on this CommandParamStub
13
- attr_accessor :get_lookup_values_block
14
-
15
- # when constructing a CommandParamStub, the +:lookup_method+ option is
16
- # set to +remote_get_lookup_values+ so that a method can be injected
17
- # from outside that will retrieve the lookup values (using the
18
- # +get_lookup_values_block+ property).
19
- def initialize(name, description, options)
20
- # we don't need to stub anything if the method does not have lookup values
21
- if (options[:has_lookup_values])
22
- options[:lookup_method] = self.method(:remote_get_lookup_values)
23
- end
24
- super(name, description, options)
25
- end
26
-
27
- def self.reconstruct_from_json(json_data)
28
- object = json_data.instance_of?(Hash) ? json_data : JSON.parse(json_data)
29
- args = object.values_at('name', 'description')
30
- args << {
31
- :allows_multiple_values => object['allows_multiple_values'],
32
- :has_lookup_values => object['has_lookup_values'],
33
- :is_default_param => object['is_default_param'],
34
- :mandatory => object['mandatory']
35
- }
36
- self.new(*args)
37
- end
38
-
39
- def remote_get_lookup_values(partial_value = "")
40
- @get_lookup_values_block.call(partial_value)
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- end
48
-
49
-
50
-
51
-
@@ -1,56 +0,0 @@
1
- require 'rhcp/command'
2
- require 'rhcp/client/command_param_stub'
3
- require 'rubygems'
4
- require 'json'
5
-
6
-
7
- module RHCP
8
-
9
- module Client
10
-
11
- # This is a stub that represents a remote RHCP::Command.
12
- # Instances of this class will live in a client that uses one of the brokers
13
- # from the RHCP::Client package. The interesting aspect about this stub is
14
- # that the execute method is modified so that it does not execute the
15
- # command directly, but can be modified from outside (by setting the
16
- # +execute_block+ property) so that broker classes can inject their
17
- # remote invocation logic.
18
- class CommandStub < RHCP::Command
19
-
20
- attr_accessor :execute_block
21
-
22
- # constructs a new instance
23
- # should not be invoked directly, but is called from +reconstruct_from_json+
24
- def initialize(name, description)
25
- super(name, description, lambda {})
26
- end
27
-
28
- # builds a CommandStub out of some json data (either serialized as string
29
- # or already unpacked into a ruby-hash)
30
- # all nested params are unmarshalled as RHCP::CommandParamStub instances
31
- # so that we are able to inject the logic for invoking get_lookup_values
32
- # remotely
33
- def self.reconstruct_from_json(json_data)
34
- object = json_data.instance_of?(Hash) ? json_data : JSON.parse(json_data)
35
- args = object.values_at('name', 'description')
36
- instance = self.new(*args)
37
- object['params'].each do |p|
38
- param = RHCP::Client::CommandParamStub.reconstruct_from_json(p)
39
- instance.add_param(param)
40
- end
41
- instance
42
- end
43
-
44
- # we don't want to execute the command block as the normal RHCP::Command
45
- # does, but rather want to call the block injected by the registry that
46
- # has created this stub.
47
- def execute_request(request)
48
- @execute_block.call(request)
49
- end
50
- end
51
-
52
- end
53
-
54
- end
55
-
56
-
@@ -1,86 +0,0 @@
1
- #require 'rhcp/rhcp'
2
- require 'rhcp/broker'
3
- require 'rhcp/rhcp_exception'
4
- require 'rhcp/client/command_stub'
5
- require 'net/http'
6
- require 'json'
7
-
8
- module RHCP
9
-
10
- module Client
11
-
12
- # This is an implementation of a RHCP broker that retrieves it's data via
13
- # http from a remote broker. Since it implements the same interface as RHCP::Broker,
14
- # clients can use it exactly as if they were talking with the broker itself.
15
- # TODO shouldn't this descent from Broker?
16
- class HttpBroker
17
-
18
- def initialize(url)
19
- # TODO should this really be an URL? or just a host name?
20
- @url = url
21
- @logger = RHCP::ModuleHelper.instance.logger
22
- @logger.debug "connecting to #{@url}"
23
- res = Net::HTTP.new(@url.host, @url.port).start { |http| http.get("/rhcp/") }
24
- if (res.code == "200")
25
- @logger.info "connected to '#{@url}' successfully."
26
- else
27
- @logger.error "cannot connect to '#{@url}' : got http status code #{res.code}"
28
- raise RHCP::RhcpException.new("could not connect to '#{@url}' : got http status code #{res.code} (#{res.message})");
29
- end
30
- end
31
-
32
- # returns a list of all known commands
33
- # TODO add caching for commands
34
- def get_command_list()
35
- res = Net::HTTP.new(@url.host, @url.port).start { |http| http.get("/rhcp/get_commands") }
36
- if (res.code != "200")
37
- raise RHCP::RhcpException.new("could not retrieve command list from remote server : http status #{res.code} (#{res.message})")
38
- end
39
-
40
- @logger.debug "raw response : >>#{res.body}<<"
41
-
42
- # the commands are transferred as array => convert into hash
43
- command_array = JSON.parse(res.body)
44
- commands = Hash.new()
45
- command_array.each do |command_string|
46
- command = RHCP::Client::CommandStub.reconstruct_from_json(command_string)
47
- commands[command.name] = command
48
- # and inject the block for executing over http
49
- command.execute_block = lambda {
50
- |req|
51
- @logger.debug("executing command #{command.name} via http using #{@url}")
52
-
53
- res = Net::HTTP.new(@url.host, @url.port).start { |http| http.post("/rhcp/execute", req.to_json()) }
54
- if (res.code != "200")
55
- raise RHCP::RhcpException.new("could not execute command using remote server : http status #{res.code} (#{res.message})")
56
- end
57
-
58
- json_response = RHCP::Response.reconstruct_from_json(res.body)
59
- @logger.debug "json response : #{json_response}"
60
- json_response
61
- }
62
-
63
- # inject appropriate blocks for all params
64
- command.params.each do |name, param|
65
- param.get_lookup_values_block = lambda {
66
- |partial_value|
67
- @logger.debug("getting lookup values for param #{name} of command #{command.name} using #{@url}")
68
- # TODO add caching for lookup values
69
- res = Net::HTTP.new(@url.host, @url.port).start { |http|
70
- http.get("/rhcp/get_lookup_values?command=#{command.name}&param=#{name}")
71
- }
72
- if (res.code != "200")
73
- raise RHCP::RhcpException.new("could not retrieve lookup values from remote server : http status #{res.code} (#{res.message})")
74
- end
75
- JSON.parse(res.body)
76
- }
77
- end
78
- end
79
- commands
80
- end
81
-
82
- end
83
-
84
- end
85
-
86
- end