gnumarcelo-campaigning 0.12.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,124 @@
1
+ # Template is defined in soap/default.rb which is automatically generated.
2
+ # In this file we add additional methods to the Template class.
3
+ require File.expand_path(File.dirname(__FILE__)) + '/module_mixin'
4
+
5
+
6
+ module Campaigning
7
+ class Template
8
+ include ModuleMixin
9
+ attr_accessor :templateID
10
+ attr_accessor :name
11
+ attr_accessor :previewURL
12
+ attr_accessor :screenshotURL
13
+
14
+ def initialize(templateID = nil, name = nil, previewURL = nil, screenshotURL = nil, opts = {})
15
+ @apiKey = opts[:apiKey] || CAMPAIGN_MONITOR_API_KEY
16
+ @templateID = templateID
17
+ @name = name
18
+ @previewURL = previewURL
19
+ @screenshotURL = screenshotURL
20
+ end
21
+
22
+ #Creates a new template for a client.
23
+ #
24
+ #Available _params_ argument are:
25
+ # * :clientID - The ID of the client who will owner of the list.
26
+ # * :templateName - The name of the template. Maximum of 30 characters (will be truncated to 30 characters if longer).
27
+ # * :htmlPageURL - The URL of the HTML page you have created for the template.
28
+ # * :zipFileURL - Optional URL of a zip file containing any other files required by the template.
29
+ # * :screenshotURL - Optional URL of a screenshot of the template. Must be in jpeg format and at least 218 pixels wide.
30
+ # * :apiKey - optional API key to use to make request. Will use CAMPAIGN_MONITOR_API_KEY if not set.
31
+ #*Return*:
32
+ #
33
+ #*Success*: Upon a successful call, this method will return a Campaigning::Template object representing the newly created
34
+ #template. The object returned isn't filled with previewURL and screenShotURL once the CampaignMonitor API generate a new
35
+ #value for that and doesn't return it on te create! method. In order to get a complete filled object call the Template.details
36
+ #method.
37
+ #
38
+ #*Error*: An Exception containing the cause of the error will be raised.
39
+ def self.create!(params)
40
+ response = @@soap.createTemplate(
41
+ :apiKey => params[:apiKey] || CAMPAIGN_MONITOR_API_KEY,
42
+ :clientID => params[:clientID],
43
+ :templateName => params[:templateName],
44
+ :hTMLPageURL => params[:htmlPageURL],
45
+ :zipFileURL => params[:zipFileURL],
46
+ :screenshotURL => params[:screenshotURL]
47
+ )
48
+ Template.new( handle_response(response.template_CreateResult), params[:templateName], nil, nil, :apiKey=> params[:apiKey] )
49
+ end
50
+
51
+ #Gets the details of a template.
52
+ #
53
+ #*Return*:
54
+ #
55
+ #*Success*: Upon a successful call, this method will return a Template object, which consists of the template ID,
56
+ #the template name, a preview URL and a screenshot URL.
57
+ #
58
+ #*Error*: An Exception containing the cause of the error will be raised.
59
+ def details
60
+ response = @@soap.getTemplateDetail(:apiKey => @apiKey, :templateID => @templateID)
61
+ handle_response response.template_GetDetailResult
62
+ end
63
+
64
+ #Updates an existing template.
65
+ #
66
+ #Available _params_ argument are:
67
+ # * :templateID - The ID of the template to be updated.
68
+ # * :templateName - The name of the template. Maximum of 30 characters (will be truncated to 30 characters if longer).
69
+ # * :htmlPageURL - The URL of the HTML page you have created for the template.
70
+ # * :zipFileURL - Optional URL of a zip file containing any other files required by the template.
71
+ # * :screenshotURL - Optional URL of a screenshot of the template. Must be in jpeg format and at least 218 pixels wide.
72
+ # * :apiKey - optional API key to use to make request. Will use CAMPAIGN_MONITOR_API_KEY if not set.
73
+ #*Return*:
74
+ #
75
+ #*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
76
+ #containing a successful message.
77
+ #
78
+ #*Error*: An Exception containing the cause of the error will be raised.
79
+ def update!(params)
80
+ response = @@soap.updateTemplate(
81
+ :apiKey => params[:apiKey] || CAMPAIGN_MONITOR_API_KEY,
82
+ :templateID => @templateID,
83
+ :templateName => params[:templateName],
84
+ :hTMLPageURL => params[:htmlPageURL],
85
+ :zipFileURL => params[:zipFileURL],
86
+ :screenshotURL => params[:screenshotURL]
87
+ )
88
+ handle_response response.template_UpdateResult
89
+ end
90
+
91
+
92
+ #Deletes a template.
93
+ #
94
+ #*Return*:
95
+ #
96
+ #*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
97
+ #containing a successful message.
98
+ #
99
+ #*Error*: An Exception containing the cause of the error will be raised.
100
+ def delete!
101
+ response = Template.delete!(@templateID, :apiKey=> @apiKey)
102
+ self.templateID, self.name = nil, nil
103
+ response
104
+ end
105
+
106
+
107
+ #Deletes a template.
108
+ #
109
+ #Aviable _opts_ arguments are:
110
+ # * :apiKey - optional API key to use to make request. Will use CAMPAIGN_MONITOR_API_KEY if not set.
111
+ #
112
+ #*Return*:
113
+ #
114
+ #*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
115
+ #containing a successful message.
116
+ #
117
+ #*Error*: An Exception containing the cause of the error will be raised.
118
+ def self.delete!(template_id, opts={})
119
+ response = @@soap.deleteTemplate(:apiKey => opts[:apiKey] || CAMPAIGN_MONITOR_API_KEY, :templateID => template_id)
120
+ handle_response response.template_DeleteResult
121
+ end
122
+
123
+ end
124
+ end
@@ -25,12 +25,6 @@ class CampaigningTest < Test::Unit::TestCase
25
25
  assert !countries.nil?
