Class: NotificationStanza

Inherits:
Skates::Base::Stanza
  • Object
show all
Defined in:
lib/stanzas/notification_stanza.rb

Overview

Notification : sent every time a feed has been fetched. It has the following methods:

  • message_status : a simple message that gives information about the last fetch

  • http_status : status of the http response

  • feed_url : url of the feed

  • next_fetch : Time when the feed will be fetched again (this is purely informative and it might change)

  • items : array of new items detected (might be empty)

<message xmlns="jabber:client" from="firehoser.superfeedr.com" to="julien@superfeedr.com">

<event xmlns="http://jabber.org/protocol/pubsub#event">
  <status xmlns="http://superfeedr.com/xmpp-pubsub-ext" feed="http://pubsubhubbub-example-app.appspot.com/feed">
    <http code="200">25002 bytes fetched in 0.73s for 1 new entries.</http>
    <next_fetch>2010-03-25T17:06:30+00:00</next_fetch>
    <title>PubSubHubBub example app</title>
  </status>
  <items node="http://pubsubhubbub-example-app.appspot.com/feed">
    <item xmlns="http://jabber.org/protocol/pubsub" chunks="1" chunk="1">
      <entry xmlns="http://www.w3.org/2005/Atom" xml:lang="" xmlns:xml="http://www.w3.org/XML/1998/namespace">
        <title>cool</title>
        <content type="text">cool</content>
        <id>tag:pubhubsubbub-example-app,2009:ahhwdWJzdWJodWJidWItZXhhbXBsZS1hcHByDQsSBUVudHJ5GMGOEAw</id>
        <published>2010-03-25T16:57:18Z</published>
        <link type="text/html" href="http://pubsubhubbub-example-app.appspot.com/ahhwdWJzdWJodWJidWItZXhhbXBsZS1hcHByDQsSBUVudHJ5GMGOEAw" title="" rel="alternate"/>
      </entry>
      <entry xmlns="http://www.w3.org/2005/Atom" xml:lang="" xmlns:xml="http://www.w3.org/XML/1998/namespace">
        <title>great</title>
        <content type="text">great</content>
        <id>tag:pubhubsubbub-example-app,2009:ahhwdWJzdWJodWJidWItZXhhbXBsZS1hcHByDQsSBUVudHJ5GMGOEAx</id>
        <published>2010-03-25T16:57:19Z</published>
        <link type="text/html" href="http://pubsubhubbub-example-app.appspot.com/ahhwdWJzdWJodWJidWItZXhhbXBsZS1hcHByDQsSBUVudHJ5GMGOEAx" title="" rel="alternate"/>
      </entry>
    </item>
  </items>
</event>

</message>

Constant Summary

XMLNS =
{
"ps" => "http://jabber.org/protocol/pubsub#event",
"ps2" => "http://jabber.org/protocol/pubsub",
"sf" => "http://superfeedr.com/xmpp-pubsub-ext" }

Instance Method Summary collapse

Instance Method Details

#entriesObject



267
268
269
270
271
272
273
274
275
# File 'lib/stanzas/notification_stanza.rb', line 267

def entries
  if !@entries
    @entries = []
    @node.xpath("./ps:event/ps:items/ps2:item", XMLNS).each do |node|
      @entries.push(Item.new(node))
    end
  end
  @entries
end

#feed_urlObject



255
256
257
# File 'lib/stanzas/notification_stanza.rb', line 255

def feed_url
  @feed_url ||= @node.at_xpath("./ps:event/sf:status/@feed", XMLNS).text
end

#http_statusObject



251
252
253
# File 'lib/stanzas/notification_stanza.rb', line 251

def http_status
  @http_status ||= @node.at_xpath("./ps:event/sf:status/sf:http/@code", XMLNS).text.to_i
end

#message_statusObject



259
260
261
# File 'lib/stanzas/notification_stanza.rb', line 259

def message_status
  @message_status ||= @node.at_xpath("./ps:event/sf:status/sf:http", XMLNS).text
end

#next_fetchObject



243
244
245
246
247
248
249
# File 'lib/stanzas/notification_stanza.rb', line 243

def next_fetch
  if !@next_fetch
    time = @node.at_xpath("./ps:event/sf:status/sf:next_fetch", XMLNS).text
    @next_fetch = Time.parse(time)
  end
  @next_fetch
end

#titleObject



263
264
265
# File 'lib/stanzas/notification_stanza.rb', line 263

def title
  @title ||= @node.at_xpath("./ps:event/sf:status/sf:title", XMLNS).text
end