Class: Redditor
- Inherits:
-
Object
- Object
- Redditor
- Defined in:
- lib/Rubbit/Rubbit_Objects.rb
Overview
Rubbit Object
Object Representing a Redditor. If the requested Redditor is logged in, this object also contains a modhash. If obtained from a subreddit list, this object will need to be rebuilt using the rebuild function
Instance Method Summary collapse
-
#get_comments(limit = 100, sort = 'new') ⇒ Object
Description.
-
#get_overview(limit = 100, sort = 'new') ⇒ Object
Description.
-
#get_submitted(limit = 100, sort = 'new') ⇒ Object
Description.
-
#initialize(json) ⇒ Redditor
constructor
A new instance of Redditor.
-
#rebuild ⇒ Object
Description.
Constructor Details
#initialize(json) ⇒ Redditor
Returns a new instance of Redditor.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/Rubbit/Rubbit_Objects.rb', line 271 def initialize(json) if(json['kind']=='t2') data = json['data'] data.each_key do |k| self.class.module_eval {attr_accessor(k)} self.send("#{k}=",data[k]) end elsif(json['id'][0..2]=='t2_') data = json data.each_key do |k| self.class.module_eval {attr_accessor(k)} self.send("#{k}=",data[k]) end end end |
Instance Method Details
#get_comments(limit = 100, sort = 'new') ⇒ Object
Description
Function for getting user comment from a profile
Attributes
-
limit- Maximum entries that the ContentGenerator can contain -
sort- Sort order by which the content is returned
309 310 311 |
# File 'lib/Rubbit/Rubbit_Objects.rb', line 309 def get_comments(limit=100,sort='new') return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/comments.json?sort='+sort,limit) end |
#get_overview(limit = 100, sort = 'new') ⇒ Object
Description
Function for getting user overview content from a profile, including both comments and posts
Attributes
-
limit- Maximum entries that the ContentGenerator can contain -
sort- Sort order by which the content is returned
296 297 298 |
# File 'lib/Rubbit/Rubbit_Objects.rb', line 296 def get_overview(limit=100,sort='new') return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/.json?sort='+sort,limit) end |
#get_submitted(limit = 100, sort = 'new') ⇒ Object
Description
Function for getting user posts from a profile
Attributes
-
limit- Maximum entries that the ContentGenerator can contain -
sort- Sort order by which the content is returned
322 323 324 |
# File 'lib/Rubbit/Rubbit_Objects.rb', line 322 def get_submitted(limit=100,sort='new') return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/submitted.json?sort='+sort,limit) end |
#rebuild ⇒ Object
Description
Function for rebuilding user object using data from their profile page
330 331 332 333 334 335 336 |
# File 'lib/Rubbit/Rubbit_Objects.rb', line 330 def rebuild rebuilt_user = Rubbit_Object_Builder.instance.build_user(@name) rebuilt_user.instance_variables.each do |attr_name| self.class.module_eval{attr_accessor(attr_name[1..-1])} self.send("#{attr_name[1..-1]}=",rebuilt_user.instance_variable_get(attr_name)) end end |