xmlrpc-endpoint 0.1.1 → 0.2.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/README.rdoc CHANGED
@@ -2,22 +2,53 @@
2
2
 
3
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
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.
5
+ xmlrpc-endpoint allows you to instead expose normal Rails controller methods via XMLRPC, tied to an xmlrpc endpoint route in your app.
6
6
 
7
+ Install
8
+
9
+ gem install xmlrpc-endpoint
10
+ config.gem "xmlrpc-endpoint" (inside environment.rb Rails::Initializer block)
11
+ -- OR --
12
+ ./script/plugin install git://github.com/wkoffel/xmlrpc-endpoint.git
13
+
7
14
  Setup your environment
8
15
 
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)
16
+ # set up a route to the controller action "xe_index" in your routes.rb file
17
+ # (this "xe_index" action will be created for you by the xmlrpc-endpoint, the route must point at 'xe_index' action to work)
18
+ # In a future release, xmlrpc-endpoint may support auto-generation of this route, and customization
19
+
20
+ map.connect 'api/xmlrpc', :controller => 'my_api_controller', :action => 'xe_index'
12
21
 
13
22
  Add this code to your controller:
14
23
 
15
24
  class MyApiController < ApplicationController
16
25
  exposes_xmlrpc_methods
26
+
27
+ def hello_world
28
+ puts "Hello XMLRPC."
29
+ end
17
30
  end
18
31
 
19
32
  Then, pointing an XMLRPC client at the defined route, your normal controller actions will handle the requests.
20
33
 
34
+ require 'xmlrpc/client'
35
+ server = XMLRPC::Client.new2("http://localhost:3000/api/xmlrpc")
36
+ server.call("hello_world")
37
+
38
+ 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:
39
+
40
+ class MyApiController < ApplicationController
41
+ exposes_xmlrpc_methods :method_prefix => "metaWeblog."
42
+
43
+ # This method will be exposed externally as "metaWeblog.newPost()"
44
+ def newPost(blogid, username, password, struct, publish)
45
+ ...
46
+ end
47
+ end
48
+
49
+ Thanks to Nathan Crause for saving me some time on the details of avoiding the standalone server.
50
+ http://nathan.crause.name/entries/programming/xlm-rpc-under-ruby-on-rails
51
+
21
52
  == Note on Patches/Pull Requests
22
53
 
23
54
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Fri, 01 Jan 2010 15:19:07 -0500
1
+ Fri, 01 Jan 2010 16:09:53 -0500
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Fri Jan 01 15:19:02 -0500 2010</td>
59
+ <td>Fri Jan 01 16:09:48 -0500 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -77,37 +77,72 @@ library examples mostly make an assumption that you will run a standalone
77
77
  server.
78
78
  </p>
79
79
  <p>
80
- xmlrpc-endpoint allows you to expose normal Rails controller methods via
81
- XMLRPC, tied to a single xmlrpc endpoint route in your normal app.
80
+ xmlrpc-endpoint allows you to instead expose normal Rails controller
81
+ methods via XMLRPC, tied to an xmlrpc endpoint route in your app.
82
82
  </p>
83
83
  <p>
84
+ Install
85
+ </p>
86
+ <pre>
87
+ gem install xmlrpc-endpoint
88
+ config.gem &quot;xmlrpc-endpoint&quot; (inside environment.rb Rails::Initializer block)
89
+ -- OR --
90
+ ./script/plugin install git://github.com/wkoffel/xmlrpc-endpoint.git
91
+ </pre>
92
+ <p>
84
93
  Setup your environment
85
94
  </p>
86
- <ul>
87
- <li>gem install xmlrpc-endpoint
88
-
89
- </li>
90
- <li>include ActionController::Acts::XmlrpcEndpoint somewhere in your
91
- environment
92
-
93
- </li>
94
- <li>set up a route to the action &quot;index&quot; in your controller (this
95
- action will be created for you by the xmlrpc-endpoint)
95
+ <pre>
96
+ # set up a route to the action &quot;xe_index&quot; in your controller
97
+ # (this &quot;xe_index&quot; action will be created for you by the xmlrpc-endpoint, the route must point at 'xe_index' action to work)
98
+ # In a future release, xmlrpc-endpoint may support auto-generation of this route, and customization
96
99
 
