Class: Reddit
- Inherits:
-
Object
- Object
- Defined in:
- lib/topcats/reddit.rb
Instance Attribute Summary collapse
-
#endpoint_url ⇒ Object
readonly
Returns the value of attribute endpoint_url.
-
#parsed_response ⇒ Object
readonly
Returns the value of attribute parsed_response.
Instance Method Summary collapse
- #display ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ Reddit
constructor
A new instance of Reddit.
- #parse(data) ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize ⇒ Reddit
Returns a new instance of Reddit.
7 8 9 10 |
# File 'lib/topcats/reddit.rb', line 7 def initialize @endpoint_url = 'http://www.reddit.com/r/cats/top/.json?sort=top&t=day' self.get end |
Instance Attribute Details
#endpoint_url ⇒ Object (readonly)
Returns the value of attribute endpoint_url.
5 6 7 |
# File 'lib/topcats/reddit.rb', line 5 def endpoint_url @endpoint_url end |
#parsed_response ⇒ Object (readonly)
Returns the value of attribute parsed_response.
5 6 7 |
# File 'lib/topcats/reddit.rb', line 5 def parsed_response @parsed_response end |
Instance Method Details
#display ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/topcats/reddit.rb', line 25 def display <<-EOS Today's top cat post is: Title: #{top['title']} Author: #{top['author']} Link: #{top['url']} EOS end |
#get ⇒ Object
12 13 14 15 |
# File 'lib/topcats/reddit.rb', line 12 def get response = RestClient.get(endpoint_url) @parsed_response = self.parse(response) end |
#parse(data) ⇒ Object
17 18 19 |
# File 'lib/topcats/reddit.rb', line 17 def parse(data) JSON.parse(data) end |
#top ⇒ Object
21 22 23 |
# File 'lib/topcats/reddit.rb', line 21 def top parsed_response['data']['children'].first['data'] end |