我有一个应用程序,允许用户使用Gibbon gem包裹MailChimp api,将其放置在MailChimp上的电子邮件列表中。我可以访问列表,通过API订阅成员。现在,我希望能够在用户配置文件中准确显示用户订阅了电子邮件列表,并根据订阅或待处理的内容显示适当的内容。
我可以检索与列表中的订阅者相对应的哈希数组,但是当我尝试查找特定用户时,我有这个错误和跟踪:
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
我也不确定,以这种方式访问整个列表是正确的,只是为了验证列表中是否存在一个用户。
任何人都知道怎么做?
更新
使用Pete在评论中提出的建议,我得以实现这一目标。
以下是用于检索MailChimp订阅者哈希的命令:
gb.lists(ENV['MAILCHIMP_LIST_ID']).members(Digest::MD5.hexdigest("test9@gmail.com")).retrieve