make the tumblr posting smarter
This commit is contained in:
parent
6e3fcdd893
commit
149c086d5e
3 changed files with 21 additions and 5 deletions
|
|
@ -1,4 +1,7 @@
|
|||
class Services::Tumblr < Service
|
||||
include ActionView::Helpers::TextHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
MAX_CHARACTERS = 1000
|
||||
|
||||
def provider
|
||||
|
|
@ -14,18 +17,28 @@ class Services::Tumblr < Service
|
|||
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', {:type => 'regular', :title => self.public_message(post, url), :generator => 'diaspora'})
|
||||
resp = access.post('http://tumblr.com/api/write', body)
|
||||
resp
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def public_message(post, url)
|
||||
super(post, MAX_CHARACTERS, url)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
5
app/views/services/tumblr.html.haml
Normal file
5
app/views/services/tumblr.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
- post.photos.each do |photo|
|
||||
= image_tag(photo.url(:scaled_full))
|
||||
%br
|
||||
%br
|
||||
= auto_link(post.text)
|
||||
|
|
@ -88,5 +88,3 @@ Feature: commenting
|
|||
And I wait for the ajax to finish
|
||||
When I am on "alice@alice.alice"'s page
|
||||
Then I should see "I think thats a cat"
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue