Class: SailthruBatchingClient
- Inherits:
-
Object
- Object
- SailthruBatchingClient
- Defined in:
- lib/sailthru_batching_client.rb
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.api_secret ⇒ Object
Returns the value of attribute api_secret.
-
.batch_size ⇒ Object
max size that Sailthru can support.
-
.file_root ⇒ Object
root at which we are going to write our temp files.
Class Method Summary collapse
-
.base_file_name ⇒ Object
where we store our temp files.
-
.clear_tmp_files ⇒ Object
clear the files we created to push data to Sailthru.
-
.client ⇒ Object
instance of sailthru client.
-
.connected? ⇒ Boolean
We are connected if a client is present.
-
.establish_connection ⇒ Object
get an instance of sailthru client.
-
.respond_to?(m) ⇒ Boolean
override respond_to? to also include methods of our instance of SailthruClient.
-
.update_users(user_data_array, clear_tmp = true) ⇒ Object
update rows of email data.
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/sailthru_batching_client.rb', line 6 def api_key @api_key end |
.api_secret ⇒ Object
Returns the value of attribute api_secret.
6 7 8 |
# File 'lib/sailthru_batching_client.rb', line 6 def api_secret @api_secret end |
.batch_size ⇒ Object
max size that Sailthru can support
16 17 18 |
# File 'lib/sailthru_batching_client.rb', line 16 def self.batch_size @batch_size ||= 10000000 end |
.file_root ⇒ Object
root at which we are going to write our temp files
45 46 47 |
# File 'lib/sailthru_batching_client.rb', line 45 def self.file_root @file_root ||= "/tmp" end |
Class Method Details
.base_file_name ⇒ Object
where we store our temp files
11 12 13 |
# File 'lib/sailthru_batching_client.rb', line 11 def self.base_file_name "#{self.file_root}/#{Process.pid}-sailthru-list" end |
.clear_tmp_files ⇒ Object
clear the files we created to push data to Sailthru
21 22 23 |
# File 'lib/sailthru_batching_client.rb', line 21 def self.clear_tmp_files FileUtils.rm_rf("#{self.base_file_name}*") end |
.client ⇒ Object
instance of sailthru client
26 27 28 29 30 31 32 |
# File 'lib/sailthru_batching_client.rb', line 26 def self.client @client ||= ::Sailthru::SailthruClient.new( self.api_key, self.api_secret, "https://api.sailthru.com" ) end |
.connected? ⇒ Boolean
We are connected if a client is present
35 36 37 |
# File 'lib/sailthru_batching_client.rb', line 35 def self.connected? @client.present? end |
.establish_connection ⇒ Object
get an instance of sailthru client
40 41 42 |
# File 'lib/sailthru_batching_client.rb', line 40 def self.establish_connection self.client end |
.respond_to?(m) ⇒ Boolean
override respond_to? to also include methods of our instance of SailthruClient
51 52 53 54 |
# File 'lib/sailthru_batching_client.rb', line 51 def self.respond_to?(m) return true if super(m) return self.client.respond_to?(m) end |
.update_users(user_data_array, clear_tmp = true) ⇒ Object
update rows of email data
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sailthru_batching_client.rb', line 57 def self.update_users(user_data_array, clear_tmp = true) # make sure we have the dir FileUtils.mkdir_p(File.dirname(self.base_file_name)) self.clear_tmp_files if clear_tmp begin self.batch_data_as_json(user_data_array).each_with_index do |rows, i| # write to the file system file = self.write_temp_file(rows, i) # send our file self.send_file(file) end return true ensure self.clear_tmp_files if clear_tmp end end |