SFEley-acts_as_icontact 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -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.3"
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-27}
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
@@ -20,6 +20,7 @@ module ActsAsIcontact
20
20
  # If we haven't flaked out so far, we must be doing okay. Make magic happen.
21
21
  include ActsAsIcontact::Rails::Callbacks
22
22
  after_create :icontact_after_create
23
+ after_update :icontact_after_update
23
24
  end
24
25
 
25
26
  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
- it "will create a new contact after record creation" do
9
- # ActsAsIcontact::Contact.any_instance.expects(:save).returns(true)
10
- @person.save
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
- it "updates the Person with the results of the contact save" do
14
- @person.save
15
- @person.icontact_id.should == 333444
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
 
@@ -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.3
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-27 00:00:00 -07:00
12
+ date: 2009-07-29 00:00:00 -07:00
13
13
  default_executable: icontact
14
14
  dependencies: []
15
15