xmlrpc-endpoint 0.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/README.rdoc +35 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/init.rb +2 -0
- data/lib/action_controller/acts/xmlrpc_endpoint.rb +51 -0
- data/test/helper.rb +10 -0
- data/test/test_xmlrpc-endpoint.rb +7 -0
- metadata +73 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= xmlrpc-endpoint
|
2
|
+
|
3
|
+
Rails has native support for xmlrpc. Most people are familiar with the 'xmlrpc/client' library. The 'xmlrpc/server' library examples mostly make an assumption that you will run a standalone server.
|
4
|
+
|
5
|
+
xmlrpc-endpoint allows you to expose normal Rails controller methods via XMLRPC, tied to a single xmlrpc endpoint route in your normal app.
|
6
|
+
|
7
|
+
Setup
|
8
|
+
<tt>
|
9
|
+
gem install xmlrpc-endpoint
|
10
|
+
include ActionController::Acts::XmlrpcEndpoint somewhere in your environment
|
11
|
+
set up a route to the action "index" in your controller (this action will be created for you by the xmlrpc-endpoint)
|
12
|
+
</tt>
|
13
|
+
|
14
|
+
Code
|
15
|
+
<tt>
|
16
|
+
class MyApiController < ApplicationController
|
17
|
+
exposes_xmlrpc_methods
|
18
|
+
end
|
19
|
+
</tt>
|
20
|
+
|
21
|
+
Then, pointing an XMLRPC client at the defined route, your normal controller actions will handle the requests.
|
22
|
+
|
23
|
+
== Note on Patches/Pull Requests
|
24
|
+
|
25
|
+
* Fork the project.
|
26
|
+
* Make your feature addition or bug fix.
|
27
|
+
* Add tests for it. This is important so I don't break it in a
|
28
|
+
future version unintentionally.
|
29
|
+
* Commit, do not mess with rakefile, version, or history.
|
30
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
31
|
+
* Send me a pull request. Bonus points for topic branches.
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2010 Will Koffel, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "xmlrpc-endpoint"
|
8
|
+
gem.summary = %Q{Expose Rails controller actions as XMLRPC method calls.}
|
9
|
+
gem.description = %Q{Expose Rails controller actions as XMLRPC method calls.}
|
10
|
+
gem.email = "wkoffel@alum.mit.edu"
|
11
|
+
gem.homepage = "http://github.com/wkoffel/xmlrpc-endpoint"
|
12
|
+
gem.authors = ["Will Koffel"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "xmlrpc-endpoint #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module ActionController
|
2
|
+
module Acts
|
3
|
+
module XmlrpcEndpoint
|
4
|
+
def self.included(controller)
|
5
|
+
controller.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def exposes_xmlrpc_methods(options = {})
|
10
|
+
configuration = { :method_prefix => nil, :endpoint_action => "index" }
|
11
|
+
configuration.update(options) if options.is_a?(Hash)
|
12
|
+
|
13
|
+
before_filter(:add_method_handlers, :only => [:index])
|
14
|
+
class_eval <<-EOV
|
15
|
+
require 'xmlrpc/server'
|
16
|
+
include ActionController::Acts::XmlrpcEndpoint::InstanceMethods
|
17
|
+
|
18
|
+
def method_prefix
|
19
|
+
'#{configuration[:method_prefix]}'
|
20
|
+
end
|
21
|
+
EOV
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
# TODO: name this via the endpoint_action option instead of hardcoding to "index"
|
27
|
+
# TODO: add route automatically for this?
|
28
|
+
def index
|
29
|
+
result = @xmlrpc_server.process(request.body)
|
30
|
+
puts "\n\n----- BEGIN RESULT -----\n#{result}----- END RESULT -----\n\n"
|
31
|
+
render :text => result, :content_type => 'text/xml'
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def add_method_handlers
|
37
|
+
@xmlrpc_server = XMLRPC::BasicServer.new
|
38
|
+
# loop through all the methods, adding them as handlers
|
39
|
+
self.class.instance_methods(false).each do |method|
|
40
|
+
unless ['index'].member?(method)
|
41
|
+
puts "Adding XMLRPC method for #{method.to_s}"
|
42
|
+
@xmlrpc_server.add_handler(method_prefix + method) do |*args|
|
43
|
+
self.send(method.to_sym, *args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xmlrpc-endpoint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will Koffel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-01 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Expose Rails controller actions as XMLRPC method calls.
|
26
|
+
email: wkoffel@alum.mit.edu
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- .document
|
35
|
+
- .gitignore
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION
|
39
|
+
- init.rb
|
40
|
+
- lib/action_controller/acts/xmlrpc_endpoint.rb
|
41
|
+
- test/helper.rb
|
42
|
+
- test/test_xmlrpc-endpoint.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/wkoffel/xmlrpc-endpoint
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Expose Rails controller actions as XMLRPC method calls.
|
71
|
+
test_files:
|
72
|
+
- test/helper.rb
|
73
|
+
- test/test_xmlrpc-endpoint.rb
|