Sha256: 1dcb4cf10f9ab7ceeb3422f1fd3addd4b0a03b71b233b8640d580881a9d7ad4a

Contents?: true

Size: 1.53 KB

Versions: 37

Compression:

Stored size: 1.53 KB

Contents

module Isomorfeus
  module Transport
    class ClientProcessor
      def self.process(json_hash)
        if json_hash.key?(:response)
          process_response(json_hash)
        elsif json_hash.key?(:notification)
          process_message(json_hash)
        end
      end

      def self.process_message(message_hash)
        processor_class_name = message_hash[:notification][:class]
        Isomorfeus.raise_error(message: "Not a valid channel class #{processor_class_name}!") unless Isomorfeus.valid_channel_class_name?(processor_class_name)
        processor_class = Isomorfeus.cached_channel_class(processor_class_name)
        unless processor_class.respond_to?(:process_message)
          Isomorfeus.raise_error(message: "Cannot process message, #{processor_class} must be a Channel and must have the on_message block defined!")
        end
        processor_class.process_message(message_hash[:notification][:message], message_hash[:notification][:error], message_hash[:notification][:channel])
      end

      def self.process_response(response_hash)
        response_hash[:response][:agent_ids].keys.each do |agent_id|
          agent = Isomorfeus::Transport::RequestAgent.get!(agent_id)
          Isomorfeus::Transport.unregister_request_in_progress(agent_id)
          unless agent.promise.realized?
            agent.full_response = response_hash
            agent.response = response_hash[:response][:agent_ids][agent_id]
            agent.promise.resolve(agent)
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
isomorfeus-transport-2.2.1 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.2.0 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.1.1 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.1.0 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.22 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.21 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.20 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.19 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.18 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.17 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.16 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.15 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.14 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.13 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.12 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.11 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.10 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.9 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.8 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-2.0.7 lib/isomorfeus/transport/client_processor.rb