GoogleBlogs.js
Go to the documentation of this file.
1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
2 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
3 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
4 
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cr = Components.results;
8 
9 const DESCRIPTION = "mashTape Provider: Google Blog Search Provider";
10 const CID = "{3814ef10-7a19-11dd-ad8b-0800200c9a66}";
11 const CONTRACTID = "@songbirdnest.com/mashTape/provider/rss/GoogleBlogs;1";
12 
13 // XPCOM constructor for our Yahoo News mashTape provider
14 function GoogleBlogs() {
15  Components.utils.import("resource://mashtape/mtUtils.jsm");
16  this.wrappedJSObject = this;
17 }
18 
19 GoogleBlogs.prototype.constructor = GoogleBlogs;
20 GoogleBlogs.prototype = {
22  classID: Components.ID(CID),
24  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMashTapeRSSProvider,
25  Ci.sbIMashTapeProvider]),
26 
27  providerName: "Google Blog Search",
28  providerUrl: "http://blogsearch.google.com",
29  providerType: "rss",
30  providerIcon: "chrome://mashtape/content/tabs/google.png",
31 
32  query: function(searchTerms, updateFn) {
33  var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
34  .createInstance(Ci.nsIXMLHttpRequest);
35  var url = "http://blogsearch.google.com/blogsearch_feeds?hl=en&c2coff=1&lr=lang_en&safe=off&q=%22" + searchTerms + "&ie=utf-8&num=10&output=rss";
36  mtUtils.log("Google Blogs", "URL:" + url);
37  req.open("GET", url, true);
38  req.provider = this;
39  req.updateFn = updateFn;
40  req.onreadystatechange = function() {
41  if (this.readyState != 4)
42  return;
43  if (this.status == 200) {
44  var x = new XML(this.responseText.replace(
45  '<?xml version="1.0" encoding="UTF-8"?>', ""));
46 
47  var dcNs = new Namespace("http://purl.org/dc/elements/1.1/");
48  var results = new Array();
49  for each (var entry in x..item) {
50  var dateObj = new Date();
51  dateObj.setISO8601(entry.dcNs::date);
52  var item = {
53  title: entry.title,
54  time: dateObj.getTime(),
55  provider: this.provider.providerName,
56  providerUrl: this.provider.providerUrl,
57  url: entry.link,
58  content: entry.description,
59  }
60  results.push(item);
61  }
62 
63  results.wrappedJSObject = results;
64  this.updateFn.wrappedJSObject.update(CONTRACTID, results);
65  }
66  }
67  req.send(null);
68  },
69 }
70 
71 var components = [GoogleBlogs];
72 function NSGetModule(compMgr, fileSpec) {
73  return XPCOMUtils.generateModule([GoogleBlogs]);
74 }
75 
classDescription entry
Definition: FeedWriter.js:1427
function GoogleBlogs()
Definition: GoogleBlogs.js:14
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
const Cr
Definition: GoogleBlogs.js:7
const Ci
Definition: GoogleBlogs.js:6
function NSGetModule(compMgr, fileSpec)
Definition: GoogleBlogs.js:72
const DESCRIPTION
Definition: GoogleBlogs.js:9
return null
Definition: FeedWriter.js:1143
const Cc
Definition: GoogleBlogs.js:5
function url(spec)
sbDeviceFirmwareAutoCheckForUpdate prototype classID
const CONTRACTID
Definition: GoogleBlogs.js:11
const CID
Definition: GoogleBlogs.js:10