constantcontact 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +7 -0
- data/constantcontact.gemspec +1 -1
- data/lib/constantcontact.rb +54 -54
- data/lib/constantcontact/api.rb +5 -3
- data/lib/constantcontact/auth/oauth2.rb +7 -4
- data/lib/constantcontact/auth/session_data_store.rb +52 -52
- data/lib/constantcontact/components/account/verified_email_address.rb +17 -17
- data/lib/constantcontact/components/activities/activity.rb +34 -34
- data/lib/constantcontact/components/activities/activity_error.rb +17 -17
- data/lib/constantcontact/components/activities/add_contacts.rb +109 -109
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -37
- data/lib/constantcontact/components/activities/export_contacts.rb +19 -19
- data/lib/constantcontact/components/component.rb +13 -13
- data/lib/constantcontact/components/contacts/address.rb +18 -18
- data/lib/constantcontact/components/contacts/contact.rb +69 -69
- data/lib/constantcontact/components/contacts/contact_list.rb +17 -17
- data/lib/constantcontact/components/contacts/custom_field.rb +17 -17
- data/lib/constantcontact/components/contacts/email_address.rb +23 -23
- data/lib/constantcontact/components/contacts/note.rb +16 -16
- data/lib/constantcontact/components/email_marketing/campaign.rb +67 -67
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +17 -17
- data/lib/constantcontact/components/email_marketing/message_footer.rb +20 -20
- data/lib/constantcontact/components/email_marketing/schedule.rb +18 -18
- data/lib/constantcontact/components/email_marketing/test_send.rb +32 -32
- data/lib/constantcontact/components/result_set.rb +15 -15
- data/lib/constantcontact/components/tracking/bounce_activity.rb +18 -18
- data/lib/constantcontact/components/tracking/click_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/forward_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/open_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/send_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/tracking_activity.rb +15 -15
- data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +18 -18
- data/lib/constantcontact/exceptions/ctct_exception.rb +15 -15
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +3 -3
- data/lib/constantcontact/exceptions/oauth2_exception.rb +3 -3
- data/lib/constantcontact/services/account_service.rb +19 -19
- data/lib/constantcontact/services/activity_service.rb +99 -99
- data/lib/constantcontact/services/base_service.rb +24 -24
- data/lib/constantcontact/services/campaign_schedule_service.rb +85 -85
- data/lib/constantcontact/services/campaign_tracking_service.rb +151 -151
- data/lib/constantcontact/services/contact_service.rb +106 -106
- data/lib/constantcontact/services/contact_tracking_service.rb +151 -151
- data/lib/constantcontact/services/email_marketing_service.rb +66 -66
- data/lib/constantcontact/services/list_service.rb +67 -67
- data/lib/constantcontact/util/config.rb +102 -96
- data/lib/constantcontact/util/helpers.rb +18 -18
- data/lib/constantcontact/version.rb +4 -4
- data/spec/constantcontact/api_spec.rb +223 -173
- data/spec/constantcontact/auth/oauth2_spec.rb +68 -4
- data/spec/constantcontact/components/contacts/address_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/contact_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/email_address_spec.rb +7 -7
- data/spec/constantcontact/services/contact_service_spec.rb +95 -95
- data/spec/constantcontact/services/list_service_spec.rb +48 -48
- data/spec/spec_helper.rb +1 -1
- metadata +55 -44
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
#
|
2
2
|
# oauth2_spec.rb
|
3
3
|
# ConstantContact
|
4
4
|
#
|
@@ -7,21 +7,85 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Auth::OAuth2 do
|
10
|
+
|
11
|
+
before(:all) {
|
12
|
+
ConstantContact::Util::Config.configure do |config|
|
13
|
+
config[:auth].delete :api_key
|
14
|
+
config[:auth].delete :api_secret
|
15
|
+
config[:auth].delete :redirect_uri
|
16
|
+
end
|
17
|
+
}
|
18
|
+
|
10
19
|
describe "#new" do
|
11
|
-
it "fails without arguments" do
|
20
|
+
it "fails without arguments and no configuration" do
|
12
21
|
lambda {
|
13
22
|
ConstantContact::Auth::OAuth2.new
|
14
23
|
}.should raise_error(ArgumentError)
|
15
24
|
end
|
16
|
-
|
25
|
+
|
17
26
|
it "takes one argument" do
|
18
27
|
opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
|
19
28
|
lambda {
|
20
29
|
ConstantContact::Auth::OAuth2.new(opts)
|
21
|
-
}.should_not raise_error
|
30
|
+
}.should_not raise_error
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
34
|
+
context "with middle-ware configuration" do
|
35
|
+
before(:all) do
|
36
|
+
ConstantContact::Util::Config.configure do |config|
|
37
|
+
config[:auth][:api_key] = "config_api_key"
|
38
|
+
config[:auth][:api_secret] = "config_api_secret"
|
39
|
+
config[:auth][:redirect_uri] = "config_redirect_uri"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
let(:proc) { lambda { ConstantContact::Auth::OAuth2.new } }
|
43
|
+
it "without error" do
|
44
|
+
proc.should_not raise_error
|
45
|
+
end
|
46
|
+
let(:oauth) { proc.call }
|
47
|
+
it "has correct api_key" do
|
48
|
+
oauth.client_id.should == "config_api_key"
|
49
|
+
end
|
50
|
+
it "has correct api_secret" do
|
51
|
+
oauth.client_secret.should == "config_api_secret"
|
52
|
+
end
|
53
|
+
it "has correct redirect_uri" do
|
54
|
+
oauth.redirect_uri.should == "config_redirect_uri"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with middle-ware configuration and explicit opts" do
|
59
|
+
before(:all) do
|
60
|
+
ConstantContact::Util::Config.configure do |config|
|
61
|
+
config[:auth][:api_key] = "config_api_key"
|
62
|
+
config[:auth][:api_secret] = "config_api_secret"
|
63
|
+
config[:auth][:redirect_uri] = "config_redirect_uri"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
let(:proc) { lambda { ConstantContact::Auth::OAuth2.new :api_key => 'explicit_api_key', :api_secret => 'explicit_api_secret', :redirect_url => 'explicit_redirect_uri' } }
|
67
|
+
it "without error" do
|
68
|
+
proc.should_not raise_error
|
69
|
+
end
|
70
|
+
let(:oauth) { proc.call }
|
71
|
+
it "has correct api_key" do
|
72
|
+
oauth.client_id.should == "explicit_api_key"
|
73
|
+
end
|
74
|
+
it "has correct api_secret" do
|
75
|
+
oauth.client_secret.should == "explicit_api_secret"
|
76
|
+
end
|
77
|
+
it "has correct redirect_uri" do
|
78
|
+
oauth.redirect_uri.should == "explicit_redirect_uri"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "with explicit arguments and no configuration" do
|
83
|
+
lambda {
|
84
|
+
ConstantContact::Auth::OAuth2.new :api_key => "api_key", :api_secret => "api_secret", :redirect_uri => "redirect_uri"
|
85
|
+
}.should raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
|
88
|
+
|
25
89
|
describe "#get_authorization_url" do
|
26
90
|
before(:each) do
|
27
91
|
opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
|
@@ -7,12 +7,12 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Components::Address do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return an address" do
|
12
|
+
json = load_json('address.json')
|
13
|
+
address = ConstantContact::Components::Address.create(JSON.parse(json))
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
address.line1.should eq('6 Main Street')
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -7,12 +7,12 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Components::ContactList do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return a list" do
|
12
|
+
json = load_json('list.json')
|
13
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json))
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
list.name.should eq('Fake List')
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -7,12 +7,12 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Components::Contact do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return a contact" do
|
12
|
+
json = load_json('contact.json')
|
13
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
contact.last_name.should eq('Smith')
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -7,12 +7,12 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Components::CustomField do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return a custom field" do
|
12
|
+
json = '{"name":"Property", "value":"Private"}'
|
13
|
+
field = ConstantContact::Components::CustomField.create(JSON.parse(json))
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
field.name.should eq('Property')
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -7,12 +7,12 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Components::EmailAddress do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return an email address" do
|
12
|
+
json = load_json('email_address.json')
|
13
|
+
email = ConstantContact::Components::EmailAddress.create(JSON.parse(json))
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
email.email_address.should eq('wm2q7rwtp77m@roving.com')
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -7,99 +7,99 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Services::ContactService do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
10
|
+
describe "#get_contacts" do
|
11
|
+
it "returns an array of contacts" do
|
12
|
+
json = load_json('contacts.json')
|
13
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
14
|
+
|
15
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
16
|
+
RestClient.stub(:get).and_return(response)
|
17
|
+
contacts = ConstantContact::Services::ContactService.get_contacts('token')
|
18
|
+
contact = contacts.results[0]
|
19
|
+
|
20
|
+
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
|
21
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#get_contact" do
|
26
|
+
it "returns a contact" do
|
27
|
+
json = load_json('contact.json')
|
28
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
29
|
+
|
30
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
31
|
+
RestClient.stub(:get).and_return(response)
|
32
|
+
contact = ConstantContact::Services::ContactService.get_contact('token', 1)
|
33
|
+
|
34
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#add_contact" do
|
39
|
+
it "adds a contact" do
|
40
|
+
json = load_json('contact.json')
|
41
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
42
|
+
|
43
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
44
|
+
RestClient.stub(:post).and_return(response)
|
45
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
46
|
+
added = ConstantContact::Services::ContactService.add_contact('token', contact)
|
47
|
+
|
48
|
+
added.should respond_to(:status)
|
49
|
+
added.status.should eq('REMOVED')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#delete_contact" do
|
54
|
+
it "deletes a contact" do
|
55
|
+
json = load_json('contact.json')
|
56
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
57
|
+
|
58
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
59
|
+
RestClient.stub(:delete).and_return(response)
|
60
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
61
|
+
ConstantContact::Services::ContactService.delete_contact('token', contact).should be_true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#delete_contact_from_lists" do
|
66
|
+
it "deletes a contact" do
|
67
|
+
json = load_json('contact.json')
|
68
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
69
|
+
|
70
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
71
|
+
RestClient.stub(:delete).and_return(response)
|
72
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
73
|
+
ConstantContact::Services::ContactService.delete_contact_from_lists('token', contact).should be_true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#delete_contact_from_list" do
|
78
|
+
it "deletes a contact" do
|
79
|
+
contact_json = load_json('contact.json')
|
80
|
+
list_json = load_json('list.json')
|
81
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
82
|
+
|
83
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
84
|
+
RestClient.stub(:delete).and_return(response)
|
85
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(contact_json))
|
86
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(list_json))
|
87
|
+
ConstantContact::Services::ContactService.delete_contact_from_list('token', contact, list).should be_true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#update_contact" do
|
92
|
+
it "updates a contact" do
|
93
|
+
json = load_json('contact.json')
|
94
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
95
|
+
|
96
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
97
|
+
RestClient.stub(:put).and_return(response)
|
98
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
99
|
+
added = ConstantContact::Services::ContactService.update_contact('token', contact)
|
100
|
+
|
101
|
+
added.should respond_to(:status)
|
102
|
+
added.status.should eq('REMOVED')
|
103
|
+
end
|
104
|
+
end
|
105
105
|
end
|
@@ -7,63 +7,63 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Services::ListService do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#get_lists" do
|
11
|
+
it "returns an array of lists" do
|
12
|
+
json = load_json('lists.json')
|
13
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
16
|
+
RestClient.stub(:get).and_return(response)
|
17
|
+
lists = ConstantContact::Services::ListService.get_lists('token')
|
18
|
+
list = lists[0]
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
lists.should be_kind_of(Array)
|
21
|
+
list.should be_kind_of(ConstantContact::Components::ContactList)
|
22
|
+
end
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
describe "#get_list" do
|
26
|
+
it "returns a list" do
|
27
|
+
json = load_json('list.json')
|
28
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
31
|
+
RestClient.stub(:get).and_return(response)
|
32
|
+
contact = ConstantContact::Services::ListService.get_list('token', 1)
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
contact.should be_kind_of(ConstantContact::Components::ContactList)
|
35
|
+
end
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
describe "#add_list" do
|
39
|
+
it "adds a list" do
|
40
|
+
json = load_json('list.json')
|
41
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
44
|
+
RestClient.stub(:post).and_return(response)
|
45
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json))
|
46
|
+
added = ConstantContact::Services::ListService.add_list('token', list)
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
added.should respond_to(:status)
|
49
|
+
added.status.should eq('ACTIVE')
|
50
|
+
end
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
describe "#get_contacts_from_list" do
|
54
|
+
it "returns an array of contacts" do
|
55
|
+
json_list = load_json('list.json')
|
56
|
+
json_contacts = load_json('contacts.json')
|
57
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
response = RestClient::Response.create(json_contacts, net_http_resp, {})
|
60
|
+
RestClient.stub(:get).and_return(response)
|
61
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json_list))
|
62
|
+
contacts = ConstantContact::Services::ListService.get_contacts_from_list('token', list)
|
63
|
+
contact = contacts.results[0]
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
|
66
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
67
|
+
end
|
68
|
+
end
|
69
69
|
end
|