Class: NchanTools::Message
- Inherits:
-
Object
- Object
- NchanTools::Message
- Defined in:
- lib/nchan_tools/pubsub.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#eventsource_event ⇒ Object
Returns the value of attribute eventsource_event.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
-
#message ⇒ Object
Returns the value of attribute message.
-
#times_seen ⇒ Object
Returns the value of attribute times_seen.
Class Method Summary collapse
Instance Method Summary collapse
- #==(msg) ⇒ Object
- #id ⇒ Object
- #id=(val) ⇒ Object
-
#initialize(msg, last_modified = nil, etag = nil) ⇒ Message
constructor
A new instance of Message.
- #length ⇒ Object
- #serverside_id ⇒ Object
- #to_s ⇒ Object
- #unique_id ⇒ Object
Constructor Details
#initialize(msg, last_modified = nil, etag = nil) ⇒ Message
Returns a new instance of Message.
52 53 54 55 56 |
# File 'lib/nchan_tools/pubsub.rb', line 52 def initialize(msg, last_modified=nil, etag=nil) @times_seen=1 , @last_modified, @etag = msg, last_modified, etag @idhist = [] end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
51 52 53 |
# File 'lib/nchan_tools/pubsub.rb', line 51 def content_type @content_type end |
#etag ⇒ Object
Returns the value of attribute etag.
51 52 53 |
# File 'lib/nchan_tools/pubsub.rb', line 51 def etag @etag end |
#eventsource_event ⇒ Object
Returns the value of attribute eventsource_event.
51 52 53 |
# File 'lib/nchan_tools/pubsub.rb', line 51 def eventsource_event @eventsource_event end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
51 52 53 |
# File 'lib/nchan_tools/pubsub.rb', line 51 def last_modified @last_modified end |
#message ⇒ Object
Returns the value of attribute message.
51 52 53 |
# File 'lib/nchan_tools/pubsub.rb', line 51 def end |
#times_seen ⇒ Object
Returns the value of attribute times_seen.
51 52 53 |
# File 'lib/nchan_tools/pubsub.rb', line 51 def times_seen @times_seen end |
Class Method Details
.each_multipart_message(content_type, body) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/nchan_tools/pubsub.rb', line 91 def self.(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 |
Instance Method Details
#==(msg) ⇒ Object
87 88 89 |
# File 'lib/nchan_tools/pubsub.rb', line 87 def ==(msg) == (msg.respond_to?(:message) ? msg. : msg) end |
#id ⇒ Object
69 70 71 |
# File 'lib/nchan_tools/pubsub.rb', line 69 def id @id||=serverside_id end |
#id=(val) ⇒ Object
66 67 68 |
# File 'lib/nchan_tools/pubsub.rb', line 66 def id=(val) @id=val.dup end |
#length ⇒ Object
84 85 86 |
# File 'lib/nchan_tools/pubsub.rb', line 84 def length self.to_s.length end |
#serverside_id ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/nchan_tools/pubsub.rb', line 57 def serverside_id =nil if last_modified = DateTime.httpdate(last_modified).to_time.utc.to_i end if last_modified || etag "#{timestamp}:#{etag}" end end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/nchan_tools/pubsub.rb', line 81 def to_s end |
#unique_id ⇒ Object
72 73 74 75 76 77 78 79 80 |
# 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 |