aeden-contacts 0.2.18 → 0.2.19

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.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 2
3
- :patch: 18
3
+ :patch: 19
4
4
  :major: 0
@@ -105,9 +105,13 @@ module Contacts
105
105
  # * path <String>:: The path of the redirect request that Yahoo sent to you
106
106
  # after authenticating the user
107
107
  #
108
- def contacts(path)
108
+ def contacts(token)
109
109
  begin
110
- validate_signature(path)
110
+ if token.is_a?(YahooToken)
111
+ @token = token.token
112
+ else
113
+ validate_signature(token)
114
+ end
111
115
  credentials = access_user_credentials()
112
116
  parse_credentials(credentials)
113
117
  contacts_json = access_address_book_api()
@@ -213,10 +217,11 @@ module Contacts
213
217
  def self.parse_contacts(json)
214
218
  contacts = []
215
219
  people = JSON.parse(json)
216
-
217
220
  people['contacts'].each do |contact|
218
221
  name = nil
219
222
  email = nil
223
+ firstname = nil
224
+ lastname = nil
220
225
  contact['fields'].each do |field|
221
226
  case field['type']
222
227
  when 'email'
@@ -225,12 +230,23 @@ module Contacts
225
230
  when 'name'
226
231
  name = "#{field['first']} #{field['last']}"
227
232
  name.strip!
233
+ lastname = field['last']
234
+ firstname = field['first']
228
235
  end
229
236
  end
230
- contacts.push Contact.new(email, name)
237
+ yahoo_contact = Contact.new(email, name, nil, firstname, lastname)
238
+ yahoo_contact.service_id = contact['cid']
239
+
240
+ contacts.push yahoo_contact
231
241
  end
232
242
  return contacts
233
243
  end
234
244
 
235
245
  end
246
+ class YahooToken
247
+ attr_reader :token
248
+ def initialize(token)
249
+ @token = token
250
+ end
251
+ end
236
252
  end
@@ -20,11 +20,11 @@ describe Contacts::Yahoo do
20
20
  redirect_path = '/?appid=i%3DB%26p%3DUw70JGIdHWVRbpqYItcMw--&token=AB.KoEg8vBwvJKFkwfcDTJEMKhGeAD6KhiDe0aZLCvoJzMeQG00-&appdata=&ts=1218501215&sig=d381fba89c7e9d3c14788720733c3fbf'
21
21
 
22
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')
23
+ results.should have_contact('Hugo Barauna', 'hugo.barauna@gmail.com', 4)
24
+ results.should have_contact('Nina Benchimol', 'nina@hotmail.com', 5)
25
+ results.should have_contact('Andrea Dimitri', 'and@yahoo.com',1)
26
+ results.should have_contact('Ricardo Fiorelli', 'ricardo@poli.usp.br',3)
27
+ results.should have_contact('Priscila', 'pizinha@yahoo.com.br', 2)
28
28
  end
29
29
 
30
30
  it 'should validate yahoo redirect signature' do
@@ -57,11 +57,11 @@ describe Contacts::Yahoo do
57
57
  it 'should parse the contacts json response' do
58
58
  json = read_file('yh_contacts.txt')
59
59
 
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')
60
+ Contacts::Yahoo.parse_contacts(json).should have_contact('Hugo Barauna', 'hugo.barauna@gmail.com', 4)
61
+ Contacts::Yahoo.parse_contacts(json).should have_contact('Nina Benchimol', 'nina@hotmail.com', 5)
62
+ Contacts::Yahoo.parse_contacts(json).should have_contact('Andrea Dimitri', 'and@yahoo.com', 1)
63
+ Contacts::Yahoo.parse_contacts(json).should have_contact('Ricardo Fiorelli', 'ricardo@poli.usp.br', 3)
64
+ Contacts::Yahoo.parse_contacts(json).should have_contact('Priscila', 'pizinha@yahoo.com.br', 2)
65
65
  end
66
66
 
67
67
  it 'should can be initialized by a YAML file' do
@@ -73,10 +73,10 @@ describe Contacts::Yahoo do
73
73
  File.open(@path + file, 'r+').read
74
74
  end
75
75
 
76
- def have_contact(name, email)
76
+ def have_contact(name, email, cid)
77
77
  matcher_class = Class.new()
78
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)}}
79
+ define_method(:matches?) {|some_contacts| some_contacts.any? {|a_contact| a_contact.name == name && a_contact.emails.include?(email) && a_contact.service_id == cid}}
80
80
  end
81
81
  matcher_class.new
82
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aeden-contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Mislav Marohni\xC6\x92\xC3\xA1"
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-07-10 00:00:00 -07:00
14
+ date: 2009-07-23 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies: []
17
17