Permalink
Browse files

Added reblog support

  • Loading branch information...
1 parent 9343872 commit 3be2ba5f77ee67d36c6ec8519f5452093e44b091 @pengwynn committed Apr 9, 2010
Showing with 57 additions and 0 deletions.
  1. +5 −0 lib/tumblr/post.rb
  2. +7 −0 lib/tumblr/writer.rb
  3. +31 −0 test/fixtures/vcr_cassettes/write/reblog.yml
  4. +14 −0 test/test_tumblr.rb
View
@@ -7,6 +7,7 @@ class Post
POST_PARAMS = [:title,:body,:source,:caption,:'click-through-url',
:quote,:name,:url,:description,:conversation,
:embed,:'externally-hosted-url']
+ REBLOG_PARAMS = [:comment, :as]
def self.parameters(*attributes)
if !attributes.blank?
@@ -88,6 +89,10 @@ def edit(email, password)
Writer.new(email,password).edit(to_h)
end
+ def reblog(email, password)
+ Writer.new(email,password).reblog(to_h)
+ end
+
def delete(email, password)
Writer.new(email,password).delete(to_h)
end
View
@@ -22,6 +22,13 @@ def initialize(*credentials)
edit.with = (Post::BASIC_PARAMS | Post::POST_PARAMS)
end
+ # http://www.tumblr.com/docs/en/api#reblogging_posts
+ post :reblog do |reblog|
+ reblog.url = 'http://www.tumblr.com/api/reblog'
+ reblog.requires = [:email, :password, :'post-id', :'reblog-key']
+ reblog.with = (Post::BASIC_PARAMS | Post::POST_PARAMS | Post::REBLOG_PARAMS)
+ end
+
# http://www.tumblr.com/docs/en/api#deleting_posts
post :delete do |del|
del.url = 'http://www.tumblr.com/api/delete'
@@ -0,0 +1,31 @@
+---
+- !ruby/struct:VCR::RecordedResponse
+ method: :post
+ uri: http://www.tumblr.com:80/api/reblog
+ response: !ruby/object:Net::HTTPCreated
+ body: "508128650"
+ body_exist: true
+ code: "201"
+ header:
+ p3p:
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
+ content-type:
+ - text/plain; charset=utf-8
+ connection:
+ - close
+ x-tumblr-usec:
+ - D=380408
+ server:
+ - Apache/2.2.3 (Red Hat)
+ date:
+ - Fri, 09 Apr 2010 12:36:41 GMT
+ content-length:
+ - "9"
+ x-tumblr-perf:
+ - "\"ch:12/country_code_for_ip,posts,tumblelogs,tumblelogs,version,users,users,tumblelogs,tumblelogs,version,users,users cm:4/rate-limiter,rate-limiter,users,version ce:0/ c:0/0 d:0/0 e:0/0\""
+ vary:
+ - Accept-Encoding
+ http_version: "1.1"
+ message: Created
+ read: true
+ socket:
View
@@ -309,6 +309,14 @@ class TestTumblr < Test::Unit::TestCase
assert response.success?
assert_equal 'Deleted', response.body
end
+
+ test 'reblogs a post' do
+ assert_respond_to Tumblr::Writer.new, :reblog
+ publisher = Tumblr::Writer.new('test@testermcgee.com','dontrevealmysecrets')
+ post = {:'post-id' => "507998507", :'reblog-key' => 'DifhdmQI'}
+ response = hijack! publisher.reblog(post), 'write/reblog'
+ assert_equal 201, response.code
+ end
end
describe 'Authenticator' do
@@ -469,6 +477,12 @@ class TestTumblr < Test::Unit::TestCase
assert post.delete('test@testermcgee.com','dontrevealmysecrets').is_a? Weary::Request
end
+ test 'reblogs itself' do
+ post = Tumblr::Post.new(123)
+ post.reblog_key = '0U812'
+ assert post.reblog('test@testermcgee.com','dontrevealmysecrets').is_a? Weary::Request
+ end
+
test 'likes itself' do
post = Tumblr::Post.new(445597771)
post.reblog_key = "DLVWOpfh"

0 comments on commit 3be2ba5

Please sign in to comment.