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