constantcontact-ruby 2.2.0
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.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/README.md +136 -0
- data/constantcontact-ruby.gemspec +31 -0
- data/lib/constantcontact/api.rb +1012 -0
- data/lib/constantcontact/auth/oauth2.rb +105 -0
- data/lib/constantcontact/auth/session_data_store.rb +69 -0
- data/lib/constantcontact/components/account/account_address.rb +26 -0
- data/lib/constantcontact/components/account/account_info.rb +38 -0
- data/lib/constantcontact/components/account/verified_email_address.rb +26 -0
- data/lib/constantcontact/components/activities/activity.rb +43 -0
- data/lib/constantcontact/components/activities/activity_error.rb +26 -0
- data/lib/constantcontact/components/activities/add_contacts.rb +127 -0
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +46 -0
- data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
- data/lib/constantcontact/components/component.rb +48 -0
- data/lib/constantcontact/components/contacts/address.rb +27 -0
- data/lib/constantcontact/components/contacts/contact.rb +92 -0
- data/lib/constantcontact/components/contacts/contact_list.rb +26 -0
- data/lib/constantcontact/components/contacts/custom_field.rb +26 -0
- data/lib/constantcontact/components/contacts/email_address.rb +33 -0
- data/lib/constantcontact/components/contacts/note.rb +26 -0
- data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
- data/lib/constantcontact/components/email_marketing/campaign_preview.rb +29 -0
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +27 -0
- data/lib/constantcontact/components/email_marketing/message_footer.rb +29 -0
- data/lib/constantcontact/components/email_marketing/schedule.rb +27 -0
- data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
- data/lib/constantcontact/components/event_spot/contact.rb +27 -0
- data/lib/constantcontact/components/event_spot/event.rb +69 -0
- data/lib/constantcontact/components/event_spot/event_address.rb +29 -0
- data/lib/constantcontact/components/event_spot/event_fee.rb +27 -0
- data/lib/constantcontact/components/event_spot/event_item.rb +36 -0
- data/lib/constantcontact/components/event_spot/event_item_attribute.rb +26 -0
- data/lib/constantcontact/components/event_spot/event_track.rb +31 -0
- data/lib/constantcontact/components/event_spot/guest.rb +31 -0
- data/lib/constantcontact/components/event_spot/guest_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
- data/lib/constantcontact/components/event_spot/online_meeting.rb +28 -0
- data/lib/constantcontact/components/event_spot/payment_address.rb +29 -0
- data/lib/constantcontact/components/event_spot/payment_summary.rb +33 -0
- data/lib/constantcontact/components/event_spot/promocode.rb +25 -0
- data/lib/constantcontact/components/event_spot/registrant.rb +52 -0
- data/lib/constantcontact/components/event_spot/registrant_fee.rb +29 -0
- data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_order.rb +39 -0
- data/lib/constantcontact/components/event_spot/registrant_promo_code.rb +31 -0
- data/lib/constantcontact/components/event_spot/registrant_promo_code_info.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/sale_item.rb +29 -0
- data/lib/constantcontact/components/library/file/library_file.rb +27 -0
- data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
- data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
- data/lib/constantcontact/components/library/info/move_results.rb +26 -0
- data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
- data/lib/constantcontact/components/result_set.rb +50 -0
- data/lib/constantcontact/components/tracking/bounce_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/click_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/forward_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/open_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/send_activity.rb +27 -0
- data/lib/constantcontact/components/tracking/tracking_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/tracking_summary.rb +27 -0
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +27 -0
- data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
- data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
- data/lib/constantcontact/exceptions/webhooks_exception.rb +11 -0
- data/lib/constantcontact/services/account_service.rb +39 -0
- data/lib/constantcontact/services/activity_service.rb +136 -0
- data/lib/constantcontact/services/base_service.rb +68 -0
- data/lib/constantcontact/services/campaign_schedule_service.rb +101 -0
- data/lib/constantcontact/services/campaign_tracking_service.rb +152 -0
- data/lib/constantcontact/services/contact_service.rb +105 -0
- data/lib/constantcontact/services/contact_tracking_service.rb +152 -0
- data/lib/constantcontact/services/email_marketing_service.rb +94 -0
- data/lib/constantcontact/services/event_spot_service.rb +448 -0
- data/lib/constantcontact/services/library_service.rb +281 -0
- data/lib/constantcontact/services/list_service.rb +81 -0
- data/lib/constantcontact/util/config.rb +180 -0
- data/lib/constantcontact/util/helpers.rb +27 -0
- data/lib/constantcontact/version.rb +12 -0
- data/lib/constantcontact/webhooks/helpers/validator.rb +30 -0
- data/lib/constantcontact/webhooks/models/billing_change_notification.rb +27 -0
- data/lib/constantcontact/webhooks/webhooks_util.rb +45 -0
- data/lib/constantcontact.rb +124 -0
- data/spec/constantcontact/api_spec.rb +1560 -0
- data/spec/constantcontact/auth/oauth2_spec.rb +125 -0
- data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
- data/spec/constantcontact/sdk_spec.rb +24 -0
- data/spec/constantcontact/services/account_service_spec.rb +46 -0
- data/spec/constantcontact/services/activity_service_spec.rb +244 -0
- data/spec/constantcontact/services/base_service_spec.rb +50 -0
- data/spec/constantcontact/services/campaign_schedule_service_spec.rb +115 -0
- data/spec/constantcontact/services/campaign_tracking_service_spec.rb +131 -0
- data/spec/constantcontact/services/contact_service_spec.rb +111 -0
- data/spec/constantcontact/services/contact_tracking_service_spec.rb +131 -0
- data/spec/constantcontact/services/email_marketing_spec.rb +100 -0
- data/spec/constantcontact/services/event_spot_spec.rb +423 -0
- data/spec/constantcontact/services/library_service_spec.rb +252 -0
- data/spec/constantcontact/services/list_service_spec.rb +89 -0
- data/spec/constantcontact/webhooks/webhooks_spec.rb +26 -0
- metadata +243 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
#
|
2
|
+
# oauth2_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
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
|
+
|
19
|
+
describe "#new" do
|
20
|
+
it "fails without arguments and no configuration" do
|
21
|
+
lambda {
|
22
|
+
ConstantContact::Auth::OAuth2.new
|
23
|
+
}.should raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "takes one argument" do
|
27
|
+
opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
|
28
|
+
lambda {
|
29
|
+
ConstantContact::Auth::OAuth2.new(opts)
|
30
|
+
}.should_not raise_error
|
31
|
+
end
|
32
|
+
end
|
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_url => "redirect_uri"
|
85
|
+
}.should_not raise_error
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:proc) { lambda { ConstantContact::Auth::OAuth2.new(:api_key => "api_key", :api_secret => "api_secret", :redirect_url => "redirect_uri") } }
|
89
|
+
let(:oauth) { proc.call }
|
90
|
+
|
91
|
+
describe "#get_authorization_url" do
|
92
|
+
it "returns a string" do
|
93
|
+
oauth.get_authorization_url.should be_kind_of(String)
|
94
|
+
oauth.get_authorization_url(true, 'my_param').should match('state=my_param')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#get_access_token" do
|
99
|
+
it "returns a Hash" do
|
100
|
+
json = load_file('access_token.json')
|
101
|
+
RestClient.stub(:post).and_return(json)
|
102
|
+
oauth.get_access_token('token').should be_kind_of(Hash)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "throws an OAuth2Exception in case of error" do
|
106
|
+
json = load_file('access_token_error.json')
|
107
|
+
RestClient.stub(:post).and_return(json)
|
108
|
+
lambda {
|
109
|
+
oauth.get_access_token('token')
|
110
|
+
}.should raise_exception(ConstantContact::Exceptions::OAuth2Exception,
|
111
|
+
'The resource owner or authorization server denied the request.')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#get_token_info" do
|
116
|
+
it "returns a Hash" do
|
117
|
+
json = load_file('token_info.json')
|
118
|
+
RestClient.stub(:post).and_return(json)
|
119
|
+
info = oauth.get_token_info('token')
|
120
|
+
info.should be_kind_of(Hash)
|
121
|
+
info['user_name'].should eq('ctcttest')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# address_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Components::Address do
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return an address" do
|
12
|
+
json = load_file('address.json')
|
13
|
+
address = ConstantContact::Components::Address.create(JSON.parse(json))
|
14
|
+
|
15
|
+
address.line1.should eq('6 Main Street')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# contact_list_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Components::ContactList do
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return a list" do
|
12
|
+
json = load_file('list.json')
|
13
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json))
|
14
|
+
|
15
|
+
list.name.should eq('Fake List')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# contact_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Components::Contact do
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return a contact" do
|
12
|
+
json = load_file('contact.json')
|
13
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
14
|
+
|
15
|
+
contact.last_name.should eq('Smith')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# custom_field_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Components::CustomField do
|
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
|
+
|
15
|
+
field.name.should eq('Property')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# email_address_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Components::EmailAddress do
|
10
|
+
describe "#from_list" do
|
11
|
+
it "should return an email address" do
|
12
|
+
json = load_file('email_address.json')
|
13
|
+
email = ConstantContact::Components::EmailAddress.create(JSON.parse(json))
|
14
|
+
|
15
|
+
email.email_address.should eq('wm2q7rwtp77m@roving.com')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# api_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::SDK do
|
10
|
+
|
11
|
+
let(:dummy_class) { Class.new { include ConstantContact::SDK } }
|
12
|
+
|
13
|
+
it "should respond to VERSION" do
|
14
|
+
expect((dummy_class.const_get("VERSION") rescue nil)).to be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a VERSION of type string" do
|
18
|
+
expect(dummy_class::VERSION).to be_a String
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a VERSION of the format x.y.z" do
|
22
|
+
expect(dummy_class::VERSION.match(/[1-9]+\.\d+\.\d+/)).to_not be_nil
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# account_service_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Services::AccountService do
|
10
|
+
before(:each) do
|
11
|
+
@request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#get_account_info" do
|
15
|
+
it "gets a summary of account information" do
|
16
|
+
json_response = load_file('account_info_response.json')
|
17
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
18
|
+
|
19
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
20
|
+
RestClient.stub(:get).and_return(response)
|
21
|
+
|
22
|
+
result = ConstantContact::Services::AccountService.get_account_info()
|
23
|
+
result.should be_kind_of(ConstantContact::Components::AccountInfo)
|
24
|
+
result.website.should eq('http://www.example.com')
|
25
|
+
result.organization_addresses.first.should be_kind_of(ConstantContact::Components::AccountAddress)
|
26
|
+
result.organization_addresses.first.city.should eq('Anytown')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#get_verified_email_addresses" do
|
31
|
+
it "gets all verified email addresses associated with an account" do
|
32
|
+
json_response = load_file('verified_email_addresses_response.json')
|
33
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
34
|
+
|
35
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
36
|
+
RestClient.stub(:get).and_return(response)
|
37
|
+
|
38
|
+
params = {}
|
39
|
+
email_addresses = ConstantContact::Services::AccountService.get_verified_email_addresses(params)
|
40
|
+
|
41
|
+
email_addresses.should be_kind_of(Array)
|
42
|
+
email_addresses.first.should be_kind_of(ConstantContact::Components::VerifiedEmailAddress)
|
43
|
+
email_addresses.first.email_address.should eq('abc@def.com')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
#
|
2
|
+
# activity_service_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Services::ActivityService do
|
10
|
+
before(:each) do
|
11
|
+
@request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#get_activities" do
|
15
|
+
it "gets a set of activities" do
|
16
|
+
json_response = load_file('activities_response.json')
|
17
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
18
|
+
|
19
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
20
|
+
RestClient.stub(:get).and_return(response)
|
21
|
+
|
22
|
+
activities = ConstantContact::Services::ActivityService.get_activities()
|
23
|
+
activities.first.should be_kind_of(ConstantContact::Components::Activity)
|
24
|
+
activities.first.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#get_activity" do
|
29
|
+
it "gets an activity" do
|
30
|
+
json_response = load_file('activity_response.json')
|
31
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
32
|
+
|
33
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
34
|
+
RestClient.stub(:get).and_return(response)
|
35
|
+
|
36
|
+
activity = ConstantContact::Services::ActivityService.get_activity('a07e1ilbm7shdg6ikeo')
|
37
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
38
|
+
activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#create_add_contacts_activity" do
|
43
|
+
it "creates an Add Contacts Activity" do
|
44
|
+
json_request = load_file('add_contacts_request.json')
|
45
|
+
json_response = load_file('add_contacts_response.json')
|
46
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
47
|
+
|
48
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
49
|
+
RestClient.stub(:post).and_return(response)
|
50
|
+
|
51
|
+
contacts = []
|
52
|
+
|
53
|
+
# first contact
|
54
|
+
import = ConstantContact::Components::AddContactsImportData.new({
|
55
|
+
:first_name => "John",
|
56
|
+
:last_name => "Smith",
|
57
|
+
:birthday_month => "1",
|
58
|
+
:birthday_day => "25",
|
59
|
+
:anniversary => "03/12/2005",
|
60
|
+
:job_title => "",
|
61
|
+
:company_name => "My Company",
|
62
|
+
:home_phone => "5555551212"
|
63
|
+
})
|
64
|
+
|
65
|
+
# add emails
|
66
|
+
import.add_email("user1@example.com")
|
67
|
+
|
68
|
+
# add addresses
|
69
|
+
address = ConstantContact::Components::Address.create(
|
70
|
+
:line1 => "123 Partridge Lane",
|
71
|
+
:line2 => "Apt. 3",
|
72
|
+
:city => "Anytown",
|
73
|
+
:address_type => "PERSONAL",
|
74
|
+
:state_code => "NH",
|
75
|
+
:country_code => "US",
|
76
|
+
:postal_code => "02145"
|
77
|
+
)
|
78
|
+
import.add_address(address)
|
79
|
+
|
80
|
+
contacts << import
|
81
|
+
|
82
|
+
# second contact
|
83
|
+
import = ConstantContact::Components::AddContactsImportData.new({
|
84
|
+
:first_name => "Jane",
|
85
|
+
:last_name => "Doe",
|
86
|
+
:job_title => "",
|
87
|
+
:company_name => "Acme, Inc.",
|
88
|
+
:home_phone => "5555551213"
|
89
|
+
})
|
90
|
+
|
91
|
+
# add emails
|
92
|
+
import.add_email("user2@example.com")
|
93
|
+
|
94
|
+
# add addresses
|
95
|
+
address = ConstantContact::Components::Address.create(
|
96
|
+
:line1 => "456 Jones Road",
|
97
|
+
:city => "AnyTownShip",
|
98
|
+
:address_type => "PERSONAL",
|
99
|
+
:state_code => "DE",
|
100
|
+
:country_code => "US",
|
101
|
+
:postal_code => "01234"
|
102
|
+
)
|
103
|
+
import.add_address(address)
|
104
|
+
|
105
|
+
# add custom fields
|
106
|
+
custom_field = ConstantContact::Components::CustomField.create(
|
107
|
+
:name => "custom_field_6",
|
108
|
+
:value => "Blue Jeans"
|
109
|
+
)
|
110
|
+
import.add_custom_field(custom_field)
|
111
|
+
|
112
|
+
custom_field = ConstantContact::Components::CustomField.create(
|
113
|
+
:name => "custom_field_12",
|
114
|
+
:value => "Special Order"
|
115
|
+
)
|
116
|
+
import.add_custom_field(custom_field)
|
117
|
+
|
118
|
+
contacts << import
|
119
|
+
|
120
|
+
lists = ['4', '5', '6']
|
121
|
+
|
122
|
+
add_contact = ConstantContact::Components::AddContacts.new(contacts, lists)
|
123
|
+
|
124
|
+
JSON.parse(json_request).should eq(JSON.parse(JSON.generate(add_contact)))
|
125
|
+
|
126
|
+
activity = ConstantContact::Services::ActivityService.create_add_contacts_activity(add_contact)
|
127
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
128
|
+
activity.type.should eq('ADD_CONTACTS')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#create_add_contacts_activity_from_file" do
|
133
|
+
it "creates an Add Contacts Activity from a file" do
|
134
|
+
content = load_file('add_contacts_request.csv')
|
135
|
+
json = load_file('add_contacts_response.json')
|
136
|
+
lists = 'list1, list2'
|
137
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
138
|
+
|
139
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
140
|
+
RestClient.stub(:post).and_return(response)
|
141
|
+
|
142
|
+
activity = ConstantContact::Services::ActivityService.create_add_contacts_activity_from_file(
|
143
|
+
'contacts.txt', content, lists)
|
144
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
145
|
+
activity.type.should eq('ADD_CONTACTS')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#add_clear_lists_activity" do
|
150
|
+
it "creates a Clear Lists Activity" do
|
151
|
+
json_clear_lists = load_file('clear_lists_response.json')
|
152
|
+
json_list = load_file('list_response.json')
|
153
|
+
|
154
|
+
lists = []
|
155
|
+
lists << ConstantContact::Components::ContactList.create(JSON.parse(json_list))
|
156
|
+
|
157
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
158
|
+
|
159
|
+
response = RestClient::Response.create(json_clear_lists, net_http_resp, {}, @request)
|
160
|
+
RestClient.stub(:post).and_return(response)
|
161
|
+
|
162
|
+
activity = ConstantContact::Services::ActivityService.add_clear_lists_activity(lists)
|
163
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
164
|
+
activity.type.should eq('CLEAR_CONTACTS_FROM_LISTS')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#add_remove_contacts_from_lists_activity" do
|
169
|
+
it "creates a Remove Contacts From Lists Activity" do
|
170
|
+
json = load_file('remove_contacts_response.json')
|
171
|
+
lists = 'list1, list2'
|
172
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
173
|
+
|
174
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
175
|
+
RestClient.stub(:post).and_return(response)
|
176
|
+
email_addresses = ["djellesma@constantcontact.com"]
|
177
|
+
|
178
|
+
activity = ConstantContact::Services::ActivityService.add_remove_contacts_from_lists_activity(
|
179
|
+
email_addresses, lists)
|
180
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
181
|
+
activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "#add_remove_contacts_from_lists_activity_from_file" do
|
186
|
+
it "creates a Remove Contacts Activity from a file" do
|
187
|
+
content = load_file('remove_contacts_request.txt')
|
188
|
+
json = load_file('remove_contacts_response.json')
|
189
|
+
lists = 'list1, list2'
|
190
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
191
|
+
|
192
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
193
|
+
RestClient.stub(:post).and_return(response)
|
194
|
+
|
195
|
+
activity = ConstantContact::Services::ActivityService.add_remove_contacts_from_lists_activity_from_file(
|
196
|
+
'contacts.txt', content, lists)
|
197
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
198
|
+
activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#add_export_contacts_activity" do
|
203
|
+
it "creates an Export Contacts Activity" do
|
204
|
+
json_request = load_file('export_contacts_request.json')
|
205
|
+
json_response = load_file('export_contacts_response.json')
|
206
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
207
|
+
|
208
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
209
|
+
RestClient.stub(:post).and_return(response)
|
210
|
+
|
211
|
+
export_contacts = ConstantContact::Components::ExportContacts.new(JSON.parse(json_request))
|
212
|
+
|
213
|
+
activity = ConstantContact::Services::ActivityService.add_export_contacts_activity(export_contacts)
|
214
|
+
activity.should be_kind_of(ConstantContact::Components::Activity)
|
215
|
+
activity.type.should eq('EXPORT_CONTACTS')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#add_remove_contacts_from_lists_activity" do
|
220
|
+
it "creates a Remove Contacts From Lists Activity" do
|
221
|
+
json_request = load_file('remove_contacts_from_lists_request.json')
|
222
|
+
json_response = load_file('remove_contacts_from_lists_response.json')
|
223
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
224
|
+
|
225
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
226
|
+
RestClient.stub(:post).and_return(response)
|
227
|
+
|
228
|
+
request_object = JSON.parse(json_request)
|
229
|
+
|
230
|
+
lists = [], email_addresses = []
|
231
|
+
request_object['lists'].each do |list|
|
232
|
+
lists << ConstantContact::Components::ContactList.create(:id => list)
|
233
|
+
end
|
234
|
+
request_object['import_data'].each do |data|
|
235
|
+
data['email_addresses'].each do |email_address|
|
236
|
+
email_addresses << email_address
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
activity = ConstantContact::Services::ActivityService.add_remove_contacts_from_lists_activity(email_addresses, lists)
|
241
|
+
activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# base_service_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Services::BaseService do
|
10
|
+
describe "#get_headers" do
|
11
|
+
it "gets a hash of headers" do
|
12
|
+
token = 'foo'
|
13
|
+
ConstantContact::Services::BaseService.access_token = token
|
14
|
+
headers = ConstantContact::Services::BaseService.send(:get_headers)
|
15
|
+
|
16
|
+
expect(headers).to be_a Hash
|
17
|
+
expect(headers[:content_type]).to be_a String
|
18
|
+
expect(headers[:content_type]).to eq('application/json')
|
19
|
+
expect(headers[:accept]).to be_a String
|
20
|
+
expect(headers[:accept]).to eq('application/json')
|
21
|
+
expect(headers[:authorization]).to be_a String
|
22
|
+
expect(headers[:authorization]).to eq("Bearer #{token}")
|
23
|
+
expect(headers[:user_agent]).to be_a String
|
24
|
+
expect(headers[:user_agent].include?("Ruby SDK v#{ConstantContact::SDK::VERSION}")).to be_true
|
25
|
+
expect(headers[:user_agent].include?(RUBY_DESCRIPTION)).to be_true
|
26
|
+
expect(headers[:x_ctct_request_source]).to be_a String
|
27
|
+
expect(headers[:x_ctct_request_source].include?(ConstantContact::SDK::VERSION)).to be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#build_url" do
|
32
|
+
it "combines all the given parameters into the url" do
|
33
|
+
components = ConstantContact::Services::BaseService.send(:build_url, "http://testing.com", :arg1 => 'abc', :arg2 => 123).split('&')
|
34
|
+
expect(components[0]).to eq('http://testing.com?api_key=api+key')
|
35
|
+
expect(components.length).to eq(3)
|
36
|
+
expect(components.include?('arg1=abc')).to be_true
|
37
|
+
expect(components.include?('arg2=123')).to be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not parse the next param when not in next_link format" do
|
41
|
+
url = ConstantContact::Services::BaseService.send(:build_url, "http://testing.com", :next => "abcdef")
|
42
|
+
expect(url).to eq('http://testing.com?api_key=api+key&next=abcdef')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "parses next id from next param given in next_link format" do
|
46
|
+
url = ConstantContact::Services::BaseService.send(:build_url, "http://testing.com", :next => "/some/path?next=abcdefg")
|
47
|
+
expect(url).to eq('http://testing.com?api_key=api+key&next=abcdefg')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|