Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
101 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var request = require('request') | ||
, TWITTER_API_URL = 'http://urls.api.twitter.com/1/urls/count.json?url={url}' | ||
|
||
var TwitterStats = { | ||
processLibrary: function (lib, callback) { | ||
request( | ||
TWITTER_API_URL.replace('{url}', encodeURIComponent(lib.url)) | ||
, function (err, response, body) { | ||
if (err) | ||
return this.error( | ||
lib | ||
, 'Error requesting tweet count from Twitter for ' + lib.url + ': ' + err | ||
, callback | ||
) | ||
var data = JSON.parse(body) | ||
|
||
if (typeof data.count == 'number') { | ||
callback(null, data) | ||
} else { | ||
this.warn(lib, 'Couldn\'t get tweet count from Twitter API') | ||
callback() | ||
} | ||
}.bind(this) | ||
) | ||
} | ||
} | ||
|
||
module.exports.create = function (main, config) { | ||
var twitterStats = Object.create(TwitterStats) | ||
twitterStats.warn = main.warn.bind(main) | ||
twitterStats.error = main.error.bind(main) | ||
return twitterStats | ||
} |
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.