Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recent podcast episodes #3

Open
wants to merge 1 commit into
base: show-recent-blog-posts
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bin/update_readme
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ require "github_readme"

readme = Readme.new("profile/README.md")
blog = RssFeed.new(url: "https://feeds.feedburner.com/GiantRobotsSmashingIntoOtherGiantRobots")
podcasts = CombinedRssFeed.new(
feed_urls: [
"https://podcast.thoughtbot.com/rss",
"https://bikeshed.thoughtbot.com/rss"
]
)

readme.update(section: "blog", items: blog.take(5))
readme.update(section: "podcasts", items: podcasts.take(5))
23 changes: 23 additions & 0 deletions lib/combined_rss_feed.rb
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
3 changes: 3 additions & 0 deletions lib/github_readme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

require "feed_item"
require "rss_feed"
require "combined_rss_feed"
require "readme"

Excon.defaults[:middlewares].push(Excon::Middleware::RedirectFollower)
2 changes: 2 additions & 0 deletions lib/rss_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require "excon"
require "feedjira"

require "feed_item"

class RssFeed
include Enumerable

Expand Down
19 changes: 19 additions & 0 deletions profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ for your business each step of the way. Since 2003, we have worked to produce
higher-quality products while improving team processes and have done so
successfully for over [1,000 clients.][case studies]

<table><tr><td valign="top" width="50%">

### Podcasts

<!-- podcasts starts -->
[554: Founding a Life Saving Business from your dorm room with Luká Yancopoulos](https://podcast.thoughtbot.com/554)

[451: Making Time for and Managing Focus](https://bikeshed.thoughtbot.com/451)

[450: Javascript-Driven Development?](https://bikeshed.thoughtbot.com/450)

[553: The One with Sami and Chad](https://podcast.thoughtbot.com/553)

[449: Evergreen skills for new-ish developers](https://bikeshed.thoughtbot.com/449)

<!-- podcasts ends -->
</td><td valign="top" width="50%">

### Writing

<!-- blog starts -->
Expand All @@ -26,6 +44,7 @@ successfully for over [1,000 clients.][case studies]
[Testing SQL queries in a Ruby service](https://thoughtbot.com/blog/testing-sql-queries-in-a-ruby-service)

<!-- blog ends -->
</td></tr></table>

[thoughtbot]: https://thoughtbot.com
[design]: https://thoughtbot.com/services/product-design
Expand Down
49 changes: 49 additions & 0 deletions spec/combined_rss_feed_spec.rb
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
114,837 changes: 114,837 additions & 0 deletions spec/fixtures/bike_shed_feed.xml

Large diffs are not rendered by default.

128,515 changes: 128,515 additions & 0 deletions spec/fixtures/giant_robots_feed.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
Excon.stubs.clear
end
end

RSpec::Matchers.define :match_date do |expected|
match do |actual|
expect(expected.strftime("%d-%m-%Y")).to eq(actual.strftime("%d-%m-%Y"))
end
end
Loading