Class: MaropostApi::Contacts
- Inherits:
-
Object
- Object
- MaropostApi::Contacts
- Defined in:
- lib/maropost_api/contacts.rb
Overview
Contains methods that get Contacts based on provided parameters. The method names themselves reveal the type of reports they are getting.
Instance Method Summary collapse
-
#create_contact(email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = false, **options) ⇒ Object
creates a contact.
-
#create_or_update_for_list(list_id, email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = true, subscribe = true) ⇒ Object
creates a contact.
-
#create_or_update_for_lists_and_workflows(email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = true, **options) ⇒ Object
creates a contact.
-
#delete_contact_for_uid(uid) ⇒ Object
deletes contact for uid.
-
#delete_from_all_lists(email) ⇒ Object
deletes contact from all the lists.
-
#delete_from_lists(contact_id, lists_to_delete_from) ⇒ Object
deletes contact from list.
-
#delete_list_contact(list_id, contact_id) ⇒ Object
deletes list for the given contact.
-
#get_clicks(contact_id, page) ⇒ Object
gets clicks for the provided.
-
#get_contact_for_list(list_id, contact_id) ⇒ Object
gets contacts for the provided.
-
#get_for_email(email) ⇒ Object
gets contact for the provided.
-
#get_for_list(list_id, page) ⇒ Object
gets contacts for the provided.
-
#get_opens(contact_id, page) ⇒ Object
gets opens for the provided.
-
#initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"]) ⇒ Contacts
constructor
Creates a new instance of Reports class.
-
#unsubscribe_all(contact_field_value, contact_field_name) ⇒ Object
unsubscribes all those contacts matching.
-
#update_for_list_and_contact(list_id, contact_id, email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = true, subscribe = true) ⇒ Object
creates a contact.
Constructor Details
#initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"]) ⇒ Contacts
Creates a new instance of Reports class.
10 11 12 13 |
# File 'lib/maropost_api/contacts.rb', line 10 def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"]) MaropostApi.instance_variable_set(:@api_key, api_key) MaropostApi.instance_variable_set(:@account, account) end |
Instance Method Details
#create_contact(email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = false, **options) ⇒ Object
creates a contact
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/maropost_api/contacts.rb', line 82 def create_contact( email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, = [], = [], remove_from_dnm = false, ** ) args = method(__method__).parameters body = {contact: {}} args.each do |arg| k = arg[1].to_s v = eval(k) body[:contact][k] = v unless v.nil? end # p body path = full_resource_path() MaropostApi.post_result(path, body) end |
#create_or_update_for_list(list_id, email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = true, subscribe = true) ⇒ Object
creates a contact
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/maropost_api/contacts.rb', line 122 def create_or_update_for_list( list_id, email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, = [], = [], remove_from_dnm = true, subscribe = true ) args = method(__method__).parameters body = {contact: {}} args.each do |arg| k = arg[1].to_s next if k == "list_id" v = eval(k) body[:contact][k] = v unless v.nil? end email_existence = get_for_email(email) if email_existence.success contact_id = email_existence.data["id"] full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", "lists") MaropostApi.put_result(full_path, body) else full_path = full_resource_path("/#{list_id}/contacts", "lists") MaropostApi.post_result(full_path, body) end end |
#create_or_update_for_lists_and_workflows(email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = true, **options) ⇒ Object
creates a contact
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/maropost_api/contacts.rb', line 172 def create_or_update_for_lists_and_workflows( email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, = [], = [], remove_from_dnm = true, ** ) args = method(__method__).parameters body = {contact: {}} args.each do |arg| k = arg[1].to_s v = eval(k) body[:contact][k] = v unless v.nil? end email_existence = get_for_email email if email_existence.success contact_id = email_existence.data["id"] full_path = full_resource_path("/#{contact_id}") body[:contact].delete("options") body[:contact]["subscribe"] = [:subscribe] if .has_key? :subscribe MaropostApi.put_result(full_path, body) else full_path = full_resource_path MaropostApi.post_result(full_path, body) end end |
#delete_contact_for_uid(uid) ⇒ Object
deletes contact for uid
287 288 289 290 291 292 |
# File 'lib/maropost_api/contacts.rb', line 287 def delete_contact_for_uid(uid) full_path = full_resource_path("/delete_all") query_params = MaropostApi.set_query_params({"uid" => uid}) MaropostApi.delete_result(full_path, query_params) end |
#delete_from_all_lists(email) ⇒ Object
deletes contact from all the lists
266 267 268 269 270 271 |
# File 'lib/maropost_api/contacts.rb', line 266 def delete_from_all_lists(email) full_path = full_resource_path('/delete_all') query_params = MaropostApi.set_query_params({"contact[email]" => email}) MaropostApi.delete_result(full_path, query_params) end |
#delete_from_lists(contact_id, lists_to_delete_from) ⇒ Object
deletes contact from list
277 278 279 280 281 282 |
# File 'lib/maropost_api/contacts.rb', line 277 def delete_from_lists(contact_id, lists_to_delete_from) full_path = full_resource_path("/#{contact_id}") query_params = MaropostApi.set_query_params({'list_ids' => lists_to_delete_from.join(',')}) MaropostApi.delete_result(full_path, query_params) end |
#delete_list_contact(list_id, contact_id) ⇒ Object
deletes list for the given contact
298 299 300 301 302 303 |
# File 'lib/maropost_api/contacts.rb', line 298 def delete_list_contact(list_id, contact_id) full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", "lists") query_params = MaropostApi.set_query_params MaropostApi.delete_result(full_path, query_params) end |
#get_clicks(contact_id, page) ⇒ Object
gets clicks for the provided
40 41 42 43 44 45 |
# File 'lib/maropost_api/contacts.rb', line 40 def get_clicks(contact_id, page) full_path = full_resource_path("/#{contact_id}/click_report") query_params = MaropostApi.set_query_params({page: page}) MaropostApi.get_result(full_path, query_params) end |
#get_contact_for_list(list_id, contact_id) ⇒ Object
gets contacts for the provided
62 63 64 65 66 67 |
# File 'lib/maropost_api/contacts.rb', line 62 def get_contact_for_list(list_id, contact_id) full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", 'lists') query_params = MaropostApi.set_query_params MaropostApi.get_result(full_path, query_params) end |
#get_for_email(email) ⇒ Object
gets contact for the provided
18 19 20 21 22 23 |
# File 'lib/maropost_api/contacts.rb', line 18 def get_for_email(email) full_path = full_resource_path("/email") query_params = MaropostApi.set_query_params({"contact[email]" => email}) MaropostApi.get_result(full_path, query_params) end |
#get_for_list(list_id, page) ⇒ Object
gets contacts for the provided
51 52 53 54 55 56 |
# File 'lib/maropost_api/contacts.rb', line 51 def get_for_list(list_id, page) full_path = full_resource_path("/#{list_id}/contacts", 'lists') query_params = MaropostApi.set_query_params({page: page}) MaropostApi.get_result(full_path, query_params) end |
#get_opens(contact_id, page) ⇒ Object
gets opens for the provided
29 30 31 32 33 34 |
# File 'lib/maropost_api/contacts.rb', line 29 def get_opens(contact_id, page) full_path = full_resource_path("/#{contact_id}/open_report") query_params = MaropostApi.set_query_params({page: page}) MaropostApi.get_result(full_path, query_params) end |
#unsubscribe_all(contact_field_value, contact_field_name) ⇒ Object
unsubscribes all those contacts matching
256 257 258 259 260 261 |
# File 'lib/maropost_api/contacts.rb', line 256 def unsubscribe_all(contact_field_value, contact_field_name) full_path = full_resource_path('/unsubscribe_all') query_params = MaropostApi.set_query_params({"contact[#{contact_field_name}]" => contact_field_value}) MaropostApi.put_result(full_path, {}, query_params) end |
#update_for_list_and_contact(list_id, contact_id, email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, add_tags = [], remove_tags = [], remove_from_dnm = true, subscribe = true) ⇒ Object
creates a contact
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/maropost_api/contacts.rb', line 223 def update_for_list_and_contact( list_id, contact_id, email, first_name, last_name, phone, fax, uid = nil, custom_field = {}, = [], = [], remove_from_dnm = true, subscribe = true ) args = method(__method__).parameters body = {contact: {}} args.each do |arg| k = arg[1].to_s next if ["list_id", "contact_id"].include? k v = eval(k) body[:contact][k] = v unless v.nil? end full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", "lists") MaropostApi.put_result(full_path, body) end |