Class: RubyRabbitmqJanus::Janus::Responses::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rrj/janus/responses/response.rb

Overview

# Read and parse a response to janus.

Read a message in rabbitmq queue. This message is formatted to JSON or Hash format. For developpment it’s possible to used a ‘nice` JSON.

Author:

Direct Known Subclasses

Standard

Instance Method Summary collapse

Constructor Details

#initialize(response_janus) ⇒ Response

Instantiate a response

Parameters:

  • response_janus (Hash)

    Request parsing after Janus/RabbitMQ receive a response to request sending by user



19
20
21
22
23
24
# File 'lib/rrj/janus/responses/response.rb', line 19

def initialize(response_janus)
  @request = response_janus

  errors      if error?
  bad_request if bad_request?
end

Instance Method Details

#error_codeObject

Return request error code

@return [Integer] Code error


50
51
52
# File 'lib/rrj/janus/responses/response.rb', line 50

def error_code
  @request['error']['code'].to_i
end

#error_reasonObject

Return request error reason

@return [String] Reason error


57
58
59
# File 'lib/rrj/janus/responses/response.rb', line 57

def error_reason
  @request['error']['reason']
end

#janusObject

Read field Janus in response message



62
63
64
# File 'lib/rrj/janus/responses/response.rb', line 62

def janus
  request['janus']
end

#to_hashHash

Return request to hash format

Returns:

  • (Hash)

    Response to Hash format



43
44
45
# File 'lib/rrj/janus/responses/response.rb', line 43

def to_hash
  @request
end

#to_json(*_args) ⇒ String

Return request to json format

Returns:

  • (String)

    Response to JSON format



29
30
31
# File 'lib/rrj/janus/responses/response.rb', line 29

def to_json(*_args)
  @request.to_json
end

#to_nice_jsonString

Return request to json format with nice format

Returns:

  • (String)

    Response to JSON format with indent



36
37
38
# File 'lib/rrj/janus/responses/response.rb', line 36

def to_nice_json
  JSON.pretty_generate to_hash
end