Class: RubyRabbitmqJanus::Janus::Response
- Inherits:
-
Object
- Object
- RubyRabbitmqJanus::Janus::Response
- Defined in:
- lib/rrj/janus/response.rb
Overview
Read and decryt a response to janus
Instance Method Summary collapse
-
#analysis ⇒ Object
private
Analysis response and send exception if janus return an error :reek:DuplicateMethodCall.
-
#data_id ⇒ Object
private
Read a hash and return an identifier.
-
#error_plugin? ⇒ Boolean
private
Test if message response contains an error in plugin.
-
#error_simple? ⇒ Boolean
private
Test if message response contains an simple error.
-
#for_plugin ⇒ Object
Return a response simple for client.
-
#initialize(response_janus) ⇒ Response
constructor
Instanciate a response.
-
#sender ⇒ Object
Return a integer to handle.
-
#session ⇒ Object
Return a integer to session.
-
#to_hash ⇒ Object
Return request to hash format.
-
#to_json ⇒ Object
Return request to json format.
-
#to_nice_json ⇒ Object
Return request to json format with nice format.
Constructor Details
#initialize(response_janus) ⇒ Response
Instanciate a response
9 10 11 12 13 14 15 16 |
# File 'lib/rrj/janus/response.rb', line 9 def initialize(response_janus) @request = response_janus rescue => error Tools::Log.instance.debug "Request error : #{@request}" raise Errors::JanusResponseInit, error else Tools::Log.instance.debug "Response return : #{to_json}" end |
Instance Method Details
#analysis ⇒ Object (private)
Analysis response and send exception if janus return an error :reek:DuplicateMethodCall
77 78 79 80 |
# File 'lib/rrj/janus/response.rb', line 77 def analysis raise Errors::JanusResponseSimple, @request['error'] if error_simple? raise Errors::JanusResponsePlugin, @request['plugindata']['data'] if error_plugin? end |
#data_id ⇒ Object (private)
Read a hash and return an identifier
68 69 70 71 72 73 |
# File 'lib/rrj/janus/response.rb', line 68 def data_id analysis @request['data']['id'].to_i rescue => error raise Errors::JanusResponseDataId, error end |
#error_plugin? ⇒ Boolean (private)
Test if message response contains an error in plugin
88 89 90 |
# File 'lib/rrj/janus/response.rb', line 88 def error_plugin? @request.key?('plugindata') && @request['plugindata']['data'].key?('error_code') end |
#error_simple? ⇒ Boolean (private)
Test if message response contains an simple error
83 84 85 |
# File 'lib/rrj/janus/response.rb', line 83 def error_simple? @request['janus'].equal? 'error' end |
#for_plugin ⇒ Object
Return a response simple for client
45 46 47 48 49 50 51 52 53 |
# File 'lib/rrj/janus/response.rb', line 45 def for_plugin case @request['janus'] when 'success' then @request['plugindata']['data'] when 'ack' then {} end rescue => error Tools::Log.instance.debug "Request error : #{@request}" raise Errors::JanusResponsePluginData, error end |
#sender ⇒ Object
Return a integer to handle
61 62 63 |
# File 'lib/rrj/janus/response.rb', line 61 def sender data_id end |
#session ⇒ Object
Return a integer to session
56 57 58 |
# File 'lib/rrj/janus/response.rb', line 56 def session data_id end |
#to_hash ⇒ Object
Return request to hash format
36 37 38 39 40 41 42 |
# File 'lib/rrj/janus/response.rb', line 36 def to_hash analysis @request rescue => error Tools::Log.instance.debug "Request error : #{@request}" raise Errors::JanusResponseHash, error end |
#to_json ⇒ Object
Return request to json format
19 20 21 22 23 24 25 |
# File 'lib/rrj/janus/response.rb', line 19 def to_json analysis @request.to_json rescue => error Tools::Log.instance.debug "Request error : #{@request}" raise Errors::JanusResponseJson, error end |
#to_nice_json ⇒ Object
Return request to json format with nice format
28 29 30 31 32 33 |
# File 'lib/rrj/janus/response.rb', line 28 def to_nice_json JSON.pretty_generate to_hash rescue => error Tools::Log.instance.debug "Request error : #{@request}" raise Errors::JanusResponsePrettyJson, error end |