Class: Tumblr::Post
- Inherits:
-
Object
- Object
- Tumblr::Post
- Defined in:
- lib/tumblr/post.rb,
lib/tumblr/post/link.rb,
lib/tumblr/post/audio.rb,
lib/tumblr/post/photo.rb,
lib/tumblr/post/quote.rb,
lib/tumblr/post/video.rb,
lib/tumblr/post/regular.rb,
lib/tumblr/post/conversation.rb
Defined Under Namespace
Classes: Audio, Conversation, Link, Photo, Quote, Regular, Video
Constant Summary collapse
- BASIC_PARAMS =
[:date,:tags,:format,:group,:generator,:private, :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']
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#format ⇒ Object
Returns the value of attribute format.
-
#generator ⇒ Object
Returns the value of attribute generator.
-
#group ⇒ Object
Returns the value of attribute group.
-
#post_id ⇒ Object
readonly
Returns the value of attribute post_id.
-
#reblog_key ⇒ Object
Returns the value of attribute reblog_key.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#state ⇒ Object
Returns the value of attribute state.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_queue(email, password, pubdate = nil) ⇒ Object
Adds to Queue.
- #delete(email, password) ⇒ Object
- #edit(email, password) ⇒ Object
-
#initialize(post_id = nil) ⇒ Post
constructor
A new instance of Post.
- #like(email, password) ⇒ Object
- #private=(bool) ⇒ Object
- #private? ⇒ Boolean
-
#publish_now(email, password) ⇒ Object
Write to Tumblr and set state to Publish.
- #publish_on(pubdate = nil) ⇒ Object
-
#save_as_draft(email, password) ⇒ Object
Save as a draft.
- #send_to_twitter(status = false) ⇒ Object
- #tags(*post_tags) ⇒ Object
-
#to_h ⇒ Object
Convert to a hash to be used in post writing/editing.
-
#to_s ⇒ Object
Convert post to a string for writing to a file.
-
#to_yaml ⇒ Object
Convert post to a YAML representation.
- #unlike(email, password) ⇒ Object
-
#write(email, password) ⇒ Object
Publish this post to Tumblr.
Constructor Details
#initialize(post_id = nil) ⇒ Post
Returns a new instance of Post.
22 23 24 |
# File 'lib/tumblr/post.rb', line 22 def initialize(post_id = nil) @post_id = post_id if post_id end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
20 21 22 |
# File 'lib/tumblr/post.rb', line 20 def date @date end |
#format ⇒ Object
Returns the value of attribute format.
19 20 21 |
# File 'lib/tumblr/post.rb', line 19 def format @format end |
#generator ⇒ Object
Returns the value of attribute generator.
20 21 22 |
# File 'lib/tumblr/post.rb', line 20 def generator @generator end |
#group ⇒ Object
Returns the value of attribute group.
20 21 22 |
# File 'lib/tumblr/post.rb', line 20 def group @group end |
#post_id ⇒ Object (readonly)
Returns the value of attribute post_id.
19 20 21 |
# File 'lib/tumblr/post.rb', line 19 def post_id @post_id end |
#reblog_key ⇒ Object
Returns the value of attribute reblog_key.
20 21 22 |
# File 'lib/tumblr/post.rb', line 20 def reblog_key @reblog_key end |
#slug ⇒ Object
Returns the value of attribute slug.
20 21 22 |
# File 'lib/tumblr/post.rb', line 20 def slug @slug end |
#state ⇒ Object
Returns the value of attribute state.
19 20 21 |
# File 'lib/tumblr/post.rb', line 19 def state @state end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/tumblr/post.rb', line 19 def type @type end |
Class Method Details
.parameters(*attributes) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/tumblr/post.rb', line 11 def self.parameters(*attributes) if !attributes.blank? @parameters = attributes attr_accessor *@parameters end @parameters end |
Instance Method Details
#add_to_queue(email, password, pubdate = nil) ⇒ Object
Adds to Queue. Pass an additional date to publish at a specific date.
122 123 124 125 126 127 |
# File 'lib/tumblr/post.rb', line 122 def add_to_queue(email, password, pubdate = nil) self.state = :queue self.publish_on(pubdate) if pubdate return edit(email,password) if post_id write(email,password) end |
#delete(email, password) ⇒ Object
91 92 93 |
# File 'lib/tumblr/post.rb', line 91 def delete(email, password) Writer.new(email,password).delete(to_h) end |
#edit(email, password) ⇒ Object
87 88 89 |
# File 'lib/tumblr/post.rb', line 87 def edit(email, password) Writer.new(email,password).edit(to_h) end |
#like(email, password) ⇒ Object
95 96 97 98 99 |
# File 'lib/tumblr/post.rb', line 95 def like(email,password) if (post_id && reblog_key) Reader.new(email,password).like(:'post-id' => post_id, :'reblog-key' => reblog_key) end end |
#private=(bool) ⇒ Object
26 27 28 |
# File 'lib/tumblr/post.rb', line 26 def private=(bool) @private = bool ? true : false end |
#private? ⇒ Boolean
30 31 32 |
# File 'lib/tumblr/post.rb', line 30 def private? @private end |
#publish_now(email, password) ⇒ Object
Write to Tumblr and set state to Publish
108 109 110 111 112 |
# File 'lib/tumblr/post.rb', line 108 def publish_now(email, password) self.state = :published return edit(email,password) if post_id write(email,password) end |
#publish_on(pubdate = nil) ⇒ Object
65 66 67 68 |
# File 'lib/tumblr/post.rb', line 65 def publish_on(pubdate=nil) @publish_on = pubdate if state.eql?(:queue) && pubdate @publish_on end |
#save_as_draft(email, password) ⇒ Object
Save as a draft
115 116 117 118 119 |
# File 'lib/tumblr/post.rb', line 115 def save_as_draft(email, password) self.state = :draft return edit(email,password) if post_id write(email,password) end |
#send_to_twitter(status = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tumblr/post.rb', line 54 def send_to_twitter(status=false) if status if status.to_sym.eql?(:no) @send_to_twitter = false else @send_to_twitter = status end end @send_to_twitter end |
#tags(*post_tags) ⇒ Object
34 35 36 37 |
# File 'lib/tumblr/post.rb', line 34 def (*) @tags = .join(',') if !.blank? @tags end |
#to_h ⇒ Object
Convert to a hash to be used in post writing/editing
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tumblr/post.rb', line 71 def to_h post_hash = {} basics = [:post_id, :type, :date, :tags, :format, :group, :generator, :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 end |
#to_s ⇒ Object
Convert post to a string for writing to a file
138 139 140 141 142 143 |
# File 'lib/tumblr/post.rb', line 138 def to_s post_string = YAML.dump(post_data) post_string += "---\x0D\x0A" post_string += YAML.load(to_yaml)['body'] post_string end |
#to_yaml ⇒ Object
Convert post to a YAML representation
130 131 132 133 134 135 |
# File 'lib/tumblr/post.rb', line 130 def to_yaml post = {} post['data'] = post_data post['body'] = to_h[post_body].to_s YAML.dump(post) end |