pezra-contacts 0.1.0 → 0.1.0.200812180934
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/contacts.gemspec +1 -1
- data/lib/contacts.rb +3 -2
- data/lib/contacts/yahoo.rb +4 -7
- data/spec/contact_spec.rb +0 -5
- data/spec/yahoo/yahoo_spec.rb +19 -13
- metadata +1 -1
data/contacts.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = %q{contacts}
|
|
3
|
-
s.version = "0.1.0"
|
|
3
|
+
s.version = "0.1.0.#{Time.now.strftime('%Y%m%d%H%M')}"
|
|
4
4
|
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
6
6
|
s.authors = ["Mislav Marohni\304\207"]
|
data/lib/contacts.rb
CHANGED
|
@@ -6,9 +6,10 @@ module Contacts
|
|
|
6
6
|
|
|
7
7
|
# An object that represents a single contact
|
|
8
8
|
class Contact
|
|
9
|
-
|
|
9
|
+
attr_accessor :name, :username
|
|
10
|
+
attr_reader :emails
|
|
10
11
|
|
|
11
|
-
def initialize(email, name = nil, username = nil)
|
|
12
|
+
def initialize(email = nil, name = nil, username = nil)
|
|
12
13
|
@emails = []
|
|
13
14
|
@emails << email if email
|
|
14
15
|
@name = name
|
data/lib/contacts/yahoo.rb
CHANGED
|
@@ -215,19 +215,16 @@ module Contacts
|
|
|
215
215
|
contacts = []
|
|
216
216
|
|
|
217
217
|
people['contacts'].each do |contact|
|
|
218
|
-
|
|
219
|
-
email = nil
|
|
218
|
+
a_contact = Contact.new
|
|
220
219
|
contact['fields'].each do |field|
|
|
221
220
|
case field['type']
|
|
222
221
|
when 'email'
|
|
223
|
-
|
|
224
|
-
email.strip!
|
|
222
|
+
a_contact.emails << field['data'].strip
|
|
225
223
|
when 'name'
|
|
226
|
-
name = "#{field['first']} #{field['last']}"
|
|
227
|
-
name.strip!
|
|
224
|
+
a_contact.name = "#{field['first']} #{field['last']}".strip
|
|
228
225
|
end
|
|
229
226
|
end
|
|
230
|
-
contacts
|
|
227
|
+
contacts << a_contact
|
|
231
228
|
end
|
|
232
229
|
return contacts
|
|
233
230
|
end
|
data/spec/contact_spec.rb
CHANGED
data/spec/yahoo/yahoo_spec.rb
CHANGED
|
@@ -19,13 +19,12 @@ describe Contacts::Yahoo do
|
|
|
19
19
|
|
|
20
20
|
redirect_path = '/?appid=i%3DB%26p%3DUw70JGIdHWVRbpqYItcMw--&token=AB.KoEg8vBwvJKFkwfcDTJEMKhGeAD6KhiDe0aZLCvoJzMeQG00-&appdata=&ts=1218501215&sig=d381fba89c7e9d3c14788720733c3fbf'
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]
|
|
22
|
+
results = @yahoo.contacts(redirect_path)
|
|
23
|
+
results.should have_contact('Hugo Barauna', 'hugo.barauna@gmail.com')
|
|
24
|
+
results.should have_contact('Nina Benchimol', 'nina@hotmail.com')
|
|
25
|
+
results.should have_contact('Andrea Dimitri', 'and@yahoo.com')
|
|
26
|
+
results.should have_contact('Ricardo Fiorelli', 'ricardo@poli.usp.br')
|
|
27
|
+
results.should have_contact('Priscila', 'pizinha@yahoo.com.br')
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
it 'should validate yahoo redirect signature' do
|
|
@@ -58,12 +57,11 @@ describe Contacts::Yahoo do
|
|
|
58
57
|
it 'should parse the contacts json response' do
|
|
59
58
|
json = read_file('yh_contacts.txt')
|
|
60
59
|
|
|
61
|
-
Contacts::Yahoo.parse_contacts(json).should
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
]
|
|
60
|
+
Contacts::Yahoo.parse_contacts(json).should have_contact('Hugo Barauna', 'hugo.barauna@gmail.com')
|
|
61
|
+
Contacts::Yahoo.parse_contacts(json).should have_contact('Nina Benchimol', 'nina@hotmail.com')
|
|
62
|
+
Contacts::Yahoo.parse_contacts(json).should have_contact('Andrea Dimitri', 'and@yahoo.com')
|
|
63
|
+
Contacts::Yahoo.parse_contacts(json).should have_contact('Ricardo Fiorelli', 'ricardo@poli.usp.br')
|
|
64
|
+
Contacts::Yahoo.parse_contacts(json).should have_contact('Priscila', 'pizinha@yahoo.com.br')
|
|
67
65
|
end
|
|
68
66
|
|
|
69
67
|
it 'should can be initialized by a YAML file' do
|
|
@@ -74,4 +72,12 @@ describe Contacts::Yahoo do
|
|
|
74
72
|
def read_file(file)
|
|
75
73
|
File.open(@path + file, 'r+').read
|
|
76
74
|
end
|
|
75
|
+
|
|
76
|
+
def have_contact(name, email)
|
|
77
|
+
matcher_class = Class.new()
|
|
78
|
+
matcher_class.instance_eval do
|
|
79
|
+
define_method(:matches?) {|some_contacts| some_contacts.any? {|a_contact| a_contact.name == name && a_contact.emails.include?(email)}}
|
|
80
|
+
end
|
|
81
|
+
matcher_class.new
|
|
82
|
+
end
|
|
77
83
|
end
|