MattHall-campaign_monitor 1.3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/list_test.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'rubygems'
2
+ require 'lib/campaign_monitor'
3
+ require 'test/unit'
4
+ require 'test/test_helper'
5
+
6
+ CLIENT_NAME = 'Spacely Space Sprockets'
7
+ LIST_NAME = 'List #1'
8
+
9
+ class CampaignMonitorTest < Test::Unit::TestCase
10
+
11
+ $debug=true
12
+
13
+ def setup
14
+ @cm = CampaignMonitor.new(ENV["API_KEY"])
15
+ # find an existing client
16
+
17
+ @client=find_test_client
18
+ assert_not_nil @client, "Please create a '#{CLIENT_NAME}' (company name) client so tests can run."
19
+
20
+ # delete all existing lists
21
+ @client.lists.each { |l| l.Delete }
22
+ @list = @client.lists.build.defaults
23
+ @list["Title"]="List #1"
24
+ assert @list.Create
25
+ end
26
+
27
+ def teardown
28
+ @list.Delete
29
+ end
30
+
31
+ def test_create_and_delete_list
32
+ list = @client.lists.build.defaults
33
+ list["Title"]="This is a new list"
34
+ list.Create
35
+ assert_success list.result
36
+ assert_not_nil list.id
37
+ assert_equal 0, list.active_subscribers(Date.new(2005,1,1)).size
38
+ saved_id=list.id
39
+ # find it all over again
40
+ list=@client.lists.detect { |x| x.name == "This is a new list" }
41
+ assert_equal saved_id, list.id
42
+ assert list.Delete
43
+ assert_success list.result
44
+ # should be gone now
45
+ assert_nil @client.lists.detect { |x| x.name == "This is a new list" }
46
+ end
47
+
48
+ def test_update_list
49
+ list=@client.lists.first
50
+ assert_equal "List #1", list.name
51
+ list["Title"]="Just another list"
52
+ list.Update
53
+ list=@client.lists.first
54
+ assert_equal "Just another list", list.name
55
+ end
56
+
57
+ def test_getdetail_for_list_instance
58
+ list=@client.lists.first
59
+ assert_equal "List #1", list.name
60
+ assert_nil list["ConfirmOptIn"]
61
+ list.GetDetail
62
+ assert_equal "false", list["ConfirmOptIn"]
63
+ end
64
+
65
+ def test_getdetail_to_load_list
66
+ list=CampaignMonitor::List.GetDetail(@list.id)
67
+ assert_equal "List #1", list.name
68
+ list=CampaignMonitor::List[@list.id]
69
+ assert_equal "List #1", list.name
70
+ end
71
+
72
+ # test that our own creative mapping of errors actually works
73
+ def test_save_with_missing_attribute
74
+ list = @client.lists.build
75
+ list["Title"]="This is a new list"
76
+ assert !list.Create
77
+ assert list.result.failure?
78
+ assert_equal 500, list.result.code
79
+ assert_equal "System.InvalidOperationException: Missing parameter: UnsubscribePage.", list.result.message
80
+ end
81
+
82
+ def test_getting_a_dummy_list
83
+ list=CampaignMonitor::List["snickers"]
84
+ assert_equal nil, list
85
+ end
86
+
87
+ def test_list_add_subscriber
88
+ list=@client.lists.first
89
+ assert_equal 0, list.active_subscribers(Date.new(2005,1,1)).size
90
+ assert_success list.add_and_resubscribe('a@test.com', 'Test A')
91
+ assert_equal 1, list.active_subscribers(Date.new(2005,1,1)).size
92
+ assert_success list.remove_subscriber('a@test.com')
93
+ end
94
+
95
+
96
+ protected
97
+
98
+ def build_new_list(options={})
99
+ {"Title" => "List #1", "ConfirmOptIn" => "false",
100
+ "UnsubscribePage" => "",
101
+ "ConfirmationSuccessPage" => ""}.merge(options)
102
+ end
103
+
104
+ def assert_success(result)
105
+ assert result.succeeded?, result.message
106
+ end
107
+
108
+ def find_test_client(clients=@cm.clients)
109
+ clients.detect { |c| c.name == CLIENT_NAME }
110
+ end
111
+
112
+ def find_test_list(lists=find_test_client.lists)
113
+ lists.detect { |l| l.name == LIST_NAME }
114
+ end
115
+ end
@@ -0,0 +1,27 @@
1
+ require 'ruby-debug'
2
+ require 'digest'
3
+
4
+ CAMPAIGN_MONITOR_API_KEY=nil
5
+
6
+ if ENV["API_KEY"].nil?
7
+ puts "Please specify the API_KEY on the command line for testing."
8
+ exit
9
+ end
10
+
11
+ class Test::Unit::TestCase #:nodoc: all
12
+
13
+ def assert_not_empty(v)
14
+ assert !v.nil?, "expected to not be empty, but was nil"
15
+ assert !v.empty?, "expected to not be empty" if v.respond_to?(:empty?)
16
+ assert !v.strip.empty?, "expected to not be empty" if v.is_a?(String)
17
+ end
18
+
19
+ def assert_success(result)
20
+ assert result.succeeded?, "#{result.code}: #{result.message}"
21
+ end
22
+
23
+ def secure_digest(*args)
24
+ Digest::SHA1.hexdigest(args.flatten.join('--'))
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MattHall-campaign_monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Weiskotten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-25 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: xml-simple
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.11
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: soap4r
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.8
34
+ version:
35
+ description: A simple wrapper class that provides basic access to the Campaign Monitor API.
36
+ email: jweiskotten@patientslikeme.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - campaign_monitor.gemspec
45
+ - init.rb
46
+ - install.rb
47
+ - MIT-LICENSE
48
+ - Rakefile
49
+ - README.rdoc
50
+ - TODO
51
+ - lib/campaign_monitor.rb
52
+ - lib/campaign_monitor/base.rb
53
+ - lib/campaign_monitor/misc.rb
54
+ - lib/campaign_monitor/campaign.rb
55
+ - lib/campaign_monitor/client.rb
56
+ - lib/campaign_monitor/helpers.rb
57
+ - lib/campaign_monitor/list.rb
58
+ - lib/campaign_monitor/result.rb
59
+ - lib/campaign_monitor/subscriber.rb
60
+ - support/class_enhancements.rb
61
+ - support/faster-xml-simple/lib/faster_xml_simple.rb
62
+ - support/faster-xml-simple/test/regression_test.rb
63
+ - support/faster-xml-simple/test/test_helper.rb
64
+ - support/faster-xml-simple/test/xml_simple_comparison_test.rb
65
+ - test/campaign_monitor_test.rb
66
+ - test/campaign_test.rb
67
+ - test/client_test.rb
68
+ - test/list_test.rb
69
+ - test/test_helper.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/patientslikeme/campaign_monitor/
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements:
90
+ - none
91
+ rubyforge_project:
92
+ rubygems_version: 1.2.0
93
+ signing_key:
94
+ specification_version: 2
95
+ summary: Provides access to the Campaign Monitor API.
96
+ test_files:
97
+ - test/campaign_monitor_test.rb