Sha256: 73d22c871653b3dd4ef48d928bad84d7c1a3325e80f96357d87bf99a8dc088c7

Contents?: true

Size: 1.47 KB

Versions: 60

Compression:

Stored size: 1.47 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)
          if agent && !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

60 entries across 60 versions & 1 rubygems

Version Path
isomorfeus-transport-23.9.0.rc12 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc11 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc10 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc9 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc8 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc7 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc6 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc5 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc4 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc3 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc2 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.9.0.rc1 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.8.0.rc3 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.8.0.rc2 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.8.0.rc1 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.7.0.rc5 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.7.0.rc4 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.7.0.rc3 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.7.0.rc2 lib/isomorfeus/transport/client_processor.rb
isomorfeus-transport-23.7.0.rc1 lib/isomorfeus/transport/client_processor.rb