facebook friend finder gathers fb friends.
This commit is contained in:
parent
e890d73de7
commit
8bc52cdb55
7 changed files with 102 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
20
app/views/services/finder.html.haml
Normal file
20
app/views/services/finder.html.haml
Normal file
|
|
@ -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)
|
||||
|
||||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = <<JSON
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"name": "#{@user2_fb_name}",
|
||||
"id": "#{@user2_fb_id}"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
@web_mock = mock()
|
||||
@web_mock.stub!(:body).and_return(@fb_list_hash)
|
||||
RestClient.stub!(:get).and_return(@web_mock)
|
||||
end
|
||||
|
||||
it 'requests a friend list' do
|
||||
RestClient.should_receive(:get).with("https://graph.facebook.com/me/friends", {:params => {: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
|
||||
|
|
|
|||
Loading…
Reference in a new issue