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, 7 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, 7 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, 7 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

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098