Class: Sailthru::Client
- Inherits:
-
Object
- Object
- Sailthru::Client
- Includes:
- Helpers
- Defined in:
- lib/sailthru/client.rb
Constant Summary collapse
- DEFAULT_API_URI =
'https://api.sailthru.com'
Instance Attribute Summary collapse
-
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
-
#api_delete(action, data) ⇒ Object
Perform API DELETE request.
-
#api_get(action, data) ⇒ Object
Perform API GET request.
-
#api_post(action, data, binary_key = nil) ⇒ Object
Perform API POST request.
-
#cancel_blast(blast_id) ⇒ Object
params: blast_id, Fixnum | String.
- #cancel_send(send_id) ⇒ Object
-
#change_email(new_email, old_email, options = {}) ⇒ Object
params: new_email, String old_email, String options, Hash mapping optional parameters returns: Hash of response data.
-
#delete_alert(email, alert_id) ⇒ Object
params email, String alert_id, String.
-
#delete_blast(blast_id) ⇒ Object
params: blast_id, Fixnum | String.
-
#delete_list(list) ⇒ Object
params list, String.
-
#delete_template(template_name) ⇒ Object
params: template_name, String returns: Hash of response data.
-
#get_alert(email) ⇒ Object
params email, String.
-
#get_blast(blast_id, options = {}) ⇒ Object
params: blast_id, Fixnum | String options, hash returns: Hash, response data from server.
-
#get_email(email) ⇒ Object
params: email, String returns: Hash, response data from server.
-
#get_job_status(job_id) ⇒ Object
get status of a job.
-
#get_last_rate_limit_info(endpoint, method) ⇒ Object
params endpoint, String a e.g.
-
#get_list(list) ⇒ Object
params list, String.
-
#get_lists ⇒ Object
params.
-
#get_send(send_id) ⇒ Object
params: send_id, Fixnum returns: Hash, response data from server.
-
#get_stats(stat) ⇒ Object
DEPRECATED: Please use either stats_list or stats_blast params: stat, String.
-
#get_template(template_name) ⇒ Object
params: template_name, String returns: Hash of response data.
-
#get_templates(templates = {}) ⇒ Object
returns: Hash of response data.
-
#get_trigger_by_event(event) ⇒ Object
params event, String Get an existing trigger.
-
#get_trigger_by_template(template, trigger_id = nil) ⇒ Object
params template, String trigger_id, String Get an existing trigger.
-
#get_triggers ⇒ Object
params Get an existing trigger.
-
#get_user_by_key(id, key, fields = {}) ⇒ Object
Get user by specified key.
-
#get_user_by_sid(id, fields = {}) ⇒ Object
Get user by Sailthru ID.
-
#initialize(api_key = nil, secret = nil, api_uri = nil, proxy_host = nil, proxy_port = nil, opts = {}) ⇒ Client
constructor
params: api_key, String secret, String api_uri, String.
- #multi_send(template_name, emails, vars = {}, options = {}, schedule_time = nil, evars = {}) ⇒ Object
-
#post_event(id, event, options = {}) ⇒ Object
params id, String event, String options, Hash (Can contain vars, Hash and/or key) Notify Sailthru of an Event.
-
#post_event_trigger(event, time, time_unit, zephyr) ⇒ Object
params template, String time, String time_unit, String zephyr, String Create or update a trigger.
-
#post_template_trigger(template, time, time_unit, event, zephyr) ⇒ Object
params template, String time, String time_unit, String event, String zephyr, String Create or update a trigger.
-
#process_export_list_job(list, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for export list job.
-
#process_import_job(list, emails, report_email = nil, postback_url = nil, options = {}) ⇒ Object
params emails, String | Array implementation for import_job.
-
#process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for import job using file upload.
-
#process_job(job, options = {}, report_email = nil, postback_url = nil, binary_key = nil) ⇒ Object
params job, String options, hash report_email, String postback_url, String binary_key, String.
-
#process_purchase_import_job_from_file(file_path, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for purchase import job using file upload.
-
#process_snapshot_job(query = {}, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for snapshot job.
-
#process_update_job_from_file(file_path, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for update job using file upload.
-
#purchase(email, items, incomplete = nil, message_id = nil, options = {}) ⇒ Object
params: email, String items, Array of Hashes incomplete, Integer message_id, String options, Hash returns: hash, response from server.
-
#push_content(title, url, date = nil, tags = nil, vars = {}, options = {}) ⇒ Object
DEPRECATED: Please use save_content params title, String url, String date, String tags, Array or Comma separated string vars, Hash options, Hash.
-
#receive_hardbounce_post(params, request) ⇒ Object
params: params, Hash request, String returns: TrueClass or FalseClass, Returns true if the incoming request is an authenticated hardbounce post.
-
#receive_list_post(params, request) ⇒ Object
List Postbacks must be enabled by Sailthru Contact your account manager or contact support to have this enabled.
-
#receive_optout_post(params, request) ⇒ Object
params: params, Hash request, String returns: TrueClass or FalseClass, Returns true if the incoming request is an authenticated optout post.
-
#receive_verify_post(params, request) ⇒ Object
params: params, Hash request, String returns: boolean, Returns true if the incoming request is an authenticated verify post.
-
#save_alert(email, type, template, _when = nil, options = {}) ⇒ Object
params email, String type, String template, String _when, String options, hash.
-
#save_content(id, options) ⇒ Object
params id, String – An identifier for the item (by default, the item’s URL).
-
#save_list(list, options = {}) ⇒ Object
params list, String options, Hash Create a list, or update a list.
-
#save_template(template_name, template_fields) ⇒ Object
params: template_name, String template_fields, Hash returns: Hash containg response from the server.
-
#save_user(id, options = {}) ⇒ Object
Create new user, or update existing user.
-
#schedule_blast(name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options = {}) ⇒ Object
params: name, String list, String schedule_time, String from_name, String from_email, String subject, String content_html, String content_text, String options, Hash returns: Hash, response data from server.
-
#schedule_blast_from_blast(blast_id, schedule_time, options = {}) ⇒ Object
Schedule a mass mail blast from previous blast.
-
#schedule_blast_from_template(template, list, schedule_time, options = {}) ⇒ Object
Schedule a mass mail blast from template.
-
#send_email(template_name, email, vars = {}, options = {}, schedule_time = nil, limit = {}) ⇒ Object
params: template_name, String email, String vars, Hash options, Hash replyto: override Reply-To header test: send as test email (subject line will be marked, will not count towards stats) returns: Hash, response data from server.
-
#set_email(email, vars = {}, lists = {}, templates = {}, options = {}) ⇒ Object
params: email, String vars, Hash lists, Hash mapping list name => 1 for subscribed, 0 for unsubscribed options, Hash mapping optional parameters returns: Hash, response data from server.
-
#stats_blast(blast_id = nil, start_date = nil, end_date = nil, options = {}) ⇒ Object
params blast_id, String start_date, String end_date, String options, Hash.
-
#stats_list(list = nil, date = nil) ⇒ Object
params list, String date, String.
-
#stats_send(template = nil, start_date = nil, end_date = nil, options = {}) ⇒ Object
params template, String start_date, String end_date, String options, Hash.
-
#update_blast(blast_id, name = nil, list = nil, schedule_time = nil, from_name = nil, from_email = nil, subject = nil, content_html = nil, content_text = nil, options = {}) ⇒ Object
params blast_id, Fixnum | String name, String list, String schedule_time, String from_name, String from_email, String subject, String content_html, String content_text, String options, hash.
Methods included from Helpers
#extract_param_values, #flatten_nested_hash, #get_signature_hash, #get_signature_string
Constructor Details
#initialize(api_key = nil, secret = nil, api_uri = nil, proxy_host = nil, proxy_port = nil, opts = {}) ⇒ Client
params:
api_key, String
secret, String
api_uri, String
Instantiate a new client; constructor optionally takes overrides for key/secret/uri and proxy server settings.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sailthru/client.rb', line 24 def initialize(api_key=nil, secret=nil, api_uri=nil, proxy_host=nil, proxy_port=nil, opts={}) @api_key = api_key || Sailthru.api_key || raise(ArgumentError, "You must provide an API key or call Sailthru.credentials() first") @secret = secret || Sailthru.secret || raise(ArgumentError, "You must provide your secret or call Sailthru.credentials() first") @api_uri = api_uri.nil? ? DEFAULT_API_URI : api_uri @proxy_host = proxy_host @proxy_port = proxy_port @verify_ssl = true @opts = opts @last_rate_limit_info = {} end |
Instance Attribute Details
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
16 17 18 |
# File 'lib/sailthru/client.rb', line 16 def verify_ssl @verify_ssl end |
Instance Method Details
#api_delete(action, data) ⇒ Object
Perform API DELETE request
762 763 764 |
# File 'lib/sailthru/client.rb', line 762 def api_delete(action, data) api_request(action, data, 'DELETE') end |
#api_get(action, data) ⇒ Object
Perform API GET request
752 753 754 |
# File 'lib/sailthru/client.rb', line 752 def api_get(action, data) api_request(action, data, 'GET') end |
#api_post(action, data, binary_key = nil) ⇒ Object
Perform API POST request
757 758 759 |
# File 'lib/sailthru/client.rb', line 757 def api_post(action, data, binary_key = nil) api_request(action, data, 'POST', binary_key) end |
#cancel_blast(blast_id) ⇒ Object
params:
blast_id, Fixnum | String
Cancel a scheduled Blast
184 185 186 |
# File 'lib/sailthru/client.rb', line 184 def cancel_blast(blast_id) api_post(:blast, {:blast_id => blast_id, :schedule_time => ''}) end |
#cancel_send(send_id) ⇒ Object
76 77 78 |
# File 'lib/sailthru/client.rb', line 76 def cancel_send(send_id) api_delete(:send, {:send_id => send_id.to_s}) end |
#change_email(new_email, old_email, options = {}) ⇒ Object
params:
new_email, String
old_email, String
options, Hash mapping optional parameters
returns:
Hash of response data.
change a user’s email address.
232 233 234 235 236 237 |
# File 'lib/sailthru/client.rb', line 232 def change_email(new_email, old_email, = {}) data = data[:email] = new_email data[:change_email] = old_email api_post(:email, data) end |
#delete_alert(email, alert_id) ⇒ Object
params
email, String
alert_id, String
delete user alert
582 583 584 585 |
# File 'lib/sailthru/client.rb', line 582 def delete_alert(email, alert_id) data = {:email => email, :alert_id => alert_id} api_delete(:alert, data) end |
#delete_blast(blast_id) ⇒ Object
params:
blast_id, Fixnum | String
Delete a Blast
192 193 194 |
# File 'lib/sailthru/client.rb', line 192 def delete_blast(blast_id) api_delete(:blast, {:blast_id => blast_id}) end |
#delete_list(list) ⇒ Object
params
list, String
Deletes a list
545 546 547 |
# File 'lib/sailthru/client.rb', line 545 def delete_list(list) api_delete(:list, {:list => list}) end |
#delete_template(template_name) ⇒ Object
params:
template_name, String
returns:
Hash of response data.
Delete a template.
276 277 278 |
# File 'lib/sailthru/client.rb', line 276 def delete_template(template_name) api_delete(:template, {:template => template_name}) end |
#get_alert(email) ⇒ Object
params
email, String
get user alert data
553 554 555 |
# File 'lib/sailthru/client.rb', line 553 def get_alert(email) api_get(:alert, {:email => email}) end |
#get_blast(blast_id, options = {}) ⇒ Object
params:
blast_id, Fixnum | String
options, hash
returns:
Hash, response data from server
Get information on a previously scheduled email blast
175 176 177 178 |
# File 'lib/sailthru/client.rb', line 175 def get_blast(blast_id, ={}) [:blast_id] = blast_id.to_s api_get(:blast, ) end |
#get_email(email) ⇒ Object
params:
email, String
returns:
Hash, response data from server
Return information about an email address, including replacement vars and lists.
202 203 204 |
# File 'lib/sailthru/client.rb', line 202 def get_email(email) api_get(:email, {:email => email}) end |
#get_job_status(job_id) ⇒ Object
get status of a job
655 656 657 |
# File 'lib/sailthru/client.rb', line 655 def get_job_status(job_id) api_get(:job, {'job_id' => job_id}) end |
#get_last_rate_limit_info(endpoint, method) ⇒ Object
params
endpoint, String a e.g. "user" or "send"
method, String "GET" or "POST"
returns
Hash rate info
Get rate info for a particular endpoint/method, as of the last time a request was sent to the given endpoint/method Includes the following keys:
limit: the per-minute limit for the given endpoint/method
remaining: the number of allotted requests remaining in the current minute for the given endpoint/method
reset: unix timestamp of the top of the next minute, when the rate limit will reset
776 777 778 779 |
# File 'lib/sailthru/client.rb', line 776 def get_last_rate_limit_info(endpoint, method) rate_info_key = get_rate_limit_info_key(endpoint, method) @last_rate_limit_info[rate_info_key] end |
#get_list(list) ⇒ Object
params
list, String
Get information about a list.
520 521 522 |
# File 'lib/sailthru/client.rb', line 520 def get_list(list) api_get(:list, {:list => list}) end |
#get_lists ⇒ Object
params
Get information about all lists
527 528 529 |
# File 'lib/sailthru/client.rb', line 527 def get_lists api_get(:list, {}) end |
#get_send(send_id) ⇒ Object
params:
send_id, Fixnum
returns:
Hash, response data from server
Get the status of a send.
72 73 74 |
# File 'lib/sailthru/client.rb', line 72 def get_send(send_id) api_get(:send, {:send_id => send_id.to_s}) end |
#get_stats(stat) ⇒ Object
DEPRECATED: Please use either stats_list or stats_blast params:
stat, String
returns:
hash, response from server
Request various stats from Sailthru.
399 400 401 402 |
# File 'lib/sailthru/client.rb', line 399 def get_stats(stat) warn "[DEPRECATION] `get_stats` is deprecated. Please use `stats_list` and `stats_blast` instead" api_get(:stats, {:stat => stat}) end |
#get_template(template_name) ⇒ Object
params:
template_name, String
returns:
Hash of response data.
Get a template.
253 254 255 |
# File 'lib/sailthru/client.rb', line 253 def get_template(template_name) api_get(:template, {:template => template_name}) end |
#get_templates(templates = {}) ⇒ Object
returns:
Hash of response data.
Get all templates
243 244 245 |
# File 'lib/sailthru/client.rb', line 243 def get_templates(templates = {}) api_get(:template, templates) end |
#get_trigger_by_event(event) ⇒ Object
params
event, String
Get an existing trigger
701 702 703 704 705 |
# File 'lib/sailthru/client.rb', line 701 def get_trigger_by_event(event) data = {} data['event'] = event api_get(:trigger, data) end |
#get_trigger_by_template(template, trigger_id = nil) ⇒ Object
params
template, String
trigger_id, String
Get an existing trigger
691 692 693 694 695 696 |
# File 'lib/sailthru/client.rb', line 691 def get_trigger_by_template(template, trigger_id = nil) data = {} data['template'] = template if trigger_id != nil then data['trigger_id'] = trigger_id end api_get(:trigger, data) end |
#get_triggers ⇒ Object
params Get an existing trigger
683 684 685 |
# File 'lib/sailthru/client.rb', line 683 def get_triggers api_get(:trigger, {}) end |
#get_user_by_key(id, key, fields = {}) ⇒ Object
Get user by specified key
665 666 667 668 669 670 671 672 |
# File 'lib/sailthru/client.rb', line 665 def get_user_by_key(id, key, fields = {}) data = { 'id' => id, 'key' => key, 'fields' => fields } api_get(:user, data) end |
#get_user_by_sid(id, fields = {}) ⇒ Object
Get user by Sailthru ID
660 661 662 |
# File 'lib/sailthru/client.rb', line 660 def get_user_by_sid(id, fields = {}) api_get(:user, {'id' => id, 'fields' => fields}) end |
#multi_send(template_name, emails, vars = {}, options = {}, schedule_time = nil, evars = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sailthru/client.rb', line 55 def multi_send(template_name, emails, vars={}, = {}, schedule_time = nil, evars = {}) post = {} post[:template] = template_name post[:email] = emails post[:vars] = vars if vars.length >= 1 post[:options] = if .length >= 1 post[:schedule_time] = schedule_time if !schedule_time.nil? post[:evars] = evars if evars.length >= 1 api_post(:send, post) end |
#post_event(id, event, options = {}) ⇒ Object
params
id, String
event, String
options, Hash (Can contain vars, Hash and/or key)
Notify Sailthru of an Event
744 745 746 747 748 749 |
# File 'lib/sailthru/client.rb', line 744 def post_event(id, event, = {}) data = data['id'] = id data['event'] = event api_post(:event, data) end |
#post_event_trigger(event, time, time_unit, zephyr) ⇒ Object
params
template, String
time, String
time_unit, String
zephyr, String
Create or update a trigger
730 731 732 733 734 735 736 737 |
# File 'lib/sailthru/client.rb', line 730 def post_event_trigger(event, time, time_unit, zephyr) data = {} data['time'] = time data['time_unit'] = time_unit data['event'] = event data['zephyr'] = zephyr api_post(:trigger, data) end |
#post_template_trigger(template, time, time_unit, event, zephyr) ⇒ Object
params
template, String
time, String
time_unit, String
event, String
zephyr, String
Create or update a trigger
714 715 716 717 718 719 720 721 722 |
# File 'lib/sailthru/client.rb', line 714 def post_template_trigger(template, time, time_unit, event, zephyr) data = {} data['template'] = template data['time'] = time data['time_unit'] = time_unit data['event'] = event data['zephyr'] = zephyr api_post(:trigger, data) end |
#process_export_list_job(list, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for export list job
648 649 650 651 652 |
# File 'lib/sailthru/client.rb', line 648 def process_export_list_job(list, report_email = nil, postback_url = nil, = {}) data = data['list'] = list process_job(:export_list_data, data, report_email, postback_url) end |
#process_import_job(list, emails, report_email = nil, postback_url = nil, options = {}) ⇒ Object
params
emails, String | Array
implementation for import_job
611 612 613 614 615 616 |
# File 'lib/sailthru/client.rb', line 611 def process_import_job(list, emails, report_email = nil, postback_url = nil, = {}) data = data['list'] = list data['emails'] = Array(emails).join(',') process_job(:import, data, report_email, postback_url) end |
#process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for import job using file upload
619 620 621 622 623 624 |
# File 'lib/sailthru/client.rb', line 619 def process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil, = {}) data = data['list'] = list data['file'] = file_path process_job(:import, data, report_email, postback_url, 'file') end |
#process_job(job, options = {}, report_email = nil, postback_url = nil, binary_key = nil) ⇒ Object
params
job, String
options, hash
report_email, String
postback_url, String
binary_key, String
interface for making request to job call
595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/sailthru/client.rb', line 595 def process_job(job, = {}, report_email = nil, postback_url = nil, binary_key = nil) data = data['job'] = job if !report_email.nil? data['report_email'] = report_email end if !postback_url.nil? data['postback_url'] = postback_url end api_post(:job, data, binary_key) end |
#process_purchase_import_job_from_file(file_path, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for purchase import job using file upload
634 635 636 637 638 |
# File 'lib/sailthru/client.rb', line 634 def process_purchase_import_job_from_file(file_path, report_email = nil, postback_url = nil, = {}) data = data['file'] = file_path process_job(:purchase_import, data, report_email, postback_url, 'file') end |
#process_snapshot_job(query = {}, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for snapshot job
641 642 643 644 645 |
# File 'lib/sailthru/client.rb', line 641 def process_snapshot_job(query = {}, report_email = nil, postback_url = nil, = {}) data = data['query'] = query process_job(:snapshot, data, report_email, postback_url) end |
#process_update_job_from_file(file_path, report_email = nil, postback_url = nil, options = {}) ⇒ Object
implementation for update job using file upload
627 628 629 630 631 |
# File 'lib/sailthru/client.rb', line 627 def process_update_job_from_file(file_path, report_email = nil, postback_url = nil, = {}) data = data['file'] = file_path process_job(:update, data, report_email, postback_url, 'file') end |
#purchase(email, items, incomplete = nil, message_id = nil, options = {}) ⇒ Object
params:
email, String
items, Array of Hashes
incomplete, Integer
message_id, String
options, Hash
returns:
hash, response from server
Record that a user has made a purchase, or has added items to their purchase total.
377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/sailthru/client.rb', line 377 def purchase(email, items, incomplete = nil, = nil, = {}) data = data[:email] = email data[:items] = items if incomplete != nil data[:incomplete] = incomplete.to_i end if != nil data[:message_id] = end api_post(:purchase, data) end |
#push_content(title, url, date = nil, tags = nil, vars = {}, options = {}) ⇒ Object
DEPRECATED: Please use save_content params
title, String
url, String
date, String
tags, Array or Comma separated string
vars, Hash
options, Hash
Push a new piece of content to Sailthru, triggering any applicable alerts. docs.sailthru.com/api/content
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/sailthru/client.rb', line 482 def push_content(title, url, date = nil, = nil, vars = {}, = {}) data = data[:title] = title data[:url] = url if date != nil data[:date] = date end if != nil if .class == Array = .join(',') end data[:tags] = end if vars.length > 0 data[:vars] = vars end api_post(:content, data) end |
#receive_hardbounce_post(params, request) ⇒ Object
params:
params, Hash
request, String
returns:
TrueClass or FalseClass, Returns true if the incoming request is an authenticated hardbounce post.
353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/sailthru/client.rb', line 353 def receive_hardbounce_post(params, request) if request.post? [:action, :email, :sig].each { |key| return false unless params.has_key?(key) } return false unless params[:action] == 'hardbounce' sig = params.delete(:sig) params.delete(:controller) sig == get_signature_hash(params, @secret) else false end end |
#receive_list_post(params, request) ⇒ Object
List Postbacks must be enabled by Sailthru Contact your account manager or contact support to have this enabled
params:
params, Hash
request, String
returns:
TrueClass or FalseClass, Returns true if the incoming request is an authenticated list post.
333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/sailthru/client.rb', line 333 def receive_list_post(params, request) if request.post? [:action, :email, :sig].each { |key| return false unless params.has_key?(key) } return false unless params[:action] == 'update' sig = params.delete(:sig) params.delete(:controller) sig == get_signature_hash(params, @secret) else false end end |
#receive_optout_post(params, request) ⇒ Object
params:
params, Hash
request, String
returns:
TrueClass or FalseClass, Returns true if the incoming request is an authenticated optout post.
311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/sailthru/client.rb', line 311 def receive_optout_post(params, request) if request.post? [:action, :email, :sig].each { |key| return false unless params.has_key?(key) } return false unless params[:action] == 'optout' sig = params.delete(:sig) params.delete(:controller) sig == get_signature_hash(params, @secret) else false end end |
#receive_verify_post(params, request) ⇒ Object
params:
params, Hash
request, String
returns:
boolean, Returns true if the incoming request is an authenticated verify post.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/sailthru/client.rb', line 285 def receive_verify_post(params, request) if request.post? [:action, :email, :send_id, :sig].each { |key| return false unless params.has_key?(key) } return false unless params[:action] == :verify sig = params.delete(:sig) params.delete(:controller) return false unless sig == get_signature_hash(params, @secret) _send = get_send(params[:send_id]) return false unless _send.has_key?('email') return false unless _send['email'] == params[:email] return true else return false end end |
#save_alert(email, type, template, _when = nil, options = {}) ⇒ Object
params
email, String
type, String
template, String
_when, String
options, hash
Add a new alert to a user. You can add either a realtime or a summary alert (daily/weekly). _when is only required when alert type is weekly or daily
566 567 568 569 570 571 572 573 574 575 |
# File 'lib/sailthru/client.rb', line 566 def save_alert(email, type, template, _when = nil, = {}) data = data[:email] = email data[:type] = type data[:template] = template if (type == 'weekly' || type == 'daily') data[:when] = _when end api_post(:alert, data) end |
#save_content(id, options) ⇒ Object
params
id, String – An identifier for the item (by default, the item’s URL).
options, Hash - Containing any of the parameters described on
https://getstarted.sailthru.com/developers/api/content/#POST_Mode
Push a new piece of content to Sailthru, triggering any applicable alerts. docs.sailthru.com/api/content
508 509 510 511 512 513 514 |
# File 'lib/sailthru/client.rb', line 508 def save_content(id, ) data = data[:id] = id data[:tags] = data[:tags].join(',') if data[:tags].respond_to?(:join) api_post(:content, data) end |
#save_list(list, options = {}) ⇒ Object
params
list, String
options, Hash
Create a list, or update a list.
535 536 537 538 539 |
# File 'lib/sailthru/client.rb', line 535 def save_list(list, = {}) data = data[:list] = list api_post(:list, data) end |
#save_template(template_name, template_fields) ⇒ Object
params:
template_name, String
template_fields, Hash
returns:
Hash containg response from the server.
Save a template.
264 265 266 267 268 |
# File 'lib/sailthru/client.rb', line 264 def save_template(template_name, template_fields) data = template_fields data[:template] = template_name api_post(:template, data) end |
#save_user(id, options = {}) ⇒ Object
Create new user, or update existing user
675 676 677 678 679 |
# File 'lib/sailthru/client.rb', line 675 def save_user(id, = {}) data = data['id'] = id api_post(:user, data) end |
#schedule_blast(name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options = {}) ⇒ Object
params:
name, String
list, String
schedule_time, String
from_name, String
from_email, String
subject, String
content_html, String
content_text, String
options, Hash
returns:
Hash, response data from server
Schedule a mass mail blast
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sailthru/client.rb', line 94 def schedule_blast(name, list, schedule_time, from_name, from_email, subject, content_html, content_text, = {}) post = ? : {} post[:name] = name post[:list] = list post[:schedule_time] = schedule_time post[:from_name] = from_name post[:from_email] = from_email post[:subject] = subject post[:content_html] = content_html post[:content_text] = content_text api_post(:blast, post) end |
#schedule_blast_from_blast(blast_id, schedule_time, options = {}) ⇒ Object
Schedule a mass mail blast from previous blast
117 118 119 120 121 122 123 |
# File 'lib/sailthru/client.rb', line 117 def schedule_blast_from_blast(blast_id, schedule_time, ={}) post = ? : {} post[:copy_blast] = blast_id #post[:name] = name post[:schedule_time] = schedule_time api_post(:blast, post) end |
#schedule_blast_from_template(template, list, schedule_time, options = {}) ⇒ Object
Schedule a mass mail blast from template
108 109 110 111 112 113 114 |
# File 'lib/sailthru/client.rb', line 108 def schedule_blast_from_template(template, list, schedule_time, ={}) post = ? : {} post[:copy_template] = template post[:list] = list post[:schedule_time] = schedule_time api_post(:blast, post) end |
#send_email(template_name, email, vars = {}, options = {}, schedule_time = nil, limit = {}) ⇒ Object
params:
template_name, String
email, String
vars, Hash
options, Hash
replyto: override Reply-To header
test: send as test email (subject line will be marked, will not count towards stats)
returns:
Hash, response data from server
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sailthru/client.rb', line 44 def send_email(template_name, email, vars={}, = {}, schedule_time = nil, limit = {}) post = {} post[:template] = template_name post[:email] = email post[:vars] = vars if vars.length >= 1 post[:options] = if .length >= 1 post[:schedule_time] = schedule_time if !schedule_time.nil? post[:limit] = limit if limit.length >= 1 api_post(:send, post) end |
#set_email(email, vars = {}, lists = {}, templates = {}, options = {}) ⇒ Object
params:
email, String
vars, Hash
lists, Hash mapping list name => 1 for subscribed, 0 for unsubscribed
options, Hash mapping optional parameters
returns:
Hash, response data from server
Set replacement vars and/or list subscriptions for an email address.
215 216 217 218 219 220 221 222 |
# File 'lib/sailthru/client.rb', line 215 def set_email(email, vars = {}, lists = {}, templates = {}, = {}) data = data[:email] = email data[:vars] = vars unless vars.empty? data[:lists] = lists unless lists.empty? data[:templates] = templates unless templates.empty? api_post(:email, data) end |
#stats_blast(blast_id = nil, start_date = nil, end_date = nil, options = {}) ⇒ Object
params
blast_id, String
start_date, String
end_date, String
options, Hash
returns:
hash, response from server
Retrieve information about a particular blast or aggregated information from all of blasts over a specified date range
432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/sailthru/client.rb', line 432 def stats_blast(blast_id = nil, start_date = nil, end_date = nil, = {}) data = if blast_id != nil data[:blast_id] = blast_id end if start_date != nil data[:start_date] = start_date end if end_date != nil data[:end_date] = end_date end data[:stat] = 'blast' api_get(:stats, data) end |
#stats_list(list = nil, date = nil) ⇒ Object
params
list, String
date, String
returns:
hash, response from server
Retrieve information about your subscriber counts on a particular list, on a particular day.
411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/sailthru/client.rb', line 411 def stats_list(list = nil, date = nil) data = {} if list != nil data[:list] = list end if date != nil data[:date] = date end data[:stat] = 'list' api_get(:stats, data) end |
#stats_send(template = nil, start_date = nil, end_date = nil, options = {}) ⇒ Object
params
template, String
start_date, String
end_date, String
options, Hash
returns:
hash, response from server
Retrieve information about a particular blast or aggregated information from all of blasts over a specified date range
456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/sailthru/client.rb', line 456 def stats_send(template = nil, start_date = nil, end_date = nil, = {}) data = if template != nil data[:template] = template end if start_date != nil data[:start_date] = start_date end if end_date != nil data[:end_date] = end_date end data[:stat] = 'send' api_get(:stats, data) end |
#update_blast(blast_id, name = nil, list = nil, schedule_time = nil, from_name = nil, from_email = nil, subject = nil, content_html = nil, content_text = nil, options = {}) ⇒ Object
params
blast_id, Fixnum | String
name, String
list, String
schedule_time, String
from_name, String
from_email, String
subject, String
content_html, String
content_text, String
options, hash
updates existing blast
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/sailthru/client.rb', line 138 def update_blast(blast_id, name = nil, list = nil, schedule_time = nil, from_name = nil, from_email = nil, subject = nil, content_html = nil, content_text = nil, = {}) data = ? : {} data[:blast_id] = blast_id if name != nil data[:name] = name end if list != nil data[:list] = list end if schedule_time != nil data[:schedule_time] = schedule_time end if from_name != nil data[:from_name] = from_name end if from_email != nil data[:from_email] = from_email end if subject != nil data[:subject] = subject end if content_html != nil data[:content_html] = content_html end if content_text != nil data[:content_text] = content_text end api_post(:blast, data) end |