Fix some bugs for finding list subscribers and setting atributes on EmailList
This commit is contained in:
parent
9d4925dc78
commit
0ca77c5c72
2 changed files with 12 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
class EmailList < ActiveRecord::Base
|
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 :nonprofit
|
||||||
belongs_to :tag_master
|
belongs_to :tag_master
|
||||||
end
|
end
|
||||||
|
|
|
@ -203,11 +203,21 @@ module Mailchimp
|
||||||
def self.get_list_mailchimp_subscribers(email_list)
|
def self.get_list_mailchimp_subscribers(email_list)
|
||||||
mailchimp_token = get_mailchimp_token(email_list.tag_master.nonprofit.id)
|
mailchimp_token = get_mailchimp_token(email_list.tag_master.nonprofit.id)
|
||||||
uri = base_uri(mailchimp_token)
|
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},
|
basic_auth: {username: "CommitChange", password: mailchimp_token},
|
||||||
headers: {'Content-Type' => 'application/json'}})
|
headers: {'Content-Type' => 'application/json'}})
|
||||||
members = result['members'].map do |i|
|
members = result['members'].map do |i|
|
||||||
{id: i['id'], email_address: i['email_address']}
|
{id: i['id'], email_address: i['email_address']}
|
||||||
end.to_a
|
end.to_a
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue