Common usage "mistakes"

Jun 4, 2012 at 7:14 PM
Edited Jun 4, 2012 at 7:23 PM

Just wanted to raise an issue of "proper" use of this wrapper.

1. First of all it refers to Opt<> class (almost all methods use this type).  I created it mainly because the original F# option lack explicit/implicit conversion operators. So use the automatic casting.

C# example:

void Foo(Opt<int[]> x)
      // Do something

// Let the compiler handle conversion
var list = new int[] {1, 2, 3};

2. Exceptions handling. In general any method's call may raise an exception (deserialization fails, MailChimp server returns an error etc.). In addition some methods return boolean as output. But you'll never see them returning "false" value (instead, you'll get an exception). 

So wrap everything in try/catch blocks!

C# example:

var mc = new MCApi("key", true);

try {
      return mc.Ping();
catch (MCExeption mex) {
catch (Exception ex) {

* MCException class exposes two relevant properties: Error (contains the error number and its message) and Response (the raw server response string).

3. Transactional emails. If you just want to send a simple email (possibly with attachments) use Mandrill API...