Sha256: 2a678f8ca6aa50b16ed988cba871d3b24f903f35ee9cd261628c358ad038e4e3

Contents?: true

Size: 1.84 KB

Versions: 34

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Janus
    # Modules for manipulate responses sending by Janus
    module Responses
      # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
      #
      # # 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.
      class Response
        # Instantiate a response
        #
        # @param [Hash] response_janus
        #   Request parsing after Janus/RabbitMQ receive a response to request
        #   sending by user
        def initialize(response_janus)
          @request = response_janus
        rescue
          raise Errors::Janus::Response::Initializer
        end

        # Return request to json format
        #
        # @return [String] Response to JSON format
        def to_json(*_args)
          @request.to_json
        rescue
          raise Errors::Janus::Response::ToJson
        end

        # Return request to json format with nice format
        #
        # @return [String] Response to JSON format with indent
        def to_nice_json
          JSON.pretty_generate to_hash
        rescue
          raise Errors::Janus::Response::ToNiceJson
        end

        # Return request to hash format
        #
        # @return [Hash] Response to Hash foramt
        def to_hash
          @request
        rescue
          raise Errors::Janus::Response::ToHash
        end

        # Test if response it's an error
        #
        # @return [Boolean]
        def error?
          @request['janus'].match?('error')
        end

        private

        attr_accessor :request
      end
    end
  end
end

require 'rrj/janus/responses/standard'
require 'rrj/janus/responses/admin'
require 'rrj/janus/responses/event'
require 'rrj/janus/responses/rspec'

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-3.0.0.pre.336 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-3.0.0.pre.335 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-3.0.0.pre.334 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-3.0.0.pre.330 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-3.0.0.pre.328 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-3.0.0.pre.327 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.322 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.320 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.319 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.318 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.317 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.316 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.315 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.314 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.312 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.310 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.309 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.308 lib/rrj/janus/responses/response.rb
ruby_rabbitmq_janus-2.7.2.pre.307 lib/rrj/janus/responses/response.rb