twitst4tz

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

rest_app_only_auth.js (2172B)


      1 var assert = require('assert')
      2 
      3 var config1 = require('../config1');
      4 var Twit = require('../lib/twitter');
      5 var checkReply = require('./rest').checkReply;
      6 var checkResponse = require('./rest').checkResponse;
      7 var checkTweet = require('./rest').checkTweet;
      8 
      9 describe('REST API using app-only auth', function () {
     10   var twit = null
     11   before(function () {
     12     var config = {
     13       consumer_key: config1.consumer_key,
     14       consumer_secret: config1.consumer_secret,
     15       app_only_auth: true,
     16     }
     17     twit = new Twit(config)
     18   })
     19 
     20   it('GET `application/rate_limit_status`', function (done) {
     21     twit.get('application/rate_limit_status', function (err, body, response) {
     22       checkReply(err, body)
     23       checkResponse(response)
     24       assert(body.rate_limit_context)
     25       done()
     26     })
     27   })
     28 
     29   it('GET `application/rate_limit_status with specific resource`', function (done) {
     30     var params = { resources: [ 'users', 'search' ]}
     31     twit.get('application/rate_limit_status', params, function (err, body, response) {
     32       checkReply(err, body)
     33       checkResponse(response)
     34       assert(body.rate_limit_context)
     35       assert(body.resources.search)
     36       assert.equal(Object.keys(body.resources).length, 2)
     37       done()
     38     })
     39   })
     40 
     41   it('GET `search/tweets` { q: "a", since_id: 12345 }', function (done) {
     42     var params = { q: 'a', since_id: 12345 }
     43     twit.get('search/tweets', params, function (err, reply, response) {
     44       checkReply(err, reply)
     45       assert.ok(reply.statuses)
     46       checkTweet(reply.statuses[0])
     47 
     48       checkResponse(response)
     49 
     50       done()
     51     })
     52   })
     53 
     54   it('GET `users/show` { screen_name: twitter } multiple times', function (done) {
     55     var index = 0
     56     var limit = 50
     57     var params = { screen_name: 'twitter' }
     58     var isDone = false;
     59 
     60     var getData = function () {
     61       twit.get('users/show', params, function (err, data) {
     62         if (data) {
     63           assert.equal(783214, data.id)
     64         } else {
     65           throw new Error(err)
     66         }
     67         index++
     68 
     69         if (index >= limit && !isDone) {
     70           isDone = true;
     71           done();
     72         }
     73       })
     74     }
     75 
     76     for (var i = 0; i <= limit; i++) {
     77       getData()
     78     }
     79   })
     80 })