WIP, almost done for twitter, just need to figure out how to follow redirects
This commit is contained in:
parent
edd4352e49
commit
c60adda3a9
5 changed files with 53 additions and 0 deletions
|
|
@ -28,6 +28,10 @@ class ServicesController < ApplicationController
|
||||||
|
|
||||||
current_user.update_profile(current_user.person.profile.from_omniauth_hash(user))
|
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'
|
flash[:notice] = I18n.t 'services.create.success'
|
||||||
if current_user.getting_started
|
if current_user.getting_started
|
||||||
redirect_to getting_started_path
|
redirect_to getting_started_path
|
||||||
|
|
|
||||||
26
app/models/jobs/fetch_profile_photo.rb
Normal file
26
app/models/jobs/fetch_profile_photo.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# 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)
|
def public_message(post, url)
|
||||||
super(post, MAX_CHARACTERS, url)
|
super(post, MAX_CHARACTERS, url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def profile_photo_url
|
||||||
|
"http://api.twitter.com/1/users/profile_image?screen_name=#{nickname}&size=bigger"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,17 @@ describe ServicesController do
|
||||||
post :create, :provider => 'twitter'
|
post :create, :provider => 'twitter'
|
||||||
@user.reload.services.first.class.name.should == "Services::Twitter"
|
@user.reload.services.first.class.name.should == "Services::Twitter"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,12 @@ describe Services::Twitter do
|
||||||
@service.post(@post, url)
|
@service.post(@post, url)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue