Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Created October 18, 2013 12:05
Show Gist options
  • Save the-teacher/7040602 to your computer and use it in GitHub Desktop.
Save the-teacher/7040602 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'hominid'
require 'json'
API_KEY = '000000000000000000000000000-us4'
TEST_EMAIL = '[email protected]'
def get_count
h = Hominid::API.new(API_KEY)
list_id = h.lists['data'].last['id']
mc_api = Hominid::Export.new API_KEY, {:secure => false}
ary = mc_api.list list_id
ary = ary.split("\n")
ary.shift
ary.map!{|item| JSON.parse(item)}
ary.map(&:first)
ary.count
end
p get_count
h = Hominid::API.new(API_KEY)
list_id = h.lists['data'].last['id']
p h.list_members(list_id, 'unsubscribed')
# Unsubscribe
p begin
h.list_unsubscribe(list_id, TEST_EMAIL)
rescue
"Unsubscripe fail"
end
# Subscribe
p begin
h.list_subscribe(list_id,
TEST_EMAIL,
merge_vars = {FNAME: 'Dear', LNAME: 'Guest'},
email_type = 'html',
double_optin = false,
update_existing = true,
replace_interests = true,
send_welcome = true)
rescue
"Subscripe fail"
end
p get_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment