class NchanTools::Message

Attributes

content_type[RW]
etag[RW]
eventsource_event[RW]
last_modified[RW]
message[RW]
times_seen[RW]

Public Class Methods

each_multipart_message(content_type, body) { |mm, mm, true| ... } click to toggle source
# File lib/nchan_tools/pubsub.rb, line 91
def self.each_multipart_message(content_type, body)
  content_type = content_type.last if Array === content_type 
  matches=/^multipart\/mixed; boundary=(?<boundary>.*)/.match content_type
  
  if matches
    splat = body.split(/^--#{Regexp.escape matches[:boundary]}-?-?\r?\n?/)
    splat.shift
    
    splat.each do |v|
      mm=(/(Content-Type:\s(?<content_type>.*?)\r\n)?\r\n(?<body>.*)\r\n/m).match v
      yield mm[:content_type], mm[:body], true
    end
    
  else
    yield content_type, body
  end
end
new(msg, last_modified=nil, etag=nil) click to toggle source
# File lib/nchan_tools/pubsub.rb, line 52
def initialize(msg, last_modified=nil, etag=nil)
  @times_seen=1
  @message, @last_modified, @etag = msg, last_modified, etag
  @idhist = []
end

Public Instance Methods

==(msg) click to toggle source
# File lib/nchan_tools/pubsub.rb, line 87
def ==(msg)
  @message == (msg.respond_to?(:message) ? msg.message : msg)
end
id() click to toggle source
# File lib/nchan_tools/pubsub.rb, line 69
def id
  @id||=serverside_id
end
id=(val) click to toggle source
# File lib/nchan_tools/pubsub.rb, line 66
def id=(val)
  @id=val.dup
end
length() click to toggle source
# File lib/nchan_tools/pubsub.rb, line 84
def length
  self.to_s.length
end
serverside_id() click to toggle source
# File lib/nchan_tools/pubsub.rb, line 57
def serverside_id
  timestamp=nil
  if last_modified
    timestamp = DateTime.httpdate(last_modified).to_time.utc.to_i
  end
  if last_modified || etag
    "#{timestamp}:#{etag}"
  end
end
to_s() click to toggle source
# File lib/nchan_tools/pubsub.rb, line 81
def to_s
  @message
end
unique_id() click to toggle source
# File lib/nchan_tools/pubsub.rb, line 72
def unique_id
  if id && id.include?(",")
    time, etag = id.split ":"
    etag = etag.split(",").map{|x| x[0] == "[" ? x : "?"}.join "," #]
    [time, etag].join ":"
  else
    id
  end
end