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 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
- attr_reader :name, :username, :emails
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
@@ -215,19 +215,16 @@ module Contacts
215
215
  contacts = []
216
216
 
217
217
  people['contacts'].each do |contact|
218
- name = nil
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
- email = field['data']
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.push([name, email])
227
+ contacts << a_contact
231
228
  end
232
229
  return contacts
233
230
  end
data/spec/contact_spec.rb CHANGED
@@ -30,9 +30,4 @@ describe Contacts::Contact do
30
30
  end
31
31
  end
32
32
 
33
- it "should fail without first argument (email)" do
34
- lambda {
35
- Contacts::Contact.new()
36
- }.should raise_error(ArgumentError)
37
- end
38
33
  end
@@ -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
- @yahoo.contacts(redirect_path).should == [ ['Hugo Barauna', 'hugo.barauna@gmail.com'],
24
- ['Nina Benchimol', 'nina@hotmail.com'],
25
- ['Andrea Dimitri', 'and@yahoo.com'],
26
- ['Ricardo Fiorelli', 'ricardo@poli.usp.br'],
27
- ['Priscila', 'pizinha@yahoo.com.br']
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 == [ ['Hugo Barauna', 'hugo.barauna@gmail.com'],
62
- ['Nina Benchimol', 'nina@hotmail.com'],
63
- ['Andrea Dimitri', 'and@yahoo.com'],
64
- ['Ricardo Fiorelli', 'ricardo@poli.usp.br'],
65
- ['Priscila', 'pizinha@yahoo.com.br']
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pezra-contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.0.200812180934
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Mislav Marohni\xC4\x87"