Class: Snooby::Subreddit
- Inherits:
-
Object
- Object
- Snooby::Subreddit
- Defined in:
- lib/snooby/subreddit.rb
Instance Method Summary collapse
-
#initialize(name) ⇒ Subreddit
constructor
A new instance of Subreddit.
- #submit(title, content) ⇒ Object
-
#subscribe(un = '') ⇒ Object
(also: #sub)
Alas, (un)subscribing by name alone doesn’t work, so a separate call must be made to obtain the subreddit’s id, thus the wait.
- #unsubscribe ⇒ Object (also: #unsub)
Methods included from About
Methods included from Posts
Methods included from Comments
Methods included from Compose
Constructor Details
#initialize(name) ⇒ Subreddit
Returns a new instance of Subreddit.
6 7 8 9 |
# File 'lib/snooby/subreddit.rb', line 6 def initialize(name) @name = name @kind = 'subreddit' end |
Instance Method Details
#submit(title, content) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/snooby/subreddit.rb', line 11 def submit(title, content) data = {:title => title, :sr => @name} data[:kind] = content[/^https?:/] ? 'link' : 'self' data[:"#{$& ? 'url' : 'text'}"] = content Snooby.request Paths[:submit], data end |
#subscribe(un = '') ⇒ Object Also known as: sub
Alas, (un)subscribing by name alone doesn’t work, so a separate call must be made to obtain the subreddit’s id, thus the wait. Maybe cache this?
20 21 22 23 |
# File 'lib/snooby/subreddit.rb', line 20 def subscribe(un = '') sr = about['name'] Snooby.request Paths[:subscribe], :action => "#{un}sub", :sr => sr end |
#unsubscribe ⇒ Object Also known as: unsub
25 26 27 |
# File 'lib/snooby/subreddit.rb', line 25 def unsubscribe subscribe 'un' end |