lib/tumblr/post.rb in tumblr-rb-1.0.0 vs lib/tumblr/post.rb in tumblr-rb-1.1.0
- old
+ new
@@ -1,11 +1,11 @@
# An object that represents a post. From:
# http://www.tumblr.com/docs/en/api#api_write
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']
def self.parameters(*attributes)
@@ -15,11 +15,11 @@
end
@parameters
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
end
@@ -69,11 +69,11 @@
# Convert to a hash to be used in post writing/editing
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?
post_hash[:private] = 1 if private?
post_hash
@@ -88,9 +88,21 @@
Writer.new(email,password).edit(to_h)
end
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
\ No newline at end of file