@@ -92,6 +92,14 @@ module Agents |
||
| 92 | 92 |
interpolated['template']['link'].presence || "https://#{ENV['DOMAIN']}"
|
| 93 | 93 |
end |
| 94 | 94 |
|
| 95 |
+ def feed_url(options = {})
|
|
| 96 |
+ feed_link + Rails.application.routes.url_helpers. |
|
| 97 |
+ web_requests_path(agent_id: id || '<id>', |
|
| 98 |
+ user_id: user_id, |
|
| 99 |
+ secret: options[:secret], |
|
| 100 |
+ format: options[:format]) |
|
| 101 |
+ end |
|
| 102 |
+ |
|
| 95 | 103 |
def feed_description |
| 96 | 104 |
interpolated['template']['description'].presence || "A feed of Events received by the '#{name}' Huginn Agent"
|
| 97 | 105 |
end |
@@ -100,7 +108,7 @@ module Agents |
||
| 100 | 108 |
if interpolated['secrets'].include?(params['secret']) |
| 101 | 109 |
items = received_events.order('id desc').limit(events_to_show).map do |event|
|
| 102 | 110 |
interpolated = interpolate_options(options['template']['item'], event) |
| 103 |
- interpolated['guid'] = {'_attributes' => {'isPermaLink' => 'false'},
|
|
| 111 |
+ interpolated['guid'] = {'_attributes' => {'isPermaLink' => 'false'},
|
|
| 104 | 112 |
'_contents' => interpolated['guid'].presence || event.id} |
| 105 | 113 |
date_string = interpolated['pubDate'].to_s |
| 106 | 114 |
date = |
@@ -128,12 +136,12 @@ module Agents |
||
| 128 | 136 |
<?xml version="1.0" encoding="UTF-8" ?> |
| 129 | 137 |
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
| 130 | 138 |
<channel> |
| 131 |
- <atom:link href="#{feed_link.encode(:xml => :text)}/users/#{user.id}/web_requests/#{id || '<id>'}/#{params['secret']}.xml" rel="self" type="application/rss+xml" />
|
|
| 132 |
- <title>#{feed_title.encode(:xml => :text)}</title>
|
|
| 133 |
- <description>#{feed_description.encode(:xml => :text)}</description>
|
|
| 134 |
- <link>#{feed_link.encode(:xml => :text)}</link>
|
|
| 135 |
- <lastBuildDate>#{Time.now.rfc2822.to_s.encode(:xml => :text)}</lastBuildDate>
|
|
| 136 |
- <pubDate>#{Time.now.rfc2822.to_s.encode(:xml => :text)}</pubDate>
|
|
| 139 |
+ <atom:link href=#{feed_url(secret: params['secret'], format: :xml).encode(xml: :attr)} rel="self" type="application/rss+xml" />
|
|
| 140 |
+ <title>#{feed_title.encode(xml: :text)}</title>
|
|
| 141 |
+ <description>#{feed_description.encode(xml: :text)}</description>
|
|
| 142 |
+ <link>#{feed_link.encode(xml: :text)}</link>
|
|
| 143 |
+ <lastBuildDate>#{Time.now.rfc2822.to_s.encode(xml: :text)}</lastBuildDate>
|
|
| 144 |
+ <pubDate>#{Time.now.rfc2822.to_s.encode(xml: :text)}</pubDate>
|
|
| 137 | 145 |
<ttl>#{feed_ttl}</ttl>
|
| 138 | 146 |
|
| 139 | 147 |
XML |
@@ -149,7 +157,7 @@ module Agents |
||
| 149 | 157 |
end |
| 150 | 158 |
else |
| 151 | 159 |
if format =~ /json/ |
| 152 |
- return [{ :error => "Not Authorized" }, 401]
|
|
| 160 |
+ return [{ error: "Not Authorized" }, 401]
|
|
| 153 | 161 |
else |
| 154 | 162 |
return ["Not Authorized", 401] |
| 155 | 163 |
end |
@@ -119,7 +119,7 @@ describe Agents::DataOutputAgent do |
||
| 119 | 119 |
<?xml version="1.0" encoding="UTF-8" ?> |
| 120 | 120 |
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
| 121 | 121 |
<channel> |
| 122 |
- <atom:linkhref="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
|
|
| 122 |
+ <atom:link href="https://yoursite.com/users/#{agent.user.id}/web_requests/#{agent.id}/secret1.xml" rel="self" type="application/rss+xml"/>
|
|
| 123 | 123 |
<title>XKCD comics as a feed</title> |
| 124 | 124 |
<description>This is a feed of recent XKCD comics, generated by Huginn</description> |
| 125 | 125 |
<link>https://yoursite.com</link> |