-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (48 loc) · 1.83 KB
/
index.js
File metadata and controls
61 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//----------------------------------------------------------------------------------------------------------------------
// Main entrypoint for the Cardcast API.
//
// @module index.js
//----------------------------------------------------------------------------------------------------------------------
var _ = require('lodash');
var Promise = require('bluebird');
var api = require('./lib/api');
var deck = require('./lib/deck');
var cards = require('./lib/cards');
var errors = require('./lib/errors');
//----------------------------------------------------------------------------------------------------------------------
function CardcastAPI(options)
{
this.options = _.defaults({}, options, {
hostname: 'https://api.cardcastgame.com',
timeout: 2000
});
} // end CardcastAPI()
CardcastAPI.prototype = {
get apiURL() {
return this.options.hostname + '/v1'
}
}; // end prototype
CardcastAPI.prototype.search = function(query, offset)
{
var url = api.buildURL(this.apiURL + '/decks', { search: query, offset: offset });
return api.makeAPICall(url, this.options.timeout);
}; // end search
CardcastAPI.prototype.deck = function(playCode)
{
// Not sure if it's required, but it's more formal
playCode = playCode.toUpperCase();
var url = this.apiURL + '/decks/' + playCode;
return api.makeAPICall(url, this.options.timeout)
.then(function(summary)
{
return deck.buildDeck(url, summary);
});
}; // end deck
//----------------------------------------------------------------------------------------------------------------------
module.exports = {
CardcastAPI: CardcastAPI,
cards: cards,
deck: deck,
errors: errors
}; // end exports
//----------------------------------------------------------------------------------------------------------------------