Skip to content

Commit

Permalink
Validate API key
Browse files Browse the repository at this point in the history
Note, I couldn’t figure out how to run the tests to verify that my
change didn’t break anything. See
gomfunkel#37
  • Loading branch information
adamloving committed Aug 6, 2014
1 parent cb91809 commit f560148
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/mailchimp/MailChimpAPI_v2_0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var http = require('http'),
request = require('request'),
helpers = require('./helpers');
request = require('request'),
helpers = require('./helpers');

/**
* MailChimp API wrapper for the API version 2.0. This object should not be
Expand All @@ -15,6 +15,11 @@ function MailChimpAPI_v2_0 (apiKey, options) {
if (!options)
var options = {};

// API Key must look like abc123-us2 (where us2 is the data center)
if (!apiKey.match(/^[a-z0-9]*\-[a-z0-9]*$/)) {
throw new Error('Unrecognized API key format: ' + apiKey + '. should look more like abc123-us2.');
}

this.version = '2.0';
this.apiKey = apiKey;
this.packageInfo = options.packageInfo;
Expand Down

0 comments on commit f560148

Please sign in to comment.