Skip to content

Commit

Permalink
Adding reblog key as post parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Mar 12, 2010
1 parent d3d6a9e commit 5c62a6f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/tumblr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def self.create_post(document)
end

def self.basic_setup(post, post_data)
%w(format state private slug date group generator).each do |basic|
post.send "#{basic}=".intern, post_data[basic] if post_data[basic]
%w(format state private slug date group generator reblog-key).each do |basic|
post.send "#{basic}=".gsub('-','_').intern, post_data[basic] if post_data[basic]
end
%w(tags send-to-twitter publish-on).each do |attribute|
post.send attribute.gsub('-','_').intern, post_data[attribute] if post_data[attribute]
Expand Down
6 changes: 3 additions & 3 deletions lib/tumblr/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Tumblr
class Post
BASIC_PARAMS = [:date,:tags,:format,:group,:generator,:private,
:slug,:state,:'send-to-twitter',:'publish-on']
:slug,:state,:'send-to-twitter',:'publish-on',:'reblog-key']
POST_PARAMS = [:title,:body,:source,:caption,:'click-through-url',
:quote,:name,:url,:description,:conversation,
:embed,:'externally-hosted-url']
Expand All @@ -17,7 +17,7 @@ def self.parameters(*attributes)
end

attr_reader :type, :state, :post_id, :format
attr_accessor :slug, :date, :group, :generator
attr_accessor :slug, :date, :group, :generator, :reblog_key

def initialize(post_id = nil)
@post_id = post_id if post_id
Expand Down Expand Up @@ -71,7 +71,7 @@ def publish_on(pubdate=nil)
def to_h
post_hash = {}
basics = [:post_id, :type, :date, :tags, :format, :group, :generator,
:slug, :state, :send_to_twitter, :publish_on]
:slug, :state, :send_to_twitter, :publish_on, :reblog_key]
params = basics.select {|opt| respond_to?(opt) && send(opt) }
params |= self.class.parameters.select {|opt| send(opt) } unless self.class.parameters.blank?
params.each { |key| post_hash[key.to_s.gsub('_','-').to_sym] = send(key) } unless params.empty?
Expand Down
1 change: 1 addition & 0 deletions lib/tumblr/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def self.build_post(post)
tumblr_post.format = post['format'].to_sym if post['format']
tumblr_post.slug = post['slug']
tumblr_post.tags post['tag'] if post['tag']
tumblr_post.reblog_key = post['reblog_key'] if post['reblog_key']
tumblr_post
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_tumblr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class TestTumblr < Test::Unit::TestCase
assert_equal :link, link_post.type
assert_equal :markdown, link_post.format
assert_equal link.first['link_url'], link_post.url
assert_equal link.first['reblog_key'], link_post.reblog_key
end
end

Expand Down Expand Up @@ -323,6 +324,13 @@ class TestTumblr < Test::Unit::TestCase
assert post.private?
end

test 'can have a reblog key' do
post = Tumblr::Post.new
assert_respond_to post, :reblog_key
post.reblog_key = 'reblog_me'
assert_equal 'reblog_me', post.reblog_key
end

test 'has a comma separated list of tags' do
post = Tumblr::Post.new
assert_respond_to post, :tags
Expand Down

0 comments on commit 5c62a6f

Please sign in to comment.