Class: EventMachine::JsonRPC::Server::Request
- Inherits:
-
Object
- Object
- EventMachine::JsonRPC::Server::Request
- Defined in:
- lib/em-jsonrpc/server.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#rpc_method ⇒ Object
readonly
Returns the value of attribute rpc_method.
Instance Method Summary collapse
-
#initialize(conn, id, rpc_method, params) ⇒ Request
constructor
A new instance of Request.
- #reply_custom_error(code, message) ⇒ Object
- #reply_internal_error(message = nil) ⇒ Object
- #reply_invalid_params(message = nil) ⇒ Object
- #reply_method_not_found(message = nil) ⇒ Object
- #reply_result(result) ⇒ Object
Constructor Details
#initialize(conn, id, rpc_method, params) ⇒ Request
Returns a new instance of Request.
143 144 145 146 147 148 |
# File 'lib/em-jsonrpc/server.rb', line 143 def initialize(conn, id, rpc_method, params) @conn = conn @id = id @rpc_method = rpc_method @params = params end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
141 142 143 |
# File 'lib/em-jsonrpc/server.rb', line 141 def id @id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
141 142 143 |
# File 'lib/em-jsonrpc/server.rb', line 141 def params @params end |
#rpc_method ⇒ Object (readonly)
Returns the value of attribute rpc_method.
141 142 143 |
# File 'lib/em-jsonrpc/server.rb', line 141 def rpc_method @rpc_method end |
Instance Method Details
#reply_custom_error(code, message) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/em-jsonrpc/server.rb', line 186 def reply_custom_error(code, ) return nil if @conn.error? unless code.is_a? Integer and (-32099..-32000).include? code raise ArgumentError, "code must be an integer between -32099 and -32000" end @conn.reply_error(@id, code, ) end |
#reply_internal_error(message = nil) ⇒ Object
171 172 173 174 |
# File 'lib/em-jsonrpc/server.rb', line 171 def reply_internal_error(=nil) return nil if @conn.error? @conn.reply_error(@id, CODE_INTERNAL_ERROR, || MSG_INTERNAL_ERROR) end |
#reply_invalid_params(message = nil) ⇒ Object
181 182 183 184 |
# File 'lib/em-jsonrpc/server.rb', line 181 def reply_invalid_params(=nil) return nil if @conn.error? @conn.reply_error(@id, CODE_INVALID_PARAMS, || MSG_INVALID_PARAMS) end |
#reply_method_not_found(message = nil) ⇒ Object
176 177 178 179 |
# File 'lib/em-jsonrpc/server.rb', line 176 def reply_method_not_found(=nil) return nil if @conn.error? @conn.reply_error(@id, CODE_METHOD_NOT_FOUND, || MSG_METHOD_NOT_FOUND) end |
#reply_result(result) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/em-jsonrpc/server.rb', line 150 def reply_result(result) return nil if @conn.error? response = { KEY_JSONRPC => VALUE_VERSION, KEY_ID => @id, KEY_RESULT => result } # Send the response in chunks (good in case of a big response). begin @conn.encoder.encode(response) do |chunk| @conn.send_data(chunk) end return true rescue Yajl::EncodeError => e reply_internal_error "response encode error: #{e.}" return false end end |