Skip to content
Extraits de code Groupes Projets
Valider 675bf614 rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

Merge pull request #3670 from MrZYX/feature/fix_services

update and fix services
parents 3aef807f 2a454702
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
## Bug Fixes ## Bug Fixes
* Fix posting to Facebook and Tumblr. Have a look at the updated [services guide](https://github.com/diaspora/diaspora/wiki/Howto-setup-services) for new Facebook instructions.
* Fix overflow button in mobile reset password. [#3697](https://github.com/diaspora/diaspora/pull/3697) * Fix overflow button in mobile reset password. [#3697](https://github.com/diaspora/diaspora/pull/3697)
* Fix issue with interacted_at in post fetcher. [#3607](https://github.com/diaspora/diaspora/pull/3607) * Fix issue with interacted_at in post fetcher. [#3607](https://github.com/diaspora/diaspora/pull/3607)
* Fix error with show post Community Spotlight. [#3658](https://github.com/diaspora/diaspora/pull/3658) * Fix error with show post Community Spotlight. [#3658](https://github.com/diaspora/diaspora/pull/3658)
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
* Fix javascripts error in invitations facebox. [#3638](https://github.com/diaspora/diaspora/pull/3638) * Fix javascripts error in invitations facebox. [#3638](https://github.com/diaspora/diaspora/pull/3638)
* Fix css overflow problem in aspect dropdown on welcome page. [#3637](https://github.com/diaspora/diaspora/pull/3637) * Fix css overflow problem in aspect dropdown on welcome page. [#3637](https://github.com/diaspora/diaspora/pull/3637)
* Fix empty page after authenticating with other services. [#3693](https://github.com/diaspora/diaspora/pull/3693) * Fix empty page after authenticating with other services. [#3693](https://github.com/diaspora/diaspora/pull/3693)
* Fix posting public posts to Facebook. [#2882](https://github.com/diaspora/diaspora/issues/2882), [#3650](https://github.com/diaspora/diaspora/issues/3650)
# 0.0.1.2 # 0.0.1.2
......
...@@ -21,11 +21,11 @@ gem 'devise', '2.1.2' ...@@ -21,11 +21,11 @@ gem 'devise', '2.1.2'
gem 'remotipart', '1.0.2' gem 'remotipart', '1.0.2'
gem 'omniauth', '1.1.1' gem 'omniauth', '1.1.1'
gem 'omniauth-facebook', '1.3.0' gem 'omniauth-facebook', '1.4.1'
gem 'omniauth-tumblr', '1.1' gem 'omniauth-tumblr', '1.1'
gem 'omniauth-twitter', '0.0.11' gem 'omniauth-twitter', '0.0.13'
gem 'twitter', '2.0.2' gem 'twitter', '4.1.1'
# mail # mail
......
...@@ -184,7 +184,7 @@ GEM ...@@ -184,7 +184,7 @@ GEM
highline (1.6.12) highline (1.6.12)
hike (1.2.1) hike (1.2.1)
http_accept_language (1.0.2) http_accept_language (1.0.2)
httpauth (0.1) httpauth (0.2.0)
i18n (0.6.1) i18n (0.6.1)
i18n-inflector (2.6.6) i18n-inflector (2.6.6)
i18n (>= 0.4.1) i18n (>= 0.4.1)
...@@ -207,6 +207,8 @@ GEM ...@@ -207,6 +207,8 @@ GEM
railties (>= 3.1.0) railties (>= 3.1.0)
jruby-pageant (1.1.1) jruby-pageant (1.1.1)
json (1.7.5) json (1.7.5)
jwt (0.1.5)
multi_json (>= 1.0)
kaminari (0.14.1) kaminari (0.14.1)
actionpack (>= 3.0.0) actionpack (>= 3.0.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
...@@ -240,25 +242,27 @@ GEM ...@@ -240,25 +242,27 @@ GEM
net-ssh-gateway (1.1.0) net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1) net-ssh (>= 1.99.1)
nokogiri (1.5.5) nokogiri (1.5.5)
oauth (0.4.6) oauth (0.4.7)
oauth2 (0.6.1) oauth2 (0.8.0)
faraday (~> 0.7) faraday (~> 0.8)
httpauth (~> 0.1) httpauth (~> 0.1)
multi_json (~> 1.3) jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.1) omniauth (1.1.1)
hashie (~> 1.2) hashie (~> 1.2)
rack rack
omniauth-facebook (1.3.0) omniauth-facebook (1.4.1)
omniauth-oauth2 (~> 1.0.2) omniauth-oauth2 (~> 1.1.0)
omniauth-oauth (1.0.1) omniauth-oauth (1.0.1)
oauth oauth
omniauth (~> 1.0) omniauth (~> 1.0)
omniauth-oauth2 (1.0.2) omniauth-oauth2 (1.1.1)
oauth2 (~> 0.6.0) oauth2 (~> 0.8.0)
omniauth (~> 1.0) omniauth (~> 1.0)
omniauth-tumblr (1.1) omniauth-tumblr (1.1)
omniauth-oauth (~> 1.0) omniauth-oauth (~> 1.0)
omniauth-twitter (0.0.11) omniauth-twitter (0.0.13)
multi_json (~> 1.3) multi_json (~> 1.3)
omniauth-oauth (~> 1.0) omniauth-oauth (~> 1.0)
orm_adapter (0.4.0) orm_adapter (0.4.0)
...@@ -361,7 +365,7 @@ GEM ...@@ -361,7 +365,7 @@ GEM
libwebsocket (~> 0.1.3) libwebsocket (~> 0.1.3)
multi_json (~> 1.0) multi_json (~> 1.0)
rubyzip rubyzip
simple_oauth (0.1.8) simple_oauth (0.1.9)
sinatra (1.3.3) sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6) rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2) rack-protection (~> 1.2)
...@@ -378,11 +382,10 @@ GEM ...@@ -378,11 +382,10 @@ GEM
treetop (1.4.10) treetop (1.4.10)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
twitter (2.0.2) twitter (4.1.1)
activesupport (>= 2.3.9, < 4) faraday (~> 0.8)
faraday (~> 0.7) multi_json (~> 1.3)
multi_json (~> 1.0) simple_oauth (~> 0.1.6)
simple_oauth (~> 0.1)
typhoeus (0.3.3) typhoeus (0.3.3)
mime-types mime-types
tzinfo (0.3.33) tzinfo (0.3.33)
...@@ -452,9 +455,9 @@ DEPENDENCIES ...@@ -452,9 +455,9 @@ DEPENDENCIES
mysql2 (= 0.3.11) mysql2 (= 0.3.11)
nokogiri (= 1.5.5) nokogiri (= 1.5.5)
omniauth (= 1.1.1) omniauth (= 1.1.1)
omniauth-facebook (= 1.3.0) omniauth-facebook (= 1.4.1)
omniauth-tumblr (= 1.1) omniauth-tumblr (= 1.1)
omniauth-twitter (= 0.0.11) omniauth-twitter (= 0.0.13)
rack-cors (= 0.2.7) rack-cors (= 0.2.7)
rack-google-analytics (= 0.11.0) rack-google-analytics (= 0.11.0)
rack-piwik (= 0.1.3) rack-piwik (= 0.1.3)
...@@ -476,7 +479,7 @@ DEPENDENCIES ...@@ -476,7 +479,7 @@ DEPENDENCIES
selenium-webdriver (= 2.25.0) selenium-webdriver (= 2.25.0)
spork (= 1.0.0rc3) spork (= 1.0.0rc3)
timecop (= 0.5.1) timecop (= 0.5.1)
twitter (= 2.0.2) twitter (= 4.1.1)
typhoeus (= 0.3.3) typhoeus (= 0.3.3)
uglifier (= 1.3.0) uglifier (= 1.3.0)
unicorn (= 4.3.1) unicorn (= 4.3.1)
......
...@@ -11,21 +11,13 @@ class Services::Facebook < Service ...@@ -11,21 +11,13 @@ class Services::Facebook < Service
def post(post, url='') def post(post, url='')
Rails.logger.debug("event=post_to_service type=facebook sender_id=#{self.user_id}") Rails.logger.debug("event=post_to_service type=facebook sender_id=#{self.user_id}")
if post.public? post_to_facebook("https://graph.facebook.com/me/feed", create_post_params(post).to_param)
post_to_facebook("https://graph.facebook.com/me/joindiaspora:make", create_open_graph_params(post).to_param)
else
post_to_facebook("https://graph.facebook.com/me/feed", create_post_params(post).to_param)
end
end end
def post_to_facebook(url, body) def post_to_facebook(url, body)
Faraday.post(url, body) Faraday.post(url, body)
end end
def create_open_graph_params(post)
{:post => "#{AppConfig.pod_uri.to_s}#{short_post_path(post)}", :access_token => self.access_token}
end
def create_post_params(post) def create_post_params(post)
message = post.text(:plain_text => true) message = post.text(:plain_text => true)
{:message => message, :access_token => self.access_token, :link => URI.extract(message, ['https', 'http']).first} {:message => message, :access_token => self.access_token, :link => URI.extract(message, ['https', 'http']).first}
......
...@@ -17,28 +17,28 @@ class Services::Tumblr < Service ...@@ -17,28 +17,28 @@ class Services::Tumblr < Service
end end
def post(post, url='') def post(post, url='')
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://api.tumblr.com')
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://tumblr.com')
access = OAuth::AccessToken.new(consumer, self.access_token, self.access_secret) access = OAuth::AccessToken.new(consumer, self.access_token, self.access_secret)
body = build_tumblr_post(post, url) body = build_tumblr_post(post, url)
begin user_info = JSON.parse(access.get("/v2/user/info").body)
resp = access.post('http://tumblr.com/api/write', body) blogs = user_info["response"]["user"]["blogs"].map { |blog| URI.parse(blog['url']) }
resp blogs.each do |blog|
rescue => e access.post("/v2/blog/#{blog.host}/post", body)
nil
end end
end end
def build_tumblr_post(post, url) def build_tumblr_post(post, url)
{:generator => 'diaspora', :type => 'regular', :body => tumblr_template(post, url)} { :type => 'text', :format => "markdown", :body => tumblr_template(post, url) }
end end
def tumblr_template(post, url) def tumblr_template(post, url)
html = '' html = ''
post.photos.each do |photo| post.photos.each do |photo|
html += "<img src='#{photo.url(:scaled_full)}'/><br>" html += "![photo](#{photo.url(:scaled_full)})\n\n"
end end
html += auto_link(post.text, :link => :urls) html += post.text
html += "\n\n[original post](#{url})"
end end
end end
...@@ -12,9 +12,7 @@ class Services::Twitter < Service ...@@ -12,9 +12,7 @@ class Services::Twitter < Service
Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}") Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
message = public_message(post, url) message = public_message(post, url)
configure_twitter client.update(message)
Twitter.update(message)
end end
...@@ -28,25 +26,14 @@ class Services::Twitter < Service ...@@ -28,25 +26,14 @@ class Services::Twitter < Service
end end
def profile_photo_url def profile_photo_url
configure_twitter client.user(nickname).profile_image_url_https("original")
Twitter.profile_image(nickname, :size => "original")
end end
private private
def configure_twitter def client
twitter_key = AppConfig.services.twitter.key @client ||= Twitter::Client.new(
twitter_consumer_secret = AppConfig.services.twitter.secret oauth_token: self.access_token,
oauth_token_secret: self.access_secret
if twitter_key.blank? || twitter_consumer_secret.blank? )
Rails.logger.info "you have a blank twitter key or secret.... you should look into that"
end
Twitter.configure do |config|
config.consumer_key = twitter_key
config.consumer_secret = twitter_consumer_secret
config.oauth_token = self.access_token
config.oauth_token_secret = self.access_secret
end
end end
end end
...@@ -56,7 +56,6 @@ defaults: ...@@ -56,7 +56,6 @@ defaults:
enable: false enable: false
app_id: app_id:
secret: secret:
open_graph_namespace: 'joindiaspora'
twitter: twitter:
enable: false enable: false
key: key:
......
...@@ -252,9 +252,6 @@ configuration: ## Section ...@@ -252,9 +252,6 @@ configuration: ## Section
#enable: true #enable: true
#app_id: 'abcdef' #app_id: 'abcdef'
#secret: 'changeme' #secret: 'changeme'
## this will be the namespace for your object,
## it should be configured in your FB app
#open_graph_namespace:
## OAuth credentials for Twitter: ## OAuth credentials for Twitter:
twitter: ## Section twitter: ## Section
......
...@@ -5,10 +5,16 @@ ...@@ -5,10 +5,16 @@
Rails.application.config.middleware.use OmniAuth::Builder do Rails.application.config.middleware.use OmniAuth::Builder do
if AppConfig.services.twitter.enable? if AppConfig.services.twitter.enable?
provider :twitter, AppConfig.services.twitter.key, AppConfig.services.twitter.secret provider :twitter, AppConfig.services.twitter.key, AppConfig.services.twitter.secret
Twitter.configure do |config|
config.consumer_key = AppConfig.services.twitter.key
config.consumer_secret = AppConfig.services.twitter.secret
end
end end
if AppConfig.services.tumblr.enable? if AppConfig.services.tumblr.enable?
provider :tumblr, AppConfig.services.tumblr.key, AppConfig.services.tumblr.secret provider :tumblr, AppConfig.services.tumblr.key, AppConfig.services.tumblr.secret
end end
if AppConfig.services.facebook.enable? if AppConfig.services.facebook.enable?
provider :facebook, AppConfig.services.facebook.app_id, AppConfig.services.facebook.secret, provider :facebook, AppConfig.services.facebook.app_id, AppConfig.services.facebook.secret,
{ :display => "popup", :scope => "publish_actions,publish_stream,offline_access", { :display => "popup", :scope => "publish_actions,publish_stream,offline_access",
......
...@@ -11,7 +11,7 @@ describe Services::Facebook do ...@@ -11,7 +11,7 @@ describe Services::Facebook do
describe '#post' do describe '#post' do
it 'posts a status message to facebook' do it 'posts a status message to facebook' do
stub_request(:post, "https://graph.facebook.com/me/joindiaspora:make"). stub_request(:post, "https://graph.facebook.com/me/feed").
to_return(:status => 200, :body => "", :headers => {}) to_return(:status => 200, :body => "", :headers => {})
@service.post(@post) @service.post(@post)
end end
...@@ -19,13 +19,13 @@ describe Services::Facebook do ...@@ -19,13 +19,13 @@ describe Services::Facebook do
it 'swallows exception raised by facebook always being down' do it 'swallows exception raised by facebook always being down' do
pending "temporarily disabled to figure out while some requests are failing" pending "temporarily disabled to figure out while some requests are failing"
stub_request(:post,"https://graph.facebook.com/me/joindiaspora:make"). stub_request(:post,"https://graph.facebook.com/me/feed").
to_raise(StandardError) to_raise(StandardError)
@service.post(@post) @service.post(@post)
end end
it 'should call public message' do it 'should call public message' do
stub_request(:post, "https://graph.facebook.com/me/joindiaspora:make"). stub_request(:post, "https://graph.facebook.com/me/feed").
to_return(:status => 200) to_return(:status => 200)
url = "foo" url = "foo"
@service.should_not_receive(:public_message) @service.should_not_receive(:public_message)
......
...@@ -11,14 +11,12 @@ describe Services::Tumblr do ...@@ -11,14 +11,12 @@ describe Services::Tumblr do
describe '#post' do describe '#post' do
it 'posts a status message to tumblr' do it 'posts a status message to tumblr' do
response = mock
response.stub(:body).and_return('{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}')
OAuth::AccessToken.any_instance.should_receive(:get).with("/v2/user/info").and_return(response)
OAuth::AccessToken.any_instance.should_receive(:post) OAuth::AccessToken.any_instance.should_receive(:post)
@service.post(@post) @service.post(@post)
end end
it 'swallows exception raised by tumblr not being webscale' do
OAuth::AccessToken.any_instance.should_receive(:post).and_raise(StandardError)
@service.post(@post)
end
end end
end end
...@@ -11,18 +11,18 @@ describe Services::Twitter do ...@@ -11,18 +11,18 @@ describe Services::Twitter do
describe '#post' do describe '#post' do
it 'posts a status message to twitter' do it 'posts a status message to twitter' do
Twitter.should_receive(:update).with(instance_of(String)) Twitter::Client.any_instance.should_receive(:update).with(instance_of(String))
@service.post(@post) @service.post(@post)
end end
it 'swallows exception raised by twitter always being down' do it 'swallows exception raised by twitter always being down' do
pending pending
Twitter.should_receive(:update).and_raise(StandardError) Twitter::Client.any_instance.should_receive(:update).and_raise(StandardError)
@service.post(@post) @service.post(@post)
end end
it 'should call public message' do it 'should call public message' do
Twitter.stub!(:update) Twitter::Client.any_instance.stub(:update)
url = "foo" url = "foo"
@service.should_receive(:public_message).with(@post, url) @service.should_receive(:public_message).with(@post, url)
@service.post(@post, url) @service.post(@post, url)
...@@ -74,12 +74,12 @@ describe Services::Twitter do ...@@ -74,12 +74,12 @@ describe Services::Twitter do
end end
describe "#profile_photo_url" do describe "#profile_photo_url" do
it 'returns the original profile photo url' do it 'returns the original profile photo url' do
stub_request(:get, "https://api.twitter.com/1/users/profile_image/joindiaspora?size=original"). user_stub = stub
to_return(:status => 302, :body => "", :headers => {:location => "http://a2.twimg.com/profile_images/uid/avatar.png"}) user_stub.should_receive(:profile_image_url_https).with("original").and_return("http://a2.twimg.com/profile_images/uid/avatar.png")
Twitter::Client.any_instance.should_receive(:user).with("joindiaspora").and_return(user_stub)
@service.nickname = "joindiaspora" @service.nickname = "joindiaspora"
@service.profile_photo_url.should == @service.profile_photo_url.should == "http://a2.twimg.com/profile_images/uid/avatar.png"
"http://a2.twimg.com/profile_images/uid/avatar.png"
end end
end 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