Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Added flattr to the feed #17

Open
wants to merge 5 commits into
base: master
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
1 change: 1 addition & 0 deletions lib/gst-kitchen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "gst-kitchen/version"
require "gst-kitchen/podcast"
require "gst-kitchen/feed"
require "gst-kitchen/flattr"
require "gst-kitchen/chapter"
require "gst-kitchen/episode"
require "gst-kitchen/media"
Expand Down
4 changes: 4 additions & 0 deletions lib/gst-kitchen/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def rfc_2822_date
self.published_at.rfc2822
end

def flattr_auto_submit_link
Flattr.auto_submit_link(podcast, podcast.deep_link_url(self), self.name, self.subtitle)
end

def duration
hours = length / (60 * 60)
minutes = (length - hours * 60 * 60) / 60
Expand Down
12 changes: 12 additions & 0 deletions lib/gst-kitchen/flattr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Flattr
def Flattr.auto_submit_link(podcast, url, title, description)
"https://flattr.com/submit/auto" +
"?user_id=#{podcast.flattr["user_id"]}" +
"&url=#{CGI.escape url}" +
"&title=#{CGI.escape title}" +
"&description=#{CGI.escape description}" +
"&language=#{podcast.flattr["language"]}" +
"&tags=#{podcast.flattr["tags"].join(',')}" +
"&category=#{podcast.flattr["category"]}"
end
end
8 changes: 7 additions & 1 deletion lib/gst-kitchen/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Podcast
:episodes,
:explicit,
:rss_output_path,
:episodes_path
:episodes_path,
:flattr

attr_accessor :formats

Expand All @@ -29,6 +30,7 @@ def self.from_yaml(yaml_file="podcast.yml")
podcast.handle = hash["handle"]
podcast.website = hash["website"]
podcast.cover = hash["cover"]
podcast.flattr = hash["flattr"]
podcast.media_url = hash["media_url"]
podcast.explicit = hash["explicit"] || false
podcast.formats = hash["formats"].map { |format| Media.format(format) }
Expand Down Expand Up @@ -80,6 +82,10 @@ def deep_link_url(episode)
url.to_s
end

def flattr_auto_submit_link
Flattr.auto_submit_link(self, self.website, self.title, self.subtitle)
end

def podcast
self
end
Expand Down
15 changes: 14 additions & 1 deletion spec/episode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
end
end


it "should have a handle" do
podcast = double("podcast")
podcast.stub(:handle).and_return("GST")
Expand All @@ -61,6 +60,20 @@
subject.handle.should == "GST042"
end

it "should generate flattr urls" do
podcast = double("podcast")
podcast.stub(:flattr).and_return({"user_id" => "gst-podcast", "language" => "de_DE", "tags" => %w(geek stammtisch podcast), "category" => "audio"})
podcast.stub(:deep_link_url) { "http://geekstammtisch.de/#GST001" }

subject.podcast = podcast
subject.name = "GST001 - Meine Tolle Folge"
subject.subtitle = "Eine tolle Folge mit viel Blafasel"

Flattr.should_receive(:auto_submit_link).with(podcast, "http://geekstammtisch.de/#GST001", "GST001 - Meine Tolle Folge", "Eine tolle Folge mit viel Blafasel")

subject.flattr_auto_submit_link
end

it "should have a title" do
podcast = double("podcast")
podcast.stub(:handle).and_return("GST")
Expand Down
11 changes: 11 additions & 0 deletions spec/flattr_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "spec_helper"

describe Flattr do
it "creates a valid flattr auto submit url" do
podcast = double("podcast")
podcast.stub(:flattr).and_return({"user_id" => "gst-podcast", "language" => "de_DE", "tags" => %w(geek stammtisch podcast), "category" => "audio"})
expected_url = "https://flattr.com/submit/auto?user_id=gst-podcast&url=http%3A%2F%2Fwww.test.de&title=Some+random+Title&description=Some+very+random+description&language=de_DE&tags=geek,stammtisch,podcast&category=audio"

Flattr.auto_submit_link(podcast, "http://www.test.de", "Some random Title", "Some very random description").should == expected_url
end
end
2 changes: 2 additions & 0 deletions templates/episodes.rss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<% @podcast.other_formats(@format).each do |format| %>
<atom:link rel="alternate" href="<%= @podcast.feed_url(format) %>" type="application/rss+xml" title="<%= format.file_ext.upcase %> Audio"/>
<% end %>
<atom:link rel="payment" href="<%= @podcast.flattr_auto_submit_link%>" />
<language><%= @podcast.language %></language>
<generator>gst-kitchen</generator>
<copyright><%= @podcast.author %>, cc-by-nc-sa</copyright>
Expand Down Expand Up @@ -44,6 +45,7 @@
<itunes:summary><![CDATA[<%= episode.summary %>]]></itunes:summary>
<description><![CDATA[<%= render_as_markdown episode.summary %>]]></description>
<atom:link rel="http://podlove.org/deep-link" href="<%= @podcast.deep_link_url(episode) %>" />
<atom:link rel="payment" href="<%= episode.flattr_auto_submit_link%>" />

<% unless episode.chapters.nil? %>
<psc:chapters>
Expand Down