Class: Sailthru::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sailthru/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sailthru/client.rb', line 5

def initialize
  @config = YAML.load(File.read(Rails.root + 'config' + 'sailthru.yml'))
  @client = Sailthru::TriggermailClient.new(
    @config['api_key'],
    @config['secret'],
    @config['api_uri'] || 'http://api.sailthru.com'
  )
 rescue Exception => ex
  raise Exception.new(
    "Please create a sailthru.yml file in your root config directory, containing api_key, secret, optional api_uri and optional mailing_list_key"
  )
end

Instance Method Details

#add_to_mailing_list(email, vars) ⇒ Object



28
29
30
# File 'lib/sailthru/client.rb', line 28

def add_to_mailing_list(email, vars)
  return @client.set_email(email, normalize_vars(vars), {mailing_list_key => 1}, {})
end

#get_blast(blast_id) ⇒ Object



50
51
52
# File 'lib/sailthru/client.rb', line 50

def get_blast(blast_id)
  @client.get_blast(blast_id)
end

#get_email(email) ⇒ Object



54
55
56
# File 'lib/sailthru/client.rb', line 54

def get_email(email)
  @client.get_email(email)
end

#get_send(send_id) ⇒ Object



42
43
44
# File 'lib/sailthru/client.rb', line 42

def get_send(send_id)
  @client.get_send(send_id)
end

#get_template(template_name) ⇒ Object



66
67
68
# File 'lib/sailthru/client.rb', line 66

def get_template(template_name)
  @client.get_template(template_name)
end

#import_contacts(email, password, with_names = false) ⇒ Object



62
63
64
# File 'lib/sailthru/client.rb', line 62

def import_contacts(email, password, with_names = false)
  @client.import_contacts(email, password, with_names)
end

#receive_verify_post(params, request) ⇒ Object



74
75
76
# File 'lib/sailthru/client.rb', line 74

def receive_verify_post(params, request)
  @client.receive_verify_post(params, request)
end

#remove_from_mailing_list(email, vars) ⇒ Object



32
33
34
# File 'lib/sailthru/client.rb', line 32

def remove_from_mailing_list(email, vars)
  return @client.set_email(email, normalize_vars(vars), {mailing_list_key => 0}, {})
end

#save_template(template_name, template_fields) ⇒ Object



70
71
72
# File 'lib/sailthru/client.rb', line 70

def save_template(template_name, template_fields)
  @client.save_template(template_name, template_fields)
end

#schedule_blast(name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options) ⇒ Object



46
47
48
# File 'lib/sailthru/client.rb', line 46

def schedule_blast(name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options)
  @client.schedule_blast(name, list, schedule_time, from_name, from_email, subject, content_html, content_text, options)
end

#send(template_name, email, vars, options = {}, schedule_time = nil) ⇒ Object

Sailthru Triggermail Client passthru methods.



38
39
40
# File 'lib/sailthru/client.rb', line 38

def send(template_name, email, vars, options = {}, schedule_time = nil)
  @client.send(template_name, email, vars, options, schedule_time)
end

#set_email(email, vars = {}, lists = {}, templates = {}) ⇒ Object



58
59
60
# File 'lib/sailthru/client.rb', line 58

def set_email(email, vars = {}, lists = {}, templates = {})
  @client.set_email(email, vars, lists, templates)
end

#toggle_email_in_mailing_list(email, wants_email, vars = {}) ⇒ Object

Additional Helper Methods



20
21
22
23
24
25
26
# File 'lib/sailthru/client.rb', line 20

def toggle_email_in_mailing_list(email, wants_email, vars={})
  if !email.blank?
    wants_email ? add_to_mailing_list(email, vars) : remove_from_mailing_list(email, vars)
  end
rescue Exception => e
  puts "EXCEPTION from Sailthru:   #{e}"
end