Skip to content
Extraits de code Groupes Projets
Valider c60adda3 rédigé par Ilya Zhitomirskiy's avatar Ilya Zhitomirskiy
Parcourir les fichiers

WIP, almost done for twitter, just need to figure out how to follow redirects

parent edd4352e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -28,6 +28,10 @@ class ServicesController < ApplicationController
current_user.update_profile(current_user.person.profile.from_omniauth_hash(user))
pp "YAY"
debugger
Resque.enqueue(Jobs::FetchProfilePhoto, current_user.id, service.id)
flash[:notice] = I18n.t 'services.create.success'
if current_user.getting_started
redirect_to getting_started_path
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
class FetchProfilePhoto < Base
@queue = :photos
def self.perform(user_id, service_id)
user = User.find(user_id)
service = Service.find(service_id)
@photo = Photo.new
@photo.author = user.person
@photo.diaspora_handle = user.person.diaspora_handle
@photo.random_string = ActiveSupport::SecureRandom.hex(10)
@photo.remote_unprocessed_image_url = service.profile_photo_url
@photo.save!
profile_params = {:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small)}
user.update_profile(profile_params)
end
end
end
......@@ -33,4 +33,8 @@ class Services::Twitter < Service
def public_message(post, url)
super(post, MAX_CHARACTERS, url)
end
def profile_photo_url
"http://api.twitter.com/1/users/profile_image?screen_name=#{nickname}&size=bigger"
end
end
......@@ -64,6 +64,17 @@ describe ServicesController do
post :create, :provider => 'twitter'
@user.reload.services.first.class.name.should == "Services::Twitter"
end
it 'queues a job to save user photo' do
request.env['omniauth.auth'] = omniauth_auth
post :create, :provider => 'twitter'
#service_stub = stub.as_null_object
Services::Twitter.any_instance.stub(:profile_photo_url).and_return("http://api.service.com/profile_photo.jpeg")
#Services::Twitter.should_receive(:new).and_return(service_stub)
Resque.should_receive(:enqueue).with(Jobs::FetchProfilePhoto, @user.id, "http://api.service.com/profile_photo.jpeg")
end
end
describe '#destroy' do
......
......@@ -27,4 +27,12 @@ describe Services::Twitter do
@service.post(@post, url)
end
end
describe "#profile_photo_url" do
it 'returns the bigger profile photo' do
@service.nickname = "joindiaspora"
@service.profile_photo_url.should ==
"http://api.twitter.com/1/users/profile_image?screen_name=joindiaspora&size=bigger"
end
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter