Class: MadMimi
- Inherits:
-
Object
- Object
- MadMimi
- Defined in:
- lib/madmimi.rb
Defined Under Namespace
Classes: MadMimiError
Constant Summary collapse
- BASE_URL =
'api.madmimi.com'
- NEW_LISTS_PATH =
'/audience_lists'
- AUDIENCE_MEMBERS_PATH =
'/audience_members'
- AUDIENCE_LISTS_PATH =
'/audience_lists/lists.xml'
- MEMBERSHIPS_PATH =
'/audience_members/%email%/lists.xml'
- SUPPRESSED_SINCE_PATH =
'/audience_members/suppressed_since/%timestamp%.txt'
- SUPPRESS_USER_PATH =
' /audience_members/%email%/suppress_email'
- IS_SUPPRESSED_PATH =
'/audience_members/%email%/is_suppressed'
- PROMOTIONS_PATH =
'/promotions.xml'
- MAILING_STATS_PATH =
'/promotions/%promotion_id%/mailings/%mailing_id%.xml'
- SEARCH_PATH =
'/audience_members/search.xml'
- MAILER_PATH =
'/mailer'
- TRANSACTIONAL_MAILING_STATUS_PATH =
'/mailers/status/%transaction_id%'
- MAILER_TO_LIST_PATH =
'/mailer/to_list'
Instance Method Summary collapse
- #add_to_list(email, list_name) ⇒ Object
- #add_user(options) ⇒ Object
-
#add_users_to_list(list_name, arr) ⇒ Object
Not the most elegant, but it works for now.
- #api_key ⇒ Object
- #audience_search(query_string, raw = false) ⇒ Object
- #csv_import(csv_string) ⇒ Object
- #default_opt ⇒ Object
- #delete_list(list_name) ⇒ Object
-
#initialize(username, api_key) ⇒ MadMimi
constructor
A new instance of MadMimi.
- #is_suppressed(email) ⇒ Object
- #lists ⇒ Object
- #mailing_stats(promotion_id, mailing_id) ⇒ Object
- #memberships(email) ⇒ Object
- #new_list(list_name) ⇒ Object
- #promotions ⇒ Object
- #remove_from_list(email, list_name) ⇒ Object
- #send_html(opt, html) ⇒ Object
- #send_mail(opt, yaml_body) ⇒ Object
- #send_plaintext(opt, plaintext) ⇒ Object
- #suppress_email(email) ⇒ Object
- #suppressed_since(timestamp) ⇒ Object
- #transactional_mailing_status(transaction_id) ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(username, api_key) ⇒ MadMimi
Returns a new instance of MadMimi.
54 55 56 |
# File 'lib/madmimi.rb', line 54 def initialize(username, api_key) @api_settings = { :username => username, :api_key => api_key } end |
Instance Method Details
#add_to_list(email, list_name) ⇒ Object
97 98 99 |
# File 'lib/madmimi.rb', line 97 def add_to_list(email, list_name) do_request("#{NEW_LISTS_PATH}/#{URI.escape(list_name)}/add", :post, :email => email) end |
#add_user(options) ⇒ Object
92 93 94 95 |
# File 'lib/madmimi.rb', line 92 def add_user() csv_data = build_csv() do_request(AUDIENCE_MEMBERS_PATH, :post, :csv_file => csv_data) end |
#add_users_to_list(list_name, arr) ⇒ Object
Not the most elegant, but it works for now. :)
154 155 156 157 158 159 |
# File 'lib/madmimi.rb', line 154 def add_users_to_list(list_name, arr) arr.each do |a| a[:add_list] = list_name add_user(a) end end |
#api_key ⇒ Object
62 63 64 |
# File 'lib/madmimi.rb', line 62 def api_key @api_settings[:api_key] end |
#audience_search(query_string, raw = false) ⇒ Object
134 135 136 137 |
# File 'lib/madmimi.rb', line 134 def audience_search(query_string, raw = false) request = do_request(SEARCH_PATH, :get, :raw => raw, :query => query_string) Crack::XML.parse(request) end |
#csv_import(csv_string) ⇒ Object
88 89 90 |
# File 'lib/madmimi.rb', line 88 def csv_import(csv_string) do_request(AUDIENCE_MEMBERS_PATH, :post, :csv_file => csv_string) end |
#default_opt ⇒ Object
66 67 68 |
# File 'lib/madmimi.rb', line 66 def default_opt { :username => username, :api_key => api_key } end |
#delete_list(list_name) ⇒ Object
84 85 86 |
# File 'lib/madmimi.rb', line 84 def delete_list(list_name) do_request("#{NEW_LISTS_PATH}/#{URI.escape(list_name)}", :post, :'_method' => 'delete') end |
#is_suppressed(email) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/madmimi.rb', line 113 def is_suppressed(email) response = do_request(IS_SUPPRESSED_PATH.gsub('%email%', email), :get) case response when 'true' true when 'false', /does not exist/ false end end |
#lists ⇒ Object
70 71 72 73 |
# File 'lib/madmimi.rb', line 70 def lists request = do_request(AUDIENCE_LISTS_PATH, :get) Crack::XML.parse(request) end |
#mailing_stats(promotion_id, mailing_id) ⇒ Object
128 129 130 131 132 |
# File 'lib/madmimi.rb', line 128 def mailing_stats(promotion_id, mailing_id) path = MAILING_STATS_PATH.gsub('%promotion_id%', promotion_id).gsub('%mailing_id%', mailing_id) request = do_request(path, :get) Crack::XML.parse(request) end |
#memberships(email) ⇒ Object
75 76 77 78 |
# File 'lib/madmimi.rb', line 75 def memberships(email) request = do_request(MEMBERSHIPS_PATH.gsub('%email%', email), :get) Crack::XML.parse(request) end |
#new_list(list_name) ⇒ Object
80 81 82 |
# File 'lib/madmimi.rb', line 80 def new_list(list_name) do_request(NEW_LISTS_PATH, :post, :name => list_name) end |
#promotions ⇒ Object
123 124 125 126 |
# File 'lib/madmimi.rb', line 123 def promotions request = do_request(PROMOTIONS_PATH, :get) Crack::XML.parse(request) end |
#remove_from_list(email, list_name) ⇒ Object
101 102 103 |
# File 'lib/madmimi.rb', line 101 def remove_from_list(email, list_name) do_request("#{NEW_LISTS_PATH}/#{URI.escape(list_name)}/remove", :post, :email => email) end |
#send_html(opt, html) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/madmimi.rb', line 161 def send_html(opt, html) = opt.dup if html.include?('[[tracking_beacon]]') || html.include?('[[peek_image]]') [:raw_html] = html if ![:list_name].nil? unless html.include?('[[unsubscribe]]') || html.include?('[[opt_out]]') raise MadMimiError, "When specifying list_name, include the [[unsubscribe]] or [[opt_out]] macro in your HTML before sending." end do_request(MAILER_TO_LIST_PATH, :post, , true) else do_request(MAILER_PATH, :post, , true) end else raise MadMimiError, "You'll need to include either the [[tracking_beacon]] or [[peek_image]] macro in your HTML before sending." end end |
#send_mail(opt, yaml_body) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/madmimi.rb', line 139 def send_mail(opt, yaml_body) = opt.dup [:body] = yaml_body.to_yaml if ![:list_name].nil? do_request(MAILER_TO_LIST_PATH, :post, , true) else do_request(MAILER_PATH, :post, , true) end end |
#send_plaintext(opt, plaintext) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/madmimi.rb', line 178 def send_plaintext(opt, plaintext) = opt.dup [:raw_plain_text] = plaintext if ![:list_name].nil? if plaintext.include?('[[unsubscribe]]') || plaintext.include?('[[opt_out]]') do_request(MAILER_TO_LIST_PATH, :post, , true) else raise MadMimiError, "You'll need to include either the [[unsubscribe]] or [[opt_out]] macro in your text before sending." end else do_request(MAILER_PATH, :post, , true) end end |
#suppress_email(email) ⇒ Object
109 110 111 |
# File 'lib/madmimi.rb', line 109 def suppress_email(email) do_request(SUPPRESS_USER_PATH.gsub('%email%', email), :post) end |
#suppressed_since(timestamp) ⇒ Object
105 106 107 |
# File 'lib/madmimi.rb', line 105 def suppressed_since() do_request(SUPPRESSED_SINCE_PATH.gsub('%timestamp%', ), :get) end |
#transactional_mailing_status(transaction_id) ⇒ Object
149 150 151 |
# File 'lib/madmimi.rb', line 149 def transactional_mailing_status(transaction_id) do_request(TRANSACTIONAL_MAILING_STATUS_PATH.gsub('%transaction_id%', transaction_id.to_s), :get) end |
#username ⇒ Object
58 59 60 |
# File 'lib/madmimi.rb', line 58 def username @api_settings[:username] end |