lib/api.js
function Api(options, schema) {
	var prop, resourceOptions, resourceConstructor;
	var apiRoot = this;

	// Set default options for any unsupplied overrides
	_.defaults(options, config);
	this.options = options;
	this.schema = schema;

	configureSchemaFromEnv(this.schema);

	// Creates a constructor with the pre-built resource as its prototype
	// this is syntactic sugar to allow callers to new up the resources.
	function createResourceConstructor(resourcePrototype) {
		function APIResource(resourceOptions) {
			// Allow creating resources without `new` keyword
			if (!(this instanceof APIResource)) {
				return new APIResource(resourceOptions);
			}

			resourceOptions = resourceOptions || {};
			// Override any default options for all requests on this resource
			_.defaults(resourceOptions.defaultParams,
				apiRoot.options.defaultParams);
			_.defaults(resourceOptions.headers,
				apiRoot.options.headers);
			_.defaults(resourceOptions, apiRoot.options);

			this.format = resourceOptions.format;
			this.logger = resourceOptions.logger;
			this.defaultParams = resourceOptions.defaultParams;
			this.headers = resourceOptions.headers;
		}

		APIResource.prototype = resourcePrototype;
		return APIResource;
	}

	for (prop in schema.resources) {
		if (schema.resources.hasOwnProperty(prop)) {
			resourceOptions = options;
			resourceOptions.api = this;
			resourceOptions.resourceDefinition =
				schema.resources[prop];

			this[prop] = createResourceConstructor(
				new Resource(resourceOptions, schema));
		}
	}

	this['OAuth'] = createResourceConstructor(new OAuth(options));
}
function Api(options, schema) {
	var prop, resourceOptions, resourceConstructor;
	var apiRoot = this;

	// Set default options for any unsupplied overrides
	_.defaults(options, config);
	this.options = options;
	this.schema = schema;

	configureSchemaFromEnv(this.schema);

	// Creates a constructor with the pre-built resource as its prototype
	// this is syntactic sugar to allow callers to new up the resources.
	function createResourceConstructor(resourcePrototype) {
		function APIResource(resourceOptions) {
			// Allow creating resources without `new` keyword
			if (!(this instanceof APIResource)) {
				return new APIResource(resourceOptions);
			}

			resourceOptions = resourceOptions || {};
			// Override any default options for all requests on this resource
			_.defaults(resourceOptions.defaultParams,
				apiRoot.options.defaultParams);
			_.defaults(resourceOptions.headers,
				apiRoot.options.headers);
			_.defaults(resourceOptions, apiRoot.options);

			this.format = resourceOptions.format;
			this.logger = resourceOptions.logger;
			this.defaultParams = resourceOptions.defaultParams;
			this.headers = resourceOptions.headers;
		}

		APIResource.prototype = resourcePrototype;
		return APIResource;
	}

	for (prop in schema.resources) {
		if (schema.resources.hasOwnProperty(prop)) {
			resourceOptions = options;
			resourceOptions.api = this;
			resourceOptions.resourceDefinition =
				schema.resources[prop];

			this[prop] = createResourceConstructor(
				new Resource(resourceOptions, schema));
		}
	}

	this['OAuth'] = createResourceConstructor(new OAuth(options));
}
function Api ( options , schema ) { var prop , resourceOptions , resourceConstructor ; var apiRoot = this ; // Set default options for any unsupplied overrides _ . defaults ( options , config ) ; this . options = options ; this . schema = schema ; configureSchemaFromEnv ( this . schema ) ; // Creates a constructor with the pre-built resource as its prototype // this is syntactic sugar to allow callers to new up the resources. function createResourceConstructor ( resourcePrototype ) { function APIResource ( resourceOptions ) { // Allow creating resources without `new` keyword if ( ! ( this instanceof APIResource ) ) { return new APIResource ( resourceOptions ) ; } resourceOptions = resourceOptions || { } ; // Override any default options for all requests on this resource _ . defaults ( resourceOptions . defaultParams , apiRoot . options . defaultParams ) ; _ . defaults ( resourceOptions . headers , apiRoot . options . headers ) ; _ . defaults ( resourceOptions , apiRoot . options ) ; this . format = resourceOptions . format ; this . logger = resourceOptions . logger ; this . defaultParams = resourceOptions . defaultParams ; this . headers = resourceOptions . headers ; } APIResource . prototype = resourcePrototype ; return APIResource ; } for ( prop in schema . resources ) { if ( schema . resources . hasOwnProperty ( prop ) ) { resourceOptions = options ; resourceOptions . api = this ; resourceOptions . resourceDefinition = schema . resources [ prop ] ; this [ prop ] = createResourceConstructor ( new Resource ( resourceOptions , schema ) ) ; } } this [ 'OAuth' ] = createResourceConstructor ( new OAuth ( options ) ) ; }
API  Creates a new API wrapper from a schema definition  - @param {Object} options - The API options, see below - @param {Object} schema - The definition of the api resources and actions see the assets/7digital-api-schema json file.  - @constructor - @param {Object} options  The options parameter should have the following properties:  - `consumerkey` your application's oauth consumer key - `consumersecret` your application's oauth consumer secret - `format` the response format - `logger` a logger instance for output
API Creates a new API wrapper from a schema definition -