97
- </li>
98
- </ul>
100
+ map.connect 'api/xmlrpc', :controller =&gt; 'my_api_controller', :action =&gt; 'xe_index'
101
+ </pre>
99
102
  <p>
100
103
  Add this code to your controller:
101
104
  </p>
102
105
  <pre>
103
106
  class MyApiController &lt; ApplicationController
104
107
  exposes_xmlrpc_methods
108
+
109
+ def hello_world
110
+ puts &quot;Hello XMLRPC.&quot;
111
+ end
105
112
  end
106
113
  </pre>
107
114
  <p>
108
115
  Then, pointing an XMLRPC client at the defined route, your normal
109
116
  controller actions will handle the requests.
110
117
  </p>
118
+ <pre>
119
+ require 'xmlrpc/client'
120
+ server = XMLRPC::Client.new2(&quot;http://localhost:3000/api/xmlrpc&quot;)
121
+ server.call(&quot;hello_world&quot;)
122
+ </pre>
123
+ <p>
124
+ To use a custom namespace prefix on all exposed methods (for example, if
125
+ using someone else&#8216;s specified protocol like <a
126
+ href="http://www.xmlrpc.com/metaWeblogApi">MetaWeblog</a>), declare a
127
+ method_prefix:
128
+ </p>
129
+ <pre>
130
+ class MyApiController &lt; ApplicationController
131
+ exposes_xmlrpc_methods :method_prefix =&gt; &quot;metaWeblog.&quot;
132
+
133
+ # This method will be exposed externally as &quot;metaWeblog.newPost()&quot;
134
+ def newPost(blogid, username, password, struct, publish)
135
+ ...
136
+ end
137
+
138
+ etc.
139
+ end
140
+ </pre>
141
+ <p>
142
+ Thanks to Nathan Crause for saving me some time on the details of avoiding
143
+ the standalone server. <a
144
+ href="http://nathan.crause.name/entries/programming/xlm-rpc-under-ruby-on-rails">nathan.crause.name/entries/programming/xlm-rpc-under-ruby-on-rails</a>
145
+ </p>
111
146
  <h2>Note on Patches/Pull Requests</h2>
112
147
  <ul>
113
148
  <li>Fork the project.
@@ -7,7 +7,7 @@ module ActionController
7
7
 
8
8
  module ClassMethods
9
9
  def exposes_xmlrpc_methods(options = {})
10
- configuration = { :method_prefix => nil, :endpoint_action => "index" }
10
+ configuration = { :method_prefix => nil }
11
11
  configuration.update(options) if options.is_a?(Hash)
12
12
 
13
13
  before_filter(:add_method_handlers, :only => [:index])
@@ -15,7 +15,7 @@ module ActionController
15
15
  require 'xmlrpc/server'
16
16
  include ActionController::Acts::XmlrpcEndpoint::InstanceMethods
17
17
 
18
- def method_prefix
18
+ def xe_method_prefix
19
19
  '#{configuration[:method_prefix]}'
20
20
  end
21
21
  EOV
@@ -23,9 +23,8 @@ module ActionController
23
23
  end
24
24
 
25
25
  module InstanceMethods
26
- # TODO: name this via the endpoint_action option instead of hardcoding to "index"
27
26
  # TODO: add route automatically for this?
28
- def index
27
+ def xe_index
29
28
  result = @xmlrpc_server.process(request.body)
30
29
  puts "\n\n----- BEGIN RESULT -----\n#{result}----- END RESULT -----\n\n"
31
30
  render :text => result, :content_type => 'text/xml'
@@ -37,9 +36,9 @@ module ActionController
37
36
  @xmlrpc_server = XMLRPC::BasicServer.new
38
37
  # loop through all the methods, adding them as handlers
39
38
  self.class.instance_methods(false).each do |method|
40
- unless ['index'].member?(method)
39
+ unless ['xe_index', 'xe_method_prefix'].member?(method)
41
40
  puts "Adding XMLRPC method for #{method.to_s}"
42
- @xmlrpc_server.add_handler(method_prefix + method) do |*args|
41
+ @xmlrpc_server.add_handler(xe_method_prefix + method) do |*args|
43
42
  self.send(method.to_sym, *args)
44
43
  end
45
44
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xmlrpc-endpoint}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Will Koffel"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlrpc-endpoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Koffel