Class: JsonRpcObjects::V10::Request

Inherits:
Generic::Request show all
Defined in:
lib/json-rpc-objects/v10/request.rb

Overview

Request object class.

Direct Known Subclasses

JsonRpcObjects::V11::WD::ProcedureCall

Constant Summary collapse

VERSION =

Holds link to its version module.

JsonRpcObjects::V10

Instance Attribute Summary collapse

Attributes inherited from Generic::Object

#serializer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic::Object

#initialize, parse, #serialize, #to_json, version

Constructor Details

This class inherits a constructor from JsonRpcObjects::Generic::Object

Instance Attribute Details

#idObject

Call (client) ID.

Returns:

  • (Object)


52
53
54
# File 'lib/json-rpc-objects/v10/request.rb', line 52

def id
  @id
end

#methodSymbol

Holds request method name.

Returns:

  • (Symbol)


36
37
38
# File 'lib/json-rpc-objects/v10/request.rb', line 36

def method
  @method
end

#paramsArray

Holds params for requested method.

Returns:

  • (Array)


44
45
46
# File 'lib/json-rpc-objects/v10/request.rb', line 44

def params
  @params
end

Class Method Details

.create(method, params = [ ], opts = { }) ⇒ V10::Request

Creates new one.

Parameters:

  • method (Symbol)

    of the request

  • params (Array) (defaults to: [ ])

    array of arguments for the request

  • opts (Hash) (defaults to: { })

    additional options

Returns:



64
65
66
67
68
69
70
71
72
# File 'lib/json-rpc-objects/v10/request.rb', line 64

def self.create(method, params = [ ], opts = { })
    data = {
        :method => method,
        :params => params
    }
    
    data.merge! opts
    return self::new(data)
end

Instance Method Details

#check!Object

Checks correctness of the request data.



78
79
80
81
82
# File 'lib/json-rpc-objects/v10/request.rb', line 78

def check!
    self.normalize!
    __check_method
    __check_params
end

#notification?Boolean

Indicates, it’s notification.

Returns:

  • (Boolean)

    true if it is, otherwise false



103
104
105
# File 'lib/json-rpc-objects/v10/request.rb', line 103

def notification?
    @id.nil?
end

#outputHash

Renders data to output hash.

Returns:

  • (Hash)

    with data of request



89
90
91
92
93
94
95
96
# File 'lib/json-rpc-objects/v10/request.rb', line 89

def output
    self.check!
    data = {
        "method" => @method.to_s,
        "params" => @params,
        "id" => @id
    }
end