Skip to content
This repository
Browse code

Added reblog support

  • Loading branch information...
commit 3be2ba5f77ee67d36c6ec8519f5452093e44b091 1 parent 9343872
Wynn Netherland authored April 09, 2010
5  lib/tumblr/post.rb
@@ -7,6 +7,7 @@ class Post
7 7
     POST_PARAMS = [:title,:body,:source,:caption,:'click-through-url',
8 8
                    :quote,:name,:url,:description,:conversation,
9 9
                    :embed,:'externally-hosted-url']
  10
+    REBLOG_PARAMS = [:comment, :as]
10 11
     
11 12
     def self.parameters(*attributes)
12 13
       if !attributes.blank?
@@ -88,6 +89,10 @@ def edit(email, password)
88 89
       Writer.new(email,password).edit(to_h)
89 90
     end
90 91
     
  92
+    def reblog(email, password)
  93
+      Writer.new(email,password).reblog(to_h)
  94
+    end
  95
+    
91 96
     def delete(email, password)
92 97
       Writer.new(email,password).delete(to_h)
93 98
     end
7  lib/tumblr/writer.rb
@@ -22,6 +22,13 @@ def initialize(*credentials)
22 22
       edit.with = (Post::BASIC_PARAMS | Post::POST_PARAMS)
23 23
     end
24 24
     
  25
+    # http://www.tumblr.com/docs/en/api#reblogging_posts
  26
+    post :reblog do |reblog|
  27
+      reblog.url = 'http://www.tumblr.com/api/reblog'
  28
+      reblog.requires = [:email, :password, :'post-id', :'reblog-key']
  29
+      reblog.with = (Post::BASIC_PARAMS | Post::POST_PARAMS | Post::REBLOG_PARAMS)
  30
+    end
  31
+    
25 32
     # http://www.tumblr.com/docs/en/api#deleting_posts
26 33
     post :delete do |del|
27 34
       del.url = 'http://www.tumblr.com/api/delete'
31  test/fixtures/vcr_cassettes/write/reblog.yml
... ...
@@ -0,0 +1,31 @@
  1
+--- 
  2
+- !ruby/struct:VCR::RecordedResponse 
  3
+  method: :post
  4
+  uri: http://www.tumblr.com:80/api/reblog
  5
+  response: !ruby/object:Net::HTTPCreated 
  6
+    body: "508128650"
  7
+    body_exist: true
  8
+    code: "201"
  9
+    header: 
  10
+      p3p: 
  11
+      - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
  12
+      content-type: 
  13
+      - text/plain; charset=utf-8
  14
+      connection: 
  15
+      - close
  16
+      x-tumblr-usec: 
  17
+      - D=380408
  18
+      server: 
  19
+      - Apache/2.2.3 (Red Hat)
  20
+      date: 
  21
+      - Fri, 09 Apr 2010 12:36:41 GMT
  22
+      content-length: 
  23
+      - "9"
  24
+      x-tumblr-perf: 
  25
+      - "\"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\""
  26
+      vary: 
  27
+      - Accept-Encoding
  28
+    http_version: "1.1"
  29
+    message: Created
  30
+    read: true
  31
+    socket: 
14  test/test_tumblr.rb
@@ -309,6 +309,14 @@ class TestTumblr < Test::Unit::TestCase
309 309
       assert response.success?
310 310
       assert_equal 'Deleted', response.body
311 311
     end
  312
+    
  313
+    test 'reblogs a post' do
  314
+      assert_respond_to Tumblr::Writer.new, :reblog
  315
+      publisher = Tumblr::Writer.new('test@testermcgee.com','dontrevealmysecrets')
  316
+      post = {:'post-id' => "507998507", :'reblog-key' => 'DifhdmQI'}
  317
+      response = hijack! publisher.reblog(post), 'write/reblog'
  318
+      assert_equal 201, response.code
  319
+    end
312 320
   end
313 321
   
314 322
   describe 'Authenticator' do
@@ -469,6 +477,12 @@ class TestTumblr < Test::Unit::TestCase
469 477
         assert post.delete('test@testermcgee.com','dontrevealmysecrets').is_a? Weary::Request
470 478
       end
471 479
       
  480
+      test 'reblogs itself' do
  481
+        post = Tumblr::Post.new(123)
  482
+        post.reblog_key = '0U812'
  483
+        assert post.reblog('test@testermcgee.com','dontrevealmysecrets').is_a? Weary::Request
  484
+      end
  485
+      
472 486
       test 'likes itself' do
473 487
         post = Tumblr::Post.new(445597771)
474 488
         post.reblog_key = "DLVWOpfh"

0 notes on commit 3be2ba5

Please sign in to comment.
Something went wrong with that request. Please try again.