Class: Reddit::Submission

Inherits:
Thing show all
Includes:
JsonListing, Voteable
Defined in:
lib/ruby_reddit_api/submission.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#debug, #last_action

Instance Method Summary collapse

Methods included from Voteable

included

Methods included from JsonListing

included

Methods inherited from Thing

#author, #id, #initialize, #report, #toggle

Methods inherited from Base

base_headers, #base_headers, #cookie, #initialize, #logged_in?, #login, #logout, #modhash, #read, #user, #user_agent, user_agent, #user_id

Constructor Details

This class inherits a constructor from Reddit::Thing

Instance Attribute Details

#clickedObject (readonly)

Returns the value of attribute clicked.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def clicked
  @clicked
end

#createdObject (readonly)

Returns the value of attribute created.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def created
  @created
end

#created_utcObject (readonly)

Returns the value of attribute created_utc.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def created_utc
  @created_utc
end

#domainObject (readonly)

Returns the value of attribute domain.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def domain
  @domain
end

#downsObject (readonly)

Returns the value of attribute downs.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def downs
  @downs
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def hidden
  @hidden
end

#is_selfObject (readonly)

Returns the value of attribute is_self.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def is_self
  @is_self
end

#kindObject (readonly)

Returns the value of attribute kind.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def kind
  @kind
end

#last_comment_idObject (readonly)

Returns the value of attribute last_comment_id.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def last_comment_id
  @last_comment_id
end

#likesObject (readonly)

Returns the value of attribute likes.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def likes
  @likes
end

#mediaObject (readonly)

Returns the value of attribute media.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def media
  @media
end

#media_embedObject (readonly)

Returns the value of attribute media_embed.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def media_embed
  @media_embed
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def name
  @name
end

#num_commentsObject (readonly)

Returns the value of attribute num_comments.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def num_comments
  @num_comments
end

#over_18Object (readonly)

Returns the value of attribute over_18.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def over_18
  @over_18
end

Returns the value of attribute permalink.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def permalink
  @permalink
end

#savedObject (readonly)

Returns the value of attribute saved.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def saved
  @saved
end

#scoreObject (readonly)

Returns the value of attribute score.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def score
  @score
end

#selftextObject (readonly)

Returns the value of attribute selftext.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def selftext
  @selftext
end

#selftext_htmlObject (readonly)

Returns the value of attribute selftext_html.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def selftext_html
  @selftext_html
end

#subredditObject (readonly)

Returns the value of attribute subreddit.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def subreddit
  @subreddit
end

#subreddit_idObject (readonly)

Returns the value of attribute subreddit_id.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def subreddit_id
  @subreddit_id
end

#thumbnailObject (readonly)

Returns the value of attribute thumbnail.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def thumbnail
  @thumbnail
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def title
  @title
end

#upsObject (readonly)

Returns the value of attribute ups.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def ups
  @ups
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/ruby_reddit_api/submission.rb', line 7

def url
  @url
end

Instance Method Details

#add_comment(text) ⇒ true, false

Add a comment to a submission

Parameters:

  • Comment (String)

    text

Returns:

  • (true, false)


16
17
18
19
# File 'lib/ruby_reddit_api/submission.rb', line 16

def add_comment(text)
  resp = self.class.post("/api/comment", {:body => {:thing_id => id, :text => text, :uh => modhash, :r => subreddit }, :headers => base_headers, :debug_output => @debug })
  resp.code == 200
end

#admin_distinguishObject



49
50
51
# File 'lib/ruby_reddit_api/submission.rb', line 49

def admin_distinguish
  add_distinction "admin"
end

#commentsArray<Reddit::Comment>

TODO:

Move to ‘Thing’ class

Fetch submission comments

Returns:



60
61
62
63
64
65
# File 'lib/ruby_reddit_api/submission.rb', line 60

def comments
  _comments = read( permalink + ".json", {:handler => "Comment", :query => {:limit => 250}} )
  @last_comment_id = _comments.last.id if _comments && _comments.any?
  _comments.shift # First 'comment' is actually the submission
  return _comments
end

#hidetrue, false

Hide submission

Returns:

  • (true, false)


35
36
37
# File 'lib/ruby_reddit_api/submission.rb', line 35

def hide
  toggle :hide
end

#indistinguishObject



53
54
55
# File 'lib/ruby_reddit_api/submission.rb', line 53

def indistinguish
  add_distinction "no"
end

#inspectObject



9
10
11
# File 'lib/ruby_reddit_api/submission.rb', line 9

def inspect
  "<Reddit::Submission id='#{id}' author='#{@author}' title='#{title}'>"
end

#moderator_distinguishObject



45
46
47
# File 'lib/ruby_reddit_api/submission.rb', line 45

def moderator_distinguish
  add_distinction "yes"
end

#savetrue, false

Save submission

Returns:

  • (true, false)


23
24
25
# File 'lib/ruby_reddit_api/submission.rb', line 23

def save
  toggle :save
end

#unhidetrue, false

Unhide submission

Returns:

  • (true, false)


41
42
43
# File 'lib/ruby_reddit_api/submission.rb', line 41

def unhide
  toggle :unhide
end

#unsavetrue, false

Unsave submission

Returns:

  • (true, false)


29
30
31
# File 'lib/ruby_reddit_api/submission.rb', line 29

def unsave
  toggle :unsave
end