Module: MuckInvitesHelper
- Defined in:
- app/helpers/muck_invites_helper.rb
Instance Method Summary collapse
- #contact_container(contacts) ⇒ Object
- #contact_list(contacts) ⇒ Object
-
#contacts_for_auto_complete(contacts, ignore_cache = false) ⇒ Object
Generates a javascript array of emails from gmail.
- #gmail_contacts(user, ignore_cache = false) ⇒ Object
- #google_oauth_for(user) ⇒ Object
- #invite_ajax_message(message) ⇒ Object
- #invite_ajax_message_container ⇒ Object
- #parse_yahoo_contacts(json) ⇒ Object
- #service_contacts(user, ignore_cache = false) ⇒ Object
- #yahoo_contacts(user, ignore_cache = false) ⇒ Object
- #yahoo_oauth_for(user) ⇒ Object
Instance Method Details
#contact_container(contacts) ⇒ Object
22 23 24 |
# File 'app/helpers/muck_invites_helper.rb', line 22 def contact_container(contacts) render :partial => 'invites/contact_container', :locals => { :contacts => contacts } end |
#contact_list(contacts) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/muck_invites_helper.rb', line 3 def contact_list(contacts) if MuckInvites.configuration.use_gravatar_in_photo_list render :partial => 'invites/contact_list_gravatar', :locals => { :contacts => contacts } else render :partial => 'invites/contact_list', :locals => { :contacts => contacts } end end |
#contacts_for_auto_complete(contacts, ignore_cache = false) ⇒ Object
Generates a javascript array of emails from gmail. Values will be put into a variable named ‘gmail_contacts’
36 37 38 39 |
# File 'app/helpers/muck_invites_helper.rb', line 36 def contacts_for_auto_complete(contacts, ignore_cache = false) contacts = contacts.collect{|contact| "'#{contact[:email]}'" } "var auto_complete_contacts = [#{contacts.join(',')}];" end |
#gmail_contacts(user, ignore_cache = false) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/muck_invites_helper.rb', line 45 def gmail_contacts(user, ignore_cache = false) if @user_gmail_contacts && @user_gmail_contacts[user] && !ignore_cache @user_gmail_contacts[user] else contacts = [] google = google_oauth_for(user) if google @user_gmail_contacts ||= {} result = google.access_token.get('https://www.google.com/m8/feeds/contacts/default/full?max-results=10000') if result.code == '200' xml_doc = Nokogiri::XML(result.body) {|config| config. = Nokogiri::XML::ParseOptions::STRICT } contacts = xml_doc.xpath('//xmlns:entry').map do |entry| if !entry.xpath('gd:email').blank? { :name => entry.xpath('xmlns:title').inner_html, :email => entry.xpath('gd:email').attr('address').value } end end contacts.flatten! end @user_gmail_contacts[user] = contacts end contacts end end |
#google_oauth_for(user) ⇒ Object
26 27 28 |
# File 'app/helpers/muck_invites_helper.rb', line 26 def google_oauth_for(user) user.authentications.find_by_provider('google') end |
#invite_ajax_message(message) ⇒ Object
15 16 17 18 19 20 |
# File 'app/helpers/muck_invites_helper.rb', line 15 def () %Q{ jQuery('#invite-messages-container').show(); jQuery('#invite-messages').html('#{escape_javascript()}'); } end |
#invite_ajax_message_container ⇒ Object
11 12 13 |
# File 'app/helpers/muck_invites_helper.rb', line 11 def ('invite-messages', 'invite-messages-container') end |
#parse_yahoo_contacts(json) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/muck_invites_helper.rb', line 94 def parse_yahoo_contacts(json) contacts = [] return contacts if json['contacts']['contact'].nil? json['contacts']['contact'].each do |contact| name = nil email = nil contact['fields'].each do |field| field['type'] if field['type'] == 'name' name = "#{field['value']['givenName']} #{field['value']['familyName']}" end if field['type'] == 'email' email = field['value'] end end if(email) name ||= email contacts << { :name => name, :email => email} end end contacts end |
#service_contacts(user, ignore_cache = false) ⇒ Object
41 42 43 |
# File 'app/helpers/muck_invites_helper.rb', line 41 def service_contacts(user, ignore_cache = false) self.gmail_contacts(user, ignore_cache) + self.yahoo_contacts(user, ignore_cache) end |
#yahoo_contacts(user, ignore_cache = false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/muck_invites_helper.rb', line 70 def yahoo_contacts(user, ignore_cache = false) if @user_yahoo_contacts && @user_yahoo_contacts[user] && !ignore_cache @user_yahoo_contacts[user] else contacts = [] yahoo = yahoo_oauth_for(user) if yahoo @user_yahoo_contacts ||= {} begin result = yahoo.access_token.get("http://social.yahooapis.com/v1/user/#{yahoo.uid}/contacts?format=json&count=max") rescue OAuth::Problem => ex return contacts end if result.code == '200' json = ActiveSupport::JSON.decode(result.body) contacts = parse_yahoo_contacts(json) end @user_yahoo_contacts[user] = contacts end contacts end end |
#yahoo_oauth_for(user) ⇒ Object
30 31 32 |
# File 'app/helpers/muck_invites_helper.rb', line 30 def yahoo_oauth_for(user) user.authentications.find_by_provider('yahoo') end |