Class: Reddit

Inherits:
Object
  • Object
show all
Defined in:
lib/topcats/reddit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReddit

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_urlObject (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_responseObject (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

#displayObject



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

#getObject



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

#topObject



21
22
23
# File 'lib/topcats/reddit.rb', line 21

def top
  parsed_response['data']['children'].first['data']
end