ppl 2.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95e88afd4d3b0aa9e6af8d3e5362b8826ff0a338
4
- data.tar.gz: 4dd553d7deaeb6880d958c92c9797230c8a601d4
3
+ metadata.gz: 29ebfed69dcf001e746e48a71e7264a479c5a3cb
4
+ data.tar.gz: 76df48178f8096c31e4c425433798ebe21dd3138
5
5
  SHA512:
6
- metadata.gz: 77825be6cccd5eda789c2ae779c94fccea8e19b703f880b22e13dd7c4acd68e26e57963feddd0e77a3bf48a8aa28d33f83973ad84075427d408570889216feab
7
- data.tar.gz: 5d4b42a641b6c9f7fe3d048afcbed0009eaab79262495e6d0c944a05ebf6179802a508b6aac0308abe048d88915bebf862bd2789a45d44e0967554f2d77ed183
6
+ metadata.gz: 5e414fbc166fc1d3eef308a476bcbbd89315fa7276a42b19c28dbc993c9945bdd8c0ea362e31214f6be89e41ba1556fd33d2be9689771bfb6d6c942de952a60f
7
+ data.tar.gz: 4620b182ccea6549b53c4ee456f239fb167db7f336d4e8c1a323f4f9d6469f445289b3ebf312ab8750a553ddf462c826a238dc686148e32d0baf94ad83a75333
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "2.1.0"
4
+ Version = "2.2.0"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -3,6 +3,8 @@ require "mail"
3
3
 
4
4
  class Ppl::Adapter::EmailScraper::Mail
5
5
 
6
+ attr_writer :storage_adapter
7
+
6
8
  def scrape_contacts(email)
7
9
  email = Mail.new(email)
8
10
  contacts = []
@@ -21,19 +23,31 @@ class Ppl::Adapter::EmailScraper::Mail
21
23
  from = email[:from]
22
24
  unless from.nil?
23
25
  sender = Ppl::Entity::Contact.new
24
- sender.name = from.tree.addresses.first.display_name
25
- sender.email_addresses << from.tree.addresses.first.address
26
+ sender.name = Ppl::Entity::Name.new
27
+ sender.name.full = from.tree.addresses.first.display_name
28
+ sender.email_addresses << Ppl::Entity::EmailAddress.new(from.tree.addresses.first.address)
26
29
  sender.id = generate_contact_id(sender)
27
30
  sender
28
31
  end
29
32
  end
30
33
 
31
34
  def generate_contact_id(contact)
32
- if !contact.name.nil?
33
- contact.name.downcase.tr(" ", "_")
35
+ if !contact.name.full.nil?
36
+ generate_contact_id_from_name(contact.name)
34
37
  elsif !contact.email_addresses.empty?
35
- contact.email_addresses.first
38
+ contact.email_addresses.first.address
39
+ end
40
+ end
41
+
42
+ def generate_contact_id_from_name(name)
43
+ name = name.full.downcase.tr(" ", "_")
44
+ base = name
45
+ suffix = 0
46
+ until @storage_adapter.load_contact(name).nil?
47
+ suffix += 1
48
+ name = "#{base}_#{suffix}"
36
49
  end
50
+ name
37
51
  end
38
52
 
39
53
  end
@@ -370,7 +370,9 @@ class Ppl::Application::Bootstrap
370
370
  end
371
371
 
372
372
  register :email_scraper do
373
- Ppl::Adapter::EmailScraper::Mail.new
373
+ email_scraper = Ppl::Adapter::EmailScraper::Mail.new
374
+ email_scraper.storage_adapter = storage_adapter
375
+ email_scraper
374
376
  end
375
377
 
376
378
  register :email_service do
data/ppl.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "2.1.0"
5
+ spec.version = "2.2.0"
6
6
  spec.date = "2013-07-20"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
@@ -3,6 +3,8 @@ describe Ppl::Adapter::EmailScraper::Mail do
3
3
 
4
4
  before(:each) do
5
5
  @adapter = Ppl::Adapter::EmailScraper::Mail.new
6
+ @storage = double(Ppl::Adapter::Storage)
7
+ @adapter.storage_adapter = @storage
6
8
  end
7
9
 
8
10
  describe "#scrape_contacts" do
@@ -23,8 +25,9 @@ describe Ppl::Adapter::EmailScraper::Mail do
23
25
  "This is a test email.",
24
26
  "Bye!",
25
27
  ].join("\n")
28
+ @storage.should_receive(:load_contact).and_return(nil)
26
29
  contacts = @adapter.scrape_contacts(email)
27
- contacts.first.name.should eq "Test User"
30
+ contacts.first.name.full.should eq "Test User"
28
31
  end
29
32
 
30
33
  it "should scrape the sender's email address" do
@@ -39,8 +42,9 @@ describe Ppl::Adapter::EmailScraper::Mail do
39
42
  "This is a test email.",
40
43
  "Bye!",
41
44
  ].join("\n")
45
+ @storage.should_receive(:load_contact).and_return(nil)
42
46
  contacts = @adapter.scrape_contacts(email)
43
- contacts.first.email_addresses.first.should eq "test@example.org"
47
+ contacts.first.email_addresses.first.address.should eq "test@example.org"
44
48
  end
45
49
 
46
50
  it "should generate an ID for the sender based on their name" do
@@ -55,6 +59,7 @@ describe Ppl::Adapter::EmailScraper::Mail do
55
59
  "This is a test email.",
56
60
  "Bye!",
57
61
  ].join("\n")
62
+ @storage.should_receive(:load_contact).and_return(nil)
58
63
  contacts = @adapter.scrape_contacts(email)
59
64
  contacts.first.id.should eq "test_user"
60
65
  end
@@ -75,6 +80,24 @@ describe Ppl::Adapter::EmailScraper::Mail do
75
80
  contacts.first.id.should eq "test@example.org"
76
81
  end
77
82
 
83
+ it "avoids overwriting an existing contact ID" do
84
+ email = [
85
+ "Date: Fri, 30 Nov 2012 17:09:33 +0000",
86
+ "From: Test User <test@example.org>",
87
+ "Message-ID: <qwertyuioasdfghjk@mail.example.org>",
88
+ "Subject: Test Email",
89
+ "To: henry@henrysmith.org",
90
+ "",
91
+ "Hey,",
92
+ "This is a test email.",
93
+ "Bye!",
94
+ ].join("\n")
95
+ @storage.should_receive(:load_contact).with("test_user").and_return(Ppl::Entity::Contact.new)
96
+ @storage.should_receive(:load_contact).with("test_user_1").and_return(nil)
97
+ contacts = @adapter.scrape_contacts(email)
98
+ contacts.first.id.should eq "test_user_1"
99
+ end
100
+
78
101
  end
79
102
 
80
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Smith