Commit 675bf614 authored by Jonne Haß's avatar Jonne Haß

Merge pull request #3670 from MrZYX/feature/fix_services

update and fix services
parents 3aef807f 2a454702
......@@ -23,6 +23,7 @@
## 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 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)
......@@ -31,6 +32,7 @@
* 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 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
......
......@@ -21,11 +21,11 @@ gem 'devise', '2.1.2'
gem 'remotipart', '1.0.2'
gem 'omniauth', '1.1.1'
gem 'omniauth-facebook', '1.3.0'
gem 'omniauth-facebook', '1.4.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
......
......@@ -184,7 +184,7 @@ GEM
highline (1.6.12)
hike (1.2.1)
http_accept_language (1.0.2)
httpauth (0.1)
httpauth (0.2.0)
i18n (0.6.1)
i18n-inflector (2.6.6)
i18n (>= 0.4.1)
......@@ -207,6 +207,8 @@ GEM
railties (>= 3.1.0)
jruby-pageant (1.1.1)
json (1.7.5)
jwt (0.1.5)
multi_json (>= 1.0)
kaminari (0.14.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
......@@ -240,25 +242,27 @@ GEM
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
nokogiri (1.5.5)
oauth (0.4.6)
oauth2 (0.6.1)
faraday (~> 0.7)
oauth (0.4.7)
oauth2 (0.8.0)
faraday (~> 0.8)
httpauth (~> 0.1)
multi_json (~> 1.3)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.1)
hashie (~> 1.2)
rack
omniauth-facebook (1.3.0)
omniauth-oauth2 (~> 1.0.2)
omniauth-facebook (1.4.1)
omniauth-oauth2 (~> 1.1.0)
omniauth-oauth (1.0.1)
oauth
omniauth (~> 1.0)
omniauth-oauth2 (1.0.2)
oauth2 (~> 0.6.0)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
omniauth-tumblr (1.1)
omniauth-oauth (~> 1.0)
omniauth-twitter (0.0.11)
omniauth-twitter (0.0.13)
multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
orm_adapter (0.4.0)
......@@ -361,7 +365,7 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
simple_oauth (0.1.8)
simple_oauth (0.1.9)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
......@@ -378,11 +382,10 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
twitter (2.0.2)
activesupport (>= 2.3.9, < 4)
faraday (~> 0.7)
multi_json (~> 1.0)
simple_oauth (~> 0.1)
twitter (4.1.1)
faraday (~> 0.8)
multi_json (~> 1.3)
simple_oauth (~> 0.1.6)
typhoeus (0.3.3)
mime-types
tzinfo (0.3.33)
......@@ -452,9 +455,9 @@ DEPENDENCIES
mysql2 (= 0.3.11)
nokogiri (= 1.5.5)
omniauth (= 1.1.1)
omniauth-facebook (= 1.3.0)
omniauth-facebook (= 1.4.1)
omniauth-tumblr (= 1.1)
omniauth-twitter (= 0.0.11)
omniauth-twitter (= 0.0.13)
rack-cors (= 0.2.7)
rack-google-analytics (= 0.11.0)
rack-piwik (= 0.1.3)
......@@ -476,7 +479,7 @@ DEPENDENCIES
selenium-webdriver (= 2.25.0)
spork (= 1.0.0rc3)
timecop (= 0.5.1)
twitter (= 2.0.2)
twitter (= 4.1.1)
typhoeus (= 0.3.3)
uglifier (= 1.3.0)
unicorn (= 4.3.1)
......
......@@ -11,21 +11,13 @@ class Services::Facebook < Service
def post(post, url='')
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/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
post_to_facebook("https://graph.facebook.com/me/feed", create_post_params(post).to_param)
end
def post_to_facebook(url, body)
Faraday.post(url, body)
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)
message = post.text(:plain_text => true)
{:message => message, :access_token => self.access_token, :link => URI.extract(message, ['https', 'http']).first}
......
......@@ -17,28 +17,28 @@ class Services::Tumblr < Service
end
def post(post, url='')
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://tumblr.com')
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://api.tumblr.com')
access = OAuth::AccessToken.new(consumer, self.access_token, self.access_secret)
body = build_tumblr_post(post, url)
begin
resp = access.post('http://tumblr.com/api/write', body)
resp
rescue => e
nil
user_info = JSON.parse(access.get("/v2/user/info").body)
blogs = user_info["response"]["user"]["blogs"].map { |blog| URI.parse(blog['url']) }
blogs.each do |blog|
access.post("/v2/blog/#{blog.host}/post", body)
end
end
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
def tumblr_template(post, url)
html = ''
post.photos.each do |photo|
html += "<img src='#{photo.url(:scaled_full)}'/><br>"
html += "![photo](#{photo.url(:scaled_full)})\n\n"
end
html += auto_link(post.text, :link => :urls)
html += post.text
html += "\n\n[original post](#{url})"
end
end
......@@ -12,9 +12,7 @@ class Services::Twitter < Service
Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
message = public_message(post, url)
configure_twitter
Twitter.update(message)
client.update(message)
end
......@@ -28,25 +26,14 @@ class Services::Twitter < Service
end
def profile_photo_url
configure_twitter
Twitter.profile_image(nickname, :size => "original")
client.user(nickname).profile_image_url_https("original")
end
private
def configure_twitter
twitter_key = AppConfig.services.twitter.key
twitter_consumer_secret = AppConfig.services.twitter.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
def client
@client ||= Twitter::Client.new(
oauth_token: self.access_token,
oauth_token_secret: self.access_secret
)
end
end
......@@ -56,7 +56,6 @@ defaults:
enable: false
app_id:
secret:
open_graph_namespace: 'joindiaspora'
twitter:
enable: false
key:
......
......@@ -252,9 +252,6 @@ configuration: ## Section
#enable: true
#app_id: 'abcdef'
#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:
twitter: ## Section
......
......@@ -5,10 +5,16 @@
Rails.application.config.middleware.use OmniAuth::Builder do
if AppConfig.services.twitter.enable?
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
if AppConfig.services.tumblr.enable?
provider :tumblr, AppConfig.services.tumblr.key, AppConfig.services.tumblr.secret
end
if AppConfig.services.facebook.enable?
provider :facebook, AppConfig.services.facebook.app_id, AppConfig.services.facebook.secret,
{ :display => "popup", :scope => "publish_actions,publish_stream,offline_access",
......
......@@ -11,7 +11,7 @@ describe Services::Facebook do
describe '#post' 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 => {})
@service.post(@post)
end
......@@ -19,13 +19,13 @@ describe Services::Facebook do
it 'swallows exception raised by facebook always being down' do
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)
@service.post(@post)
end
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)
url = "foo"
@service.should_not_receive(:public_message)
......
......@@ -11,14 +11,12 @@ describe Services::Tumblr do
describe '#post' 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)
@service.post(@post)
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
......@@ -11,18 +11,18 @@ describe Services::Twitter do
describe '#post' 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)
end
it 'swallows exception raised by twitter always being down' do
pending
Twitter.should_receive(:update).and_raise(StandardError)
Twitter::Client.any_instance.should_receive(:update).and_raise(StandardError)
@service.post(@post)
end
it 'should call public message' do
Twitter.stub!(:update)
Twitter::Client.any_instance.stub(:update)
url = "foo"
@service.should_receive(:public_message).with(@post, url)
@service.post(@post, url)
......@@ -74,12 +74,12 @@ describe Services::Twitter do
end
describe "#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").
to_return(:status => 302, :body => "", :headers => {:location => "http://a2.twimg.com/profile_images/uid/avatar.png"})
user_stub = stub
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.profile_photo_url.should ==
"http://a2.twimg.com/profile_images/uid/avatar.png"
@service.profile_photo_url.should == "http://a2.twimg.com/profile_images/uid/avatar.png"
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment