xmlrpc 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b3f1922edd931c783c840f45865c76b1f535a19
4
+ data.tar.gz: 12b38e9e3f0d94a73bec9fa2a02944c914b2f15b
5
+ SHA512:
6
+ metadata.gz: 88ad59a4a1028d7912bff03208909c0009526fe1ec77a61ef140e3e82c143077f1573b00c246d6e953a15352857b7e803b2e27ac14b7e9afae9aeebe58b0705c
7
+ data.tar.gz: 1890b83eefe2fb6f3e0baf3c6a4afb221c8a164d9eb43d455aca46734c1912d16daaea41c854dae8ec395cbfe0a3fb4f003b7434af529dd988c87eaa3ee8eba4
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -0,0 +1,58 @@
1
+ # XMLRPC
2
+
3
+ ## Overview
4
+
5
+ XMLRPC is a lightweight protocol that enables remote procedure calls over
6
+ HTTP. It is defined at http://www.xmlrpc.com.
7
+
8
+ XMLRPC allows you to create simple distributed computing solutions that span
9
+ computer languages. Its distinctive feature is its simplicity compared to
10
+ other approaches like SOAP and CORBA.
11
+
12
+ The Ruby standard library package 'xmlrpc' enables you to create a server that
13
+ implements remote procedures and a client that calls them. Very little code
14
+ is required to achieve either of these.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'xmlrpc'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install xmlrpc
31
+
32
+ ## Example
33
+
34
+ Try the following code. It calls a standard demonstration remote procedure.
35
+
36
+ ```ruby
37
+ require 'xmlrpc/client'
38
+ require 'pp'
39
+
40
+ server = XMLRPC::Client.new2("http://xmlrpc-c.sourceforge.net/api/sample.php")
41
+ result = server.call("sample.sumAndDifference", 5, 3)
42
+ pp result
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/xmlrpc.
54
+
55
+
56
+ ## License
57
+
58
+ Released under the same term of license as Ruby.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/test_*.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xmlrpc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,293 @@
1
+ # frozen_string_literal: false
2
+ # == Author and Copyright
3
+ #
4
+ # Copyright (C) 2001-2004 by Michael Neumann (mailto:mneumann@ntecs.de)
5
+ #
6
+ # Released under the same term of license as Ruby.
7
+ #
8
+ # == Overview
9
+ #
10
+ # XMLRPC is a lightweight protocol that enables remote procedure calls over
11
+ # HTTP. It is defined at http://www.xmlrpc.com.
12
+ #
13
+ # XMLRPC allows you to create simple distributed computing solutions that span
14
+ # computer languages. Its distinctive feature is its simplicity compared to
15
+ # other approaches like SOAP and CORBA.
16
+ #
17
+ # The Ruby standard library package 'xmlrpc' enables you to create a server that
18
+ # implements remote procedures and a client that calls them. Very little code
19
+ # is required to achieve either of these.
20
+ #
21
+ # == Example
22
+ #
23
+ # Try the following code. It calls a standard demonstration remote procedure.
24
+ #
25
+ # require 'xmlrpc/client'
26
+ # require 'pp'
27
+ #
28
+ # server = XMLRPC::Client.new2("http://xmlrpc-c.sourceforge.net/api/sample.php")
29
+ # result = server.call("sample.sumAndDifference", 5, 3)
30
+ # pp result
31
+ #
32
+ # == Documentation
33
+ #
34
+ # See http://www.ntecs.de/ruby/xmlrpc4r/. There is plenty of detail there to
35
+ # use the client and implement a server.
36
+ #
37
+ # == Features of XMLRPC for Ruby
38
+ #
39
+ # * Extensions
40
+ # * Introspection
41
+ # * multiCall
42
+ # * optionally nil values and integers larger than 32 Bit
43
+ #
44
+ # * Server
45
+ # * Standalone XML-RPC server
46
+ # * CGI-based (works with FastCGI)
47
+ # * Apache mod_ruby server
48
+ # * WEBrick servlet
49
+ #
50
+ # * Client
51
+ # * synchronous/asynchronous calls
52
+ # * Basic HTTP-401 Authentication
53
+ # * HTTPS protocol (SSL)
54
+ #
55
+ # * Parsers
56
+ # * REXML (XMLParser::REXMLStreamParser)
57
+ # * Not compiled (pure ruby)
58
+ # * See ruby standard library
59
+ # * libxml (LibXMLStreamParser)
60
+ # * Compiled
61
+ # * See https://rubygems.org/gems/libxml-ruby/
62
+ #
63
+ # * General
64
+ # * possible to choose between XMLParser module (Expat wrapper) and REXML (pure Ruby) parsers
65
+ # * Marshalling Ruby objects to Hashes and reconstruct them later from a Hash
66
+ # * SandStorm component architecture XMLRPC::Client interface
67
+ #
68
+ # == Howto
69
+ #
70
+ # === Client
71
+ #
72
+ # require "xmlrpc/client"
73
+ #
74
+ # # Make an object to represent the XML-RPC server.
75
+ # server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
76
+ #
77
+ # # Call the remote server and get our result
78
+ # result = server.call("sample.sumAndDifference", 5, 3)
79
+ #
80
+ # sum = result["sum"]
81
+ # difference = result["difference"]
82
+ #
83
+ # puts "Sum: #{sum}, Difference: #{difference}"
84
+ #
85
+ # === XMLRPC::Client with XML-RPC fault-structure handling
86
+ #
87
+ # There are two possible ways, of handling a fault-structure:
88
+ #
89
+ # ==== by catching a XMLRPC::FaultException exception
90
+ #
91
+ # require "xmlrpc/client"
92
+ #
93
+ # # Make an object to represent the XML-RPC server.
94
+ # server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
95
+ #
96
+ # begin
97
+ # # Call the remote server and get our result
98
+ # result = server.call("sample.sumAndDifference", 5, 3)
99
+ #
100
+ # sum = result["sum"]
101
+ # difference = result["difference"]
102
+ #
103
+ # puts "Sum: #{sum}, Difference: #{difference}"
104
+ #
105
+ # rescue XMLRPC::FaultException => e
106
+ # puts "Error: "
107
+ # puts e.faultCode
108
+ # puts e.faultString
109
+ # end
110
+ #
111
+ # ==== by calling "call2" which returns a boolean
112
+ #
113
+ # require "xmlrpc/client"
114
+ #
115
+ # # Make an object to represent the XML-RPC server.
116
+ # server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
117
+ #
118
+ # # Call the remote server and get our result
119
+ # ok, result = server.call2("sample.sumAndDifference", 5, 3)
120
+ #
121
+ # if ok
122
+ # sum = result["sum"]
123
+ # difference = result["difference"]
124
+ #
125
+ # puts "Sum: #{sum}, Difference: #{difference}"
126
+ # else
127
+ # puts "Error: "
128
+ # puts result.faultCode
129
+ # puts result.faultString
130
+ # end
131
+ #
132
+ # === Using XMLRPC::Client::Proxy
133
+ #
134
+ # You can create a Proxy object onto which you can call methods. This way it
135
+ # looks nicer. Both forms, _call_ and _call2_ are supported through _proxy_ and
136
+ # _proxy2_. You can additionally give arguments to the Proxy, which will be
137
+ # given to each XML-RPC call using that Proxy.
138
+ #
139
+ # require "xmlrpc/client"
140
+ #
141
+ # # Make an object to represent the XML-RPC server.
142
+ # server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
143
+ #
144
+ # # Create a Proxy object
145
+ # sample = server.proxy("sample")
146
+ #
147
+ # # Call the remote server and get our result
148
+ # result = sample.sumAndDifference(5,3)
149
+ #
150
+ # sum = result["sum"]
151
+ # difference = result["difference"]
152
+ #
153
+ # puts "Sum: #{sum}, Difference: #{difference}"
154
+ #
155
+ # === CGI-based server using XMLRPC::CGIServer
156
+ #
157
+ # There are also two ways to define handler, the first is
158
+ # like C/PHP, the second like Java, of course both ways
159
+ # can be mixed:
160
+ #
161
+ # ==== C/PHP-like (handler functions)
162
+ #
163
+ # require "xmlrpc/server"
164
+ #
165
+ # s = XMLRPC::CGIServer.new
166
+ #
167
+ # s.add_handler("sample.sumAndDifference") do |a,b|
168
+ # { "sum" => a + b, "difference" => a - b }
169
+ # end
170
+ #
171
+ # s.serve
172
+ #
173
+ # ==== Java-like (handler classes)
174
+ #
175
+ # require "xmlrpc/server"
176
+ #
177
+ # s = XMLRPC::CGIServer.new
178
+ #
179
+ # class MyHandler
180
+ # def sumAndDifference(a, b)
181
+ # { "sum" => a + b, "difference" => a - b }
182
+ # end
183
+ # end
184
+ #
185
+ # # NOTE: Security Hole (read below)!!!
186
+ # s.add_handler("sample", MyHandler.new)
187
+ # s.serve
188
+ #
189
+ #
190
+ # To return a fault-structure you have to raise an XMLRPC::FaultException e.g.:
191
+ #
192
+ # raise XMLRPC::FaultException.new(3, "division by Zero")
193
+ #
194
+ # ===== Security Note
195
+ #
196
+ # From Brian Candler:
197
+ #
198
+ # Above code sample has an extremely nasty security hole, in that you can now call
199
+ # any method of 'MyHandler' remotely, including methods inherited from Object
200
+ # and Kernel! For example, in the client code, you can use
201
+ #
202
+ # puts server.call("sample.send","`","ls")
203
+ #
204
+ # (backtick being the method name for running system processes). Needless to
205
+ # say, 'ls' can be replaced with something else.
206
+ #
207
+ # The version which binds proc objects (or the version presented below in the next section)
208
+ # doesn't have this problem, but people may be tempted to use the second version because it's
209
+ # so nice and 'Rubyesque'. I think it needs a big red disclaimer.
210
+ #
211
+ #
212
+ # From Michael:
213
+ #
214
+ # A solution is to undef insecure methods or to use
215
+ # XMLRPC::Service::PublicInstanceMethodsInterface as shown below:
216
+ #
217
+ # class MyHandler
218
+ # def sumAndDifference(a, b)
219
+ # { "sum" => a + b, "difference" => a - b }
220
+ # end
221
+ # end
222
+ #
223
+ # # ... server initialization ...
224
+ #
225
+ # s.add_handler(XMLRPC::iPIMethods("sample"), MyHandler.new)
226
+ #
227
+ # # ...
228
+ #
229
+ # This adds only public instance methods explicitly declared in class MyHandler
230
+ # (and not those inherited from any other class).
231
+ #
232
+ # ==== With interface declarations
233
+ #
234
+ # Code sample from the book Ruby Developer's Guide:
235
+ #
236
+ # require "xmlrpc/server"
237
+ #
238
+ # class Num
239
+ # INTERFACE = XMLRPC::interface("num") {
240
+ # meth 'int add(int, int)', 'Add two numbers', 'add'
241
+ # meth 'int div(int, int)', 'Divide two numbers'
242
+ # }
243
+ #
244
+ # def add(a, b) a + b end
245
+ # def div(a, b) a / b end
246
+ # end
247
+ #
248
+ #
249
+ # s = XMLRPC::CGIServer.new
250
+ # s.add_handler(Num::INTERFACE, Num.new)
251
+ # s.serve
252
+ #
253
+ # === Standalone XMLRPC::Server
254
+ #
255
+ # Same as CGI-based server, the only difference being
256
+ #
257
+ # server = XMLRPC::CGIServer.new
258
+ #
259
+ # must be changed to
260
+ #
261
+ # server = XMLRPC::Server.new(8080)
262
+ #
263
+ # if you want a server listening on port 8080.
264
+ # The rest is the same.
265
+ #
266
+ # === Choosing a different XMLParser or XMLWriter
267
+ #
268
+ # The examples above all use the default parser (which is now since 1.8
269
+ # XMLParser::REXMLStreamParser) and a default XMLRPC::XMLWriter.
270
+ # If you want to use a different XMLParser, then you have to call the
271
+ # ParserWriterChooseMixin#set_parser method of XMLRPC::Client instances
272
+ # or instances of subclasses of XMLRPC::BasicServer or by editing
273
+ # xmlrpc/config.rb.
274
+ #
275
+ # XMLRPC::Client Example:
276
+ #
277
+ # # ...
278
+ # server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
279
+ # server.set_parser(XMLRPC::XMLParser::XMLParser.new)
280
+ # # ...
281
+ #
282
+ # XMLRPC::Server Example:
283
+ #
284
+ # # ...
285
+ # s = XMLRPC::CGIServer.new
286
+ # s.set_parser(XMLRPC::XMLParser::XMLParser.new)
287
+ # # ...
288
+ #
289
+ #
290
+ # You can change the XML-writer by calling method ParserWriterChooseMixin#set_writer.
291
+ module XMLRPC
292
+ VERSION = "0.1.0"
293
+ end