giannichiappetta-contacts 1.0.16 → 1.0.16.1

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.
Files changed (2) hide show
  1. data/lib/contacts/hotmail.rb +29 -7
  2. metadata +1 -1
@@ -66,6 +66,7 @@ class Contacts
66
66
  end
67
67
 
68
68
  @contacts = []
69
+ build_contacts = []
69
70
  go = true
70
71
  index = 0
71
72
 
@@ -75,18 +76,39 @@ class Contacts
75
76
  http = open_http(url)
76
77
  resp, data = http.get(get_contact_list_url(index), "Cookie" => @cookies)
77
78
 
78
- url_match_text_beginning = Regexp.escape("http://m.mail.live.com/?rru=compose&to=")
79
- url_match_text_end = Regexp.escape("&")
80
- @contacts = @contacts + resp.body.scan(/#{url_match_text_beginning}(.*)#{url_match_text_end}/)
79
+ email_match_text_beginning = Regexp.escape("http://m.mail.live.com/?rru=compose&to=")
80
+ email_match_text_end = Regexp.escape("&")
81
+
82
+ raw_html = resp.body.grep(/(?:e|dn)lk[0-9]+/)
83
+ raw_html.delete_at 0
84
+ raw_html.inject do |memo, row|
85
+ c_info = row.match(/(e|dn)lk([0-9])+/)
86
+
87
+ # Same contact, or different?
88
+ build_contacts << [] if memo != c_info[2]
89
+
90
+ # Grab info
91
+ case c_info[1]
92
+ when "e" # Email
93
+ build_contacts.last[1] = row.match(/#{email_match_text_beginning}(.*)#{email_match_text_end}/)[1]
94
+ when "dn" # Name
95
+ build_contacts.last[0] = row.match(/<a[^>]*>(.+)<\/a>/)[1]
96
+ end
97
+
98
+ # Set memo to contact id
99
+ c_info[2]
100
+ end
81
101
 
82
102
  go = resp.body.include?("Next page")
83
103
  index += 1
84
104
  end
85
105
 
86
- @contacts.each do |contact|
87
- contact = contact.to_a
88
- contact[1] = CGI::unescape(contact[0])
89
- contact[0] = nil
106
+ build_contacts.each do |contact|
107
+ unless contact[1].nil?
108
+ # Only return contacts with email addresses
109
+ contact[1] = CGI::unescape(contact[1])
110
+ @contacts << contact
111
+ end
90
112
  end
91
113
  return @contacts
92
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giannichiappetta-contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Carlson