parliament-utils 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2504e7de24d05b087cf9ea9bf3cde72ec598da85
4
- data.tar.gz: 627a166006535486f8df00678e78b119a6bc5f37
3
+ metadata.gz: 0cb432daa9677919ecd34cd9775baa536dff7e18
4
+ data.tar.gz: d34c734e9ec1af9840100f1abac03d55b5a54fcd
5
5
  SHA512:
6
- metadata.gz: a601b2ed3fc5e6dbba9850883dc3d7e92db360fd29084da22140151d5663da7b20bafb6215c6acbb42534cc94b6c558f8e0ad6a5601afa670e97432990e38b1d
7
- data.tar.gz: f55cb7ff4855549cd59eaeba9f810f2babc547677cba9d8fc5ecc0588e2308472aff3ac356e8e05f54b6cb988e08d1447c8ac8f8288d7638c9438b61359b52e5
6
+ metadata.gz: c441f4bca5f06c89e9a79cf47cda7f08860fd15386637a637a5a8231d1827d825edcdef9562ef1c2dba6aab5a3d9415c89dcc04b88a49e5f7a10b9187cd40e05
7
+ data.tar.gz: 4843f4ba860cd812f84eafa6a71dc9099598b727bd5b112014c83fa415209f70383885acaeab299e3af605b6e77b49c3a4f656c7e1bdf0f2f7315555aa9d898d
@@ -14,6 +14,7 @@ module Parliament
14
14
  # If they are, transparently redirect them with a '302: Found' status code
15
15
  def data_check
16
16
  # Check format to see if it is available from the data API
17
+ # We DO NOT offer data formats for constituency maps
17
18
  return if !Parliament::Utils::Helpers::FormatHelper::DATA_FORMATS.include?(request.formats.first) || (params[:controller] == 'constituencies' && params[:action] == 'map')
18
19
 
19
20
  # Find the current controller/action's API url
@@ -23,13 +24,13 @@ module Parliament
23
24
  raise StandardError, 'Data URL does not exist' if @data_url.nil?
24
25
 
25
26
  response.headers['Accept'] = request.formats.first
26
- # Store format_type if format in url is json or xml
27
- request.path_parameters[:format] == 'json' || request.path_parameters[:format] == 'xml' ? format_type = request.path_parameters[:format] : format_type = nil
27
+ # Get the file extension for a given type
28
+ format_type = Parliament::Utils::Helpers::FormatHelper::DATA_FORMATS[request.formats.first]
29
+
28
30
  # Set redirect_url as URI object
29
31
  redirect_url = URI(@data_url.call(params).query_url)
30
- # add format_type to path if format in url is json or xml
31
- redirect_url.path = redirect_url.path + '.' + format_type if format_type
32
- redirect_to(redirect_url.to_s) && return
32
+ redirect_url.path += ".#{format_type}"
33
+ return redirect_to(redirect_url.to_s)
33
34
  end
34
35
 
35
36
  # Get the data URL for our current controller and action OR raise a StandardError
@@ -55,7 +56,12 @@ module Parliament
55
56
  alternates = []
56
57
 
57
58
  Parliament::Utils::Helpers::FormatHelper::DATA_FORMATS.each do |format|
58
- alternates << { type: format, href: url }
59
+ uri = URI.parse(url)
60
+
61
+ uri_form = URI.decode_www_form(String(uri.query)) << ['format',format]
62
+
63
+ uri.query = URI.encode_www_form(uri_form)
64
+ alternates << { type: format, href: uri.to_s }
59
65
  end
60
66
 
61
67
  Pugin.alternates = alternates
@@ -2,16 +2,21 @@ module Parliament
2
2
  module Utils
3
3
  module Helpers
4
4
  module FormatHelper
5
- DATA_FORMATS = ['text/csv',
6
- 'text/vnd.graphviz',
7
- 'text/n3',
8
- 'application/json',
9
- 'application/n-triples',
10
- 'application/rdf+xml',
11
- 'application/rdf+json',
12
- 'application/xml',
13
- 'text/tab-separated-values',
14
- 'text/turtle'].freeze
5
+ DATA_FORMATS = %w(
6
+ application/n-triples
7
+ text/turtle
8
+ text/n3
9
+ application/n-quads
10
+ application/x-trig
11
+ application/trix
12
+ application/sparql-results+xml
13
+ application/sparql-results+json
14
+ application/rdf+xml
15
+ application/json
16
+ text/csv
17
+ text/tab-separated-values
18
+ text/vnd.graphviz
19
+ ).freeze
15
20
  end
16
21
  end
17
22
  end
@@ -1,7 +1,7 @@
1
1
  require_relative './test_helpers/rails_helper' if defined?(::Rails)
2
2
  require_relative './test_helpers/rspec_helper'
3
3
  require_relative './test_helpers/simplecov_helper'
4
- require_relative './test_helpers/vcr_helper' if defined?(::VCR) || ENV['RUN_VCR_IN_GEM']
4
+ require_relative './test_helpers/vcr_helper'
5
5
  require_relative './test_helpers/webmock_helper'
6
6
  require_relative './test_helpers/bandiera_helper'
7
7
 
@@ -11,7 +11,7 @@ module Parliament
11
11
  include Parliament::Utils::TestHelpers::RailsHelper if defined?(::Rails)
12
12
  include Parliament::Utils::TestHelpers::RSpecHelper
13
13
  include Parliament::Utils::TestHelpers::SimpleCovHelper
14
- include Parliament::Utils::TestHelpers::VCRHelper if defined?(::VCR) || ENV['RUN_VCR_IN_GEM']
14
+ include Parliament::Utils::TestHelpers::VCRHelper
15
15
  include Parliament::Utils::TestHelpers::WebmockHelper
16
16
  include Parliament::Utils::TestHelpers::BandieraHelper
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Parliament
2
2
  module Utils
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.3.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parliament-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rebecca Appleyard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parliament-ruby