constantcontact 1.0.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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/README.md +132 -0
  4. data/constantcontact.gemspec +32 -0
  5. data/lib/constantcontact.rb +75 -0
  6. data/lib/constantcontact/api.rb +541 -0
  7. data/lib/constantcontact/auth/oauth2.rb +82 -0
  8. data/lib/constantcontact/auth/session_data_store.rb +69 -0
  9. data/lib/constantcontact/components/account/verified_email_address.rb +27 -0
  10. data/lib/constantcontact/components/activities/activity.rb +44 -0
  11. data/lib/constantcontact/components/activities/activity_error.rb +27 -0
  12. data/lib/constantcontact/components/activities/add_contacts.rb +117 -0
  13. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +45 -0
  14. data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
  15. data/lib/constantcontact/components/component.rb +23 -0
  16. data/lib/constantcontact/components/contacts/address.rb +28 -0
  17. data/lib/constantcontact/components/contacts/contact.rb +86 -0
  18. data/lib/constantcontact/components/contacts/contact_list.rb +27 -0
  19. data/lib/constantcontact/components/contacts/custom_field.rb +27 -0
  20. data/lib/constantcontact/components/contacts/email_address.rb +34 -0
  21. data/lib/constantcontact/components/contacts/note.rb +25 -0
  22. data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
  23. data/lib/constantcontact/components/email_marketing/click_through_details.rb +28 -0
  24. data/lib/constantcontact/components/email_marketing/message_footer.rb +30 -0
  25. data/lib/constantcontact/components/email_marketing/schedule.rb +29 -0
  26. data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
  27. data/lib/constantcontact/components/result_set.rb +27 -0
  28. data/lib/constantcontact/components/tracking/bounce_activity.rb +29 -0
  29. data/lib/constantcontact/components/tracking/click_activity.rb +28 -0
  30. data/lib/constantcontact/components/tracking/forward_activity.rb +28 -0
  31. data/lib/constantcontact/components/tracking/open_activity.rb +28 -0
  32. data/lib/constantcontact/components/tracking/send_activity.rb +28 -0
  33. data/lib/constantcontact/components/tracking/tracking_activity.rb +27 -0
  34. data/lib/constantcontact/components/tracking/tracking_summary.rb +28 -0
  35. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +29 -0
  36. data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
  37. data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
  38. data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
  39. data/lib/constantcontact/services/account_service.rb +29 -0
  40. data/lib/constantcontact/services/activity_service.rb +107 -0
  41. data/lib/constantcontact/services/base_service.rb +37 -0
  42. data/lib/constantcontact/services/campaign_schedule_service.rb +107 -0
  43. data/lib/constantcontact/services/campaign_tracking_service.rb +159 -0
  44. data/lib/constantcontact/services/contact_service.rb +114 -0
  45. data/lib/constantcontact/services/contact_tracking_service.rb +159 -0
  46. data/lib/constantcontact/services/email_marketing_service.rb +87 -0
  47. data/lib/constantcontact/services/list_service.rb +85 -0
  48. data/lib/constantcontact/util/config.rb +140 -0
  49. data/lib/constantcontact/util/helpers.rb +27 -0
  50. data/lib/constantcontact/version.rb +12 -0
  51. data/spec/constantcontact/api_spec.rb +183 -0
  52. data/spec/constantcontact/auth/oauth2_spec.rb +48 -0
  53. data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
  54. data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
  55. data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
  56. data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
  57. data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
  58. data/spec/constantcontact/services/contact_service_spec.rb +105 -0
  59. data/spec/constantcontact/services/list_service_spec.rb +69 -0
  60. data/spec/spec_helper.rb +13 -0
  61. metadata +134 -0
