Module: RedditKit::Client::Users
- Included in:
- RedditKit::Client
- Defined in:
- lib/redditkit/client/users.rb
Overview
Methods for interacting with reddit users.
Instance Method Summary collapse
-
#friend(user) ⇒ Object
Adds a user to the current user’s friend list.
-
#friends ⇒ Array<OpenStruct>
Gets the current user’s friends.
-
#my_content(options = {}) ⇒ RedditKit::PaginatedResponse
Gets links and comments for the current user.
-
#register(username, password, options = {}) ⇒ Object
Registers a new reddit account.
-
#unfriend(user) ⇒ Object
Removes a user from the current user’s friend list.
-
#user(username = nil) ⇒ RedditKit::User
Gets a user object.
-
#user_content(user, options = {}) ⇒ RedditKit::PaginatedResponse
Gets links and comments for a user.
-
#username_available?(username) ⇒ Boolean
Checks whether a specific username is available.
Instance Method Details
#friend(user) ⇒ Object
Adds a user to the current user’s friend list.
72 73 74 75 |
# File 'lib/redditkit/client/users.rb', line 72 def friend(user) friend_name = extract_string(user, :username) friend_request 'friend', :container => current_user.full_name, :name => friend_name, :type => :friend end |
#friends ⇒ Array<OpenStruct>
Gets the current user’s friends.
61 62 63 64 65 66 67 |
# File 'lib/redditkit/client/users.rb', line 61 def friends response = request(:get, 'prefs/friends.json', nil, https_connection) body = response[:body] friends = body[0][:data][:children] friends.map { |friend| OpenStruct.new(friend) } end |
#my_content(options = {}) ⇒ RedditKit::PaginatedResponse
Gets links and comments for the current user.
30 31 32 33 34 35 36 37 38 |
# File 'lib/redditkit/client/users.rb', line 30 def my_content( = {}) = .clone category = [:category] || :overview path = "user/#{@username}/#{category}.json" .delete :category objects_from_response(:get, path, ) end |
#register(username, password, options = {}) ⇒ Object
Registers a new reddit account.
103 104 105 106 |
# File 'lib/redditkit/client/users.rb', line 103 def register(username, password, = {}) parameters = { :user => username, :passwd => password, :passwd2 => password, :email => [:email], :captcha => [:captcha], :iden => [:captcha_identifier] } post('api/register', parameters) end |
#unfriend(user) ⇒ Object
Removes a user from the current user’s friend list.
80 81 82 83 |
# File 'lib/redditkit/client/users.rb', line 80 def unfriend(user) friend_name = extract_string(user, :username) friend_request 'unfriend', :container => current_user.full_name, :name => friend_name, :type => :friend end |
#user(username = nil) ⇒ RedditKit::User
Gets a user object.
15 16 17 18 19 20 21 |
# File 'lib/redditkit/client/users.rb', line 15 def user(username = nil) if username object_from_response(:get, "user/#{username}/about.json", nil) else object_from_response(:get, 'api/me.json', nil) end end |
#user_content(user, options = {}) ⇒ RedditKit::PaginatedResponse
Public access to the liked and disliked categories is disabled by default, so this will return an empty array for most users.
Gets links and comments for a user.
48 49 50 51 52 53 54 55 56 |
# File 'lib/redditkit/client/users.rb', line 48 def user_content(user, = {}) = .clone username = user path = "user/#{username}/%s.json" % ([:category] if [:category]) .delete :category objects_from_response(:get, path, ) end |
#username_available?(username) ⇒ Boolean
Checks whether a specific username is available.
90 91 92 93 |
# File 'lib/redditkit/client/users.rb', line 90 def username_available?(username) response = get('api/username_available.json', :user => username) response[:body] end |