Skip to content

Commit a4925a6

Browse files
author
Hovhannes Babayan
committed
refactor
1 parent 2a9b44f commit a4925a6

18 files changed

Lines changed: 7575 additions & 101 deletions

dist/attask.js

Lines changed: 7296 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
var username = document.getElementById('username').value;
1414
var password = document.getElementById('password').value;
1515

16-
var instance = window.Api.getInstance({hostname: host, version: '5.0', port: port});
16+
var instance = window.ApiFactory.getInstance({hostname: host, version: '5.0', port: port});
1717
instance.login(username, password).then(function(data){
1818
console.log(data)
1919
}, console.error);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var ApiFactory = require('./../../').ApiFactory;
2+
var util = require('util');
3+
4+
var instance = ApiFactory.getInstance({
5+
hostname: 'localhost',
6+
version: '5.0',
7+
port: 8080
8+
});
9+
10+
util.log('Logging in ...');
11+
instance.login('new@user.attask', 'user').then(
12+
function(data) {
13+
util.log('Creating new project ...');
14+
instance.post('proj', {name: 'API Project', description: 'This project has been created using API'}).then(
15+
function(data) {
16+
util.log('Create success. Received data:');
17+
console.log(util.inspect(data, {colors:true}));
18+
},
19+
function(error) {
20+
util.log('Create failure. Received data:');
21+
console.log(util.inspect(error, {colors:true}));
22+
}
23+
);
24+
},
25+
function(error) {
26+
util.log('Login failure. Received data:');
27+
console.log(util.inspect(error, {colors:true}));
28+
}
29+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var ApiFactory = require('./../../').ApiFactory;
2+
var util = require('util');
3+
4+
var instance = ApiFactory.getInstance({
5+
hostname: 'localhost',
6+
version: '5.0',
7+
port: 8080
8+
});
9+
10+
util.log('Logging in ...');
11+
instance.login('new@user.attask', 'user').then(
12+
function(data) {
13+
util.log('Getting project and owner details by project id ...');
14+
instance.get('proj', '5461f8e3000006d43674695aff4cdf52', ['*', 'owner:*']).then(
15+
function(data) {
16+
util.log('Get success. Received data:');
17+
console.log(util.inspect(data, {colors:true}));
18+
},
19+
function(error) {
20+
util.log('Get failure. Received data:');
21+
console.log(util.inspect(error, {colors:true}));
22+
}
23+
);
24+
},
25+
function(error) {
26+
util.log('Login failure. Received data:');
27+
console.log(util.inspect(error, {colors:true}));
28+
}
29+
);

examples/node/login.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var ApiFactory = require('./../../').ApiFactory;
2+
var util = require('util');
3+
4+
var instance = ApiFactory.getInstance({
5+
hostname: 'localhost',
6+
version: '5.0',
7+
port: 8080
8+
});
9+
10+
util.log('Logging in ...');
11+
instance.login('new@user.attask', 'user').then(
12+
function(data) {
13+
util.log('Login success. Received data:');
14+
console.log(util.inspect(data, {colors:true}));
15+
},
16+
function(error) {
17+
util.log('Login failure. Received data:');
18+
console.log(util.inspect(error, {colors:true}));
19+
}
20+
);

examples/node/logout.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var ApiFactory = require('./../../').ApiFactory;
2+
var util = require('util');
3+
4+
var instance = ApiFactory.getInstance({
5+
hostname: 'localhost',
6+
version: '5.0',
7+
port: 8080
8+
});
9+
10+
util.log('Logging in ...');
11+
instance.login('new@user.attask', 'user').then(
12+
function(data) {
13+
util.log('Logging out ...');
14+
instance.logout().then(
15+
function(data) {
16+
util.log('Logout success. Received data:');
17+
console.log(util.inspect(data, {colors:true}));
18+
},
19+
function(error) {
20+
util.log('Logout failure. Received data:');
21+
console.log(util.inspect(error, {colors:true}));
22+
}
23+
);
24+
},
25+
function(error) {
26+
util.log('Login failure. Received data:');
27+
console.log(util.inspect(error, {colors:true}));
28+
}
29+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var ApiFactory = require('./../../').ApiFactory;
2+
var util = require('util');
3+
4+
var instance = ApiFactory.getInstance({
5+
hostname: 'localhost',
6+
version: '5.0',
7+
port: 8080
8+
});
9+
10+
util.log('Logging in ...');
11+
instance.login('new@user.attask', 'user').then(
12+
function(data) {
13+
util.log('Searching for projects with percentComplete > 0 ...');
14+
instance.search('proj', {percentComplete: 0, percentComplete_Mod: 'gt'}).then(
15+
function(data) {
16+
util.log('Search success. Received data:');
17+
console.log(util.inspect(data, {colors:true}));
18+
},
19+
function(error) {
20+
util.log('Search failure. Received data:');
21+
console.log(util.inspect(error, {colors:true}));
22+
}
23+
);
24+
},
25+
function(error) {
26+
util.log('Login failure. Received data:');
27+
console.log(util.inspect(error, {colors:true}));
28+
}
29+
);

gulpfile.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const COVERAGE_DIR = 'coverage';
55

66
gulp.task('default', ['build']);
77

8+
gulp.task('clean', ['clean-coverage', 'clean-build']);
9+
810
/**
911
* Empties BUILD_DIR
1012
*/
11-
gulp.task('clean', ['clean-coverage'], function(cb) {
13+
gulp.task('clean-build', function(cb) {
1214
var del = require('del');
1315
del([BUILD_DIR + '*', COVERAGE_DIR], cb);
1416
});
@@ -26,17 +28,17 @@ gulp.task('clean-coverage', function(cb) {
2628
* Generates browser-ready version for API in BUILD_DIR
2729
* File will be named as api.js
2830
*/
29-
gulp.task('build', ['clean'], function() {
31+
gulp.task('build', ['clean-build'], function() {
3032
var browserify = require('browserify');
3133
var source = require('vinyl-source-stream');
3234
return browserify(
33-
'./src/api.js',
35+
'./index.js',
3436
{
35-
standalone: 'Api'
37+
standalone: 'AtTask'
3638
}
3739
)
3840
.bundle()
39-
.pipe(source('api.js'))
41+
.pipe(source('attask.js'))
4042
.pipe(gulp.dest(BUILD_DIR));
4143
});
4244

index.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
var api = require('./src/api');
1+
var ApiFactory = require('./src/ApiFactory');
2+
var Api = require('./src/Api');
23

3-
var instance = api.getInstance({hostname: 'localhost', version: '5.0', port: 8080});
4-
var instance2 = api.getInstance();
5-
//var instance4 = api.getInstance({hostname: 'localhost', version: '4.0', port: 8080});
6-
7-
var instance3 = api.getInstance({hostname: 'localhost', version: '4.0', port: 8080}, true);
8-
9-
instance.login('new@user.attask', 'user').then(function(data){
10-
instance.search('proj', {percentComplete: 0, percentComplete_Mod: 'gt'}).then(console.log, console.error);
11-
//instance2.search('task', null, ['*']).then(console.log, console.error);
12-
//instance.logout().then(console.log, console.error);
13-
// instance2.get('proj', '5461f8e3000006d43674695aff4cdf52').then(console.log, console.error);
14-
//instance.post('task', {name: 'API Task', projectID: '5461f8e3000006d43674695aff4cdf52'}).then(console.log, console.error);
15-
}, console.error);
4+
module.exports = {
5+
Api: Api,
6+
ApiFactory: ApiFactory
7+
};

src/constructor.js renamed to src/Api.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ function Api(config) {
1414
}
1515
}
1616

17+
require('./request')(Api);
18+
require('./login')(Api);
19+
require('./logout')(Api);
20+
require('./search')(Api);
21+
require('./get')(Api);
22+
require('./post')(Api);
23+
1724
module.exports = Api;

0 commit comments

Comments
 (0)