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.
150 151 152 153 154 155 |
# File 'lib/em-jsonrpc/server.rb', line 150 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.
148 149 150 |
# File 'lib/em-jsonrpc/server.rb', line 148 def id @id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
148 149 150 |
# File 'lib/em-jsonrpc/server.rb', line 148 def params @params end |
#rpc_method ⇒ Object (readonly)
Returns the value of attribute rpc_method.
148 149 150 |
# File 'lib/em-jsonrpc/server.rb', line 148 def rpc_method @rpc_method end |
Instance Method Details
#reply_custom_error(code, message) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/em-jsonrpc/server.rb', line 193 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
178 179 180 181 |
# File 'lib/em-jsonrpc/server.rb', line 178 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
188 189 190 191 |
# File 'lib/em-jsonrpc/server.rb', line 188 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
183 184 185 186 |
# File 'lib/em-jsonrpc/server.rb', line 183 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
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/em-jsonrpc/server.rb', line 157 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 |