parliament-utils 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0cb432daa9677919ecd34cd9775baa536dff7e18
|
|
4
|
+
data.tar.gz: d34c734e9ec1af9840100f1abac03d55b5a54fcd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
#
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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 =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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'
|
|
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
|
|
14
|
+
include Parliament::Utils::TestHelpers::VCRHelper
|
|
15
15
|
include Parliament::Utils::TestHelpers::WebmockHelper
|
|
16
16
|
include Parliament::Utils::TestHelpers::BandieraHelper
|
|
17
17
|
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.
|
|
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-
|
|
11
|
+
date: 2017-10-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: parliament-ruby
|