-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We fetch the most recent episodes from both the Giant Robots and Bike Shed feeds, then list them in the README. The two feeds are combined in order, so it appears like there's one list even though it comes from different sources.
- Loading branch information
1 parent
5d5c862
commit ea4937d
Showing
9 changed files
with
243,461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "rss_feed" | ||
|
||
class CombinedRssFeed | ||
include Enumerable | ||
|
||
def initialize(feed_urls:) | ||
@rss_feeds = feed_urls.map { |url| RssFeed.new(url: url) } | ||
end | ||
|
||
def each | ||
rss_feeds | ||
.map(&:entries) | ||
.flatten | ||
.compact | ||
.sort_by(&:created_at) | ||
.reverse! | ||
.each { |entry| yield entry } | ||
end | ||
|
||
private | ||
|
||
attr_reader :rss_feeds | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
require "excon" | ||
require "feedjira" | ||
|
||
require "feed_item" | ||
|
||
class RssFeed | ||
include Enumerable | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "spec_helper" | ||
require "combined_rss_feed" | ||
|
||
RSpec.describe CombinedRssFeed do | ||
it "combines a given set of feeds into an ordered list by most recent" do | ||
Excon.stub( | ||
{host: "podcast.thoughtbot.com"}, | ||
{status: 200, body: giant_robots_feed} | ||
) | ||
Excon.stub( | ||
{host: "bikeshed.thoughtbot.com"}, | ||
{status: 200, body: bike_shed_feed} | ||
) | ||
|
||
combined_items = described_class.new( | ||
feed_urls: [ | ||
"https://podcast.thoughtbot.com/rss", | ||
"https://bikeshed.thoughtbot.com/rss" | ||
] | ||
) | ||
recent = combined_items.take(3) | ||
|
||
expect(recent).to include( | ||
have_attributes( | ||
title: "451: Making Time for and Managing Focus", | ||
url: "https://bikeshed.thoughtbot.com/451", | ||
created_at: match_date(Date.new(2024, 12, 17)) | ||
), | ||
have_attributes( | ||
title: "450: Javascript-Driven Development?", | ||
url: "https://bikeshed.thoughtbot.com/450", | ||
created_at: match_date(Date.new(2024, 12, 10)) | ||
), | ||
have_attributes( | ||
title: "553: The One with Sami and Chad", | ||
url: "https://podcast.thoughtbot.com/553", | ||
created_at: match_date(Date.new(2024, 12, 5)) | ||
) | ||
) | ||
end | ||
|
||
def giant_robots_feed | ||
File.read("spec/fixtures/giant_robots_feed.xml") | ||
end | ||
|
||
def bike_shed_feed | ||
File.read("spec/fixtures/bike_shed_feed.xml") | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters