I have an app that allows users to subscirbe to an email list housed on MailChimp, using the Gibbon gem to wrap the MailChimp api. I am able to access the list, subscribe members via the API. Now I want to be able to show accurately in the user profile, that a user is subscribed to the email list and display content that is appropriate based on whether they are subscribed or pending.
I can retrieve an array of hashes corresponding to the subscribers on my list but when I attempt to find a specific user, I have this error and trace:
gb.lists(ENV['MAILCHIMP_LIST_ID']).members.retrieve.find{|h| h['email_address'] == 'test9@gmail.com'}
TypeError: no implicit conversion of String into Integer
from (irb):26:in `[]'
from (irb):26:in `block in irb_binding'
from (irb):26:in `each'
from (irb):26:in `find'
from (irb):26
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
from /Users/dariusgoore/development/blackops/bin/rails:8:in `<top (required)>'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/commands/rails.rb:6:in `call'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/command_wrapper.rb:38:in `call'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:183:in `block in serve'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:156:in `fork'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:156:in `serve'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:131:in `block in run'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:125:in `loop'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:125:in `run'
from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/dariusgoore/.rubies/ruby-2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/dariusgoore/.rubies/ruby-2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'>> ^C
I also am not sure, it is right to access the entire list this way , just to verify the existence of one user on the list.
Anyone know how to do this?
Update:
Using Pete's suggestion from the comments, I was able to get this working.
Here is the command that works to retrieve the MailChimp subscriber hash:
gb.lists(ENV['MAILCHIMP_LIST_ID']).members(Digest::MD5.hexdigest("test9@gmail.com")).retrieve