Skip to content

Instantly share code, notes, and snippets.

@smtm
Created April 4, 2011 11:02
Show Gist options
  • Save smtm/901474 to your computer and use it in GitHub Desktop.
Save smtm/901474 to your computer and use it in GitHub Desktop.
ruby person model to interface with mailchimp thru the hominid gem
person.rb methods
def self.initMailchimpList
#do the initial sync of all people in the DB for a customer with
#pushing it into one list
end
def syncMailchimpList
# we need the mailchimp api key on hotel level
# get the structure of the list
# see if we have the person in the mailchimp list
# add to list if not in the list
# update details if changed - firstname - lastname
# push the updated interest and lang fields
# get some stats back from mailchimp
end
# when we remove a contact from out list we want to remove it from mailchimp
def delFromMailchimpList
# remove or deactivate from mailchimp list
# no further sending to this email address
# but keep history?
end
#########################
#the lib file
h = Hominid::API.new("abcdefgehiklmen12345677657675566-us1")
h.lists
ownlist = h.lists['data'].last
list_id= "abcdefghij"
#listSubscribe(string apikey, string id, string email_address, array merge_vars, string email_type, bool double_optin, bool update_existing, bool replace_interests, bool send_welcome)
# pump it into the mailchimp list - no permission mail
h.list_subscribe(list_id, "hominid1@yourdomain.com", [], "html", false,false,false,false,false)
# short subscribe triggers permission mail
h.list_subscribe(list_id, "hominid1@yourdomain.com")
h.list_subscribe(list_id, "stefan.glaser@yourdomain.com", {:FNAME =>"Stefan",:LNAME=>"Glaser"}, "html", false,false,false,false,false)
# if none present an error is thrown
#>h.list_interest_grouping_del(10) Delete an obsolete list
h.list_interest_groupings(list_id)
h.list_interest_grouping_add(list_id,"lang", "hidden",{1=>"DE",2=>"EN", 3=>"IT",4=>"FR"})
h.list_interest_grouping_add(list_id,"interest", "hidden",{1=>"ball",2=>"kultur", 3=>"neujahrskonzert",4=>"festwochen"})
h.list_merge_vars(list_id)
h.list_update_member(list_id,"stefan.glaser@yourdomain.com", {:GROUPINGS=>[{:groups=>"neujahrskonzert, kultur", :name=>"interesse"},{:groups=>"EN", :name=>"lang"}]})
h.list_update_member(list_id,"moosa.ominid@yourdomain.com", {:GROUPINGS=>[{:groups=>"festwochen, ball", :name=>"interesse"},{:groups=>"IT", :name=>"lang"}]})
h.list_member_info(list_id,{:email=>"stefan.glaser@yourdomain.com"})
h.list_member_info(list_id,{:email=>"homer3.ominid@yourdomain.com"})
#listUpdateMember(string apikey, string id, string email_address, array merge_vars, string email_type, boolean replace_interests)
#array GROUPINGS Set Interest Groups by Grouping. Each element in this array should be an array containing the "groups" parameter which contains a comma delimited list of Interest Groups to add. Commas in Interest Group names should be escaped with a backslash. ie, "," => "\," and either an "id" or "name" parameter to specify the Grouping - get from listInterestGroupings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment