Class: Popularity::RedditShare

Inherits:
Crawler
  • Object
show all
Includes:
ContainerMethods
Defined in:
lib/popularity/networks/reddit_share.rb

Instance Attribute Summary

Attributes inherited from Crawler

#url

Instance Method Summary collapse

Methods included from ContainerMethods

included

Methods inherited from Crawler

#as_json, #async_done?, #fetch, #fetch_async, #has_response?, #host, property_names, #response, #response_json, stats, #total, #valid?

Constructor Details

#initialize(*args) ⇒ RedditShare

Returns a new instance of RedditShare.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/popularity/networks/reddit_share.rb', line 6

def initialize(*args)
  super(*args)
  posts_json = response_json["data"]["children"]
  posts_json.each do |child|
    new_json = response_json.clone

    new_json["data"]["children"] = [child]
    url = "http://reddit.com#{child["data"]["permalink"]}"
    post = RedditResult.new(url, JSON.dump([new_json]))

    self.add_result(post)
  end

  self
end

Instance Method Details

#nameObject



26
27
28
# File 'lib/popularity/networks/reddit_share.rb', line 26

def name
  "reddit"
end

#postsObject



22
23
24
# File 'lib/popularity/networks/reddit_share.rb', line 22

def posts
  @results.size rescue 0
end

#request_urlObject



30
31
32
# File 'lib/popularity/networks/reddit_share.rb', line 30

def request_url
  "http://www.reddit.com/r/search/search.json?q=url:#{@url}"
end