gtfs_engine 1.3.0 → 1.4.0
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: 146717ee9ac8cc7dc0455271478b5d37986f8d81
|
4
|
+
data.tar.gz: 67be5776653dad9d7d4038f30fe49606f4843199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cb0dd5b1904e1c456fc83635c9ae94c9d8483956967dbb603f0822a3317921151853360d016e95e961c70170d2f7cb2a9f2d46f393d8871fbc06c25e5ddff0a
|
7
|
+
data.tar.gz: c965696b02274443d77454c6c75aceff13d6d478fed0f0afe8e28900f5872bc992b91c410b3d45a1d7614ada5e6419229700b0e41436dcb2cd89303c559214a0
|
data/lib/gtfs_engine/engine.rb
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
# The following line is required for jsend_wrapper/rails to be available when
|
17
17
|
# mounted in another rails application.
|
18
|
+
require 'gtfs_engine/middleware/json_parse_errors'
|
18
19
|
require 'jsend_wrapper/rails'
|
19
20
|
|
20
21
|
module GtfsEngine
|
@@ -29,5 +30,10 @@ module GtfsEngine
|
|
29
30
|
javascripts false
|
30
31
|
fixture_replacement :factory_girl, dir: 'spec/factories'
|
31
32
|
end
|
33
|
+
|
34
|
+
initializer 'gtfs_engine.middleware' do |app|
|
35
|
+
app.config.middleware.insert_before ActionDispatch::ParamsParser,
|
36
|
+
GtfsEngine::Middleware::JsonParseErrors
|
37
|
+
end
|
32
38
|
end
|
33
39
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This file is part of the KNOWtime server.
|
2
|
+
#
|
3
|
+
# The KNOWtime server is free software: you can redistribute it and/or modify it
|
4
|
+
# under the terms of the GNU General Public License as published by the Free
|
5
|
+
# Software Foundation, either version 3 of the License, or (at your option) any
|
6
|
+
# later version.
|
7
|
+
#
|
8
|
+
# The KNOWtime server is distributed in the hope that it will be useful, but
|
9
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
11
|
+
# details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
# The following line is required for jsend_wrapper/rails to be available when
|
17
|
+
# mounted in another rails application.
|
18
|
+
module GtfsEngine
|
19
|
+
module Middleware
|
20
|
+
class Base
|
21
|
+
attr_reader :app
|
22
|
+
|
23
|
+
HEADERS = { 'Content-Type' => 'application/json' }
|
24
|
+
|
25
|
+
def initialize(app)
|
26
|
+
@app = app
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def accepts_json?(env)
|
32
|
+
request = ActionDispatch::Request.new env
|
33
|
+
!!collector.negotiate_format(request)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def collector
|
39
|
+
@collector ||= ActionController::MimeResponds::Collector.new ['json']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This file is part of the KNOWtime server.
|
2
|
+
#
|
3
|
+
# The KNOWtime server is free software: you can redistribute it and/or modify it
|
4
|
+
# under the terms of the GNU General Public License as published by the Free
|
5
|
+
# Software Foundation, either version 3 of the License, or (at your option) any
|
6
|
+
# later version.
|
7
|
+
#
|
8
|
+
# The KNOWtime server is distributed in the hope that it will be useful, but
|
9
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
11
|
+
# details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
# The following line is required for jsend_wrapper/rails to be available when
|
17
|
+
# mounted in another rails application.
|
18
|
+
require 'gtfs_engine/middleware/base'
|
19
|
+
require 'jsend_wrapper/renderers/error_renderer'
|
20
|
+
|
21
|
+
module GtfsEngine
|
22
|
+
module Middleware
|
23
|
+
# Normally one handles exceptions with `rescue_from`; however, the body of
|
24
|
+
# the request is parsed before your controller gets involved, so we need to
|
25
|
+
# handle parse errors at the middleware-level.
|
26
|
+
#
|
27
|
+
# Rails has a built-in JSON response when such an error occurs, but this
|
28
|
+
# middleware will return an error message in JSend format.
|
29
|
+
class JsonParseErrors < Base
|
30
|
+
ERROR_CODE = 1001
|
31
|
+
MESSAGE = 'The body of your request is not valid JSON'
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
app.call env
|
35
|
+
|
36
|
+
rescue ActionDispatch::ParamsParser::ParseError => error
|
37
|
+
raise error unless accepts_json? env
|
38
|
+
|
39
|
+
[ 400, HEADERS, [create_json(error)] ]
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def create_json(cause)
|
45
|
+
JsendWrapper::ErrorRenderer.new(
|
46
|
+
MESSAGE, code: ERROR_CODE, data: cause.to_s
|
47
|
+
).to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/gtfs_engine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtfs_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Sangster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -228,6 +228,8 @@ files:
|
|
228
228
|
- lib/gtfs_engine/engine.rb
|
229
229
|
- lib/gtfs_engine/exceptions.rb
|
230
230
|
- lib/gtfs_engine/json_responder.rb
|
231
|
+
- lib/gtfs_engine/middleware/base.rb
|
232
|
+
- lib/gtfs_engine/middleware/json_parse_errors.rb
|
231
233
|
- lib/gtfs_engine/sources.rb
|
232
234
|
- lib/gtfs_engine/version.rb
|
233
235
|
- lib/tasks/gtfs_engine_tasks.rake
|