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=“[email protected]”>

<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>

Instance Method Summary collapse

Instance Method Details

#entriesObject



247
248
249
250
251
252
253
254
255
# File 'lib/stanzas/notification_stanza.rb', line 247

def entries
  if !@entries
    @entries = []
    @node.xpath("./ps:event/ps:items/ps2:item", {"ps" => "http://jabber.org/protocol/pubsub#event", "ps2" => "http://jabber.org/protocol/pubsub"}).each do |node|
      @entries.push(Item.new(node))
    end
  end
  @entries
end

#feed_urlObject



239
240
241
# File 'lib/stanzas/notification_stanza.rb', line 239

def feed_url
  @feed_url ||= @node.at_xpath("./ps:event/sf:status/@feed", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).text
end

#http_statusObject



235
236
237
# File 'lib/stanzas/notification_stanza.rb', line 235

def http_status
  @http_status ||= @node.at_xpath("./ps:event/sf:status/sf:http/@code", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).text.to_i
end

#message_statusObject



243
244
245
# File 'lib/stanzas/notification_stanza.rb', line 243

def message_status
  @message_status ||= @node.at_xpath("./ps:event/sf:status/sf:http", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).text
end

#next_fetchObject



227
228
229
230
231
232
233
# File 'lib/stanzas/notification_stanza.rb', line 227

def next_fetch
  if !@next_fetch
    time = @node.at_xpath("./ps:event/sf:status/sf:next_fetch", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).text
    @next_fetch = Time.parse(time)
  end
  @next_fetch
end