├── package.json ├── index.js └── README.md /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "twitter-kv", 3 | "description": "Short lived key-value store using Twitter user feeds.", 4 | "version": "0.0.3", 5 | "repository": { 6 | "url": "git://github.com/noffle/twitter-kv.git" 7 | }, 8 | "main": "index.js", 9 | "scripts": { 10 | "test": "tape test/*.js" 11 | }, 12 | "dependencies": { 13 | "latest-tweets": "^0.1.5" 14 | }, 15 | "devDependencies": { 16 | "tape": "*" 17 | }, 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var tweets = require('latest-tweets') 2 | 3 | module.exports = function (user, key, cb) { 4 | if (!user) return new Error('missing username') 5 | if (!key) return new Error('missing key') 6 | 7 | tweets(user, function (err, res) { 8 | if (err) return cb(err) 9 | 10 | var value = null 11 | res.forEach(function (tweet) { 12 | if (tweet.content) { 13 | var m = tweet.content.match(/(.*) = (.*)/) 14 | if (m) { 15 | var k = m[1] 16 | var v = m[2] 17 | if (k === key) { 18 | // console.log('match for', k, '=', v) 19 | if (!value) { 20 | value = v 21 | } 22 | } 23 | } else { 24 | // console.log('no match') 25 | } 26 | } else { 27 | // console.log('bad content', tweet) 28 | } 29 | }) 30 | 31 | cb(null, value) 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # twitter-kv 2 | 3 | > Short lived key-value store using Twitter user feeds. 4 | 5 | ## Background 6 | 7 | Sometimes you'd like to store a simple (key, value) mapping for a short time 8 | using a service that's already running and is highly available -- like Twitter. 9 | 10 | *No access tokens required!* 11 | 12 | Since HTTP scraping is used under the hood in 13 | [`latest-tweets`](https://github.com/noffle/latest-tweets), only the last couple 14 | dozen tweets will be available, making this ideal for use as a transient store. 15 | 16 | ## Usage 17 | 18 | ```js 19 | var resolve = require('twitter-kv') 20 | 21 | resolve('noffle', 'test', function (err, value) { 22 | if (err) return console.log(err) 23 | 24 | console.log('value:', value) 25 | }) 26 | ``` 27 | 28 | This will look for a recent tweet in my timeline of the format 29 | 30 | ``` 31 | key = value 32 | ``` 33 | 34 | If it finds it -- let's say I have a tweet that says `foo = bar` -- I can expect 35 | the following output 36 | 37 | ``` 38 | value: bar 39 | ``` 40 | 41 | ## API 42 | 43 | ```js 44 | var twitterKv = require('twitter-kv') 45 | ``` 46 | 47 | ### resolve(user, key, cb) 48 | 49 | Queries the twitter user feed for `user`, looking for an entry of the form `key 50 | = value`. Calls `cb(err, value)` with the most recent value for `key`. Expect 51 | `key` to be `null` if no value was found. 52 | 53 | ## Install 54 | 55 | With [npm](https://npmjs.org/) installed, run 56 | 57 | ``` 58 | $ npm install twitter-kv 59 | ``` 60 | 61 | ## See Also 62 | 63 | - [latest-tweets](https://github.com/noffle/latest-tweets) 64 | 65 | ## License 66 | 67 | ISC 68 | 69 | --------------------------------------------------------------------------------