Result Codes - Ruby Library

Can someone please tell me why this doesn't work:

#!/usr/bin/ruby
require 'campaign_monitor'
list = CampaignMonitor::List.new('0123456789')
puts(CampaignMonitor::Result.new(list.add_subscriber('foo@bar.com','John Doe')).code)

Here is what I get:

/usr/lib/ruby/1.8/campaign_monitor/result.rb:7:in `initialize': undefined method `[]' for #<CampaignMonitor::Result:0xb7c4d5f8 @message="Success", @code=0> (NoMethodError)
    from ./test2:4:in `new'
    from ./test2:4

Thanks very much for any input.  I think this is about my last hurdle on this thing.

        ... doug

djolley, 8 years ago

I'll answer my own question just in case someone else has this problem.

The reason is that one doesn't do it that way.  To get at the result codes, do something like this:

list.add_subscriber('foo@bar.com','John Doe').code

          ... doug

Mathew Mathew, 8 years ago

Well answered Doug!


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
jeremy, 8 years ago

Doug,

I recommend stashing the result in a variable, and getting the code from the result object.

result = list.add_subscriber('foo@bar.com','John Doe')
result.code

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free
1-888-533-8098