26
26
  end
27
27
 
28
- def test_client_get_all_clients
29
- clients = Campaigning::Client.get_all_clients
30
- assert clients.length > 0
31
- #clients.each{ |c| puts c.clientID + " - " + c.name }
32
- end
33
-
34
28
  def test_client_lists
35
29
  client = Campaigning::Client.find_by_name("Client One Company")
36
30
  assert client.lists.length > 0
data/test/client_test.rb CHANGED
@@ -3,14 +3,27 @@ require 'test_helper'
3
3
  # Replace this API key with your own (http://www.campaignmonitor.com/api/)
4
4
  CAMPAIGN_MONITOR_API_KEY = '__PUT_YOUR_API_KEY_HERE__'
5
5
 
6
+
6
7
  class ClientTest < Test::Unit::TestCase
7
8
 
8
9
 
9
10
  def setup
10
11
  #Campaigning.set_endpoint_url "http://127.0.0.1:8088/mockapiSoap"
11
- Campaigning.set_debug_mode(:on)
12
+ #Campaigning.set_debug_mode(:on)
13
+ end
14
+
15
+ def test_client_get_templates
16
+ client = Campaigning::Client.get_all_clients.first
17
+ puts "#{client.name} - #{client.clientID}"
18
+ puts "Templates: #{client.templates.inspect}"
12
19
  end
13
20
 
21
+ def test_client_get_all_clients
22
+ clients = Campaigning::Client.get_all_clients
23
+ assert clients.length > 0
24
+ #clients.each{ |c| puts c.clientID + " - " + c.name }
25
+ end
26
+
14
27
  def test_client_create!
15
28
  client_created = Campaigning::Client.create!(
16
29
  :companyName => "My test clients22",
@@ -21,34 +34,34 @@ class ClientTest < Test::Unit::TestCase
21
34
  )
22
35
  assert !client_created.clientID.nil?
23
36
  end
24
-
37
+
25
38
  def test_client_delete
26
39
  response = Campaigning::Client.delete!(client_created.clientID)
27
40
  assert response.code == 0
28
41
  end
29
-
42
+
30
43
  def test_client_delete_itself
31
44
  client = Campaigning::Client.find_by_name("Orange Company 7")
32
45
  client.delete!
33
46
  end
34
-
47
+
35
48
  def test_client_segments
36
49
  client = Campaigning::Client.find_by_name("Client One Company")
37
50
  assert client.segments.length > 0
38
51
  end
39
-
40
-
52
+
53
+
41
54
  def test_find_client_by_name
42
55
  client = Campaigning::Client.find_by_name("Client One Company")
43
56
  assert !client.nil? && client.name == "Client One Company"
44
57
  end
45
-
46
-
58
+
59
+
47
60
  def test_get_client_campaigns
48
61
  client = Campaigning::Client.find_by_name("Client One Company")
49
62
  puts client.campaigns.inspect
50
63
  end
51
-
64
+
52
65
  def test_get_client_details
53
66
  client = Campaigning::Client.find_by_name("Client One Company")
54
67
  # client_details = client.details
@@ -70,16 +83,16 @@ class ClientTest < Test::Unit::TestCase
70
83
  # Cost per Recipient: #{access_and_billing_details.costPerRecipient} - \n
71
84
  # Design and Span test Fee: #{access_and_billing_details.designAndSpamTestFee} - \n
