Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Posts can like/unlike themselves

  • Loading branch information...
commit d1c5a0f80777680167309811b61e178c96d1bca5 1 parent 2548996
@mwunsch mwunsch authored
Showing with 41 additions and 2 deletions.
  1. +1 −2  README.md
  2. +12 −0 lib/tumblr/post.rb
  3. +28 −0 test/test_tumblr.rb
View
3  README.md
@@ -101,7 +101,6 @@ To publish to Tumblr, do this:
## TODO:
-+ Tumblr::Post needs methods for liking and unliking.
+ Add option to CLI for passing a YAML file for authentication, with keys for email & password.
+ File-uploading for Photos, Videos, Audio (needs to get into Weary)
@@ -109,4 +108,4 @@ To publish to Tumblr, do this:
The Tumblr gem is Copyright (c) 2010 Mark Wunsch and is licensed under the [MIT License](http://creativecommons.org/licenses/MIT/).
-Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr.
+Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.
View
12 lib/tumblr/post.rb
@@ -92,6 +92,18 @@ def delete(email, password)
Writer.new(email,password).delete(to_h)
end
+ def like(email,password)
+ if (post_id && reblog_key)
+ Reader.new(email,password).like(:'post-id' => post_id, :'reblog-key' => reblog_key)
+ end
+ end
+
+ def unlike(email,password)
+ if (post_id && reblog_key)
+ Reader.new(email,password).unlike(:'post-id' => post_id, :'reblog-key' => reblog_key)
+ end
+ end
+
# Write to Tumblr and set state to Publish
def publish_now(email, password)
self.state = :published
View
28 test/test_tumblr.rb
@@ -200,6 +200,18 @@ class TestTumblr < Test::Unit::TestCase
assert_respond_to reader, :like
assert_respond_to reader, :unlike
end
+
+ test 'likes a post' do
+ reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
+ like = hijack! reader.like(:'post-id' => '445597771', :'reblog-key' => 'DLVWOpfh'), 'read/like'
+ assert like.success?
+ end
+
+ test 'unlikes a post' do
+ reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
+ unlike = hijack! reader.unlike(:'post-id' => '445597771', :'reblog-key' => 'DLVWOpfh'), 'read/unlike'
+ assert unlike.success?
+ end
test 'parses posts out of a read' do
reader = Tumblr::Reader
@@ -430,6 +442,22 @@ class TestTumblr < Test::Unit::TestCase
post = Tumblr::Post.new(123)
assert post.delete('test@testermcgee.com','dontrevealmysecrets').is_a? Weary::Request
end
+
+ test 'likes itself' do
+ post = Tumblr::Post.new(445597771)
+ post.reblog_key = "DLVWOpfh"
+ like = post.like('test@testermcgee.com','dontrevealmysecrets')
+ assert like.is_a? Weary::Request
+ assert_equal 'http://www.tumblr.com/api/like', like.uri.to_s
+ end
+
+ test 'unlikes itself' do
+ post = Tumblr::Post.new(445597771)
+ post.reblog_key = "DLVWOpfh"
+ unlike = post.unlike('test@testermcgee.com','dontrevealmysecrets')
+ assert unlike.is_a? Weary::Request
+ assert_equal 'http://www.tumblr.com/api/unlike', unlike.uri.to_s
+ end
test 'publishes to tumblr' do
klass = Class.new Tumblr::Post
Please sign in to comment.
Something went wrong with that request. Please try again.