muck-invites 3.3.2 → 3.3.3

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 CHANGED
@@ -1 +1 @@
1
- 3.3.2
1
+ 3.3.3
@@ -27,6 +27,10 @@ module MuckInvitesHelper
27
27
  user.authentications.find_by_provider('google')
28
28
  end
29
29
 
30
+ def yahoo_oauth_for(user)
31
+ user.authentications.find_by_provider('yahoo')
32
+ end
33
+
30
34
  # Generates a javascript array of emails from gmail. Values will be
31
35
  # put into a variable named 'gmail_contacts'
32
36
  def gmail_contacts_for_auto_complete(user, ignore_cache = false)
@@ -35,15 +39,19 @@ module MuckInvitesHelper
35
39
  "var gmail_contacts = [#{contacts.join(',')}];"
36
40
  end
37
41
 
42
+ def service_contacts(user, ignore_cache = false)
43
+ self.gmail_contacts(user, ignore_cache) + self.yahoo_contacts(user, ignore_cache)
44
+ end
45
+
38
46
  def gmail_contacts(user, ignore_cache = false)
39
47
  if @user_gmail_contacts && @user_gmail_contacts[user] && !ignore_cache
40
48
  @user_gmail_contacts[user]
41
49
  else
50
+ contacts = []
42
51
  google = google_oauth_for(user)
43
52
  if google
44
53
  @user_gmail_contacts ||= {}
45
54
  result = google.access_token.get('https://www.google.com/m8/feeds/contacts/default/full?max-results=10000')
46
- contacts = []
47
55
  if result.code == '200'
48
56
  xml_doc = Nokogiri::XML(result.body) {|config| config.options = Nokogiri::XML::ParseOptions::STRICT }
49
57
  contacts = xml_doc.xpath('//xmlns:entry').map do |entry|
@@ -55,7 +63,63 @@ module MuckInvitesHelper
55
63
  end
56
64
  @user_gmail_contacts[user] = contacts
57
65
  end
66
+ contacts
58
67
  end
59
68
  end
60
-
69
+
70
+ def yahoo_contacts(user, ignore_cache = false)
71
+ if @user_yahoo_contacts && @user_yahoo_contacts[user] && !ignore_cache
72
+ @user_yahoo_contacts[user]
73
+ else
74
+ contacts = []
75
+ yahoo = yahoo_oauth_for(user)
76
+ if yahoo
77
+ @user_yahoo_contacts ||= {}
78
+ begin
79
+ result = yahoo.access_token.get("http://social.yahooapis.com/v1/user/#{yahoo.uid}/contacts?format=json&count=max")
80
+ rescue OAuth::Problem => ex
81
+ return contacts
82
+ end
83
+ if result.code == '200'
84
+ json = ActiveSupport::JSON.decode(result.body)
85
+ contacts = parse_yahoo_contacts(json)
86
+ end
87
+ @user_yahoo_contacts[user] = contacts
88
+ end
89
+ contacts
90
+ end
91
+ end
92
+
93
+
94
+ def parse_yahoo_contacts(json)
95
+ contacts = []
96
+
97
+ return contacts if json['contacts']['contact'].nil?
98
+
99
+ json['contacts']['contact'].each do |contact|
100
+
101
+ name = nil
102
+ email = nil
103
+
104
+ contact['fields'].each do |field|
105
+ field['type']
106
+
107
+ if field['type'] == 'name'
108
+ name = "#{field['value']['givenName']} #{field['value']['familyName']}"
109
+ end
110
+
111
+ if field['type'] == 'email'
112
+ email = field['value']
113
+ end
114
+ end
115
+
116
+ if(email)
117
+ name ||= email
118
+ contacts << { :name => name, :email => email}
119
+ end
120
+ end
121
+
122
+ contacts
123
+ end
124
+
61
125
  end
@@ -0,0 +1,9 @@
1
+ <% return unless logged_in? -%>
2
+ <% if google_oauth_for(current_user) || yahoo_oauth_for(current_user) -%>
3
+ <p><%=translate('muck.invites.select_emails') %></p>
4
+ <div id="contacts-from-services" class="invite-query">
5
+ <div class="contact-list">
6
+ <%= contact_container(service_contacts(current_user)) %>
7
+ </div>
8
+ </div>
9
+ <% end -%>
@@ -13,10 +13,7 @@
13
13
  -->
14
14
  <div id="invite-contents">
15
15
  <%= invite_ajax_message_container %>
16
- <% if google_oauth_for(current_user) -%>
17
- <p><%=translate('muck.invites.select_emails') %></p>
18
- <%= render :partial => 'invites/gmail_oauth' %>
19
- <% end -%>
16
+ <%= render :partial => 'invites/contacts_from_services' %>
20
17
  <%#= render :partial => 'invites/contacts_query', :locals => { :id => 'yahoo', :title => 'Yahoo' } %>
21
18
  <%#= render :partial => 'invites/contacts_query', :locals => { :id => 'windows', :title => 'Windows Live' } %>
22
19
  <%#= render :partial => 'invites/contacts_query', :locals => { :id => 'aol', :title => 'AOL' } %>
@@ -0,0 +1,10 @@
1
+ <% return unless logged_in? -%>
2
+ <div id="yahoo" class="invite-query">
3
+ <% if yahoo_oauth_for(current_user) -%>
4
+ <div class="contact-list">
5
+ <%= contact_container(yahoo_contacts(current_user)) %>
6
+ </div>
7
+ <% else -%>
8
+ <p><a href="/auth/google">Connect to Yahoo</a></p>
9
+ <% end -%>
10
+ </div>
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muck-invites}
8
- s.version = "3.3.2"
8
+ s.version = "3.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Ball, Joel Duffin"]
@@ -30,12 +30,14 @@ Gem::Specification.new do |s|
30
30
  "app/views/invites/_contact_container.erb",
31
31
  "app/views/invites/_contact_list.erb",
32
32
  "app/views/invites/_contact_list_gravatar.erb",
33
+ "app/views/invites/_contacts_from_services.html.erb",
33
34
  "app/views/invites/_contacts_loading.erb",
34
35
  "app/views/invites/_contacts_query.erb",
35
36
  "app/views/invites/_gmail_oauth.erb",
36
37
  "app/views/invites/_invite_compose.erb",
37
38
  "app/views/invites/_invite_scripts.erb",
38
39
  "app/views/invites/_invite_standard.erb",
40
+ "app/views/invites/_yahoo_oauth.html.erb",
39
41
  "app/views/invites/compose.erb",
40
42
  "app/views/invites/create.erb",
41
43
  "app/views/invites/create.html.erb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-invites
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 3
9
- - 2
10
- version: 3.3.2
9
+ - 3
10
+ version: 3.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Ball, Joel Duffin
@@ -117,12 +117,14 @@ files:
117
117
  - app/views/invites/_contact_container.erb
118
118
  - app/views/invites/_contact_list.erb
119
119
  - app/views/invites/_contact_list_gravatar.erb
120
+ - app/views/invites/_contacts_from_services.html.erb
120
121
  - app/views/invites/_contacts_loading.erb
121
122
  - app/views/invites/_contacts_query.erb
122
123
  - app/views/invites/_gmail_oauth.erb
123
124
  - app/views/invites/_invite_compose.erb
124
125
  - app/views/invites/_invite_scripts.erb
125
126
  - app/views/invites/_invite_standard.erb
127
+ - app/views/invites/_yahoo_oauth.html.erb
126
128
  - app/views/invites/compose.erb
127
129
  - app/views/invites/create.erb
128
130
  - app/views/invites/create.html.erb