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 collapse

DEFAULT_PATH =
'/rpc'

Instance Attribute Summary collapse

Attributes inherited from Middleware

#app, #options

Instance Method Summary collapse

Constructor Details

#initialize(app, server, options = {}) ⇒ Endpoint

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

#serverServer (readonly)

Returns:



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

def server
  @server
end

Instance Method Details

#call(env) ⇒ Array

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

#pathString

Returns:

  • (String)


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

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