Class: Rack::RPC::Endpoint

Inherits:
Middleware show all
Defined in:
lib/rack/rpc/endpoint.rb,
lib/rack/rpc/endpoint/jsonrpc.rb,
lib/rack/rpc/endpoint/xmlrpc.rb

Overview

A Rack middleware for RPC endpoints.

Defined Under Namespace

Modules: JSONRPC, XMLRPC

Constant Summary

DEFAULT_PATH =
'/rpc'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Endpoint) initialize(app, server, options = {})

Returns a new instance of Endpoint

Parameters:

  • app (#call)
  • server (Server)
  • options (Hash) (defaults to: {})


21
22
23
24
# File 'lib/rack/rpc/endpoint.rb', line 21

def initialize(app, server, options = {})
  @server = server
  super(app, options)
end

Instance Attribute Details

- (#call) app (readonly) Originally defined in class Middleware

Returns:

  • (#call)

- (Hash) options (readonly) Originally defined in class Middleware

Returns:

  • (Hash)

- (Server) server (readonly)

Returns:



11
12
13
# File 'lib/rack/rpc/endpoint.rb', line 11

def server
  @server
end

Instance Method Details

- (Array) call(env)

Parameters:

  • env (Hash)

Returns:

  • (Array)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rack/rpc/endpoint.rb', line 35

def call(env)
  return super unless env['PATH_INFO'].eql?(path)
  return super unless env['REQUEST_METHOD'].eql?('POST')
  case content_type = env['CONTENT_TYPE']
    when %r(^application/xml), %r(^text/xml)
      XMLRPC::Server.new(server).execute(Rack::Request.new(env)).finish
    when %r(^application/json)
      JSONRPC::Server.new(server).execute(Rack::Request.new(env)).finish
    else super
  end
end

- (String) path

Returns:

  • (String)


28
29
30
# File 'lib/rack/rpc/endpoint.rb', line 28

def path
  @path ||= options[:path] || DEFAULT_PATH
end