danesparza / MailChimp.NET

:envelope: .NET Wrapper for the MailChimp v2.0 API
MIT License
179 stars 119 forks source link

'_dataCenterPrefix' never gets set when using IMailChimpManager #170

Closed williamsonjake closed 8 years ago

williamsonjake commented 8 years ago

hey out there,

just found this excellent wrapper, by far the best i've found so far AND it's got an interface so i can unit test everything. nice.

i've ran into one issue though, it maybe related to how i'm setting things up but thought i'd report it.

this is my code - pretty simple, just subscribes someone:

_mailChimpManager.APIKey = apiKey;

var emailParameter = new EmailParameter
{
    Email = email
};

var result = _mailChimpManager.Subscribe(listId, emailParameter, mergeVars, doubleOptIn: false, updateExisting: true);

but i was getting an exception: API key not valid (datacenter not specified)

debugging the code, it looks like 'GetDatacenterPrefix()' only gets called in the constructor...

the way i got things working was to use ninject with a 'WithConstructorArgument' e.g.

kernel.Bind<IMailChimpManager>().To<MailChimpManager>()
.WithConstructorArgument("apiKey", ConfigurationManager.AppSettings["MailChimpApiKey"]);

worth mentioning as it was a bit of a head scratcher ;)

thanks for writing the wrapper, it's tops!

cheers,

jake

danesparza commented 8 years ago

Thanks for the heads up, @williamsonjake! Do you mind doing a pull request and fixing it? :+1:

I'll make sure your fix gets in the repo.