Class: Post

Inherits:
Object
  • Object
show all
Defined in:
lib/Rubbit/Rubbit_Objects.rb

Overview

Rubbit Object

Object representing a Reddit Post

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Post

Returns a new instance of Post.



570
571
572
573
574
575
576
577
578
579
# File 'lib/Rubbit/Rubbit_Objects.rb', line 570

def initialize(json)
	@comments = nil
	if(json['kind']=='t3')
		data = json['data']
		data.each_key do |k|
			self.class.module_eval {attr_accessor(k)}
			self.send("#{k}=",data[k])
		end
	end
end

Instance Method Details

#deleteObject

Description

Deletes this post. Only works if you made the post.



612
613
614
# File 'lib/Rubbit/Rubbit_Objects.rb', line 612

def delete
	Rubbit_Poster.instance.delete(@name)
end

#edit(text) ⇒ Object

Description

Modifies the text of this post. Only works if the post was made by you and is a self post.

Attributes

  • text - The new post body.



624
625
626
# File 'lib/Rubbit/Rubbit_Objects.rb', line 624

def edit(text)
	Rubbit_Poster.instance.edit(@name,text)
end

#hideObject

Description

Hides the post and no longer displays it when retrieving Reddit data



632
633
634
# File 'lib/Rubbit/Rubbit_Objects.rb', line 632

def hide
	Rubbit_Poster.instance.hide(@name)
end

#mark_nsfwObject

Description

Marks a post as NSFW. Only works if you made the post or are a moderator of the subreddit it is in.



640
641
642
# File 'lib/Rubbit/Rubbit_Objects.rb', line 640

def mark_nsfw
	Rubbit_Poster.instance.mark_nsfw(@name)
end

#replies(limit = 100) ⇒ Object

Description

Retrieves the comments of a post in a list tree.



601
602
603
604
605
606
# File 'lib/Rubbit/Rubbit_Objects.rb', line 601

def replies(limit=100)
	if(@comments==nil)
		@comments = Rubbit_Object_Builder.instance.get_comments("http://www.reddit.com#{permalink}.json",limit)
	end
	return @comments
end

#reply(text) ⇒ Object

Description

Makes a reply to a post

Attributes

  • text - The new comment body.



589
590
591
# File 'lib/Rubbit/Rubbit_Objects.rb', line 589

def reply(text)
	return Rubbit_Poster.instance.comment(@name,text)
end

#set_as_sticky(state) ⇒ Object



593
594
595
# File 'lib/Rubbit/Rubbit_Objects.rb', line 593

def set_as_sticky(state)
	return Rubbit_Poster.instance.set_subreddit_sticky(@name,state)
end