Sha256: c92c787f9a7f24847e0b00f886f13c2a8fc046f311ffdf58e120e287caa5c981

Contents?: true

Size: 1012 Bytes

Versions: 9

Compression:

Stored size: 1012 Bytes

Contents

class Syncano
  module Packets
    # Class representing call packets used in communication with the Sync Server
    class Call < Syncano::Packets::Base
      attr_reader :message_id, :resource_name, :method_name, :data

      # Constructor for Syncano::Packets::Call object
      # @param [Hash] attributes
      def initialize(attributes)
        super(attributes)
        self.resource_name = attributes[:resource_name]
        self.method_name = attributes[:method_name]
        self.data = attributes[:data]
        self.message_id = attributes[:message_id] || rand(10**12)
      end

      # Overwritten method for preparing hash for json serialization
      # @param [Hash] options
      # @return [Hash]
      def as_json(options = {})
        {
          type: 'call',
          method: "#{resource_name}.#{method_name}",
          params: data,
          message_id: message_id.to_s
        }
      end

      private

      attr_writer :message_id, :resource_name, :method_name, :data
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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