Sha256: 9853373466aaf38df1a54b5923b08213f058152d09ed987f0ce5f763da7f7f23

Contents?: true

Size: 770 Bytes

Versions: 2

Compression:

Stored size: 770 Bytes

Contents

module Popularity
  class RedditPost < Crawler
    def score
      begin
        response_json[0]["data"]["children"][0]["data"]["score"] 
      rescue
        0
      end
    end

    def comments
      begin
        response_json[0]["data"]["children"][0]["data"]["num_comments"] 
      rescue
        0
      end
    end

    def as_json(options = {})      
      {
        "comments" => comments,
        "score" => score
      }
    end

    def total
      comments + score
    end

    def valid?
      return false unless host == 'reddit.com'
      
      path = URI.parse(@url).path
      path.split('/').delete_if { |a| a.empty? }.size < 6
    end

    def name
      "reddit"
    end

    protected

    def request_url
      "#{@url}.json"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
popularity-0.1.0 lib/popularity/networks/reddit_post.rb
popularity-0.0.1 lib/popularity/reddit_post.rb