Last active
August 29, 2015 14:12
-
-
Save getflourish/af086151146d20a2a20f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var request = require('request'), | |
| query = require('querystring'), | |
| args = require('optimist'). | |
| options('key', { alias: 'k' }). | |
| options('secret', { alias: 's' }). | |
| options('signature', { alias: 'm', default: "HMAC-SHA1" }). | |
| argv; | |
| var options = { | |
| url: 'https://secure.splitwise.com/api/v3.0/get_request_token', | |
| method: 'POST' | |
| }; | |
| if (!args.key) | |
| throw new Error('Missing Consumer Key! -key cli option'); | |
| if (!args.secret) | |
| throw new Error('Missing Consumer Secret! -secret cli option'); | |
| request({ | |
| method: 'POST', | |
| uri: 'http://localhost:3000/store', | |
| form: { | |
| oauth_consumer_key: args.key, | |
| oauth_consumer_secret: args.secret, | |
| oauth_signature_method: args.signature, | |
| oauth_callback: "oob", | |
| oauth_version: "1.0" | |
| } | |
| }, function (error, response, body) { | |
| if (error) return console.log(error); | |
| body = JSON.parse(body); | |
| request({ | |
| method: 'POST', | |
| uri: 'http://localhost:3000/start', | |
| form: { | |
| hash: body.hash, | |
| // Request Details | |
| method: options.method, | |
| url: options.url | |
| }, | |
| followAllRedirects: true | |
| }, function (error, response, body) { | |
| var auth = JSON.parse(body).authorization; | |
| var req = request({ | |
| method: options.method, | |
| uri: options.url, | |
| headers: { | |
| "Authorization": auth | |
| } | |
| }, function (error, response, body) { | |
| console.log(body); | |
| }); | |
| console.log(req.headers); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment