xmlrpc-rack_server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in xmlrpc-rack_server.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,51 @@
1
+ = XMLRPC::RackServer
2
+
3
+ This gem extends the Ruby standard library XML-RPC server to be Rack
4
+ compatible.
5
+
6
+ == Installation
7
+
8
+ If bundler is used, just include the relevant line to Gemfile:
9
+
10
+ gem 'xmlrpc-rack_server'
11
+
12
+ or in other projects:
13
+
14
+ require 'rubygems'
15
+ require 'xmlrpc-rack_server'
16
+
17
+ == Usage
18
+
19
+ Use the XML-RPC server as a normal Rack server, extended by the functionality
20
+ of the Ruby standard library XML-RPC server.
21
+
22
+ The Ruby standard library XML-RPC component documentation can be found at:
23
+ http://www.ruby-doc.org/stdlib-1.9.3/libdoc/xmlrpc/rdoc/index.html and the Rack
24
+ documentation at: http://rack.rubyforge.org/doc/
25
+
26
+ == Examples
27
+
28
+ This creates a simple XML-RPC ping server running on Rack:
29
+
30
+ class Ping
31
+ def self.call(env)
32
+ server = XMLRPC::RackServer.new
33
+ server.add_introspection
34
+ server.add_handler('weblogUpdates', self.new)
35
+ server.call(env)
36
+ end
37
+
38
+ def ping(title, url)
39
+ # Do whatever with title and url
40
+ {:flerror => false, :message => 'Thanks for the ping.'}
41
+ end
42
+ end
43
+
44
+ If Ruby on Rails framework is used the Rack server can be mounted on routes.rb:
45
+
46
+ Rails.application.routes.draw do |map|
47
+ mount Ping => '/ping'
48
+ end
49
+
50
+
51
+ Copyright (c) 2010-2011 Nikolaos Anastopoulos, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,60 @@
1
+ require "xmlrpc/server"
2
+ require "rack/request"
3
+ require "rack/response"
4
+
5
+ module XMLRPC
6
+ # Implements a Rack based XML-RPC server.
7
+ #
8
+ # Extends the XMLRPC::BasicServer by implementing the Rack callback
9
+ # requirement, creating a Rack compatible XML-RPC server. It is used as a
10
+ # normal XML-RPC server:
11
+ #
12
+ # server = XMLRPC::RackServer.new
13
+ # server.add_introspection
14
+ # server.add_handler("weblogUpdates", Ping)
15
+ #
16
+ # The XMLRPC::RackServer instance may be mounted to a Rack chain.
17
+ class RackServer < BasicServer
18
+ VERSION = "0.0.1".freeze
19
+
20
+ # Creates a new XMLRPC::RackServer instance.
21
+ #
22
+ # All parameters given are by-passed to XMLRPC::BasicServer initializer.
23
+ def initialize(*args)
24
+ super(*args)
25
+ end
26
+
27
+ # Implements the Rack callback requirement.
28
+ #
29
+ # Responds to any bad requests with HTTP errors, parses the input and
30
+ # process it, responding with the output.
31
+ def call(env)
32
+ request = Rack::Request.new(env)
33
+
34
+ return [405, {}, "Method Not Allowed"] unless request.post?
35
+
36
+ return [400, {}, "Bad Request"] unless not request.content_type.nil? and
37
+ ["application/xml", "text/xml"].include? parse_content_type(request.content_type).first
38
+
39
+ length = request.content_length.to_i
40
+ return [411, {}, "Length Required"] unless length > 0
41
+
42
+ data = request.body
43
+ return [400, {}, "Bad Request"] if data.nil? or data.size != length
44
+
45
+ input = data.read(length)
46
+ output = nil
47
+ begin
48
+ output = process(input)
49
+ rescue RuntimeError => e
50
+ return [400, {}, "Bad Request"] if e.message =~ /No valid method call/
51
+ end
52
+ return [500, {}, "Internal Server Error"] if output.nil? or output.size <= 0
53
+
54
+ response = Rack::Response.new
55
+ response.write output
56
+ response["Content-Type"] = "text/xml; charset=utf-8"
57
+ response.finish
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'xmlrpc/rack_server'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "xmlrpc-rack_server"
7
+ s.version = XMLRPC::RackServer::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nikolaos Anastopoulos"]
10
+ s.email = ["ebababi@ebababi.net"]
11
+ s.homepage = "https://github.com/ebababi/xmlrpc-rack_server"
12
+ s.summary = %q{Rack compatible XML-RPC server}
13
+ s.description = %q{Extends the Ruby standard library XMLRPC::BasicServer, providing the Rack compatible XMLRPC::RackServer.}
14
+ s.license = 'MIT'
15
+ s.has_rdoc = true
16
+ s.extra_rdoc_files = ['README']
17
+
18
+ #s.rubyforge_project = "xmlrpc-rack_server"
19
+
20
+ s.add_dependency 'rack'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xmlrpc-rack_server
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Nikolaos Anastopoulos
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-29 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Extends the Ruby standard library XMLRPC::BasicServer, providing the Rack compatible XMLRPC::RackServer.
35
+ email:
36
+ - ebababi@ebababi.net
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README
47
+ - Rakefile
48
+ - lib/xmlrpc/rack_server.rb
49
+ - xmlrpc-rack_server.gemspec
50
+ homepage: https://github.com/ebababi/xmlrpc-rack_server
51
+ licenses:
52
+ - MIT
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.10
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Rack compatible XML-RPC server
83
+ test_files: []
84
+