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 atom feeds to travel advice #257

Merged
merged 5 commits into from
Mar 3, 2017
Merged

Add atom feeds to travel advice #257

merged 5 commits into from
Mar 3, 2017

Conversation

fofr
Copy link
Contributor

@fofr fofr commented Feb 24, 2017

https://trello.com/c/mNRwOtHL/139-2-render-travel-advice-atom-feeds-in-government-frontend-m

Render atom feeds for travel advice countries. Output of atom feed is identical to multipage-frontend’s (and live). Template and tests ported from multipage-frontend.

When reviewing please double-check the routing logic and tests

Add support for rendering atom routes:

  • Update routing to allow atom format
  • Use a regex to constrain matches on locale and format
  • Test that all supported locales work with regex
  • Append the locale when matched to the content_item_path
  • Return 406 when unacceptable format requested

Paired with @andrewgarner

Example feed:
Matches: https://www.gov.uk/foreign-travel-advice/thailand.atom

<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>https://www.gov.uk/foreign-travel-advice/thailand</id>
  <link rel="alternate" type="text/html" href="https://www.gov.uk/foreign-travel-advice/thailand"/>
  <link rel="self" type="application/atom+xml" href="http://government-frontend.dev.gov.uk/foreign-travel-advice/thailand.atom"/>
  <title>Travel Advice Summary</title>
  <updated>2017-02-08T10:23:34+00:00</updated>
  <author>
    <name>GOV.UK</name>
  </author>
  <entry>
    <id>https://www.gov.uk/foreign-travel-advice/thailand#2017-02-08T10:23:34+00:00</id>
    <updated>2017-02-08T10:23:34+00:00</updated>
    <link rel="alternate" type="text/html" href="https://www.gov.uk/foreign-travel-advice/thailand"/>
    <title>Thailand travel advice</title>
    <link rel="self" type="application/atom+xml" href="https://www.gov.uk/foreign-travel-advice/thailand.atom"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Latest update: Summary – updated guidance for visitors following the passing of His Majesty King Bhumibol Adulyadej
</p>      </div>
    </summary>
  </entry>
</feed>

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 February 24, 2017 17:45 Inactive
@fofr fofr force-pushed the travel-advice-atom branch from 21430ce to ba4a046 Compare February 24, 2017 17:46
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 February 24, 2017 17:46 Inactive
get '*path(.:locale)(.:format)' => 'content_items#show',
constraints: {
format: /atom/,
locale: /\w{2}(-[\d\w]{2,3})?/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex is gnarly for my simple monkey brain, should we have a few tests around this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a test: https://github.com/alphagov/government-frontend/pull/257/files#diff-7dd9638113bd162736166ccac21fae7cR25

It tests every supported locale against the regex. If we add a new locale that's not supported, the test will fail.

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 February 27, 2017 13:55 Inactive
# FIXME: Update when https://trello.com/c/w8HN3M4A/ is ready
get 'foreign-travel-advice/:country/:part' => 'travel_advice#show'

get '*path(.:locale)(.:format)' => 'content_items#show',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the only thing that constrains this route is that it's got an /atom/ and a valid locale.

What happens when you try to render something that is not a travel advice format? Does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns a 406: ba4a046 (ie not an accepted format)
If the templates were added, they would work.

@fofr fofr requested a review from gpeng February 27, 2017 22:09
Copy link
Contributor

@mcgoooo mcgoooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@@ -1,3 +1,5 @@
require 'htmlentities'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? I think bundler will require it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and rebased.

@fofr fofr force-pushed the travel-advice-atom branch from d34e48f to a867eff Compare March 2, 2017 12:50
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 March 2, 2017 12:50 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 March 2, 2017 13:00 Inactive
@fofr fofr force-pushed the travel-advice-atom branch from eefb0b9 to 3e8e5dd Compare March 2, 2017 13:05
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 March 2, 2017 13:05 Inactive
fofr added 5 commits March 3, 2017 09:24
* Update routing to allow atom format
* Use a regex to constrain matches on locale and format
* Test that all supported locales work with regex
* Append the locale when matched to the content_item_path

Paired with @andrewgarner
* Output of atom feed identical to multipage frontend (and live)
* Port template and tests from multipage frontend
* Use html entities gem to encode HTML entities for XML feed

Context: alphagov/multipage-frontend#6
Previously, calling a format without an atom feed via:
/government/consultations/postgraduate-doctoral-loans.atom

Would have 404’d. Now there is atom support this retrieves a content
item, but throws a “MissingTemplate” error when it comes to rendering.

Catch this error and return a “not acceptable” 406 response. eg The
target resource does not have a current representation that would be
acceptable to the user agent
* Matches multipage-frontend
* Allows supporting browsers to highlight when feeds are available for
content
* Makes country name method public for use with feed link
@fofr fofr force-pushed the travel-advice-atom branch from 3e8e5dd to 89990f8 Compare March 3, 2017 09:26
@fofr fofr merged commit 039651b into master Mar 3, 2017
@fofr fofr deleted the travel-advice-atom branch March 3, 2017 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants