twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

user_stream.js (1049B)


      1 var assert = require('assert')
      2 var Twit = require('../lib/twitter')
      3 var config1 = require('../config1')
      4 var streaming = require('./streaming')
      5 
      6 //verify `friendsMsg` is a twitter 'friends' message object
      7 function checkFriendsMsg (friendsMsg) {
      8     var friendIds = friendsMsg.friends
      9 
     10     assert(friendIds)
     11     assert(Array.isArray(friendIds))
     12     assert(friendIds[0])
     13 }
     14 
     15 describe('user events', function () {
     16     it('friends', function (done) {
     17         var twit = new Twit(config1);
     18         var stream = twit.stream('user');
     19 
     20         //make sure we're connected to the right endpoint
     21         assert.equal(stream.reqOpts.url, 'https://userstream.twitter.com/1.1/user.json')
     22 
     23         stream.on('friends', function (friendsMsg) {
     24             checkFriendsMsg(friendsMsg)
     25 
     26             stream.stop()
     27             done()
     28         })
     29 
     30         stream.on('connect', function () {
     31             console.log('\nuser stream connecting..')
     32         })
     33 
     34         stream.on('connected', function () {
     35             console.log('user stream connected.')
     36         })
     37     })
     38 })