72
85
  # Access Level: #{access_and_billing_details.accessLevel}"
73
-
86
+
74
87
  assert !client.details.nil?
75
-
88
+
76
89
  end
77
-
90
+
78
91
  def test_get_client_suppression_list
79
92
  client = Campaigning::Client.find_by_name("Client One Company")
80
93
  puts client.suppression_list.inspect
81
94
  end
82
-
95
+
83
96
  def test_client_update_access_and_billing!
84
97
  client = Campaigning::Client.find_by_name("Client One Company")
85
98
  response = client.update_access_and_billing!(
@@ -106,11 +119,11 @@ class ClientTest < Test::Unit::TestCase
106
119
  )
107
120
  assert response.code == 0
108
121
  end
109
-
122
+
110
123
  def test_client_find_list_by_name
111
124
  client = Campaigning::Client.find_by_name("Client One Company")
112
125
  list = client.find_list_by_name "My Friends"
113
126
  assert list.nil? == false
114
127
  end
115
-
128
+
116
129
  end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ # Replace this API key with your own (http://www.campaignmonitor.com/api/)
4
+ CAMPAIGN_MONITOR_API_KEY = '__PUT_YOUR_API_KEY_HERE__'
5
+ HTML_PAGE_URL = "http://s4ve.as:80/pages/download/17767/template-with-editor-tags.html"
6
+ ZIP_FILE_URL = "http://s4ve.as:80/pages/download/17766/Archive.zip"
7
+ SCREENSHOT_URL = "http://s4ve.as:80/pages/download/17768/screenshot.png"
8
+
9
+ class TemplateTest < Test::Unit::TestCase
10
+
11
+
12
+ def setup
13
+ #Campaigning.set_endpoint_url "http://127.0.0.1:8088/mockapiSoap"
14
+ Campaigning.set_debug_mode(:on)
15
+ end
16
+
17
+ def test_create!
18
+ client = Campaigning::Client.get_all_clients.first
19
+ template_created = Campaigning::Template.create!(
20
+ :clientID => client.clientID,
21
+ :templateName => "template_BY_API",
22
+ :htmlPageURL => HTML_PAGE_URL,
23
+ :zipFileURL => ZIP_FILE_URL,
24
+ :screenshotURL => SCREENSHOT_URL
25
+ )
26
+ puts template_created.details
27
+ puts "\n INSPECT: #{template_created.inspect} \n"
28
+ assert !template_created.nil?
29
+ end
30
+
31
+ # #Should I return a new Template object?
32
+ # def test_details
33
+ # client = Campaigning::Client.get_all_clients.first
34
+ # template = client.templates.first
35
+ # assert !template.details.nil?
36
+ # end
37
+ #
38
+ # def test_update!
39
+ # client = Campaigning::Client.get_all_clients.first
40
+ # template = client.templates.first
41
+ # result = template.update!(
42
+ # :templateName => "template_BY_API-updt",
43
+ # :htmlPageURL => HTML_PAGE_URL,
44
+ # :zipFileURL => ZIP_FILE_URL,
45
+ # :screenshotURL => SCREENSHOT_URL
46
+ # )
47
+ # assert result.code == 0
48
+ # end
49
+ #
50
+ # def test_delete!
51
+ # client = Campaigning::Client.get_all_clients.first
52
+ # template = client.templates.last
53
+ # result = template.delete!
54
+ # assert result.code == 0
55
+ # assert template.templateID == nil
56
+ #
57
+ # #deleting template by templateID
58
+ # result = Campaigning::Template.delete!("d0814103dcee1073ef84516dd96a12c4")
59
+ # assert result.code == 0
60
+ # end
61
+
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnumarcelo-campaigning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Menezes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-04 00:00:00 -07:00
12
+ date: 2009-09-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -46,11 +46,13 @@ files:
46
46
  - lib/campaigning/soap/generated/defaultDriver.rb
47
47
  - lib/campaigning/soap/generated/defaultMappingRegistry.rb
48
48
  - lib/campaigning/subscriber.rb
49
+ - lib/campaigning/template.rb
49
50
  - test/campaign_test.rb
50
51
  - test/campaigning_test.rb
51
52
  - test/client_test.rb
52
53
  - test/list_test.rb
53
54
  - test/subscriber_test.rb
55
+ - test/template_test.rb
54
56
  - test/test_helper.rb
55
57
  has_rdoc: true
56
58
  homepage: http://github.com/gnumarcelo/campaigning
@@ -84,4 +86,5 @@ test_files:
84
86
  - test/client_test.rb
85
87
  - test/list_test.rb
86
88
  - test/subscriber_test.rb
89
+ - test/template_test.rb
87
90
  - test/test_helper.rb