(apiKey, options)
| 53 | }; |
| 54 | |
| 55 | const SparkPost = function(apiKey, options) { |
| 56 | |
| 57 | options = handleOptions(apiKey, options); |
| 58 | |
| 59 | this.apiKey = options.key || process.env.SPARKPOST_API_KEY; |
| 60 | |
| 61 | if (typeof this.apiKey === 'undefined') { |
| 62 | throw new Error('Client requires an API Key.'); |
| 63 | } |
| 64 | |
| 65 | // adding version to object |
| 66 | this.version = version; |
| 67 | |
| 68 | // setting up default headers |
| 69 | this.defaultHeaders = _.merge({ |
| 70 | 'User-Agent': createVersionStr(version, options) |
| 71 | , 'Content-Type': 'application/json' |
| 72 | }, options.headers); |
| 73 | |
| 74 | //Optional client config |
| 75 | this.origin = options.origin; |
| 76 | this.apiVersion = options.apiVersion || defaults.apiVersion; |
| 77 | this.debug = (typeof options.debug === 'boolean') ? options.debug : defaults.debug; |
| 78 | |
| 79 | this.inboundDomains = require('./inboundDomains')(this); |
| 80 | this.messageEvents = require('./messageEvents')(this); |
| 81 | this.recipientLists = require('./recipientLists')(this); |
| 82 | this.relayWebhooks = require('./relayWebhooks')(this); |
| 83 | this.sendingDomains = require('./sendingDomains')(this); |
| 84 | this.subaccounts = require('./subaccounts')(this); |
| 85 | this.suppressionList = require('./suppressionList')(this); |
| 86 | this.templates = require('./templates')(this); |
| 87 | this.transmissions = require('./transmissions')(this); |
| 88 | this.webhooks = require('./webhooks')(this); |
| 89 | }; |
| 90 | |
| 91 | SparkPost.prototype.request = function(options, callback) { |
| 92 | const baseUrl = `${this.origin}/api/${this.apiVersion}/`; |
nothing calls this directly
no test coverage detected