-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for Api constructor, moved non-exported methods into plug…
…ins/ folder
- Loading branch information
Hovhannes Babayan
committed
Dec 26, 2014
1 parent
f51765a
commit 91b404b
Showing
8 changed files
with
54 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
/** | ||
* Creates new Api instance. Accepts configuration object with the following keys: | ||
* hostname {String} - Required. A name of host to connect to | ||
* port {String} - Optional. A port on host to connect to. Defaults to 80. | ||
* version {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) | ||
* @param {Object} config | ||
* @constructor | ||
*/ | ||
function Api(config) { | ||
this.httpOptions = { | ||
hostname: config.hostname, | ||
port: config.port || 80, | ||
path: '/attask/api', | ||
method: 'GET', | ||
withCredentials: false | ||
}; | ||
|
||
// Append version to hostname if provided | ||
if (config.version) { | ||
this.httpOptions.path = this.httpOptions.path + '/v' + config.version; | ||
// Append version to path if provided | ||
var path; | ||
if (config.version === 'internal') { | ||
path = '/attask/api-internal' | ||
} | ||
else { | ||
path = '/attask/api'; | ||
if (config.version) { | ||
path = path + '/v' + config.version; | ||
} | ||
} | ||
this.httpOptions.path = path; | ||
} | ||
|
||
require('./request')(Api); | ||
require('./login')(Api); | ||
require('./logout')(Api); | ||
require('./search')(Api); | ||
require('./get')(Api); | ||
require('./post')(Api); | ||
var plugins = [ | ||
'request', | ||
'login', | ||
'logout', | ||
'search', | ||
'get', | ||
'post' | ||
]; | ||
for(var i=0; i<plugins.length; ++i) { | ||
require('./plugins/' + plugins[i])(Api); | ||
} | ||
|
||
module.exports = Api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var Api = require('./Api'); | ||
var Api = require('./../Api'); | ||
|
||
module.exports = function(Api) { | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var Api = require('./Api'); | ||
var Api = require('./../Api'); | ||
|
||
module.exports = function(Api) { | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters