Sha256: 78646d0c6d01cfb901d4fff526c1c482eaa49e552e28fb96c4d3af84fcb59e7e

Contents?: true

Size: 922 Bytes

Versions: 3

Compression:

Stored size: 922 Bytes

Contents

module Popularity
  class Soundcloud < Crawler
    def plays
      response.scan(/\"soundcloud:play_count\" content=\"([0-9]*)\"/).flatten.first.to_f.to_i
    end

    def likes
      response.scan(/\"soundcloud:like_count\" content=\"([0-9]*)\"/).flatten.first.to_f.to_i
    end

    def comments
      response.scan(/\"soundcloud:comments_count\" content=\"([0-9]*)\"/).flatten.first.to_f.to_i
    end

    def downloads
      response.scan(/\"soundcloud:download_count\" content=\"([0-9]*)\"/).flatten.first.to_f.to_i
    end

    def as_json(options = {})      
      {"plays" => plays,
       "likes" => likes,
       "comments" => comments,
       "downloads" => downloads }
    end

    def total
      plays + likes + downloads + comments
    end

    def valid?
      host == 'soundcloud.com'
    end

    protected

    def response_json
      #not json!
    end

    def request_url
      @url
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
popularity-0.1.1 lib/popularity/networks/soundcloud.rb
popularity-0.1.0 lib/popularity/networks/soundcloud.rb
popularity-0.0.1 lib/popularity/soundcloud.rb