SFEley-acts_as_icontact 0.2.3 → 0.2.4
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/VERSION +1 -1
- data/acts_as_icontact.gemspec +2 -2
- data/lib/acts_as_icontact/rails/callbacks.rb +29 -1
- data/lib/acts_as_icontact/rails/macro.rb +1 -0
- data/lib/acts_as_icontact/resources/contact.rb +7 -0
- data/lib/acts_as_icontact/resources/list.rb +7 -0
- data/spec/rails_spec/callbacks_spec.rb +24 -7
- data/spec/resources/contact_spec.rb +7 -0
- data/spec/resources/list_spec.rb +8 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/acts_as_icontact.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{acts_as_icontact}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Stephen Eley"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-29}
|
10
10
|
s.default_executable = %q{icontact}
|
11
11
|
s.description = %q{ActsAsIcontact connects Ruby applications with the iContact e-mail marketing service using the iContact API v2.0. Building on the RestClient gem, it offers two significant feature sets:
|
12
12
|
|
@@ -22,8 +22,36 @@ module ActsAsIcontact
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
self.save
|
25
|
+
@icontact_in_progress = false # Very primitive loop prevention
|
25
26
|
end
|
26
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
def icontact_after_update
|
30
|
+
unless @icontact_in_progress # Avoid callback loops
|
31
|
+
c = find_contact_by_identity
|
32
|
+
self.class.icontact_mappings.each do |rails, iContact|
|
33
|
+
if (value = self.send(rails))
|
34
|
+
ic = (iContact.to_s + '=').to_sym # Blah. This feels like it should be easier.
|
35
|
+
c.send(ic, value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
c.save
|
39
|
+
# No need to update the record this time; iContact field changes don't have side effects
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def find_contact_by_identity
|
45
|
+
im = self.class.icontact_identity_map
|
46
|
+
if (im[1] == :contactId)
|
47
|
+
ActsAsIcontact::Contact.find(self.send(im[0]))
|
48
|
+
elsif (im[0] == :id)
|
49
|
+
ActsAsIcontact::Contact.find(im[1] => id)
|
50
|
+
else
|
51
|
+
ActsAsIcontact::Contact.find(:email => self.send(im[0]))
|
52
|
+
end
|
53
|
+
rescue ActsAsIcontact::QueryError
|
54
|
+
nil
|
27
55
|
end
|
28
56
|
|
29
57
|
end
|
@@ -21,5 +21,12 @@ module ActsAsIcontact
|
|
21
21
|
@lists ||= ActsAsIcontact::Subscription.lists(:contactId => id)
|
22
22
|
end
|
23
23
|
|
24
|
+
# Creates a new subscription for the contact to the specified list
|
25
|
+
def subscribe(list)
|
26
|
+
l = ActsAsIcontact::List.find(list)
|
27
|
+
s = ActsAsIcontact::Subscription.new(:contactId => id, :listId => l.id)
|
28
|
+
s.save
|
29
|
+
end
|
30
|
+
|
24
31
|
end
|
25
32
|
end
|
@@ -30,5 +30,12 @@ module ActsAsIcontact
|
|
30
30
|
@subscribers ||= ActsAsIcontact::Subscription.contacts(:listId => id)
|
31
31
|
end
|
32
32
|
|
33
|
+
# Creates a new subscription for the specified list by the contact
|
34
|
+
def subscribe(contact)
|
35
|
+
c = ActsAsIcontact::Contact.find(contact)
|
36
|
+
s = ActsAsIcontact::Subscription.new(:contactId => c.id, :listId => id)
|
37
|
+
s.save
|
38
|
+
end
|
39
|
+
|
33
40
|
end
|
34
41
|
end
|
@@ -5,15 +5,32 @@ share_as :Callbacks do
|
|
5
5
|
@person = @class.new(:firstName => "John", :surname => "Smith", :email => "john@example.org")
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
context "for creation" do
|
9
|
+
it "creates a new contact" do
|
10
|
+
conn = mock('Class Connection')
|
11
|
+
conn.expects(:post).with(regexp_matches(/Smith/)).returns('{"contacts":{}}')
|
12
|
+
ActsAsIcontact::Contact.expects(:connection).returns(conn)
|
13
|
+
@person.save
|
14
|
+
end
|
15
|
+
|
16
|
+
it "updates the Person with the results of the contact creation" do
|
17
|
+
@person.save
|
18
|
+
@person.icontact_id.should == 333444
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
context "for update" do
|
23
|
+
before(:each) do
|
24
|
+
@person.save
|
25
|
+
@person.surname = "Nielsen Hayden"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "updates the contact with the new fields" do
|
29
|
+
conn = mock('Instance Connection')
|
30
|
+
conn.expects(:post).with(regexp_matches(/Nielsen Hayden/)).returns('{"contact":{}}')
|
31
|
+
ActsAsIcontact::Contact.any_instance.expects(:connection).returns(conn)
|
32
|
+
@person.save
|
33
|
+
end
|
16
34
|
end
|
17
|
-
|
18
35
|
end
|
19
36
|
end
|
@@ -22,6 +22,13 @@ describe ActsAsIcontact::Contact do
|
|
22
22
|
@john.lists.first.should == ActsAsIcontact::List.find(444444)
|
23
23
|
end
|
24
24
|
|
25
|
+
it "can subscribe oneself to a list" do
|
26
|
+
conn = mock('Class Connection')
|
27
|
+
conn.expects(:post).with(regexp_matches(/444444/) && regexp_matches(/333333/)).returns('{"subscriptions":{}}')
|
28
|
+
ActsAsIcontact::Subscription.expects(:connection).returns(conn)
|
29
|
+
@john.subscribe(444444)
|
30
|
+
end
|
31
|
+
|
25
32
|
it "knows its history"
|
26
33
|
end
|
27
34
|
|
data/spec/resources/list_spec.rb
CHANGED
@@ -40,5 +40,13 @@ describe ActsAsIcontact::List do
|
|
40
40
|
it "knows its welcome message" do
|
41
41
|
@list.welcomeMessage.should == ActsAsIcontact::Message.find(555555)
|
42
42
|
end
|
43
|
+
|
44
|
+
it "can be subscribed to by a subscriber" do
|
45
|
+
conn = mock('Class Connection')
|
46
|
+
conn.expects(:post).with(regexp_matches(/444444/) && regexp_matches(/333333/)).returns('{"subscriptions":{}}')
|
47
|
+
ActsAsIcontact::Subscription.expects(:connection).returns(conn)
|
48
|
+
@list.subscribe(333333)
|
49
|
+
end
|
50
|
+
|
43
51
|
end
|
44
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SFEley-acts_as_icontact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Eley
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-29 00:00:00 -07:00
|
13
13
|
default_executable: icontact
|
14
14
|
dependencies: []
|
15
15
|
|