Sha256: b26c4cf4ec57e80493997e3943c53de1a2a3e49b7d377664fbc52d2a18a2cb1d

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

class Syncano
  # Module used as a scope for classes representing packets
  module Packets
    # Base class for representing packets used in communication with the Sync Server
    class Base
      attr_reader :object, :timestamp

      # Constructor for Syncano::Packets::Base object
      # @param [Hash] attributes
      def initialize(attributes)
        super()
        self.timestamp = attributes[:timestamp]
        self.object = attributes[:object]
      end

      # Proxy method for creating instance of proper subclass
      # @param [Hash] data
      # @return [Syncano::Packets::Base]
      def self.instantize_packet(data)
        mapping = {
          auth: ::Syncano::Packets::Auth,
          call: ::Syncano::Packets::Call,
          callresponse: ::Syncano::Packets::CallResponse,
          error: ::Syncano::Packets::Error,
          message: ::Syncano::Packets::Message,
          new: ::Syncano::Packets::Notification,
          change: ::Syncano::Packets::Notification,
          delete: ::Syncano::Packets::Notification,
          ping: ::Syncano::Packets::Ping
        }

        mapping[data[:type].to_sym].new(data)
      end

      # Returns true if is a notification packet
      # @return [TrueClass, FalseClass]
      def notification?
        false
      end

      # Returns true if is a ping packet
      # @return [TrueClass, FalseClass]
      def ping?
        false
      end

      # Returns true if is a call response packet
      # @return [TrueClass, FalseClass]
      def call_response?
        false
      end

      # Returns true if is a message packet
      # @return [TrueClass, FalseClass]
      def message?
        false
      end

      private

      attr_writer :object, :timestamp
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
syncano-3.1.1.beta lib/syncano/packets/base.rb