Module: Wreddit

Defined in:
lib/wreddit.rb,
lib/wreddit/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#comment(comment_id) ⇒ Object



28
29
30
31
# File 'lib/wreddit.rb', line 28

def comment(comment_id)
  @uri += "/#{comment_id}"
  self
end

#comments(article_id = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/wreddit.rb', line 15

def comments(article_id = nil)
  # gets all comments if article_id is unspecified
  @uri += "/comments"
  # add article_id if article is specified
  if article_id
    @uri += "/#{article_id}"
  end
  self
end

#parser(method = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wreddit.rb', line 32

def parser(method = nil)
  # method of parsing your request
  case method
  when "json"
    JSON.parse(Net::HTTP.get(URI(@uri + '.json')))
  when "xml"
    Nokogiri::XML(Net::HTTP.get(URI(@uri + '.xml')))
  when "html"
    Nokogiri::HTML(Net::HTTP.get(URI(@uri)))
  else
    # assume the user wants it in JSON format
    JSON.parse(Net::HTTP.get(URI(@uri + '.json')))
  end
end

#subreddit(subreddit_name) ⇒ Object



7
8
9
10
# File 'lib/wreddit.rb', line 7

def subreddit(subreddit_name)
  @uri = "https://www.reddit.com/r/#{subreddit_name}"
  self
end

#title(title_name) ⇒ Object



24
25
26
27
# File 'lib/wreddit.rb', line 24

def title(title_name)
  @uri += "/#{title_name}"
  self
end

#user(user_name) ⇒ Object



11
12
13
14
# File 'lib/wreddit.rb', line 11

def user(user_name)
  @uri = "https://www.reddit.com/user/#{user_name}"
  self
end