From 0ca77c5c72f154fe6410433455080ca22d045d78 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Wed, 17 Oct 2018 20:47:26 -0500 Subject: [PATCH] Fix some bugs for finding list subscribers and setting atributes on EmailList --- app/models/email_list.rb | 2 +- lib/mailchimp.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/email_list.rb b/app/models/email_list.rb index 1d148f22..c866eeaf 100644 --- a/app/models/email_list.rb +++ b/app/models/email_list.rb @@ -1,5 +1,5 @@ class EmailList < ActiveRecord::Base - attr_accessible :list_name, :mailchimp_list_id + attr_accessible :list_name, :mailchimp_list_id, :nonprofit, :tag_master belongs_to :nonprofit belongs_to :tag_master end diff --git a/lib/mailchimp.rb b/lib/mailchimp.rb index 03460de7..31f06bc4 100644 --- a/lib/mailchimp.rb +++ b/lib/mailchimp.rb @@ -203,11 +203,21 @@ module Mailchimp def self.get_list_mailchimp_subscribers(email_list) mailchimp_token = get_mailchimp_token(email_list.tag_master.nonprofit.id) uri = base_uri(mailchimp_token) - result = get(uri + "/lists/#{email_list.mailchimp_list_id}/members", { + result = get(uri + "/lists/#{email_list.mailchimp_list_id}/members?count=1000000000", { basic_auth: {username: "CommitChange", password: mailchimp_token}, headers: {'Content-Type' => 'application/json'}}) members = result['members'].map do |i| {id: i['id'], email_address: i['email_address']} end.to_a end + + def self.get_email_lists(nonprofit) + mailchimp_token = get_mailchimp_token(nonprofit.id) + uri = base_uri(mailchimp_token) + result = get(uri + "/lists", { + basic_auth: {username: "CommitChange", password: mailchimp_token}, + headers: {'Content-Type' => 'application/json'}}) + result['lists'] + + end end