I've recently added the ability to subscribe people to a mailchimp list from my rails app using the Gibbon gem.
It is working perfectly to subscribe people to list when they register, and when they login it updates their information on the mailchimp list (eg login count and last_login_date).
However there are other users using the app that I would like to add to the mailchimp list but because they already have an account they aren't going to sign up again, therefore won't get subscribed.
I'm trying to add an if statement to the login page that subscribes them to the list if they don't already exist, but can't figure out the syntax.
If, for example, I test it to find a user that I know doesn't exist, like this:
Gibbon::API.lists.member_info({:id => list_id, :emails => [{:email => "[email protected]"}]})
Then it returns this:
{"success_count"=>0, "error_count"=>1, "errors"=>[{"email"=>{"email"=>"[email protected]"}, "error"=>"The id passed does not exist on this list", "code"=>232}], "data"=>[]}
But what I need is just a true or false...
I've tried:
Gibbon::API.lists.member_info({:id => list_id, :emails => [{:email => "[email protected]"}]}).include("success_count"=>0)?
but that obviously doesn't work as it says undefined method include? for Hash...
Any ideas on how I can get it to a true or false boolean?
OK so eventually after trying a few different things I got around this by doing this: