monkey_party 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +16 -2
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +9 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE +4 -2
  8. data/README.md +44 -0
  9. data/Rakefile +7 -56
  10. data/lib/monkey_party/base.rb +8 -4
  11. data/lib/monkey_party/error.rb +1 -0
  12. data/lib/monkey_party/list.rb +6 -5
  13. data/lib/monkey_party/subscriber.rb +1 -0
  14. data/lib/monkey_party/version.rb +4 -0
  15. data/lib/monkey_party.rb +26 -7
  16. data/monkey_party.gemspec +20 -80
  17. data/spec/cassettes/MonkeyParty_List/subscribing/handles_errors_gracefully.yml +135 -0
  18. data/spec/cassettes/MonkeyParty_List/subscribing/subscribes_someone_successfully.yml +205 -0
  19. data/spec/cassettes/MonkeyParty_List/unsubscribing/should_have_valid_subscribers.yml +205 -0
  20. data/spec/monkey_party/list_spec.rb +43 -0
  21. data/spec/monkey_party/subscriber_spec.rb +12 -0
  22. data/spec/spec_helper.rb +14 -0
  23. data/spec/support/credentials.rb.example +3 -0
  24. data/spec/support/vcr.rb +28 -0
  25. metadata +124 -117
  26. data/README.rdoc +0 -26
  27. data/VERSION.yml +0 -5
  28. data/features/create_and_add_api_key.feature +0 -21
  29. data/features/list_subscribe.feature +0 -13
  30. data/features/list_unsubscribe.feature +0 -14
  31. data/features/step_definitions/create_and_add_api_key_steps.rb +0 -45
  32. data/features/step_definitions/list_steps.rb +0 -17
  33. data/features/step_definitions/list_unsubscribe_steps.rb +0 -17
  34. data/features/support/env.rb +0 -4
  35. data/features/support/mailchimp/account.rb +0 -8
  36. data/features/support/mailchimp/account.yml.example +0 -2
  37. data/features/support/mailchimp/cleaner.rb +0 -3
  38. data/lib/monkey_party/account.rb +0 -48
  39. data/test/fixtures/batch_subscribe_failed.xml +0 -28
  40. data/test/fixtures/batch_subscribe_successful.xml +0 -12
  41. data/test/fixtures/batch_unsubscribe_failed.xml +0 -19
  42. data/test/fixtures/batch_unsubscribe_successful.xml +0 -12
  43. data/test/fixtures/lists_failed.xml +0 -11
  44. data/test/fixtures/lists_successful.xml +0 -16
  45. data/test/fixtures/login_failed.xml +0 -11
  46. data/test/fixtures/login_successful.xml +0 -8
  47. data/test/monkey_party/account_test.rb +0 -91
  48. data/test/monkey_party/error_test.rb +0 -18
  49. data/test/monkey_party/list_test.rb +0 -173
  50. data/test/monkey_party/subscriber_test.rb +0 -44
  51. data/test/test_helper.rb +0 -31
@@ -1,91 +0,0 @@
1
- require "test_helper"
2
-
3
- class MonkeyParty::AccountTest < Test::Unit::TestCase
4
- context "successfully logging in" do
5
- setup do
6
- configatron.mailchimp.api_key
7
-
8
- mock_login_response(true)
9
-
10
- @account = MonkeyParty::Account.login(@user_name, @password)
11
- end
12
-
13
- should "return an api key" do
14
- assert_not_nil @account.api_key
15
- end
16
-
17
- should "set the user_name" do
18
- assert_not_nil @account.user_name
19
- end
20
-
21
- should "set the global api key" do
22
- assert_not_nil configatron.mailchimp.api_key
23
- end
24
- end
25
-
26
- context "logging in with invalid credentials" do
27
- setup do
28
- mock_login_response(false)
29
- end
30
-
31
- should "raise an error" do
32
- assert_raises MonkeyParty::Error do
33
- MonkeyParty::Account.login(@user_name, @password)
34
- end
35
- end
36
- end
37
-
38
- context "adding an api key" do
39
- setup do
40
- @account = MonkeyParty::Account.new(
41
- :user_name => "test",
42
- :password => "password",
43
- :api_key => "api_key")
44
- end
45
-
46
- context "with proper credentials" do
47
- setup do
48
- mock_response("password=#{@account.password}&" +
49
- "apikey=#{@account.api_key}&method=apikeyAdd&" +
50
- "output=xml&username=#{@account.user_name}",
51
- "login_successful")
52
- end
53
-
54
- should "return an api key" do
55
- response = @account.add_api_key
56
- assert_kind_of String, response
57
- end
58
-
59
- should "add the resulting api key to extra keys" do
60
- response = @account.add_api_key
61
- assert @account.keys.include?(response)
62
- end
63
- end
64
-
65
- context "with improper credentials" do
66
- setup do
67
- mock_response("password=#{@account.password}&" +
68
- "apikey=#{@account.api_key}&method=apikeyAdd&" +
69
- "output=xml&username=#{@account.user_name}",
70
- "login_failed")
71
- end
72
-
73
- should "raise an error if I don't have the right credentials" do
74
- assert_raise MonkeyParty::Error do
75
- @account.add_api_key
76
- end
77
- end
78
- end
79
- end
80
-
81
- private
82
- def mock_login_response(successful = true)
83
- @user_name = "test_user"
84
- @password = "password"
85
-
86
- mock_response("method=login&username=#{@user_name}" +
87
- "&password=#{@password}&output=xml",
88
- successful ? "login_successful" : "login_failed")
89
-
90
- end
91
- end
@@ -1,18 +0,0 @@
1
- require "test_helper"
2
-
3
- class MonkeyParty::ErrorTest < Test::Unit::TestCase
4
- context "An error" do
5
- setup do
6
- error_body = File.read(xml_fixture_path("login_failed")).gsub(/.*<MCAPI/m, "<MCAPI")
7
- @error = MonkeyParty::Error.parse(error_body)
8
- end
9
-
10
- should "have a code" do
11
- assert_not_nil @error.code
12
- end
13
-
14
- should "have an error message" do
15
- assert_not_nil @error.message
16
- end
17
- end
18
- end
@@ -1,173 +0,0 @@
1
- require "test_helper"
2
-
3
- class MonkeyParty::ListTest < Test::Unit::TestCase
4
- context "a list" do
5
- should "have a set of members" do
6
-
7
- end
8
-
9
- should "allow me to add members to the list" do
10
- end
11
-
12
- should "allow me to unsubscribe members from the list" do
13
-
14
- end
15
-
16
- should "have an id" do
17
-
18
- end
19
-
20
- should "have a web_id" do
21
-
22
- end
23
-
24
- should "have a name" do
25
-
26
- end
27
-
28
- should "have a date of creation" do
29
-
30
- end
31
-
32
- should "have a member count" do
33
-
34
- end
35
-
36
- end
37
-
38
- context "when subscribing" do
39
-
40
- setup do
41
- mock_all_response
42
-
43
- @list = MonkeyParty::List.all[0]
44
-
45
- @subscribers = []
46
- @subscribers << MonkeyParty::Subscriber.new("user@example.com",
47
- {:fname => "A User"})
48
- @subscribers << MonkeyParty::Subscriber.new("user3@example.com",
49
- {:fname => "Another User"})
50
-
51
-
52
- end
53
-
54
- context "successfully" do
55
- setup do
56
- mock_subscription
57
- @resultant_subscribers = @list.create_subscribers(@subscribers)
58
- end
59
-
60
- should "return an array of subscribers" do
61
- assert_kind_of MonkeyParty::Subscriber, @resultant_subscribers[0]
62
- end
63
-
64
- should "indicate that each subscription was valid" do
65
- @resultant_subscribers.each do |s|
66
- assert s.valid?
67
- end
68
- end
69
- end
70
-
71
- context "resulting in error(s)" do
72
- setup do
73
- mock_subscription(false)
74
- @resultant_subscribers = @list.create_subscribers(@subscribers)
75
- end
76
-
77
- should "have invalid subscribers" do
78
- assert !@resultant_subscribers[0].valid?
79
- end
80
-
81
- should "have a subscriber with an error" do
82
- assert_not_nil @resultant_subscribers[0].error
83
- assert_kind_of MonkeyParty::Error, @resultant_subscribers[0].error
84
- end
85
- end
86
- end
87
-
88
- context "when unsubscribing" do
89
- setup do
90
- mock_all_response
91
- @list = MonkeyParty::List.all[0]
92
- @unsubscribers = [
93
- MonkeyParty::Subscriber.new("user@example.com"),
94
- MonkeyParty::Subscriber.new("user3@example.com")
95
- ]
96
- end
97
-
98
- context "successfully" do
99
- setup do
100
- mock_unsubscription
101
-
102
- @resultant_unsubscribers = @list.destroy_subscribers(@unsubscribers)
103
- end
104
-
105
- should "have all valid subscribers" do
106
- @resultant_unsubscribers.each do |s|
107
- assert s.valid?
108
- end
109
- end
110
- end
111
-
112
- context "resulting in errors(s)" do
113
- setup do
114
- mock_unsubscription(false)
115
- @resultant_unsubscribers = @list.destroy_subscribers(@unsubscribers)
116
- end
117
-
118
- should "have an invalid subscriber" do
119
- assert !@resultant_unsubscribers[0].valid?
120
- end
121
-
122
- should "have a usable error for the invalid subscriber" do
123
- assert_not_nil @resultant_unsubscribers[0].error.message
124
- end
125
- end
126
- end
127
-
128
- context "lists" do
129
- should "retrieving all of the lists" do
130
- mock_all_response
131
- lists = MonkeyParty::List.all
132
- assert_kind_of Array, lists
133
- assert_not_nil lists[0]
134
- assert_not_nil lists[0].name
135
- end
136
-
137
- should "raise an error if something goes wrong" do
138
- mock_all_response(false)
139
- assert_raises MonkeyParty::Error do
140
- lists = MonkeyParty::List.all
141
- end
142
- end
143
-
144
- should "find by name" do
145
- mock_all_response
146
- assert_equal "Testing", MonkeyParty::List.find_by_name("Testing").name
147
- end
148
- end
149
-
150
- private
151
- def mock_all_response(success = true)
152
- mock_response("apikey=2491541245g978jkasf&method=lists&output=xml",
153
- success ? "lists_successful" : "lists_failed")
154
- end
155
-
156
- def mock_subscription(success = true)
157
- mock_response(
158
- "double_optin=true&update_existing=false&replace_interests=true&" +
159
- "method=listBatchSubscribe&batch[1][EMAIL]=user3%40example.com&" +
160
- "batch[1][FNAME]=Another%20User&output=xml&" +
161
- "batch[0][EMAIL]=user%40example.com&batch[0][FNAME]=A%20User&"+
162
- "apikey=2491541245g978jkasf&id=d40bbc3056",
163
- success ? "batch_subscribe_successful" : "batch_subscribe_failed")
164
- end
165
-
166
- def mock_unsubscription(success = true)
167
- mock_response(
168
- "delete_member=false&send_goodbye=true&method=listBatchUnsubscribe&" +
169
- "send_notify=false&output=xml&apikey=2491541245g978jkasf&id=d40bbc3056&" +
170
- "emails[0]=user3%40example.com",
171
- success ? "batch_unsubscribe_successful" : "batch_unsubscribe_failed")
172
- end
173
- end
@@ -1,44 +0,0 @@
1
- require "test_helper"
2
-
3
- class MonkeyParty::SubscriberTest < Test::Unit::TestCase
4
- context "A subscriber" do
5
- setup do
6
- @merge_vars = {:merge_var => "MERGE VAR 1"}
7
- @email = "user@example.com"
8
- @subscriber = MonkeyParty::Subscriber.new(@email, @merge_vars)
9
- end
10
-
11
- should "have an email" do
12
- assert_equal @email, @subscriber.email
13
- end
14
-
15
- should "have a list of merge fields" do
16
- assert_equal @merge_vars, @subscriber.merge_fields
17
- end
18
-
19
- should "have a hashed version of all the attributes" do
20
- intended_hash = {
21
- :email => @email
22
- }.merge(@merge_vars)
23
-
24
- assert_equal intended_hash, @subscriber.to_h
25
- end
26
-
27
- should "have a mailchimp style hash of all the attributes" do
28
- intended_hash = {}
29
- intended_hash["EMAIL"] = @email
30
- @merge_vars.each do |key, value|
31
- intended_hash[key.to_s.upcase] = value
32
- end
33
-
34
- assert_equal intended_hash, @subscriber.to_mailchimp_hash
35
- end
36
-
37
- should "limit merge vars to 10 characters" do
38
- @merge_vars = {:a_really_long_merge_var => "LONG ONE"}
39
- @subscriber = MonkeyParty::Subscriber.new(@email, @merge_vars)
40
- assert @subscriber.to_mailchimp_hash.keys.include?("A_REALLY_L")
41
-
42
- end
43
- end
44
- end
data/test/test_helper.rb DELETED
@@ -1,31 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- begin
6
- require "redgreen"
7
- rescue LoadError; end
8
-
9
- require 'fake_web'
10
-
11
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
- require 'monkey_party'
14
-
15
- FakeWeb.allow_net_connect = false
16
-
17
- configatron.mailchimp.api_key = "api_key"
18
-
19
- class Test::Unit::TestCase
20
- protected
21
- def mock_response(path, fixture)
22
- FakeWeb.register_uri(
23
- "http://api.mailchimp.com/1.2?#{path}",
24
- :response => xml_fixture_path(fixture))
25
- end
26
-
27
- def xml_fixture_path(fixture)
28
- File.join(File.dirname(__FILE__), "fixtures", "#{fixture}.xml")
29
- end
30
-
31
- end