Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit f1aaa2573e429f7014ec84a78e401db6138174f1 0 parents
@adamalex adamalex authored
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules
+.idea
1  .npmignore
@@ -0,0 +1 @@
+/node_modules/
21 COPYING
@@ -0,0 +1,21 @@
+Copyright (C) 2013, ExactTarget, Inc.
+All rights reserved.
+
+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.
+
+====================================================================
83 README.md
@@ -0,0 +1,83 @@
+# mashery
+
+Client for Mashery API
+
+## Getting Started
+Install the module with: `npm install mashery`
+
+```javascript
+// Load and configure the module
+var mashery = require('mashery').configure({
+ url: 'https://api.mashery.com/v2/json-rpc/000',
+ key: 'xxxxxxxxxxxxxxxxxxxxxxxx',
+ secret: 'xxxxxxxxxx'
+});
+
+// Prepare the request
+var parameters = {
+ service_key: 'xxxxxxxxxxxxxxxxxxxxxxxx',
+ client: {
+ client_id: 'xxxxxxxxxxxxxxxxxxxxxxxx',
+ client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxx'
+ },
+ token_data: {
+ grant_type: 'client_credentials'
+ }
+};
+
+// Call the API (this example creates an OAuth token)
+mashery('oauth2.createAccessToken', parameters, function (error, response, body) {
+ if (error) {
+ console.log(error);
+ } else {
+ console.log(body);
+ }
+});
+```
+
+## Release History
+
+_This module is semantically versioned: <http://semver.org>_
+
+### Version 0.1.0 `2013-01-06`
+
+* Initial release
+
+## Contributing
+Before writing code, we suggest you [search for issues](https://github.com/ExactTarget/node-mashery/issues?state=open)
+or [create a new one](https://github.com/ExactTarget/node-mashery/issues/new) to confirm where your contribution fits into
+our roadmap.
+
+In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
+Lint and test your code using [grunt](https://github.com/cowboy/grunt).
+
+## Acknowledgements
+
+We are grateful to the following maintainers, contributors, and sponsors of the technologies used by this module.
+
+* [Node.js](http://nodejs.org)
+
+* [Request](https://github.com/mikeal/request) (De facto HTTP request module for Node)
+
+* [grunt](https://github.com/cowboy/grunt) (Build tool for JavaScript projects)
+
+##Authors
+
+**Adam Alexander**
+
++ http://twitter.com/adamalex
++ http://github.com/adamalex
+
+## Copyright and license
+
+Copyright (c) 2013 ExactTarget
+
+Licensed under the MIT License (the "License");
+you may not use this work except in compliance with the License.
+You may obtain a copy of the License in the COPYING file.
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
40 grunt.js
@@ -0,0 +1,40 @@
+module.exports = function (grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: '<json:package.json>',
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'default'
+ },
+ jshint: {
+ options: {
+ curly: false,
+ strict: false,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true
+ },
+ globals: {
+ exports: true
+ }
+ }
+ });
+
+ // Default task.
+ grunt.registerTask('default', 'lint test');
+
+};
68 lib/mashery.js
@@ -0,0 +1,68 @@
+/*
+ * mashery
+ * https://github.com/ExactTarget/node-mashery
+ *
+ * Copyright (c) 2013 ExactTarget
+ * Licensed under the MIT license.
+ */
+
+var crypto = require('crypto');
+var request = require('request');
+
+function mashery(method, params, config, callback) {
+
+ if (!callback) {
+ callback = config;
+ config = {};
+ }
+
+ if (!mashery._validateConfig(config, callback)) return;
+
+ var signature = mashery._signature(config, Date.now());
+ var requestUrl = [config.url, '?apikey=', config.key, '&sig=', signature].join('');
+
+ var command = {
+ jsonrpc: '2.0',
+ method: method,
+ params: params,
+ id: 1
+ };
+
+ var requestOptions = {
+ url: requestUrl,
+ method: 'POST',
+ body: command,
+ json: true
+ };
+
+ return mashery._performRequest(requestOptions, callback);
+}
+
+mashery.configure = function (config) {
+ return function (method, params, callback) {
+ return mashery(method, params, config, callback);
+ };
+};
+
+mashery._validateConfig = function (config, callback) {
+ var message = 'mashery not configured - missing url, key, or secret';
+
+ if (config.url && config.key && config.secret) {
+ return true;
+ } else {
+ callback(new Error(message));
+ return false;
+ }
+};
+
+mashery._signature = function (config, now) {
+ var timestamp = Math.floor(now / 1000);
+ var composite = config.key + config.secret + timestamp;
+ return crypto.createHash('md5').update(composite).digest("hex");
+};
+
+mashery._performRequest = function (requestOptions, callback) {
+ return request(requestOptions, callback);
+};
+
+module.exports = mashery;
40 package.json
@@ -0,0 +1,40 @@
+{
+ "name": "mashery",
+ "description": "Client for Mashery API",
+ "version": "0.1.0",
+ "homepage": "https://github.com/ExactTarget/node-mashery",
+ "author": {
+ "name": "ExactTarget",
+ "email": "aalexander@exacttarget.com",
+ "url": "http://code.exacttarget.com"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/ExactTarget/node-mashery.git"
+ },
+ "bugs": {
+ "url": "https://github.com/ExactTarget/node-mashery/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/ExactTarget/node-mashery/blob/master/COPYING"
+ }
+ ],
+ "main": "lib/mashery",
+ "engines": {
+ "node": ">= 0.6.0"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.17"
+ },
+ "keywords": [
+ "mashery"
+ ],
+ "dependencies": {
+ "request": "~2.12.0"
+ }
+}
32 test/mashery_test.js
@@ -0,0 +1,32 @@
+var mashery = require('../lib/mashery.js');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+ */
+
+exports['modulefunction'] = {
+ setUp: function (done) {
+ done();
+ },
+ 'test': function (test) {
+ test.expect(1);
+ test.equal(typeof mashery, 'function', 'module should be a function');
+ test.done();
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.