Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

deprecated auth endpoint #1

Merged
merged 2 commits into from

2 participants

@tonyto

As the auth endpoint is deprecated, it was causing issues when trying to make requests to the api. As a result, I've removed the auth method completely, and made the api_token a mandatory parameter when a new Posterous object is created.

I've added some sample usage in the example folder.

@andzdroid andzdroid merged commit fa279b2 into andzdroid:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -1,3 +1,5 @@
*.swo
*.swp
tests/config/index.js
+*.log
+
View
8 examples/config/index.sample.js
@@ -0,0 +1,8 @@
+//To run the tests, rename this file to index.js
+//and fill in your posterous account details
+
+module.exports = {
+ user: '',
+ pass: ''
+ , api_token: ''
+};
View
13 examples/spec_site.js
@@ -0,0 +1,13 @@
+var Posterous = require('../index');
+var config = require('./config');
+
+var posterous = new Posterous(config.user, config.pass, config.api_token);
+
+console.log('Fetching user details...');
+posterous.get('Sites', {site_id: 'tonyto85'}, function(err, result) {
+ console.error(!err, 'An error occurred: ' + err);
+
+ console.log(result, 'Did not retrieve site information');
+
+ console.log(result);
+});
View
13 examples/spec_user.js
@@ -0,0 +1,13 @@
+var Posterous = require('../index');
+var config = require('./config');
+
+ var posterous = new Posterous(config.user, config.pass, config.api_token);
+
+ console.log('Fetching user details...');
+ posterous.get('User', null, function(err, result) {
+ console.error(!err, 'An error occurred: ' + err);
+
+ console.log(result, 'Did not retrieve user information');
+
+ console.log(result);
+ });
View
25 lib/posterous.js
@@ -6,9 +6,9 @@ var HOST = 'posterous.com';
var PATH = '/api/2/';
-var Posterous = function(user, pass) {
+var Posterous = function(user, pass, api_token) {
this._auth = 'Basic ' + new Buffer(user + ':' + pass).toString('base64');
- this._token = null;
+ this._token = api_token;
};
@@ -44,6 +44,7 @@ Posterous.prototype.request = function(method, api, args, callback) {
headers: headers
};
+ console.log('uri path: ' + reqOptions.path);
//Make request to Posterous API
var req = http.request(reqOptions, function apiRequest(res) {
//Gather response
@@ -81,6 +82,7 @@ Posterous.prototype.request = function(method, api, args, callback) {
};
Posterous.prototype.makeRequest = function(method, args) {
+console.log('in makeRequest trying');
if (args.length < 3) {
return console.error('[Posterous] You must pass arguments to the method.');
}
@@ -126,6 +128,7 @@ Posterous.prototype.makeRequest = function(method, args) {
Posterous.prototype.get = function() {
+ console.log('about to get');
this.makeRequest('GET', arguments);
};
@@ -141,22 +144,4 @@ Posterous.prototype.del = Posterous.prototype.delete = function() {
this.makeRequest('DELETE', arguments);
};
-
-//Get api token
-Posterous.prototype.auth = function(callback) {
- var t = this;
-
- this.request('GET', 'auth/token', null, function(err, result) {
- if (err) {
- return callback(err);
- }
-
- //Save api token
- t._token = result.api_token;
-
- callback(null, result.api_token);
- });
-};
-
-
module.exports = Posterous;
Something went wrong with that request. Please try again.