Module: Snoo::User

Defined in:
lib/snoo/users.rb

Overview

Methods for interacting with users, such as adding and removing friends, getting user info, etc

Author:

Instance Method Summary collapse

Instance Method Details

#friend(name, friend_id, note = nil) ⇒ Object

Friend a user

Parameters:

  • name (String)

    The username to target

  • note (String) (defaults to: nil)

    A friend tag. Requires reddit gold.



12
13
14
# File 'lib/snoo/users.rb', line 12

def friend name, friend_id, note = nil
  friend_wrapper(api_name = name, api_container = @userid, api_note = note, api_type = "friend")
end

#get_friendsObject

Get a list of friends



27
28
29
30
# File 'lib/snoo/users.rb', line 27

def get_friends
  logged_in?
  get('/prefs/friends.json')
end

#get_user_info(username) ⇒ Object

Get info about a user account

Parameters:

  • username (String)

    The username to target.



35
36
37
# File 'lib/snoo/users.rb', line 35

def  username
  get("/user/#{username}/about.json")
end

#get_user_listing(username, opts = {}) ⇒ Object

Get a listing of user posts. Some options may be restricted

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

  • username (String)

    The username to target.

  • opts (Hash) (defaults to: {})

    An options hash

Options Hash (opts):

  • :type (overview, submitted, comments, liked, disliked, hidden, saved)

    Type of post to return. Most users only allow the first 3 types.

  • :sort (new, hot, top, controversial)

    The sort order

  • :after (String)

    Return things after this id

  • :before (String)

    Return things before this id

  • :limit (1..100)

    Number of results to return



49
50
51
52
53
54
55
# File 'lib/snoo/users.rb', line 49

def get_user_listing username, opts = {}
  opts[:type] = 'overview' if opts[:type].nil?
  url = "/user/%s%s.json" % [username, ('/' + opts[:type] if opts[:type] != 'overview')]
  opts.delete :type
  query = opts
  get(url, query: query)
end

#unfriend(id) ⇒ Object

Unfriend a user

Parameters:

  • id (String)

    The friend id to remove. Must be in t2_id form



20
21
22
# File 'lib/snoo/users.rb', line 20

def unfriend id
  unfriend_wrapper api_id = id, api_container = @userid, api_type = "friend"
end