@@ -0,0 +1,48 @@
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
+ describe "#new" do
11
+ it "fails without arguments" do
12
+ lambda {
13
+ ConstantContact::Auth::OAuth2.new
14
+ }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "takes one argument" do
18
+ opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
19
+ lambda {
20
+ ConstantContact::Auth::OAuth2.new(opts)
21
+ }.should_not raise_error(ArgumentError)
22
+ end
23
+ end
24
+
25
+ describe "#get_authorization_url" do
26
+ before(:each) do
27
+ opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
28
+ @auth = ConstantContact::Auth::OAuth2.new(opts)
29
+ end
30
+
31
+ it "returns a string" do
32
+ @auth.get_authorization_url.should be_kind_of(String)
33
+ end
34
+ end
35
+
36
+ describe "#get_access_token" do
37
+ before(:each) do
38
+ opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
39
+ @auth = ConstantContact::Auth::OAuth2.new(opts)
40
+ end
41
+
42
+ it "returns a Hash" do
43
+ json = load_json('access_token.json')
44
+ RestClient.stub(:post).and_return(json)
45
+ @auth.get_access_token('token').should be_kind_of(Hash)
46
+ end
47
+ end
48
+ 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_json('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_json('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_json('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_json('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,105 @@
1
+ #
2
+ # contact_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::ContactService do
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
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # list_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::ListService do
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
+
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
+
20
+ lists.should be_kind_of(Array)
21
+ list.should be_kind_of(ConstantContact::Components::ContactList)
22
+ end
23
+ end
24
+
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
+
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
+
34
+ contact.should be_kind_of(ConstantContact::Components::ContactList)
35
+ end
36
+ end
37
+
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
+
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
+
48
+ added.should respond_to(:status)
49
+ added.status.should eq('ACTIVE')
50
+ end
51
+ end
52
+
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
+
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
+
65
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
66
+ contact.should be_kind_of(ConstantContact::Components::Contact)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,13 @@
1
+ #
2
+ # spec_helper.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
8
+ require 'constantcontact'
9
+
10
+
11
+ def load_json(file_name)
12
+ json = File.read(File.join(File.dirname(__FILE__), 'fixtures', file_name))
13
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: constantcontact
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ConstantContact
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2013-04-09 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - &id002
20
+ - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ prerelease: false
28
+ requirement: &id003 !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - *id002
31
+ type: :runtime
32
+ version_requirements: *id003
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ prerelease: false
36
+ requirement: &id004 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - *id002
39
+ type: :development
40
+ version_requirements: *id004
41
+ description: Ruby library for interactions with Constant Contact v2 API
42
+ email: apisupport@constantcontact.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - .rspec
51
+ - constantcontact.gemspec
52
+ - README.md
53
+ - lib/constantcontact/api.rb
54
+ - lib/constantcontact/auth/oauth2.rb
55
+ - lib/constantcontact/auth/session_data_store.rb
56
+ - lib/constantcontact/components/account/verified_email_address.rb
57
+ - lib/constantcontact/components/activities/activity.rb
58
+ - lib/constantcontact/components/activities/activity_error.rb
59
+ - lib/constantcontact/components/activities/add_contacts.rb
60
+ - lib/constantcontact/components/activities/add_contacts_import_data.rb
61
+ - lib/constantcontact/components/activities/export_contacts.rb
62
+ - lib/constantcontact/components/component.rb
63
+ - lib/constantcontact/components/contacts/address.rb
64
+ - lib/constantcontact/components/contacts/contact.rb
65
+ - lib/constantcontact/components/contacts/contact_list.rb
66
+ - lib/constantcontact/components/contacts/custom_field.rb
67
+ - lib/constantcontact/components/contacts/email_address.rb
68
+ - lib/constantcontact/components/contacts/note.rb
69
+ - lib/constantcontact/components/email_marketing/campaign.rb
70
+ - lib/constantcontact/components/email_marketing/click_through_details.rb
71
+ - lib/constantcontact/components/email_marketing/message_footer.rb
72
+ - lib/constantcontact/components/email_marketing/schedule.rb
73
+ - lib/constantcontact/components/email_marketing/test_send.rb
74
+ - lib/constantcontact/components/result_set.rb
75
+ - lib/constantcontact/components/tracking/bounce_activity.rb
76
+ - lib/constantcontact/components/tracking/click_activity.rb
77
+ - lib/constantcontact/components/tracking/forward_activity.rb
78
+ - lib/constantcontact/components/tracking/open_activity.rb
79
+ - lib/constantcontact/components/tracking/send_activity.rb
80
+ - lib/constantcontact/components/tracking/tracking_activity.rb
81
+ - lib/constantcontact/components/tracking/tracking_summary.rb
82
+ - lib/constantcontact/components/tracking/unsubscribe_activity.rb
83
+ - lib/constantcontact/exceptions/ctct_exception.rb
84
+ - lib/constantcontact/exceptions/illegal_argument_exception.rb
85
+ - lib/constantcontact/exceptions/oauth2_exception.rb
86
+ - lib/constantcontact/services/account_service.rb
87
+ - lib/constantcontact/services/activity_service.rb
88
+ - lib/constantcontact/services/base_service.rb
89
+ - lib/constantcontact/services/campaign_schedule_service.rb
90
+ - lib/constantcontact/services/campaign_tracking_service.rb
91
+ - lib/constantcontact/services/contact_service.rb
92
+ - lib/constantcontact/services/contact_tracking_service.rb
93
+ - lib/constantcontact/services/email_marketing_service.rb
94
+ - lib/constantcontact/services/list_service.rb
95
+ - lib/constantcontact/util/config.rb
96
+ - lib/constantcontact/util/helpers.rb
97
+ - lib/constantcontact/version.rb
98
+ - lib/constantcontact.rb
99
+ - spec/constantcontact/api_spec.rb
100
+ - spec/constantcontact/auth/oauth2_spec.rb
101
+ - spec/constantcontact/components/contacts/address_spec.rb
102
+ - spec/constantcontact/components/contacts/contact_list_spec.rb
103
+ - spec/constantcontact/components/contacts/contact_spec.rb
104
+ - spec/constantcontact/components/contacts/custom_field_spec.rb
105
+ - spec/constantcontact/components/contacts/email_address_spec.rb
106
+ - spec/constantcontact/services/contact_service_spec.rb
107
+ - spec/constantcontact/services/list_service_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: http://www.constantcontact.com
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+
114
+ post_install_message:
115
+ rdoc_options: []
116
+
117
+ require_paths:
118
+ - lib
119
+ - spec
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - *id002
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - *id002
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Constant Contact SDK for Ruby
133
+ test_files: []
134
+