Skip to content

Instantly share code, notes, and snippets.

View AntonNguyen's full-sized avatar

Anton Nguyen AntonNguyen

View GitHub Profile
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.*;
import org.apache.http.entity.mime.content.*;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.StringEntity;
import javax.net.ssl.*;

The OAuth Dance with FreshBooks

Terminology

  • User - The FreshBooks account, whose information we are trying to access via OAuth
  • Consumer - The FreshBooks account, who we authorize to access the user's information
  • Consumer key - The consumer's subdomain, consumer_key.freshbooks.com
  • Consumer Secret - The consumer's secret, that we will use to make OAuth requests.
  • Request Token - A value used by the consumer to obtain authorization and an access token from the user.
  • Access Token - A value used by the consumer to access the user's information.
  • Access Token Secret - A secret used by the consumer to establish ownership of a given Token.
exports.create = function(req, res) {
Subscriptions
.saveToDatabase(req.body)
.then(function(subscription) {
return subscription.verify();
}).then(function(body) {
returnVerifyResponse(body, res);
}).fail(function(body) {
@AntonNguyen
AntonNguyen / gist:5349783
Created April 9, 2013 21:56
Writing Clean Code With Nested Promises

I'm writing an app that talks to Apple to verifyReceipts. They have both a sandbox and production url that you can post to.

When communicating with Apple, if you receive a 21007 status, it means you were posting to the production url, when you should be posting to the sandbox one.

So I wrote some code to facilitate the retry logic. Here's a simplified version of my code:

var request = require('request')
  , Q = require('q')
  ;