Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial import of recurring into git.
- Loading branch information
C J Silverio
committed
Nov 14, 2012
0 parents
commit 3532ef1
Showing
24 changed files
with
1,728 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
config.json |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
// == Enforcing Options =============================================== | ||
// | ||
// These options tell JSHint to be more strict towards your code. Use | ||
// them if you want to allow only a safe subset of JavaScript, very | ||
// useful when your codebase is shared with a big number of developers | ||
// with different skill levels. | ||
|
||
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.). | ||
"curly" : false, // Require {} for every new block or scope. | ||
"eqeqeq" : true, // Require triple equals i.e. `===`. | ||
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`. | ||
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` | ||
"latedef" : true, // Prohibit variable use before definition. | ||
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. | ||
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. | ||
"noempty" : true, // Prohibit use of empty blocks. | ||
"nonew" : true, // Prohibit use of constructors for side-effects. | ||
"plusplus" : false, // Prohibit use of `++` & `--`. | ||
"regexp" : false, // Prohibit `.` and `[^...]` in regular expressions. | ||
"undef" : true, // Require all non-global variables be declared before they are used. | ||
"strict" : false, // Require `use strict` pragma in every file. | ||
"trailing" : true, // Prohibit trailing whitespaces. | ||
|
||
// == Relaxing Options ================================================ | ||
// | ||
// These options allow you to suppress certain types of warnings. Use | ||
// them only if you are absolutely positive that you know what you are | ||
// doing. | ||
|
||
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). | ||
"boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. | ||
"debug" : false, // Allow debugger statements e.g. browser breakpoints. | ||
"eqnull" : false, // Tolerate use of `== null`. | ||
"es5" : true, // Allow EcmaScript 5 syntax. | ||
"esnext" : false, // Allow ES.next specific features such as `const` and `let`. | ||
"evil" : false, // Tolerate use of `eval`. | ||
"expr" : true, // Tolerate `ExpressionStatement` as Programs. | ||
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside. | ||
"globalstrict" : false, // Allow global "use strict" (also enables 'strict'). | ||
"iterator" : false, // Allow usage of __iterator__ property. | ||
"lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block. | ||
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. | ||
"laxcomma" : true, // Suppress warnings about comma-first coding style. | ||
"loopfunc" : false, // Allow functions to be defined within loops. | ||
"multistr" : false, // Tolerate multi-line strings. | ||
"onecase" : false, // Tolerate switches with just one case. | ||
"proto" : false, // Tolerate __proto__ property. This property is deprecated. | ||
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`. | ||
"scripturl" : false, // Tolerate script-targeted URLs. | ||
"smarttabs" : true, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only. | ||
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. | ||
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. | ||
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`. | ||
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function. | ||
|
||
// == Environments ==================================================== | ||
// | ||
// These options pre-define global variables that are exposed by | ||
// popular JavaScript libraries and runtime environments—such as | ||
// browser or node.js. | ||
|
||
"browser" : false, // Standard browser globals e.g. `window`, `document`. | ||
"couch" : false, // Enable globals exposed by CouchDB. | ||
"devel" : false, // Allow development statements e.g. `console.log();`. | ||
"dojo" : false, // Enable globals exposed by Dojo Toolkit. | ||
"jquery" : false, // Enable globals exposed by jQuery JavaScript library. | ||
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework. | ||
"node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment. | ||
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape. | ||
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework. | ||
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment. | ||
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host. | ||
|
||
// == JSLint Legacy =================================================== | ||
// | ||
// These options are legacy from JSLint. Aside from bug fixes they will | ||
// not be improved in any way and might be removed at any point. | ||
|
||
"nomen" : false, // Prohibit use of initial or trailing underbars in names. | ||
"onevar" : false, // Allow only one `var` statement per function. | ||
"passfail" : false, // Stop on first error. | ||
"white" : false, // Check against strict whitespace and indentation rules. | ||
|
||
// == Undocumented Options ============================================ | ||
// | ||
// While I've found these options in [example1][2] and [example2][3] | ||
// they are not described in the [JSHint Options documentation][4]. | ||
// | ||
// [4]: http://www.jshint.com/options/ | ||
|
||
"maxerr" : 100, // Maximum errors before stopping. | ||
"predef" : [ // Extra globals. | ||
//"exampleVar", | ||
//"anotherCoolGlobal", | ||
//"iLoveDouglas" | ||
], | ||
"indent" : 4 // Specify indentation spacing | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2012 C J Silverio | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
A node client for [recurly](https://recurly.com)'s v2 api, with support for secure parameter signing for [recurly.js](https://docs.recurly.com/recurlyjs) embedded forms. | ||
|
||
__This code is still in development and is not ready for production use.__ In particular, the example usage below might radically change. | ||
|
||
## Recurly API | ||
|
||
A work in progress. | ||
|
||
```javascript | ||
var recurly = require('recurring'); | ||
recurly.setAPIKey('your-api-key'); | ||
|
||
var account = new recurly.Account('account-id'); | ||
account.fetch(function(err) | ||
{ | ||
account.fetchSubscriptions(function(err, subscriptions) | ||
{ | ||
console.log(subscriptions[0].plan); | ||
}); | ||
}); | ||
|
||
recurly.Account.all(function(accounts) | ||
{ | ||
// accounts is an array containing all customer accounts | ||
}); | ||
|
||
recurly.Plan.all(function(plans) | ||
{ | ||
// plans is an array containing all plans set up for your account | ||
}); | ||
|
||
``` | ||
|
||
## SignedQuery | ||
|
||
This provides the back-end support for signing parameters for forms embedded using recurly.js. See Recurly's [signature documentation](https://docs.recurly.com/api/recurlyjs/signatures) for details on which parameters must be signed for each form type. | ||
|
||
```javascript | ||
var recurly = require('recurring'); | ||
|
||
var signer = new recurly.SignedQuery('your-private-api-key'); | ||
signer.set('account', { account_code: 'account-id' }); | ||
var signedParameters = signer.toString(); | ||
``` | ||
|
||
The `nonce` & `timestamp` parameters are generated for you if you don't provide them. The nonce is created using [node-uuid](https://github.com/broofa/node-uuid). | ||
|
||
## License | ||
|
||
MIT. See accompanying LICENSE file. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var recurly = require('./recurly'); | ||
|
||
exports.setAPIKey = recurly.setAPIKey; | ||
exports.Account = recurly.Account; | ||
exports.Addon = recurly.Addon; | ||
exports.BillingInfo = recurly.BillingInfo; | ||
exports.Coupon = recurly.Coupon; | ||
exports.FormResponseToken = recurly.FormResponseToken; | ||
exports.Invoice = recurly.Invoice; | ||
exports.Plan = recurly.Plan; | ||
exports.Subscription = recurly.Subscription; | ||
exports.Transaction = recurly.Transaction; | ||
|
||
exports.SignedQuery = require('./signer').SignedQuery; | ||
exports.createParser = require('./parser').createParser; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/*jshint node:true */ | ||
|
||
var | ||
assert = require('assert'), | ||
querystring = require('querystring'), | ||
xml2js = require('xml2js') | ||
; | ||
|
||
|
||
function parseTypes(input) | ||
{ | ||
var result = {}; | ||
var item, key; | ||
var keys = Object.keys(input); | ||
var mode = 'normal'; | ||
|
||
try | ||
{ | ||
for (var i = 0; i < keys.length; i++) | ||
{ | ||
key = keys[i]; | ||
item = input[key]; | ||
|
||
if (mode === 'array') | ||
{ | ||
mode = 'normal'; | ||
|
||
if (Array.isArray(item)) | ||
{ | ||
result = []; | ||
for (var j = 0; j < item.length; j++) | ||
result.push(parseTypes(item[j])); | ||
} | ||
else | ||
result = [ parseTypes(item) ]; | ||
|
||
} | ||
else if (typeof item === 'object') | ||
{ | ||
if (item['#'] && item.type && (item.type === 'datetime')) | ||
result[key] = new Date(item['#']); | ||
else if (item['#'] && item.type && (item.type === 'integer')) | ||
result[key] = parseInt(item['#'], 10); | ||
else if (item['#'] && item.type && (item.type === 'boolean')) | ||
result[key] = ( item.type['#'] === 'true' ? true : false ); | ||
else if (item.nil && (item.nil === 'nil')) | ||
result[key] = ''; | ||
else | ||
result[key] = parseTypes(item); | ||
} | ||
else if ((typeof item === 'string') && (key === 'type')) | ||
mode = 'array'; // this is pure hackery | ||
else | ||
result[key] = item; | ||
} | ||
} | ||
catch (exception) | ||
{ | ||
// console.error('recurly.parseTypes: @ ' + key + ' ' + item + ' ' + JSON.stringify(exception)); | ||
result = input; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function RecurlyParser() | ||
{ | ||
this.parser = new xml2js.Parser( | ||
{ | ||
mergeAttrs: true, | ||
attrkey: '#', | ||
charkey: '#', | ||
explicitArray: false, | ||
explicitRoot: false, | ||
}); | ||
} | ||
|
||
RecurlyParser.prototype.parseXML = function(input, callback) | ||
{ | ||
this.parser.parseString(input, function (err, json) | ||
{ | ||
if (err) | ||
return callback(err); | ||
|
||
callback(null, parseTypes(json)); | ||
}); | ||
}; | ||
|
||
function createParser() | ||
{ | ||
return new RecurlyParser(); | ||
|
||
} | ||
|
||
exports.createParser = createParser; |
Oops, something went wrong.