Class: Snooby::Subreddit

Inherits:
Object
  • Object
show all
Includes:
About, Comments, Compose, Posts
Defined in:
lib/snooby/subreddit.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) ⇒ 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

#unsubscribeObject Also known as: unsub



25
26
27
# File 'lib/snooby/subreddit.rb', line 25

def unsubscribe
  subscribe 'un'
end