Class: Reddit::Thing
- Includes:
- JsonListing
- Defined in:
- lib/ruby_reddit_api/thing.rb
Overview
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#author ⇒ Reddit::User
The author of the entity.
-
#id ⇒ String
The reddit ID of this entity.
-
#initialize(data) ⇒ Thing
constructor
A new instance of Thing.
-
#report ⇒ true, false
Report thing.
- #toggle(which) ⇒ Object
Methods included from JsonListing
Methods inherited from Base
base_headers, #base_headers, #cookie, #inspect, #logged_in?, #login, #logout, #modhash, #read, #user, #user_agent, user_agent, #user_id
Constructor Details
#initialize(data) ⇒ Thing
Returns a new instance of Thing.
6 7 8 9 |
# File 'lib/ruby_reddit_api/thing.rb', line 6 def initialize(data) parse(data) @debug = StringIO.new end |
Instance Method Details
#author ⇒ Reddit::User
The author of the entity. The data is lazy-loaded and cached on the object
19 20 21 22 |
# File 'lib/ruby_reddit_api/thing.rb', line 19 def response = read("/user/#{@author}/about.json", :handler => "User") if @author @author_data ||= response[0] if response end |
#id ⇒ String
The reddit ID of this entity
13 14 15 |
# File 'lib/ruby_reddit_api/thing.rb', line 13 def id "#{kind}_#{@id}" end |
#report ⇒ true, false
Report thing
26 27 28 |
# File 'lib/ruby_reddit_api/thing.rb', line 26 def report toggle :report end |
#toggle(which) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ruby_reddit_api/thing.rb', line 30 def toggle(which) return false unless logged_in? mapping = {:save => "save", :unsave => "unsave", :hide => "hidden", :unhide => "unhidden", :report => "report"} mode = mapping[which] resp = self.class.post("/api/#{which}", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => mode }, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |