Class: Reddit::User

Inherits:
Api show all
Includes:
JsonListing
Defined in:
lib/ruby_reddit_api/user.rb

Overview

Author:

  • James Cook

Instance Attribute Summary collapse

Attributes inherited from Api

#last_action, #password, #user

Attributes inherited from Base

#last_action

Instance Method Summary collapse

Methods included from JsonListing

included

Methods inherited from Api

#browse, #comments, #post_replies, #received_messages, #search, #sent_messages, #unread_messages

Methods inherited from Base

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

Constructor Details

#initialize(json) ⇒ User

Returns a new instance of User.



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

def initialize(json)
  @debug = StringIO.new
  parse(json)
end

Instance Attribute Details

#comment_karmaObject (readonly)

Returns the value of attribute comment_karma.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def comment_karma
  @comment_karma
end

#createdObject (readonly)

Returns the value of attribute created.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def created
  @created
end

#created_utcObject (readonly)

Returns the value of attribute created_utc.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def created_utc
  @created_utc
end

#debugObject (readonly)

Returns the value of attribute debug.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def debug
  @debug
end

#has_mod_mailObject (readonly)

Returns the value of attribute has_mod_mail.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def has_mod_mail
  @has_mod_mail
end

#is_modObject (readonly)

Returns the value of attribute is_mod.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def is_mod
  @is_mod
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def kind
  @kind
end

Returns the value of attribute link_karma.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def link_karma
  @link_karma
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/ruby_reddit_api/user.rb', line 5

def name
  @name
end

Instance Method Details

#friendtrue, false

Add redditor as friend. Requires a authenticated user.

Returns:

  • (true, false)


28
29
30
31
32
# File 'lib/ruby_reddit_api/user.rb', line 28

def friend
  capture_user_id
  resp=self.class.post("/api/friend", {:body => {:name => name, :container => user_id, :type => "friend", :uh => modhash}, :headers => base_headers, :debug_output => @debug })
  resp.code == 200
end

#idString

The reddit ID of this submission

Returns:

  • (String)


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

def id
  "#{kind}_#{@id}"
end

#inspectObject



11
12
13
# File 'lib/ruby_reddit_api/user.rb', line 11

def inspect
  "<Reddit::User name='#{name}'>"
end

#to_sString

Returns:

  • (String)


22
23
24
# File 'lib/ruby_reddit_api/user.rb', line 22

def to_s
  name
end

#unfriendtrue, false

Remove redditor as friend. Requires a authenticated user.

Returns:

  • (true, false)


36
37
38
39
40
# File 'lib/ruby_reddit_api/user.rb', line 36

def unfriend
  capture_user_id
  resp=self.class.post("/api/unfriend", {:body => {:name => name, :container => user_id, :type => "friend", :uh => modhash}, :headers => base_headers, :debug_output => @debug })
  resp.code == 200
end