Sha256: 35fe29c76868b76e9b54eb8a1e680b9f2c0f4b7a73c0f3807d9fadec994b5881

Contents?: true

Size: 771 Bytes

Versions: 5

Compression:

Stored size: 771 Bytes

Contents

require 'net/http'
require 'uri'
require 'benchmark'

module PRSS
  class Feed
    PERSONAL_FEED_URL = ENV.fetch('PRSS_FEED_URL') { 'https://hdbits.org/rss/my'.freeze }

    attr_reader :uri

    def initialize(passkey)
      #@passkey = passkey
      @uri = URI(PERSONAL_FEED_URL)
      @uri.query = "passkey=#{passkey}"
      @uri.freeze
    end

    def response
      response = nil
      time = Benchmark.realtime do
        response = Net::HTTP.get(@uri)
      end

      puts "Fetched #{@uri} in #{time.round(2)}s"
      response
    end

    def output
      response
    end

    def links
      Links.new(output)
    end

    def download_to(output)
      downloader.download_to(output)
    end

    def downloader
      Downloader.new(links)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
prss-0.2.4 lib/prss/feed.rb
prss-0.2.3 lib/prss/feed.rb
prss-0.2.2 lib/prss/feed.rb
prss-0.2.1 lib/prss/feed.rb
prss-0.2.0 lib/prss/feed.rb