rails-xmlrpc 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/README.rdoc +69 -0
- data/Rakefile +53 -0
- data/init.rb +1 -0
- data/lib/action_controller/acts/rails_xmlrpc.rb +76 -0
- data/lib/rails-xmlrpc.rb +8 -0
- data/rails-xmlrpc.gemspec +49 -0
- data/test/helper.rb +10 -0
- data/test/test_rails-xmlrpc.rb +7 -0
- metadata +90 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
= rails-xmlrpc
|
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
|
+
rails-xmlrpc allows you to instead expose normal Rails controller methods via XMLRPC, tied to an xmlrpc endpoint route in your app.
|
6
|
+
|
7
|
+
==Install
|
8
|
+
|
9
|
+
Run in terminal:
|
10
|
+
gem install rails-xmlrpc
|
11
|
+
|
12
|
+
=== For Rails 2
|
13
|
+
Add row to environment.rb inside Rails::Initializer block:
|
14
|
+
config.gem "rails-xmlrpc"
|
15
|
+
|
16
|
+
Add row to routes.rb
|
17
|
+
map.connect 'api/xmlrpc', :controller => 'my_controller', :action => 'xe_index'
|
18
|
+
|
19
|
+
=== For Rails 3
|
20
|
+
Add row to Gemfile:
|
21
|
+
gem "rails-xmlrpc"
|
22
|
+
|
23
|
+
Set up a route in your routes.rb file
|
24
|
+
match 'api/xmlrpc' => 'my#xe_index'
|
25
|
+
|
26
|
+
|
27
|
+
== Examples
|
28
|
+
Add this code to your controller:
|
29
|
+
|
30
|
+
class MyController < ApplicationController
|
31
|
+
exposes_xmlrpc_methods
|
32
|
+
|
33
|
+
add_method 'Container.method_name' do
|
34
|
+
return 'Hello World'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
Then, pointing an XMLRPC client at the defined route, your normal controller actions will handle the requests.
|
40
|
+
|
41
|
+
require 'xmlrpc/client'
|
42
|
+
server = XMLRPC::Client.new2("http://localhost:3000/api/xmlrpc")
|
43
|
+
server.call("Container.method_name")
|
44
|
+
|
45
|
+
To use a custom namespace prefix on all exposed methods (for example, if using someone else's specified protocol like MetaWeblog[http://www.xmlrpc.com/metaWeblogApi]), declare a method_prefix:
|
46
|
+
|
47
|
+
class MyApiController < ApplicationController
|
48
|
+
exposes_xmlrpc_methods :method_prefix => "metaWeblog."
|
49
|
+
|
50
|
+
# This method will be exposed externally as "metaWeblog.newPost()"
|
51
|
+
def newPost(blogid, username, password, struct, publish)
|
52
|
+
...
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
== Note on Patches/Pull Requests
|
58
|
+
|
59
|
+
* Fork the project.
|
60
|
+
* Make your feature addition or bug fix.
|
61
|
+
* Add tests for it. This is important so I don't break it in a
|
62
|
+
future version unintentionally.
|
63
|
+
* Commit, do not mess with rakefile, version, or history.
|
64
|
+
(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)
|
65
|
+
* Send me a pull request. Bonus points for topic branches.
|
66
|
+
|
67
|
+
== Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2011 Aleksei Kvitinskii, 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 = "rails-xmlrpc"
|
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/Axt/rails-xmlrpc"
|
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 = "rails-xmlrpc #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails-xmlrpc'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module ActionController
|
2
|
+
module Acts
|
3
|
+
module RailsXmlrpc
|
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 }
|
11
|
+
configuration.update(options) if options.is_a?(Hash)
|
12
|
+
|
13
|
+
before_filter(:add_method_handlers, :only => [:xe_index])
|
14
|
+
class_eval <<-EOV
|
15
|
+
require 'xmlrpc/server'
|
16
|
+
include ActionController::Acts::RailsXmlrpc::InstanceMethods
|
17
|
+
|
18
|
+
def xe_method_prefix
|
19
|
+
'#{configuration[:method_prefix]}'
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.add_method name, &block
|
23
|
+
@method_list ||= []
|
24
|
+
lambda_block = lambda &block
|
25
|
+
@method_list << { :name => name, :block => lambda_block}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.xe_method_list
|
29
|
+
@method_list ||= []
|
30
|
+
@method_list
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.method_size
|
34
|
+
@method_list
|
35
|
+
end
|
36
|
+
EOV
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module InstanceMethods
|
41
|
+
# TODO: add route automatically for this?
|
42
|
+
def xe_index
|
43
|
+
result = @xmlrpc_server.process(request.body)
|
44
|
+
puts "\n\n----- BEGIN RESULT -----\n#{result}----- END RESULT -----\n\n"
|
45
|
+
render :text => result, :content_type => 'text/xml'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def add_method_handlers
|
51
|
+
@xmlrpc_server = XMLRPC::BasicServer.new
|
52
|
+
# loop through all the methods, adding them as handlers
|
53
|
+
self.class.xe_method_list.each do |method|
|
54
|
+
puts "Adding XMLRPC method for #{method[:name].to_s}"
|
55
|
+
@xmlrpc_server.add_handler method[:name], &method[:block]
|
56
|
+
# method[:block].call
|
57
|
+
# end
|
58
|
+
end
|
59
|
+
|
60
|
+
@xmlrpc_server.add_handler 'demo3' do
|
61
|
+
self.class.method_size[0][:name]
|
62
|
+
end
|
63
|
+
|
64
|
+
self.class.instance_methods(false).each do |method|
|
65
|
+
unless ['xe_index', 'xe_method_prefix', 'xe_method_list'].member?(method)
|
66
|
+
puts "Adding XMLRPC method for #{method.to_s}"
|
67
|
+
@xmlrpc_server.add_handler(xe_method_prefix + method) do |*args|
|
68
|
+
self.send(method.to_sym, *args)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/rails-xmlrpc.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# This file loads when the gem is included, and does plugin-style initialization
|
2
|
+
|
3
|
+
module ActionController::Acts
|
4
|
+
autoload :RailsXmlrpc, "#{File.dirname(__FILE__)}/action_controller/acts/rails_xmlrpc.rb"
|
5
|
+
end
|
6
|
+
|
7
|
+
ActionController::Base.send(:include, ActionController::Acts::RailsXmlrpc )
|
8
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{rails-xmlrpc}
|
5
|
+
s.version = "0.3.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Aleksei Kvitinskii","Will Koffel"]
|
9
|
+
s.date = %q{2011-04-10}
|
10
|
+
s.description = %q{Gem allows you to use our RubyOnRails project like XMLRPC server. Support Rails 3.}
|
11
|
+
s.email = %q{aleksei.wm@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"README.rdoc",
|
18
|
+
"Rakefile",
|
19
|
+
"init.rb",
|
20
|
+
"lib/action_controller/acts/rails_xmlrpc.rb",
|
21
|
+
"lib/rails-xmlrpc.rb",
|
22
|
+
"test/helper.rb",
|
23
|
+
"test/test_rails-xmlrpc.rb",
|
24
|
+
"rails-xmlrpc.gemspec"
|
25
|
+
]
|
26
|
+
s.homepage = %q{http://github.com/Axy/rails-xmlrpc}
|
27
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
s.rubygems_version = %q{1.3.5}
|
30
|
+
s.summary = %q{Gem allows you to use our RubyOnRails project like XMLRPC server. Support Rails 3.}
|
31
|
+
s.test_files = [
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_rails-xmlrpc.rb"
|
34
|
+
]
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
44
|
+
end
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-xmlrpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Aleksei Kvitinskii
|
14
|
+
- Will Koffel
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-04-10 00:00:00 +03:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: thoughtbot-shoulda
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Gem allows you to use our RubyOnRails project like XMLRPC server. Support Rails 3.
|
37
|
+
email: aleksei.wm@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- init.rb
|
49
|
+
- lib/action_controller/acts/rails_xmlrpc.rb
|
50
|
+
- lib/rails-xmlrpc.rb
|
51
|
+
- test/helper.rb
|
52
|
+
- test/test_rails-xmlrpc.rb
|
53
|
+
- rails-xmlrpc.gemspec
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/Axy/rails-xmlrpc
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.4.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Gem allows you to use our RubyOnRails project like XMLRPC server. Support Rails 3.
|
88
|
+
test_files:
|
89
|
+
- test/helper.rb
|
90
|
+
- test/test_rails-xmlrpc.rb
|