Skip to content

Commit 4cdb288

Browse files
author
Hamlet Hakobyan
committed
Configured package and karma runner. Added some tests. Created service skeleton.
1 parent d31f28c commit 4cdb288

16 files changed

+922
-7
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing-whitespace = true
8+
insert_final-newline = true
9+
10+
[*.md]
11+
trim_trailing-whitespace = false

.eslintrc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"env": {
3+
"commonjs": true
4+
},
5+
"extends": "eslint:recommended",
6+
"rules": {
7+
"indent": [
8+
1,
9+
4
10+
],
11+
"no-extra-semi": [
12+
1
13+
],
14+
"linebreak-style": [
15+
1,
16+
"windows"
17+
],
18+
"quotes": [
19+
1,
20+
"single"
21+
],
22+
"semi": [
23+
2,
24+
"always"
25+
],
26+
"no-unused-vars": [
27+
1
28+
],
29+
"strict": [
30+
2
31+
],
32+
"eol-last": [
33+
1
34+
],
35+
"semi-spacing": [
36+
1,
37+
{ "before": false, "after": true }
38+
]
39+
}
40+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode/
2+
node_modules/
3+
bower_components/

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode/
2+
node_modules/
3+
src/

app.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var angular = require('angular');
4+
5+
var ngModule = angular.module('streamApi', []);
6+
7+
require('./src/ApiServiceProvider')(ngModule);
8+
9+
module.exports = ngModule.name;

bower.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "angular-stream-api",
3+
"description": "A Workfront Stream API for AngularJS",
4+
"main": "app.js",
5+
"authors": [
6+
"Hamlet Hakobyan <[email protected]>"
7+
],
8+
"license": "MIT",
9+
"keywords": [
10+
"workfront",
11+
"streamapi",
12+
"stream",
13+
"api",
14+
"angular"
15+
],
16+
"homepage": "https://github.com/HamletHakobyan/angular-stream-api",
17+
"ignore": [
18+
"**/.*",
19+
"node_modules",
20+
"bower_components",
21+
"test",
22+
"tests"
23+
],
24+
"devDependencies": {
25+
"angular": "^1.5.5",
26+
"angular-mocks": "^1.5.5"
27+
}
28+
}

jsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=759670
3+
// for the documentation about the jsconfig.json format
4+
"compilerOptions": {
5+
"target": "es6",
6+
"module": "commonjs",
7+
"allowSyntheticDefaultImports": true
8+
},
9+
"exclude": [
10+
"node_modules",
11+
"bower_components",
12+
"jspm_packages",
13+
"tmp",
14+
"temp"
15+
]
16+
}

package.json

+18-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
"name": "angular-stream-api",
33
"version": "0.0.1",
44
"description": "A Workfront Stream API for AngularJS",
5+
"license": "MIT",
6+
"author": "Workfront",
7+
"contributors": [
8+
"Hamlet Hakobyan <[email protected]>"
9+
],
510
"main": "app.js",
611
"scripts": {
7-
"test": "karma start"
12+
"test": "karma start ./src/spec/karma.conf.js"
813
},
914
"repository": {
1015
"type": "git",
@@ -17,13 +22,19 @@
1722
"api",
1823
"angular"
1924
],
20-
"author": "Workfront",
21-
"contributors": [
22-
"Hamlet Hakobyan <[email protected]>"
23-
],
24-
"license": "MIT",
2525
"bugs": {
2626
"url": "https://github.com/HamletHakobyan/angular-stream-api/issues"
2727
},
28-
"homepage": "https://github.com/HamletHakobyan/angular-stream-api#readme"
28+
"homepage": "https://github.com/HamletHakobyan/angular-stream-api#readme",
29+
"devDependencies": {
30+
"eslint": "^2.10.2",
31+
"jasmine": "^2.4.1",
32+
"karma": "^0.13.22",
33+
"karma-jasmine": "^1.0.2",
34+
"karma-phantomjs-launcher": "^1.0.0",
35+
"karma-webpack": "^1.7.0",
36+
"phantomjs-prebuilt": "^2.1.7",
37+
"url-parse": "^1.1.1",
38+
"webpack": "^1.13.1"
39+
}
2940
}

src/ApiServiceProvider.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
/**
4+
* Creates StreamAPI Provider Service instance.
5+
*/
6+
function streamApiServiceProvider() {
7+
this.$get = streamApiServiceFactory;
8+
}
9+
10+
streamApiServiceFactory.$inject = ['$http', '$q'];
11+
function streamApiServiceFactory($http, $q) {
12+
var Api = require('./service/Api'),
13+
factory = {},
14+
_instance;
15+
16+
factory.getInstance = function(config, returnNewInstance) {
17+
if(returnNewInstance) {
18+
return new Api(config);
19+
}
20+
21+
if(!_instance) {
22+
_instance = new Api(config);
23+
}
24+
25+
return _instance;
26+
};
27+
28+
factory.deleteInstance = function() {
29+
_instance = undefined;
30+
};
31+
32+
return factory;
33+
}
34+
35+
module.exports = function(ngModule) {
36+
ngModule.provider('streamApiService', streamApiServiceProvider);
37+
};

src/service/Api.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
var angular = require('angular');
4+
var Url = require('url-parse');
5+
6+
function Api(config) {
7+
if(!(config && angular.isObject(config))) {
8+
throw new Error('Please provide valid configuration object.');
9+
}
10+
11+
if(!(('url' in config) && (typeof config.url === 'string'))) {
12+
throw new Error('\'config\' should have \'url\' property of type \'string\'');
13+
}
14+
15+
if(config.url.indexOf('http://') !== 0
16+
&& config.url.indexOf('https://') !== 0) {
17+
throw new Error('You must provide valid scheme with \'url\'');
18+
}
19+
20+
var parsedUrl = new Url(config.url);
21+
22+
var path;
23+
if (config.version === 'internal' || config.version === 'unsupported') {
24+
path = '/attask/api-' + config.version;
25+
}
26+
else {
27+
path = '/attask/api';
28+
if (config.version) {
29+
path = path + '/v' + config.version;
30+
}
31+
}
32+
33+
this.config = {
34+
url: parsedUrl.protocol + '//' + parsedUrl.host + path
35+
};
36+
37+
this.Constants = require('./ApiConstants');
38+
this.Methods = require('./ApiMethods');
39+
}
40+
41+
module.exports = Api;

0 commit comments

Comments
 (0)