class ExactTargetClient::ExactTargetAPI
Attributes
oauth_token[RW]
refresh_token[RW]
rest_client[RW]
soap_client[RW]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 15 def initialize yield self if block_given? raise ArgumentError, 'block not given' unless block_given? init_clients end
Public Instance Methods
create_content_area(name, content)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 63 def create_content_area(name, content) response = soap_client.create('ContentArea', {'Name' => name, 'Content' => content} ) check_response(response) end
create_data_extension(properties)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 81 def create_data_extension(properties) response = soap_client.create('DataExtension', properties) check_response(response) end
create_email(email_name, subject, html_template)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 40 def create_email(email_name, subject, html_template) response = soap_client.create('Email', {'Name' => email_name, 'Subject' => subject, 'HTMLBody' => html_template} ) check_response(response) end
delete_content_area(content_area_id)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 76 def delete_content_area(content_area_id) response = soap_client.delete('ContentArea', {'ID' => content_area_id}) check_response(response) end
delete_email(email_id)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 58 def delete_email(email_id) response = soap_client.delete('Email', {'ID' => email_id}) check_response(response) end
get_emails(ids = nil)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 31 def get_emails(ids = nil) properties = %w(ID Name HTMLBody) if ids.present? filter = {property: 'ID', value: ids} end response = soap_client.retrieve('Email', properties, filter) check_response(response) end
get_subscribers_by_email(email, properties)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 94 def get_subscribers_by_email(email, properties) response = soap_client.retrieve('Subscriber', properties, {property: 'EmailAddress', value: email}) check_response(response) end
increment_data_extension_row(data_extension_customer_key, primary_key_name, primary_key_value, column, step = 1)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 90 def increment_data_extension_row(data_extension_customer_key, primary_key_name, primary_key_value, column, step = 1) rest_client.increment_data_extension_row(data_extension_customer_key, primary_key_name, primary_key_value, column, step) end
refresh_oauth_token()
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 21 def refresh_oauth_token results = @rest_client.get_oauth_token(Conf.client_id, Conf.client_secret, refresh_token) if results @oauth_token = results['accessToken'] @refresh_token = results['refreshToken'] refresh_clients(results['accessToken']) results end end
update_content_area(content_area_id, name, content)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 71 def update_content_area(content_area_id, name, content) response = soap_client.update('ContentArea', {'ID' => content_area_id, 'Name' => name, 'Content' => content}) check_response(response) end
update_email(email_id, name, html_template, subject = nil)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 49 def update_email(email_id, name, html_template, subject = nil) properties = {'ID' => email_id, 'Name' => name, 'HTMLBody' => html_template} if subject.present? properties['Subject'] = subject end response = soap_client.update('Email', properties) check_response(response) end
upsert_data_extension_row(data_extension_customer_key, primary_key_name, primary_key_value, object_hash)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 86 def upsert_data_extension_row(data_extension_customer_key, primary_key_name, primary_key_value, object_hash) rest_client.upsert_data_extension_row(data_extension_customer_key, primary_key_name, primary_key_value, object_hash) end
Private Instance Methods
check_response(response)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 117 def check_response(response) if response.success? response.results else raise ClientException.new(response.message) end end
init_clients()
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 102 def init_clients @soap_client = ExactTargetClient::ExactTargetSoapClient.new do |c| c.oauth_token = oauth_token c.wsdl = Conf.wsdl % {:instance => oauth_token[0]} # WSDL instance is determined by first char of token end @rest_client = ExactTargetClient::ExactTargetRestClient.new do |c| c.oauth_token = oauth_token end end
refresh_clients(token)
click to toggle source
# File lib/exact_target_client/exact_target_api.rb, line 112 def refresh_clients(token) @soap_client.set_oauth_token(token) @rest_client.set_oauth_token(token) end