active_esp 0.1.0.alpha1 → 0.1.0.alpha2
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/active_esp.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["bmorton@sdreader.com"]
|
7
7
|
gem.description = %q{Framework and tools for managing email service providers.}
|
8
8
|
gem.summary = %q{ActiveESP is an abstraction library for managing subscribers, campaigns, and other email marketing facilities. It provides a consistent interface to interact with the numerous ESPs.}
|
9
|
-
gem.homepage = "
|
9
|
+
gem.homepage = "https://github.com/bmorton/active_esp"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_runtime_dependency "json", "> 1.4.0"
|
19
19
|
gem.add_runtime_dependency "httparty", "~> 0.8.1"
|
20
|
-
gem.add_runtime_dependency "activesupport", ">= 3.
|
20
|
+
gem.add_runtime_dependency "activesupport", ">= 3.1.0"
|
21
21
|
gem.add_runtime_dependency "shuber-interface", "~> 0.0.4"
|
22
22
|
|
23
23
|
gem.add_development_dependency "rspec", "~> 2.8.0"
|
@@ -57,21 +57,24 @@ module ActiveESP
|
|
57
57
|
|
58
58
|
# Interface implementation
|
59
59
|
|
60
|
-
#
|
61
|
-
#
|
62
|
-
# Note: On iContact, a user cannot be subscribed to a list that they have
|
63
|
-
# previously unsubscribed from.
|
60
|
+
# Find a contact stored in the iContact account.
|
64
61
|
#
|
65
|
-
# @see ActiveESP::Providers::Interface#
|
66
|
-
def
|
62
|
+
# @see ActiveESP::Providers::Interface#find_subscriber
|
63
|
+
def find_subscriber(params)
|
64
|
+
response = call(:get, "/a/#{account_id}/c/#{client_folder_id}/contacts", params)
|
65
|
+
return [] unless response['contacts']
|
66
|
+
|
67
|
+
response['contacts'].map do |contact|
|
68
|
+
contact_as_subscriber(contact)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_subscriber(subscriber)
|
67
73
|
response = call(:post, "/a/#{account_id}/c/#{client_folder_id}/contacts", [{:email => subscriber.email, :firstName => subscriber.first_name, :lastName => subscriber.last_name}])
|
68
74
|
subscriber.id = response['contacts'].first['contactId']
|
69
|
-
if list
|
70
|
-
list_response = call(:post, "/a/#{account_id}/c/#{client_folder_id}/subscriptions", [{:listId => list.id, :contactId => subscriber.id, :status => 'normal' }])
|
71
|
-
raise ActiveESP::Providers::CouldNotSubscribeToListException, list_response['warnings'] if list_response['warnings']
|
72
|
-
end
|
73
75
|
subscriber
|
74
76
|
end
|
77
|
+
alias :find_or_create_subscriber :create_subscriber
|
75
78
|
|
76
79
|
# Unsubscribe a subscriber from the provided list.
|
77
80
|
#
|
@@ -90,6 +93,19 @@ module ActiveESP
|
|
90
93
|
call(:get, "/a/#{account_id}/c/#{client_folder_id}/lists")
|
91
94
|
end
|
92
95
|
|
96
|
+
# Create a contact and optionally subscribe them to a provided list.
|
97
|
+
#
|
98
|
+
# Note: On iContact, a user cannot be subscribed to a list that they have
|
99
|
+
# previously unsubscribed from.
|
100
|
+
#
|
101
|
+
# @see ActiveESP::Providers::Interface#subscribe
|
102
|
+
def subscribe_to_list(subscriber, list)
|
103
|
+
subscriber = find_or_create_subscriber(subscriber) unless subscriber.id
|
104
|
+
list_response = call(:post, "/a/#{account_id}/c/#{client_folder_id}/subscriptions", [{:listId => list.id, :contactId => subscriber.id, :status => 'normal' }])
|
105
|
+
raise ActiveESP::Providers::CouldNotSubscribeToListException, list_response['warnings'] if list_response['warnings']
|
106
|
+
return subscriber
|
107
|
+
end
|
108
|
+
|
93
109
|
# Getting iContact-specific account information
|
94
110
|
|
95
111
|
# Retrieves the iContact account information attached to the credentials
|
@@ -142,6 +158,22 @@ module ActiveESP
|
|
142
158
|
end
|
143
159
|
attr_writer :client_folder_id
|
144
160
|
|
161
|
+
# Representing iContact models as ActiveESP models
|
162
|
+
|
163
|
+
# Returns a new ActiveESP::Subscriber object from a contact hash returned from
|
164
|
+
# an iContact response.
|
165
|
+
#
|
166
|
+
# @param [Hash] contact A single contact from an iContact response
|
167
|
+
# @return [Subscriber] Returns a new Subscriber object
|
168
|
+
def contact_as_subscriber(contact)
|
169
|
+
Subscriber.new(
|
170
|
+
:first_name => contact['firstName'],
|
171
|
+
:last_name => contact['lastName'],
|
172
|
+
:email => contact['email'],
|
173
|
+
:id => contact['contactId']
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
145
177
|
private
|
146
178
|
def call(method, resource, params = {})
|
147
179
|
self.class.base_uri self.endpoint
|
@@ -3,13 +3,15 @@ module ActiveESP
|
|
3
3
|
module Interface
|
4
4
|
# Subscription methods
|
5
5
|
|
6
|
-
def
|
6
|
+
def find_subscriber(params); end
|
7
|
+
def create_subscriber(subscriber); end
|
7
8
|
def unsubscribe(subscriber, list = nil); end
|
8
9
|
def subscribed?(subscriber, list = nil); end
|
9
10
|
|
10
11
|
# List methods
|
11
12
|
|
12
13
|
def lists; end
|
14
|
+
def subscribe_to_list(subscriber, list); end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -17,6 +17,8 @@ module ActiveESP
|
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
|
+
# This implementation mostly comes from the MailChimp gibbon gem
|
21
|
+
# available at: https://github.com/amro/gibbon
|
20
22
|
def call(method, params = {})
|
21
23
|
api_url = endpoint + '/?method=' + method.to_s.camelize(:lower)
|
22
24
|
params = api_params(params)
|
@@ -106,13 +106,18 @@ module ActiveESP
|
|
106
106
|
|
107
107
|
# Accessing commonly used API calls
|
108
108
|
|
109
|
+
def create!
|
110
|
+
raise ActiveESP::ProviderNotConfiguredException unless ActiveESP.provider
|
111
|
+
ActiveESP.provider.create_subscriber(self)
|
112
|
+
end
|
113
|
+
|
109
114
|
# Add the subscriber to the provider and optionally subscribe them to the
|
110
115
|
# given list.
|
111
116
|
#
|
112
117
|
# @see ActiveESP::Providers::Interface#subscribe
|
113
118
|
def subscribe!(list = nil)
|
114
119
|
raise ActiveESP::ProviderNotConfiguredException unless ActiveESP.provider
|
115
|
-
ActiveESP.provider.
|
120
|
+
ActiveESP.provider.subscribe_to_list(self, list)
|
116
121
|
end
|
117
122
|
|
118
123
|
# Remove the subscriber from the given list.
|
@@ -122,5 +127,12 @@ module ActiveESP
|
|
122
127
|
raise ActiveESP::ProviderNotConfiguredException unless ActiveESP.provider
|
123
128
|
ActiveESP.provider.unsubscribe(self, list)
|
124
129
|
end
|
130
|
+
|
131
|
+
class << self
|
132
|
+
def find(params)
|
133
|
+
raise ActiveESP::ProviderNotConfiguredException unless ActiveESP.provider
|
134
|
+
ActiveESP.provider.find_subscriber(params)
|
135
|
+
end
|
136
|
+
end
|
125
137
|
end
|
126
138
|
end
|
data/lib/active_esp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_esp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70159683606680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70159683606680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70159683606140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,21 +32,21 @@ dependencies:
|
|
32
32
|
version: 0.8.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70159683606140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &70159683605640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 3.
|
43
|
+
version: 3.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70159683605640
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shuber-interface
|
49
|
-
requirement: &
|
49
|
+
requirement: &70159683605160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.0.4
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70159683605160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70159683604640 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.8.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70159683604640
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: factory_girl
|
71
|
-
requirement: &
|
71
|
+
requirement: &70159683604160 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.5.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70159683604160
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: yard
|
82
|
-
requirement: &
|
82
|
+
requirement: &70159683603680 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 0.7.5
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70159683603680
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: thin
|
93
|
-
requirement: &
|
93
|
+
requirement: &70159683603200 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.3.1
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70159683603200
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: redcarpet
|
104
|
-
requirement: &
|
104
|
+
requirement: &70159683602740 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 2.1.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70159683602740
|
113
113
|
description: Framework and tools for managing email service providers.
|
114
114
|
email:
|
115
115
|
- bmorton@sdreader.com
|
@@ -142,7 +142,7 @@ files:
|
|
142
142
|
- spec/providers/mail_chimp_spec.rb
|
143
143
|
- spec/spec_helper.rb
|
144
144
|
- spec/support/matchers/implement_interface.rb
|
145
|
-
homepage:
|
145
|
+
homepage: https://github.com/bmorton/active_esp
|
146
146
|
licenses: []
|
147
147
|
post_install_message:
|
148
148
|
rdoc_options: []
|