chirp-rest
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -13,3 +13,3 @@ var ChirpRest = require('./'); | ||
}); | ||
/* | ||
//get user timeline | ||
@@ -29,2 +29,8 @@ twitter.get('https://api.twitter.com/1.1/statuses/user_timeline.json', function(err, res, body) { | ||
//get user timeline count = 10 | ||
twitter.get('https://api.twitter.com/1.1/statuses/user_timeline.json?count=10', function(err, res, body) { | ||
console.log(err); | ||
console.log(body.length); | ||
}); | ||
/* | ||
//post new status | ||
@@ -31,0 +37,0 @@ twitter.post('https://api.twitter.com/1.1/statuses/update.json', { |
77
index.js
var qs = require('querystring'); | ||
var debug = require('debug')('chirp-rest'); | ||
var request = require('request'); | ||
var OAuth = require('oauth-1.0a'); | ||
var debug = require('debug')('chirp-rest'); | ||
var OAuth = require('oauth-request'); | ||
@@ -26,3 +25,4 @@ module.exports = ChirpRest; | ||
this.oauth = OAuth({ | ||
consumer: this.consumer | ||
consumer: this.consumer, | ||
token: this.token | ||
}); | ||
@@ -38,21 +38,3 @@ } | ||
/** | ||
* send api request | ||
* @param {Object} opt | ||
* @param {Function} callback | ||
* | ||
* @api private | ||
*/ | ||
ChirpRest.prototype._api = function(opt, callback) { | ||
//enable json | ||
opt.json = true; | ||
this._log('api', opt); | ||
request(opt, callback); | ||
}; | ||
ChirpRest.prototype.get = function(url, param, callback) { | ||
var self = this; | ||
if(arguments.length === 2) { | ||
@@ -71,12 +53,8 @@ callback = param; | ||
var request_data = { | ||
url: url, | ||
method: 'GET', | ||
data: param | ||
}; | ||
this._log('#get', url, param); | ||
self._api({ | ||
this.oauth.get({ | ||
url: url, | ||
method: 'GET', | ||
qs: self.oauth.authorize(request_data, self.token) | ||
qs: param, | ||
json: true | ||
}, callback); | ||
@@ -101,40 +79,9 @@ }; | ||
var request_data = { | ||
url: url, | ||
method: 'POST', | ||
data: param | ||
}; | ||
this._log('#post', url, param); | ||
/* | ||
LOL this shit take me a whole day ! | ||
Cant use !!! | ||
self._api({ | ||
this.oauth.post({ | ||
url: url, | ||
method: 'POST', | ||
form: self.oauth.authorize(request_data, self.token) | ||
form: param, | ||
json: true | ||
}, callback); | ||
below is the correct way | ||
*/ | ||
var body = qs.stringify(self.oauth.authorize(request_data, self.token)) | ||
.replace(/\-/g, "%2D") | ||
.replace(/\_/g, "%5F") | ||
.replace(/\./g, "%2E") | ||
.replace(/\!/g, "%21") | ||
.replace(/\*/g, "%2A") | ||
.replace(/\'/g, "%27") | ||
.replace(/\(/g, "%28") | ||
.replace(/\)/g, "%29"); | ||
self._api({ | ||
url: url, | ||
method: 'POST', | ||
body: body, | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
} | ||
}, callback); | ||
}; |
{ | ||
"name": "chirp-rest", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "twitter rest apis in nodejs", | ||
@@ -27,4 +27,3 @@ "main": "index.js", | ||
"debug": "^0.8.1", | ||
"oauth-1.0a": "^0.1.0", | ||
"request": "^2.36.0" | ||
"oauth-request": "0.0.1" | ||
}, | ||
@@ -31,0 +30,0 @@ "devDependencies": { |
@@ -46,3 +46,3 @@ var expect = require('chai').expect; | ||
var tweet_id; | ||
var message = 'Yay....!!!'; | ||
var message = 'Yay_-....!!!'; | ||
@@ -49,0 +49,0 @@ describe("#post new tweet", function() { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
0
10683
165
+ Addedoauth-request@0.0.1
+ Addedoauth-request@0.0.1(transitive)
- Removedoauth-1.0a@^0.1.0
- Removedrequest@^2.36.0