Class: Snooby::User

Inherits:
Object
  • Object
show all
Includes:
About, Comments, Compose, Posts
Defined in:
lib/snooby/user.rb

Instance Method Summary collapse

Methods included from About

#about

Methods included from Posts

#posts

Methods included from Comments

#comments

Methods included from Compose

#compose

Constructor Details

#initialize(name) ⇒ User

Returns a new instance of User.



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

def initialize(name)
  @name = name
  @kind = 'user'
end

Instance Method Details

#disliked(count = 25) ⇒ Object



24
25
26
# File 'lib/snooby/user.rb', line 24

def disliked(count = 25)
  Snooby.build(Post, :disliked, @name, count)
end

#friendObject

Raises:



32
33
34
35
36
37
# File 'lib/snooby/user.rb', line 32

def friend
  raise RedditError, 'You are not logged in.' unless Snooby.active

  data = {:name => @name, :type => 'friend', :container => Snooby.active.id}
  Snooby.request(Paths[:friend], data)
end

#hidden(count = 25) ⇒ Object



28
29
30
# File 'lib/snooby/user.rb', line 28

def hidden(count = 25)
  Snooby.build(Post, :hidden, @name, count)
end

#liked(count = 25) ⇒ Object



20
21
22
# File 'lib/snooby/user.rb', line 20

def liked(count = 25)
  Snooby.build(Post, :liked, @name, count)
end

#trophiesObject

Returns an array of 2-tuples containing the user’s trophy information in the form of [name, description], the latter containing the empty string if inapplicable.



13
14
15
16
17
18
# File 'lib/snooby/user.rb', line 13

def trophies
  # Only interested in trophies; request the minimum amount of content.
  html = Snooby.request(URI(Paths[:user] % @name) + '?limit=1')
  # Entry-level black magic.
  html.scan(/"trophy-name">(.+?)<.+?"\s?>([^<]*)</)
end

#unfriendObject

Raises:



39
40
41
42
43
44
# File 'lib/snooby/user.rb', line 39

def unfriend
  raise RedditError, 'You are not logged in.' unless Snooby.active

  data = {:name => @name, :type => 'friend', :container => Snooby.active.id}
  Snooby.request(Paths[:unfriend], data)
end