-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (47 loc) · 1.3 KB
/
index.js
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
'use strict'
var Resource = require('./lib/resource.js')
var Marvel, merge, hasProp
hasProp = function(o, p) {
return Object.prototype.hasOwnProperty.call(o, p)
}
// merge
merge = function(a, b) {
var k
for (k in a) {
if (hasProp(a, k) && hasProp(b, k) === false) {
b[k] = a[k]
}
}
return b
}
Marvel = function(opts) {
var defaults = {
apiDomain: 'https://gateway.marvel.com'
}
var resOpt
opts = merge(defaults, opts || {})
if (opts.privateKey === undefined || opts.publicKey === undefined) {
throw new Error(
'Unable to create a hash because of missing privateKey/publicKey'
)
}
this.param = {}
this.publicKey = opts.publicKey
this.privateKey = opts.privateKey
this.apiDomain = opts.apiDomain
resOpt = merge(opts, { API_VERSION: Marvel.API_VERSION })
this.characters = new Resource('characters', resOpt)
this.comics = new Resource('comics', resOpt)
this.creators = new Resource('creators', resOpt)
this.events = new Resource('events', resOpt)
this.series = new Resource('series', resOpt)
this.stories = new Resource('stories', resOpt)
}
Marvel.API_VERSION = 'v1'
Marvel.VERSION = require('./package').version
Marvel.prototype.keys = function(priv, pub) {
this.privateKey = priv
this.publicKey = pub
return this
}
module.exports = Marvel