diaspora/app/models/services/tumblr.rb
Jonne Haß 2a4db54db9 New configuration system
* Throw away old system
* Add new system
* Add new example files
* Replace all calls
* add the most important docs
* Add Specs
* rename disable_ssl_requirement to require_ssl
* cloudfiles isn't used/called in our code
* since community_spotlight.list is only used as enable flag replace it with such one and remove all legacy and irelevant codepaths around it
* die if session secret is unset and on heroku
* First basic infrastructure for version information
2012-09-26 20:19:37 +02:00

44 lines
1,011 B
Ruby

class Services::Tumblr < Service
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
MAX_CHARACTERS = 1000
def provider
"tumblr"
end
def consumer_key
AppConfig.services.tumblr.key
end
def consumer_secret
AppConfig.services.tumblr.secret
end
def post(post, url='')
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://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
end
end
def build_tumblr_post(post, url)
{:generator => 'diaspora', :type => 'regular', :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>"
end
html += auto_link(post.text, :link => :urls)
end
end