Sha256: e0f769df686ccb5de70cd7d63e8199f278d31308b28627f13ac660f1a1e35714

Contents?: true

Size: 1.83 KB

Versions: 8

Compression:

Stored size: 1.83 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

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

      private

      attr_writer :object, :timestamp
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
syncano-3.1.4 lib/syncano/packets/base.rb
syncano-3.1.3 lib/syncano/packets/base.rb
syncano-3.1.2 lib/syncano/packets/base.rb
syncano-3.1.1 lib/syncano/packets/base.rb
syncano-3.1.1.beta5 lib/syncano/packets/base.rb
syncano-3.1.1.beta4 lib/syncano/packets/base.rb
syncano-3.1.1.beta3 lib/syncano/packets/base.rb
syncano-3.1.1.beta2 lib/syncano/packets/base.rb