Class: Cheezmiz::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = nil) ⇒ Message

Returns a new instance of Message.



25
26
27
28
29
30
31
32
33
34
# File 'lib/protocol/message.rb', line 25

def initialize(params = nil)
  if params.respond_to?(:each_pair)
    @params = params
  else
    @params, @sequence_number = decode(params)
    @prototype = params
  end
  check_params @params if self.respond_to? :check_params
  @options = populate_from(@params)
end

Class Method Details

.parse(stream) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/protocol/message.rb', line 36

def self.parse(stream)
  message = case stream
    when /^CTPv1\.[123] Kamusta/ then ConnectionEstablished.new stream
    when /^30:/ then BuddyListBegin.new stream
    when /^31:/ then BuddyInformation.new stream
    when /^39:/ then BuddyListEnd.new stream
    when /^40:/ then KeepAliveRequest.new stream
    when /^41:/ then AccountInformation.new stream
    when /^51:/ then LoginResponse.new stream
    when /^55:/ then SystemMessage.new stream
    when /^64:/ then SubmitResponse.new stream
    else                 UnknownOperation.new stream
    end
  message
end

Instance Method Details

#data_fieldsObject



56
57
58
# File 'lib/protocol/message.rb', line 56

def data_fields
  @params
end

#operationObject



60
61
62
# File 'lib/protocol/message.rb', line 60

def operation
  self.class.simple_name.underscore.to_sym
end

#prototypeObject



64
65
66
# File 'lib/protocol/message.rb', line 64

def prototype
  @prototype || "#{header}#{data}"
end

#sequence_numberObject



52
53
54
# File 'lib/protocol/message.rb', line 52

def sequence_number
  @sequence_number
end