added sharing to Tumblr
This commit is contained in:
parent
f8a20099fa
commit
65e514c55d
6
Gemfile
6
Gemfile
|
@ -37,7 +37,6 @@ gem 'ruby-progressbar'
|
|||
|
||||
gem 'rails_admin'
|
||||
|
||||
gem 'twitter'
|
||||
gem 'sidekiq'
|
||||
gem 'sinatra', require: false
|
||||
|
||||
|
@ -49,6 +48,11 @@ gem 'redcarpet'
|
|||
# OmniAuth and providers
|
||||
gem 'omniauth'
|
||||
gem 'omniauth-twitter'
|
||||
gem 'omniauth-tumblr'
|
||||
|
||||
# OAuth clients
|
||||
gem 'twitter'
|
||||
gem 'tumblr_client'
|
||||
|
||||
gem 'foreman'
|
||||
gem 'redis'
|
||||
|
|
13
Gemfile.lock
13
Gemfile.lock
|
@ -111,6 +111,8 @@ GEM
|
|||
i18n (~> 0.5)
|
||||
faraday (0.9.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
faraday_middleware (0.9.1)
|
||||
faraday (>= 0.7.4, < 0.10)
|
||||
font-awesome-rails (4.2.0.0)
|
||||
railties (>= 3.2, < 5.0)
|
||||
font-kit-rails (1.1.0)
|
||||
|
@ -170,6 +172,8 @@ GEM
|
|||
omniauth-oauth (1.0.1)
|
||||
oauth
|
||||
omniauth (~> 1.0)
|
||||
omniauth-tumblr (1.1)
|
||||
omniauth-oauth (~> 1.0)
|
||||
omniauth-twitter (1.1.0)
|
||||
multi_json (~> 1.3)
|
||||
omniauth-oauth (~> 1.0)
|
||||
|
@ -308,6 +312,13 @@ GEM
|
|||
tilt (1.4.1)
|
||||
timers (4.0.1)
|
||||
hitimes
|
||||
tumblr_client (0.8.5)
|
||||
faraday (~> 0.9.0)
|
||||
faraday_middleware (~> 0.9.0)
|
||||
json
|
||||
mime-types
|
||||
oauth
|
||||
simple_oauth
|
||||
turbolinks (2.5.3)
|
||||
coffee-rails
|
||||
twitter (5.13.0)
|
||||
|
@ -368,6 +379,7 @@ DEPENDENCIES
|
|||
jquery-turbolinks
|
||||
mysql2
|
||||
omniauth
|
||||
omniauth-tumblr
|
||||
omniauth-twitter
|
||||
paperclip (~> 4.2)
|
||||
pg
|
||||
|
@ -389,6 +401,7 @@ DEPENDENCIES
|
|||
spring
|
||||
sweetalert-rails
|
||||
thin
|
||||
tumblr_client
|
||||
turbolinks
|
||||
twitter
|
||||
uglifier (>= 1.3.0)
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
class Services::Tumblr < Service
|
||||
include Rails.application.routes.url_helpers
|
||||
include MarkdownHelper
|
||||
|
||||
def provider
|
||||
"tumblr"
|
||||
end
|
||||
|
||||
def post(answer)
|
||||
Rails.logger.debug "posting to Tumblr {'answer' => #{answer.id}, 'user' => #{self.user_id}}"
|
||||
create_post answer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def client
|
||||
@client ||= Tumblr::Client.new(
|
||||
consumer_key: APP_CONFIG['sharing']['tumblr']['consumer_key'],
|
||||
consumer_secret: APP_CONFIG['sharing']['tumblr']['consumer_secret'],
|
||||
oauth_token: self.access_token,
|
||||
oauth_token_secret: self.access_secret
|
||||
)
|
||||
end
|
||||
|
||||
def create_post(answer)
|
||||
answer_url = show_user_answer_url(
|
||||
id: answer.id,
|
||||
username: answer.user.screen_name,
|
||||
host: APP_CONFIG['hostname'],
|
||||
protocol: (APP_CONFIG['https'] ? :https : :http)
|
||||
)
|
||||
asker = if answer.question.author_is_anonymous?
|
||||
APP_CONFIG['anonymous_name']
|
||||
else
|
||||
answer.question.user.display_name.blank? ? answer.question.user.screen_name : answer.question.user.display_name
|
||||
end
|
||||
client.text(
|
||||
self.uid,
|
||||
title: "#{asker} asked: #{answer.question.content}",
|
||||
body: "#{answer.content}\n\n[Smile or comment on the answer here](#{answer_url})",
|
||||
format: 'markdown',
|
||||
tweet: 'off'
|
||||
)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,7 @@
|
|||
Rails.application.config.middleware.use OmniAuth::Builder do
|
||||
if APP_CONFIG['sharing']['twitter']['enabled']
|
||||
provider :twitter, APP_CONFIG['sharing']['twitter']['consumer_key'], APP_CONFIG['sharing']['twitter']['consumer_secret']
|
||||
%w(facebook twitter tumblr).each do |service|
|
||||
if APP_CONFIG['sharing'][service]['enabled']
|
||||
provider service.to_sym, APP_CONFIG['sharing'][service]['consumer_key'], APP_CONFIG['sharing'][service]['consumer_secret']
|
||||
end
|
||||
end
|
||||
end
|
|
@ -41,6 +41,7 @@ RailsAdmin.config do |config|
|
|||
Report
|
||||
Service
|
||||
Services::Twitter
|
||||
Services::Tumblr
|
||||
Smile
|
||||
User
|
||||
]
|
||||
|
|
|
@ -21,6 +21,11 @@ sharing:
|
|||
consumer_secret: ''
|
||||
facebook:
|
||||
enabled: false
|
||||
tumblr:
|
||||
enabled: true
|
||||
# Get the tokens from https://www.tumblr.com/oauth/apps
|
||||
consumer_key: ''
|
||||
consumer_secret: ''
|
||||
|
||||
# Redis
|
||||
redis_url: "redis://localhost:6379"
|
Loading…
Reference in New Issue