Skip to content

Instantly share code, notes, and snippets.

@alandotcom
Created November 25, 2012 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandotcom/4142405 to your computer and use it in GitHub Desktop.
Save alandotcom/4142405 to your computer and use it in GitHub Desktop.
SuperFeedr PubSubHubbub API inside a Rails App

Structure of the JSON response from SuperFeedr

When working with the SuperFeedr REST API it is important to understand the notifications that SuperFeedr will send to your server.

I am using th JSON response here, as the format is familiar and easy to parse using the Ruby API.

Receiving feed updates

After successfully subscribing to a feed, SuperFeedr will send notifications to the callback URI specified during the subscription process.

The notification will be in the form of a POST request to your server. The response body will contain the data. In this case, I specified JSON during the subscription process, therefore, I receive my notifications as JSON.

The JSON response body is accessible via the params environment variable, when working within the Rails environment.

Params contains the JSON data from SuperFeedr

params["items"] #=> returns array of "items" hashes

Items hash

Keys:

["id",
 "published",
 "updated",
 "title",
 "summary",
 "permalinkUrl",
 "standardLinks"]

ID

Contains a unique description of the item => "gellies-bicycle-handlebar-grips-blue-or-purple-1-free-shipping-2012-11-25t03-09-32z"

Published and Updated

Date-time of published date 1353812972

*Not sure about this format

Title

Item title Gellies Bicycle Handlebar Grips (Blue or Purple) $1 + Free Shipping

Summary

Not clear what this is for <img src=\"http://feeds.feedburner.com/~r/SlickdealsnetFP/~4/WvH9t0qK684\" height=\"1\" width=\"1\"/>"

Might be feed-specific

permaLinkUrl

Contains a permalinkURL if one exists http://feedproxy.google.com/~r/SlickdealsnetFP/~3/WvH9t0qK684/84194

standardLinks

Contains a hash of additional links, including the originals.

{"alternate"=>
  [{"title"=>
     "Gellies Bicycle Handlebar Grips (Blue or Purple) $1 + Free Shipping",
    "rel"=>"alternate",
    "href"=>
     "http://feedproxy.google.com/~r/SlickdealsnetFP/~3/WvH9t0qK684/84194",
    "type"=>"text/html"}],
 "replies"=>
  [{"title"=>
     "Gellies Bicycle Handlebar Grips (Blue or Purple) $1 + Free Shipping",
    "rel"=>"replies",
    "href"=>"http://forums.slickdeals.net/showthread.php?threadid=5574034",
    "type"=>"text/html"}],
 "canonical"=>
  [{"title"=>
     "Gellies Bicycle Handlebar Grips (Blue or Purple) $1 + Free Shipping",
    "rel"=>"canonical",
    "href"=>"http://slickdeals.net/permadeal/84194",
    "type"=>"text/html"}]}

params["status"]

The request from SuperFeedr also includes information about the feed.

params["status"]
=> {"code"=>200,
 "http"=>"Fetched (ring) 200 and parsed 7/8 entries",
 "nextFetch"=>1353816615,
 "entriesCountSinceLastMaintenance"=>318,
 "period"=>900,
 "lastFetch"=>1353815715,
 "lastParse"=>1353815715,
 "lastMaintenanceAt"=>1353769339,
 "feed"=>"http://feeds.feedburner.com/SlickdealsnetHT"}

One more example

params["items"].first #=>

{"id"=>
  "canon-pixma-mx892-all-in-one-office-inkjet-printer-69-free-shipping-no-tax-in-ca-just-ny-pays-tax-5-replies--2012-11-24t22-55-32z",
 "published"=>1353797732,
 "updated"=>1353797732,
 "title"=>
  "Canon PIXMA MX892 All-In-One Office Inkjet Printer $69 + Free Shipping (No Tax in CA just NY pays tax) (5 replies)",
 "summary"=>
  "<img src=\"http://feeds.feedburner.com/~r/SlickdealsnetHT/~4/Z17IMn-N7Mo\" height=\"1\" width=\"1\"/>",
 "permalinkUrl"=>
  "http://feedproxy.google.com/~r/SlickdealsnetHT/~3/Z17IMn-N7Mo/showthread.php",
 "standardLinks"=>
  {"alternate"=>
    [{"title"=>
       "Canon PIXMA MX892 All-In-One Office Inkjet Printer $69 + Free Shipping (No Tax in CA just NY pays tax) (5 replies)",
      "rel"=>"alternate",
      "href"=>
       "http://feedproxy.google.com/~r/SlickdealsnetHT/~3/Z17IMn-N7Mo/showthread.php",
      "type"=>"text/html"}],
   "canonical"=>
    [{"title"=>
       "Canon PIXMA MX892 All-In-One Office Inkjet Printer $69 + Free Shipping (No Tax in CA just NY pays tax) (5 replies)",
      "rel"=>"canonical",
      "href"=>"http://forums.slickdeals.net/showthread.php?t=5573588",
      "type"=>"text/html"}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment