Class: ExactTargetClient::ExactTargetAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/exact_target_client/exact_target_api.rb

Defined Under Namespace

Classes: ClientException, TimeOut, TokenExpired

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ ExactTargetAPI

Returns a new instance of ExactTargetAPI.

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


15
16
17
18
19
# 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

Instance Attribute Details

#oauth_tokenObject

Returns the value of attribute oauth_token.



7
8
9
# File 'lib/exact_target_client/exact_target_api.rb', line 7

def oauth_token
  @oauth_token
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



7
8
9
# File 'lib/exact_target_client/exact_target_api.rb', line 7

def refresh_token
  @refresh_token
end

Instance Method Details

#create_content_area(name, content) ⇒ Object



63
64
65
66
67
68
69
# 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) ⇒ Object



81
82
83
84
# 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) ⇒ Object



40
41
42
43
44
45
46
47
# 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) ⇒ Object



76
77
78
79
# 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) ⇒ Object



58
59
60
61
# 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) ⇒ Object



31
32
33
34
35
36
37
38
# 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) ⇒ Object



94
95
96
97
# 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) ⇒ Object



90
91
92
# 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_tokenObject



21
22
23
24
25
26
27
28
29
# 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) ⇒ Object



71
72
73
74
# 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) ⇒ Object



49
50
51
52
53
54
55
56
# 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) ⇒ Object



86
87
88
# 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