diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index c2abfaf1e..f113ea5f4 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -34,7 +34,6 @@ class ServicesController < ApplicationController end end - def failure Rails.logger.info "error in oauth #{params.inspect}" flash[:error] = t('services.failure.error') @@ -47,4 +46,9 @@ class ServicesController < ApplicationController flash[:notice] = I18n.t 'services.destroy.success' redirect_to services_url end + + def finder + service = current_user.services.where(:provider => params[:provider]).first + @friends = service ? service.finder : {} + end end diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 69abb4caa..e644c4638 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -14,4 +14,14 @@ class Services::Facebook < Service def public_message(post, url) super(post, MAX_CHARACTERS, url) end + + def finder + Rails.logger.debug("event=friend_finder type=facebook sender_id=#{self.user_id}") + response = RestClient.get("https://graph.facebook.com/me/friends", {:params => {:access_token => self.access_token}}) + data = JSON.parse(response.body)['data'] + + Hash[*data.collect {|v| + [v['id'], {:name => v['name']}] + }.flatten] + end end diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index f6a4cff35..c3bed4da1 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -44,3 +44,9 @@ %h4= t('shared.invitations.invites') = render "shared/invitations", :invites => @invites + .section + %h4 + Find your friends + + = link_to "From Facebook", friend_finder_path('facebook') + diff --git a/app/views/services/finder.html.haml b/app/views/services/finder.html.haml new file mode 100644 index 000000000..f4d2ae36f --- /dev/null +++ b/app/views/services/finder.html.haml @@ -0,0 +1,20 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +- content_for :head do + = include_javascripts :aspects + +%h3 + facebook friend finder + +.contact_list + = search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('shared.contact_list.all_contacts') + %ul + - for friend in @friends + %li + %h4.name + = link_to friend['name'], '#' + /.right + /= aspect_membership_button(aspect, contact, contact.person) + diff --git a/config/routes.rb b/config/routes.rb index 36fc5d057..9eb03388b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ Diaspora::Application.routes.draw do resources :status_messages, :only => [:create, :destroy, :show] resources :comments, :only => [:create] resources :requests, :only => [:destroy, :create] + + match 'services/finder/:provider' => 'services#finder', :as => 'friend_finder' resources :services match 'statistics/generate_single' => 'statistics#generate_single' diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 6c4b70eb0..ca8d75660 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -79,4 +79,17 @@ describe ServicesController do }.should change(@user.services, :count).by(-1) end end + + describe '#finder' do + before do + @service1 = Factory.create(:service, :provider => 'facebook') + @user.services << @service1 + end + + it 'calls the finder method for the service for that user' do + @user.services.stub!(:where).and_return([@service1]) + @service1.should_receive(:finder).and_return({}) + get :finder, :provider => @service1.provider + end + end end diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index 926a7b32b..8b895195f 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -26,4 +26,50 @@ describe Services::Facebook do @service.post(@post, url) end end + + describe '#finder' do + before do + @user2 = Factory(:user) + @user2_fb_id = '820651' + @user2_fb_name = 'Maxwell Salzberg' + @user2.services << Factory.build(:service, :provider => 'facebook' , :uid => @user2_fb_id) + @fb_list_hash = < {:access_token => @service.access_token}}).and_return(@web_mock) + @service.finder + end + + context 'returns a hash' do + it 'returns a hash' do + @service.finder.class.should == Hash + end + it 'contains a name' do + @service.finder.values.include?({:name => @user2_fb_name}).should be_true + end + it 'contains a photo url' do + pending + end + it 'contains a FB id' do + @service.finder.include?(@user2_fb_id).should be_true + end + it 'contains a diaspora person object' do + pending + end + end + + end end