Skip to content

Commit 301019d

Browse files
author
Chris Park
committed
No jira code style cleanup, script returns 1 if any examples fail
1 parent a57085c commit 301019d

File tree

16 files changed

+1516
-1525
lines changed

16 files changed

+1516
-1525
lines changed

docker/runAll.sh

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,30 @@ npm install mocha
8686
npm install -g istanbul
8787
npm install chai
8888
npm install nock
89+
npm install -g eslint
90+
npm install multipart-stream
8991
istanbul cover _mocha unittests.js
92+
#run eslint
93+
eslint ../lib/**
94+
95+
retcode=0
96+
97+
function runExample() {
98+
echo -e "\n---------- ${1} start -------------"
99+
result=""
100+
if [ -z ${ALT_URL} ]; then
101+
result="$(node ${1} --key ${API_KEY})"
102+
else
103+
result="$(node ${1} --key ${API_KEY} --url ${ALT_URL})"
104+
fi
105+
echo ${result}
106+
echo -e "\n---------- ${1} end -------------"
107+
if [[ $result == *"Exception"* ]]; then
108+
retcode=1
109+
elif [[ $result == *"processingFailure"* ]]; then
110+
retcode=1
111+
fi
112+
}
90113

91114
#Run the examples
92115
if [ ! -z ${API_KEY} ]; then
@@ -96,24 +119,17 @@ if [ ! -z ${API_KEY} ]; then
96119
npm install argparse
97120
npm install temporary
98121
if [ ! -z ${FILENAME} ]; then
99-
if [ ! -z ${ALT_URL} ]; then
100-
node ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
101-
else
102-
node ${FILENAME} --key ${API_KEY}
103-
fi
104-
elif [ ! -z ${ALT_URL} ]; then
105-
find . -name '*.js' -exec node {} --key ${API_KEY} --url ${ALT_URL} \;
122+
runExample ${FILENAME}
106123
else
107-
find . -name '*.js' -exec node {} --key ${API_KEY} \;
124+
for file in *.js; do
125+
runExample $file
126+
done
108127
fi
109128
else
110129
HELP
130+
retcode=1
111131
fi
112132

113-
#run eslint
114-
npm install -g eslint
115-
eslint ../lib/**
116-
117133
#Generate gh-pages and push them to git account (if git username is provided)
118134
if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
119135
#clone nodejs git repo
@@ -134,3 +150,6 @@ if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
134150
git commit -a -m "publish grunt apidocs ${VERSION}"
135151
git push
136152
fi
153+
154+
exit ${retcode}
155+

examples/base64_input.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

lib/Api.js

Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,119 @@
1-
/**
2-
* Rosette API.
3-
*
4-
* @copyright 2014-2015 Basis Technology Corporation.
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
7-
* with the License. You may obtain a copy of the License at
8-
* @license http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software distributed under the License is
11-
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
* See the License for the specific language governing permissions and limitations under the License.
13-
**/
14-
"use strict";
15-
16-
var rosetteConstants = require("./rosetteConstants");
17-
var RosetteException = require("./rosetteExceptions");
18-
var paramObj = require("./parameters");
19-
20-
var relationships = require("./relationships");
21-
var matchedName = require("./nameSimilarity");
22-
var translatedName = require("./nameTranslation");
23-
var sentiment = require("./sentiment");
24-
var categories = require("./categories");
25-
var entities = require("./entities");
26-
var morphology = require("./morphology");
27-
var tokens = require("./tokens");
28-
var sentences = require("./sentences");
29-
var language = require("./language");
30-
var ping = require("./ping");
31-
var info = require("./info");
32-
var checkVersion = require("./checkVersion");
33-
34-
/**
35-
* Compatible server version.
36-
*
37-
* @type string
38-
*/
39-
var BINDING_VERSION = "0.8";
40-
41-
/**
42-
* @class
43-
*
44-
* Node.js Client Binding API; representation of a Api server.
45-
* Call instance methods upon this object to communicate with particular
46-
* Api server endpoints.
47-
*
48-
* @example var api = new API(userKey, serviceUrl);
49-
* @copyright 2014-2015 Basis Technology Corporation.
50-
* @license http://www.apache.org/licenses/LICENSE-2.0
51-
*/
52-
function Api(userKey, serviceURL) {
53-
/**
54-
* @type {string}
55-
* @desc The Rosette API key used for authentication
56-
*/
57-
this.userKey = userKey;
58-
59-
/**
60-
* @type {object}
61-
* @desc The Rosette API endpoint parameters
62-
*/
63-
this.parameters = new paramObj();
64-
65-
/**
66-
* @type {string}
67-
* @desc URL of the API
68-
* @default
69-
*/
70-
if (serviceURL) {
71-
if(serviceURL.slice(-1) != '/'){
72-
serviceURL = serviceURL.concat('/')
73-
this.serviceURL = serviceURL;
74-
} else {
75-
this.serviceURL = serviceURL;
76-
}
77-
} else {
78-
this.serviceURL = "https://api.rosette.com/rest/v1/";
79-
}
80-
81-
this.versionChecked = false;
82-
83-
};
84-
85-
/**
86-
* @type {string}
87-
* @desc Accepts a Rosette API endpoint name and forwards user parameters to the endpoint
88-
* @param {string} endpoint - The Rosette API endpoint to be utilized
89-
*/
90-
Api.prototype.rosette = function(endpoint, callback) {
91-
92-
var api = this;
93-
endpoint = require("./" + endpoint);
94-
var e = new endpoint();
95-
var c = new checkVersion();
96-
97-
// check if server and client API versions match
98-
c.check(this.userKey, this.serviceURL, function(err, res) {
99-
if (err) {
100-
throw err;
101-
} else if (!res.versionChecked) {
102-
throw new RosetteException("incompatibleVersion", "The server version is not compatible with binding version " + BINDING_VERSION, res.Version);
103-
} else {
104-
// mark api binding version as checked
105-
api.versionChecked = true;
106-
107-
// send parameters to the specified endpoint
108-
e.getResults(api.parameters, api.userKey, api.serviceURL, function(err, res) {
109-
if (err) {
110-
return callback(err);
111-
} else {
112-
return callback(null, res);
113-
}
114-
});
115-
}
116-
});
117-
};
118-
119-
module.exports = Api;
1+
/**
2+
* Rosette API.
3+
*
4+
* @copyright 2014-2015 Basis Technology Corporation.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at
8+
* @license http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
11+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and limitations under the License.
13+
**/
14+
"use strict";
15+
16+
var rosetteConstants = require("./rosetteConstants");
17+
var RosetteException = require("./rosetteExceptions");
18+
var paramObj = require("./parameters");
19+
20+
var relationships = require("./relationships");
21+
var matchedName = require("./nameSimilarity");
22+
var translatedName = require("./nameTranslation");
23+
var sentiment = require("./sentiment");
24+
var categories = require("./categories");
25+
var entities = require("./entities");
26+
var morphology = require("./morphology");
27+
var tokens = require("./tokens");
28+
var sentences = require("./sentences");
29+
var language = require("./language");
30+
var ping = require("./ping");
31+
var info = require("./info");
32+
var checkVersion = require("./checkVersion");
33+
34+
/**
35+
* Compatible server version.
36+
*
37+
* @type string
38+
*/
39+
var BINDING_VERSION = "0.8";
40+
41+
/**
42+
* @class
43+
*
44+
* Node.js Client Binding API; representation of a Api server.
45+
* Call instance methods upon this object to communicate with particular
46+
* Api server endpoints.
47+
*
48+
* @example var api = new API(userKey, serviceUrl);
49+
* @copyright 2014-2015 Basis Technology Corporation.
50+
* @license http://www.apache.org/licenses/LICENSE-2.0
51+
*/
52+
function Api(userKey, serviceURL) {
53+
/**
54+
* @type {string}
55+
* @desc The Rosette API key used for authentication
56+
*/
57+
this.userKey = userKey;
58+
59+
/**
60+
* @type {object}
61+
* @desc The Rosette API endpoint parameters
62+
*/
63+
this.parameters = new paramObj();
64+
65+
/**
66+
* @type {string}
67+
* @desc URL of the API
68+
* @default
69+
*/
70+
if (serviceURL) {
71+
if (serviceURL.slice(-1) != '/') {
72+
serviceURL = serviceURL.concat('/')
73+
this.serviceURL = serviceURL;
74+
} else {
75+
this.serviceURL = serviceURL;
76+
}
77+
} else {
78+
this.serviceURL = "https://api.rosette.com/rest/v1/";
79+
}
80+
81+
this.versionChecked = false;
82+
83+
};
84+
85+
/**
86+
* @type {string}
87+
* @desc Accepts a Rosette API endpoint name and forwards user parameters to the endpoint
88+
* @param {string} endpoint - The Rosette API endpoint to be utilized
89+
*/
90+
Api.prototype.rosette = function(endpoint, callback) {
91+
92+
var api = this;
93+
endpoint = require("./" + endpoint);
94+
var e = new endpoint();
95+
var c = new checkVersion();
96+
97+
// check if server and client API versions match
98+
c.check(this.userKey, this.serviceURL, function(err, res) {
99+
if (err) {
100+
throw err;
101+
} else if (!res.versionChecked) {
102+
throw new RosetteException("incompatibleVersion", "The server version is not compatible with binding version " + BINDING_VERSION, res.Version);
103+
} else {
104+
// mark api binding version as checked
105+
api.versionChecked = true;
106+
107+
// send parameters to the specified endpoint
108+
e.getResults(api.parameters, api.userKey, api.serviceURL, function(err, res) {
109+
if (err) {
110+
return callback(err);
111+
} else {
112+
return callback(null, res);
113+
}
114+
});
115+
}
116+
});
117+
};
118+
119+
module.exports = Api;

0 commit comments

Comments
 (0)