Skip to content

Commit 966d863

Browse files
author
Hovhannes Babayan
committed
added documentation
1 parent 945d0da commit 966d863

11 files changed

Lines changed: 315 additions & 140 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ node_modules
88

99
# coverage reporter output
1010
coverage
11+
docs

README.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,83 @@
11
# attask-api
2-
[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url] [![Coverage][coveralls-image]][coveralls-url]
2+
[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![Apache v2 License][license-image]][license-url] [![Build Status][travis-image]][travis-url] [![Coverage][coveralls-image]][coveralls-url]
33

44
An AtTask API for the Node and Web
55

6+
7+
## Status
8+
9+
This is currently work in progress. Package will be published to NPM registry once everything will be ready. Use source code at your own risk.
10+
11+
612
## Usage
713

8-
This is currently work in progress. Do not try to use this in development or production.
9-
This section will be updated and package will be published to NPM registry once everything will be ready.
14+
#### Server-side usage
15+
16+
Install as a dev dependency:
17+
18+
npm install attask-api --save-dev
19+
20+
Then `require('attask-api')` in your code. For example:
21+
```javascript
22+
var attask = require('attask-api'),
23+
util = require('util');
24+
25+
/**
26+
* The console.log statement below will output the following:
27+
* {
28+
* Api: [Function: Api],
29+
* ApiFactory: [Object],
30+
* ApiUtil: [Object],
31+
* ApiConstants: [Object]
32+
* }
33+
*/
34+
console.log(util.inspect(attask, {depth:0}));
35+
```
36+
37+
#### In a browser
38+
39+
This package uses [Browserify](http://browserify.org) to generate [dist/attask.min.js](dist/attask.min.js). Loading that script will create `window.AtTask` object which will contain all the classes and methods just as in the server-side environment (see [Server-side usage](#server-side-usage) section).
40+
This package makes use of [Promises](https://www.promisejs.org). Promises are not currently supported by all browsers (see [kangax compatibility tables](http://kangax.github.io/compat-table/es6/#Promise) but there are many polyfills available, including one listed in [www.promisejs.org](https://www.promisejs.org). Load polyfill before `attask.min.js` and everything will work just fine.
41+
Although the lack of CORS support may prevent you from sending request to AtTask servers, there are some usage examples in [examples/browser](examples/browser) folder to give you an idea.
42+
43+
44+
## Documentation
45+
46+
API documentation is available at [http://bhovhannes.github.io/attask-api/](http://bhovhannes.github.io/attask-api/).
47+
48+
49+
## Examples
50+
51+
A number of examples can be found under [examples](examples) directory. It includes examples for both [node](examples/node) and [browser](examples/browser) environments.
52+
In order to run these examples clone a copy of attask-api repository:
53+
54+
git clone git://github.com/bhovhannes/attask-api.git
55+
56+
#### Running [node](examples/node) examples
57+
58+
First enter into `attask-api` directory and install all the dependencies:
59+
60+
cd attask-api
61+
npm install
62+
63+
Use `node` to run the examples. For examples:
64+
65+
node examples/node/get-use-count.js
66+
67+
Each example script outputs all its results into console and contains comments in the source code explaining what is happenning in more details.
68+
69+
#### Running [browser](examples/browser) examples
70+
71+
There is a separate [Gulp](http://gulpjs.com) task for starting web server.
72+
To start webserver type:
73+
74+
node ./node_modules/gulp/bin/gulp.js serve
75+
76+
or, if you have Gulp installed globally, just:
77+
78+
gulp serve
79+
80+
Visit [http://localhost:8000/examples/browser/](http://localhost:8000/examples/browser/) to see list of all examples available for browser.
1081

1182

1283
[license-image]: http://img.shields.io/badge/license-APv2-blue.svg?style=flat

gulpfile.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
var gulp = require('gulp');
22

33
const BUILD_DIR = './dist/';
4+
const DOCS_DIR = './docs/';
45
const COVERAGE_DIR = 'coverage';
56

67
gulp.task('default', ['build']);
78

8-
gulp.task('clean', ['clean-coverage', 'clean-build']);
9+
/**
10+
* Empties BUILD_DIR, DOCS_DIR and cleans coverage data
11+
*/
12+
gulp.task('clean', ['clean-coverage', 'clean-build', 'clean-docs']);
913

1014
/**
1115
* Empties BUILD_DIR
1216
*/
1317
gulp.task('clean-build', function(cb) {
1418
var del = require('del');
15-
del([BUILD_DIR + '*', COVERAGE_DIR], cb);
19+
del([BUILD_DIR + '*'], cb);
1620
});
1721

1822
/**
@@ -23,6 +27,14 @@ gulp.task('clean-coverage', function(cb) {
2327
del([COVERAGE_DIR], cb);
2428
});
2529

30+
/**
31+
* Empties DOCS_DIR
32+
*/
33+
gulp.task('clean-docs', function(cb) {
34+
var del = require('del');
35+
del([DOCS_DIR + '*'], cb);
36+
});
37+
2638

2739
/**
2840
* Generates browser-ready version for API in BUILD_DIR
@@ -47,7 +59,30 @@ gulp.task('build', ['clean-build'], function() {
4759
.pipe(gulp.dest(BUILD_DIR));
4860
});
4961

62+
/**
63+
* Generate documentation in ./docs/ directory
64+
*/
65+
gulp.task('docs', ['clean-docs'], function() {
66+
var jsdoc = require("gulp-jsdoc");
67+
return gulp.src(["src/**/*.js", "README.md"])
68+
.pipe(
69+
jsdoc(DOCS_DIR, {
70+
path: 'ink-docstrap',
71+
systemName: 'AtTask',
72+
//footer: "Something",
73+
//copyright: "Something",
74+
navType: "vertical",
75+
theme: "united",
76+
linenums: true,
77+
collapseSymbols: false,
78+
inverseNav: false
79+
})
80+
)
81+
});
5082

83+
/**
84+
* Opens web server in a project directory
85+
*/
5186
gulp.task('serve', function() {
5287
var webserver = require('gulp-webserver');
5388
gulp.src('./')
@@ -61,14 +96,20 @@ gulp.task('serve', function() {
6196
});
6297

6398

64-
var runMocha = function() {
99+
var runTests = function() {
65100
var mocha = require('gulp-mocha');
66101
return gulp.src('test/**/*Spec.js', {read: false})
67102
.pipe(mocha({}));
68103
};
69104

70-
gulp.task('test', runMocha);
105+
/**
106+
* Runs all tests
107+
*/
108+
gulp.task('test', runTests);
71109

110+
/**
111+
* Runs all tests with coverage
112+
*/
72113
gulp.task('test-coverage', ['clean-coverage'], function(cb) {
73114
var mocha = require('gulp-mocha');
74115
var istanbul = require('gulp-istanbul');
@@ -77,12 +118,16 @@ gulp.task('test-coverage', ['clean-coverage'], function(cb) {
77118
.pipe(istanbul()) // Covering files
78119
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
79120
.on('finish', function () {
80-
runMocha()
121+
runTests()
81122
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
82123
.on('end', cb);
83124
});
84125
});
85126

127+
/**
128+
* This intended to be run only on Travis CI.
129+
* Runs all tests with coverage, when upload coverage data to coveralls.io
130+
*/
86131
gulp.task('test-ci', ['test-coverage'], function() {
87132
var coveralls = require('gulp-coveralls');
88133
return gulp.src(COVERAGE_DIR + '/lcov.info')

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
require('promise/polyfill');
22

3+
/**
4+
* Simplifies creation of API instances as singletons
5+
* @type {exports}
6+
*/
37
var ApiFactory = require('./src/ApiFactory');
8+
9+
/**
10+
* An Api class
11+
* @type {exports}
12+
*/
413
var Api = require('./src/Api');
14+
15+
/**
16+
* Various utility methods for working with API
17+
* @type {exports}
18+
*/
519
var ApiUtil = require('./src/ApiUtil');
20+
21+
/**
22+
* Constants to be used when working with API
23+
* @type {exports}
24+
*/
625
var ApiConstants = require('./src/ApiConstants');
726

827
module.exports = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"gulp": "^3.8.10",
1414
"gulp-coveralls": "^0.1.3",
1515
"gulp-istanbul": "^0.5.0",
16+
"gulp-jsdoc": "^0.1.4",
1617
"gulp-mocha": "^2.0.0",
1718
"gulp-uglify": "^1.0.2",
1819
"gulp-webserver": "^0.9.0",

src/Api.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/**
2-
* Creates new Api instance. Accepts configuration object with the following keys:
3-
* hostname {String} - Required. A name of host to connect to
4-
* port {String} - Optional. A port on host to connect to. Defaults to 80.
5-
* version {String} - Optional. Which version of api to use.
6-
* At the moment of writing can be 1.0, 2.0, 3.0, 4.0, 5.0.
7-
* Pass 'internal' to use AtTask internal API (this is the latest version, maybe unstable)
8-
* @param {Object} config
2+
* Creates new Api instance.
3+
* @param {Object} config An object with the following keys:<br/>
4+
* <code>hostname</code> {String} - Required. A name of host to connect to<br/>
5+
* <code>port</code> {String} - Optional. A port on host to connect to. Defaults to 80.<br/>
6+
* <code>version</code> {String} - Optional. Which version of api to use. At the moment of writing can be 1.0, 2.0, 3.0, 4.0, 5.0. Pass 'internal' to use AtTask internal API (this is the latest version, maybe unstable)
97
* @constructor
108
*/
119
function Api(config) {

0 commit comments

Comments
 (0)