Browse Source

only add itunes icon if ns_itunes

Shaya G 7 years ago
parent
commit
5e1e5a1907

+ 7 - 1
app/models/agents/data_output_agent.rb

@@ -163,6 +163,12 @@ module Agents
       interpolated['template']['icon'].presence || feed_link + '/favicon.ico'
     end
 
+    def itunes_icon
+      if(boolify(interpolated['ns_itunes']))
+        "<itunes:image href=#{feed_icon.encode(xml: :attr)} />"
+      end  
+    end
+
     def feed_description
       interpolated['template']['description'].presence || "A feed of Events received by the '#{name}' Huginn Agent"
     end
@@ -295,8 +301,8 @@ module Agents
 <channel>
  <atom:link href=#{feed_url(secret: params['secret'], format: :xml).encode(xml: :attr)} rel="self" type="application/rss+xml" />
  <atom:icon>#{feed_icon.encode(xml: :text)}</atom:icon>
+ #{itunes_icon}
 #{hub_links}
- <itunes:image href=#{feed_icon.encode(xml: :attr)} />
  <title>#{feed_title.encode(xml: :text)}</title>
  <description>#{feed_description.encode(xml: :text)}</description>
  <link>#{feed_link.encode(xml: :text)}</link>

+ 4 - 4
spec/models/agents/data_output_agent_spec.rb

@@ -161,7 +161,6 @@ describe Agents::DataOutputAgent do
           <channel>
            <atom:link href="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
            <atom:icon>https://yoursite.com/favicon.ico</atom:icon>
-           <itunes:image href="https://yoursite.com/favicon.ico" />
            <title>XKCD comics as a feed</title>
            <description>This is a feed of recent XKCD comics, generated by Huginn</description>
            <link>https://yoursite.com</link>
@@ -467,10 +466,11 @@ describe Agents::DataOutputAgent do
           content, status, content_type = agent.receive_web_request({ 'secret' => 'secret1' }, 'get', 'text/xml')
           expect(status).to eq(200)
           expect(content_type).to eq('application/rss+xml')
-
+          
           doc = Nokogiri(content)
           namespaces = doc.collect_namespaces
           expect(namespaces).not_to include("xmlns:itunes")
+          expect(doc.at("/rss/channel/*[local-name()='itunes:image']")).to be_nil
         end
       end
 
@@ -485,12 +485,13 @@ describe Agents::DataOutputAgent do
           content, status, content_type = agent.receive_web_request({ 'secret' => 'secret1' }, 'get', 'text/xml')
           expect(status).to eq(200)
           expect(content_type).to eq('application/rss+xml')
-
+          
           doc = Nokogiri(content)
           namespaces = doc.collect_namespaces
           expect(namespaces).to include(
             "xmlns:itunes" => 'http://www.itunes.com/dtds/podcast-1.0.dtd'
           )
+          expect(doc.at('/rss/channel/itunes:image').attr('href')).to eq('https://yoursite.com/favicon.ico')          
         end
       end
 
@@ -615,7 +616,6 @@ describe Agents::DataOutputAgent do
           <channel>
            <atom:link href="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
            <atom:icon>https://yoursite.com/favicon.ico</atom:icon>
-           <itunes:image href="https://yoursite.com/favicon.ico" />
            <title>XKCD comics as a feed</title>
            <description>This is a feed of recent XKCD comics, generated by Huginn</description>
            <link>https://yoursite.com</link>