Class: Snooby::User
- Inherits:
-
Object
- Object
- Snooby::User
- Defined in:
- lib/snooby/user.rb
Instance Method Summary collapse
- #disliked(count = 25) ⇒ Object
- #friend ⇒ Object
- #hidden(count = 25) ⇒ Object
-
#initialize(name) ⇒ User
constructor
A new instance of User.
- #liked(count = 25) ⇒ Object
-
#trophies ⇒ Object
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.
- #unfriend ⇒ Object
Methods included from About
Methods included from Posts
Methods included from Comments
Methods included from 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 |
#friend ⇒ Object
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 |
#trophies ⇒ Object
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 |
#unfriend ⇒ Object
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 |