gtfs_engine 1.2.0 → 1.3.0

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: 6e84da8bed1f68352eaf059a895bd270f31e7d0a
4
- data.tar.gz: 2f5e288cfce8186cc9e54ec22d664ff972866c65
3
+ metadata.gz: 41bacc2ca460c53a0d6bfab8dad6a6accba8d24d
4
+ data.tar.gz: 92aad173090d8dd6105e35e1e40d9603e197d5ea
5
5
  SHA512:
6
- metadata.gz: c98750840af8e9d732371abfb185f3fd9b5c036c503cccb95975ec4e0c4f9b1be063b9647d3b345c52ba3edcb318beb53833201661e43aa986b42b1d00b8cc54
7
- data.tar.gz: def1c054d81f293665ec81b1afd38f2a4d42562092e7df5461aed213355172e2c9fc2a70b931acca02cb432009533459d6e4508d218d2f4a5d12ff1b1ee83fa5
6
+ metadata.gz: a7ee299a9408d4d277c9006cf08d1184d98c1e81e4a7fb16127bb5b9b639e4256bf3da6f88a2abd6f6431f068a9b711d9162443a5a6e86463b7da819a9c1a7d8
7
+ data.tar.gz: 30b80c487979031d30a18af1ab036f5f2fd0cd85fcb4a447df21d9aae97a65a8fa154a6809c37287562a063f138451d63741b3430de6a97cd0478e82814b2d81
@@ -17,21 +17,15 @@ module GtfsEngine
17
17
  def index(json, records)
18
18
  json.cache! [controller_name, filter] do
19
19
  json.ignore_nil! true
20
-
21
- json.status 'success'
22
- json.data do
23
- json.array!(records) {|record| json.extract! record, *fields }
24
- end
20
+ json.array!(records) {|record| json.extract! record, *fields }
25
21
  end
26
22
  end
27
23
 
24
+
28
25
  def show(json, record)
29
26
  json.cache! record do
30
27
  json.ignore_nil! true
31
- json.status 'success'
32
- json.data do
33
- json.extract! record, *fields
34
- end
28
+ json.extract! record, *fields
35
29
  end
36
30
  end
37
31
  end
@@ -12,8 +12,11 @@
12
12
  #
13
13
  # You should have received a copy of the GNU General Public License
14
14
  # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
- json.status 'success'
16
- json.data do
17
- json.extract! @data_set, *%i(id name title url etag created_at)
18
- json.details @data_set.details
15
+ json.ignore_nil! true
16
+ @data_sets.each do |name, sets|
17
+ json.set! name do
18
+ json.array! sets do |set|
19
+ json.extract! set, *%i(id name title url etag created_at)
20
+ end
21
+ end
19
22
  end
@@ -0,0 +1,16 @@
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
+ json.extract! @data_set, *%i(id name title url etag created_at)
16
+ json.details @data_set.details
@@ -1,8 +1,24 @@
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
+
1
16
  # A Controller +Concern+ for convenient access to the +DataSet+ specified in
2
17
  # the URL.
3
18
  module GtfsEngine::Concerns::Controllers::DataAccess
4
19
  extend ActiveSupport::Concern
5
20
 
21
+
6
22
  #@param param_key <Symbol> The key of the URL param to use as the feed's ID
7
23
  #@return <DataSet>
8
24
  def data(param_key=:data_set_id)
@@ -17,12 +33,12 @@ module GtfsEngine::Concerns::Controllers::DataAccess
17
33
  end
18
34
  end
19
35
 
36
+
20
37
  def data_cache(key)
21
- Rails.cache.fetch "#{data.id}::#{key}" do
22
- yield
23
- end
38
+ Rails.cache.fetch("#{data.id}::#{key}") { yield }
24
39
  end
25
40
 
41
+
26
42
  #@return <Bool> +true+ if the key is the name of the GTFS feed,
27
43
  # instead of its ID
28
44
  def param_is_data_set_name?(param_key)
@@ -18,6 +18,7 @@
18
18
  module GtfsEngine::Concerns::Controllers::Gtfs
19
19
  extend ActiveSupport::Concern
20
20
 
21
+
21
22
  included do
22
23
  around_filter :gtfs_cache, only: [:index, :show]
23
24
 
@@ -35,12 +36,14 @@ module GtfsEngine::Concerns::Controllers::Gtfs
35
36
  @gtfs_id or controller_name.singularize.foreign_key
36
37
  end
37
38
 
39
+
38
40
  def filters(*attrs)
39
41
  attrs.flatten!
40
42
  @filters = attrs unless attrs.empty?
41
43
  @filters ||= []
42
44
  end
43
45
 
46
+
44
47
  #@return [Class] the +ActiveRecord::Base+ class associated with this
45
48
  # controller
46
49
  def record_class
@@ -58,12 +61,14 @@ module GtfsEngine::Concerns::Controllers::Gtfs
58
61
  respond_with @records, template: 'gtfs_engine/gtfs/index'
59
62
  end
60
63
 
64
+
61
65
  # GET /:id for a specific element of the given GTFS type
62
66
  def show
63
67
  @record = record
64
68
  respond_with @record, template: 'gtfs_engine/gtfs/show'
65
69
  end
66
70
 
71
+
67
72
  #@return <ActionController::Parameters> the map of fields to filter;
68
73
  # derived from the query string
69
74
  def filter
@@ -73,8 +78,7 @@ module GtfsEngine::Concerns::Controllers::Gtfs
73
78
  query[q] = true if v.blank? # blank value indicates boolean filter
74
79
  filters.include?(q.to_sym) ? nil : q
75
80
  end.compact
76
- require 'pry'
77
- binding.pry
81
+
78
82
  unless unknown.empty?
79
83
  raise GtfsEngine::UnknownFilters.new(unknown), 'unknown filter'
80
84
  end
@@ -83,39 +87,48 @@ require 'pry'
83
87
  end
84
88
  end
85
89
 
90
+
86
91
  protected
87
92
 
93
+
88
94
  #@return [ActiveRecord::Relation] all the records in this GTFS association
89
95
  def collection
90
96
  data.send controller_name
91
97
  end
92
98
 
99
+
93
100
  #@return [ActiveRecord::Relation] all the records in this GTFS
94
101
  # association that match the filter specified in the query string
95
102
  def filtered_collection
96
103
  collection.where filter
97
104
  end
98
105
 
106
+
99
107
  #@return [ActiveRecord::Base] the record identified by +params[:id]+ in this
100
108
  # GTFS association
101
109
  def record
102
110
  collection.find_by! gtfs_id => params[:id]
103
111
  end
104
112
 
113
+
105
114
  def gtfs_id
106
115
  self.class.gtfs_id
107
116
  end
108
117
 
118
+
109
119
  def filters
110
120
  self.class.filters
111
121
  end
112
122
 
123
+
113
124
  def query
114
125
  request.query_parameters
115
126
  end
116
127
 
128
+
117
129
  private
118
130
 
131
+
119
132
  def format
120
133
  request.format.to_sym
121
134
  end
@@ -131,28 +144,34 @@ require 'pry'
131
144
  yield if stale? options
132
145
  end
133
146
 
147
+
134
148
  #@param ex [GtfsEngine::UnknownFilter]
135
149
  def unknown_filter(ex)
136
- json = {status: 'fail', data: ex.to_hash}
137
- render status: :bad_request, format => json
150
+ render status: :bad_request, jsend: {
151
+ error: 'unknown filter', data: ex.to_h
152
+ }
138
153
  end
139
154
 
155
+
140
156
  def statement_invalid(ex)
141
157
  inner = ex.original_exception
142
158
  case inner
143
159
  when PG::InvalidDatetimeFormat, PG::DatetimeFieldOverflow
144
160
  lines = inner.message.split "\n"
145
161
  /.*"([^"]+)"[^"]+/ === lines[1][0..lines[2].size] and begin
146
- json = {status: 'fail', data: {$1 => 'invalid date'}}
147
- render status: :bad_request, format => json
162
+ render status: :bad_request, jsend: {
163
+ message: 'invalid date', data: {$1 => 'invalid date'}
164
+ }
148
165
  end
149
166
  else
150
167
  raise ex
151
168
  end
152
169
  end
153
170
 
171
+
154
172
  def record_not_found(ex)
155
- json = {status: 'fail', data: {gtfs_id => params[:id]}}
156
- render status: :not_found, format => json
173
+ render status: :not_found, jsend: {
174
+ error: 'record not found', data: {gtfs_id => params[:id]}
175
+ }
157
176
  end
158
177
  end
@@ -12,6 +12,11 @@
12
12
  #
13
13
  # You should have received a copy of the GNU General Public License
14
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 'jsend_wrapper/rails'
19
+
15
20
  module GtfsEngine
16
21
  class Engine < ::Rails::Engine
17
22
  isolate_namespace GtfsEngine
@@ -19,17 +19,18 @@ module GtfsEngine
19
19
  class UnknownFilters < Error
20
20
  attr_reader :fields
21
21
 
22
+
22
23
  #@param fields [Array<String>] the names of the unknown fields which the
23
24
  # caller tried to filter with
24
25
  def initialize(fields)
25
26
  @fields = fields
26
27
  end
27
28
 
29
+
28
30
  def to_hash
29
- fields.each_with_object({}) do |field, hash|
31
+ fields.each_with_object( {} ) do |field, hash|
30
32
  hash[field] = message
31
33
  end
32
34
  end
33
35
  end
34
36
  end
35
-
@@ -24,8 +24,10 @@ class GtfsEngine::JsonResponder < ActionController::Responder
24
24
  protected
25
25
 
26
26
  def display_errors
27
- status_code = options[:status] || :unprocessable_entity
28
- data = { status: 'error', data: resource_errors[:errors] }
29
- controller.render format => data, status: status_code
27
+ options[:status] ||= :unprocessable_entity
28
+
29
+ controller.render status: options[:status], jsend: {
30
+ error: 'could not process request', data: resource_errors[:errors]
31
+ }
30
32
  end
31
33
  end
@@ -16,7 +16,7 @@ module GtfsEngine
16
16
  module Version
17
17
  # The following four lines are generated, so don't mess with them.
18
18
  MAJOR = 1
19
- MINOR = 2
19
+ MINOR = 3
20
20
  PATCH = 0
21
21
  BUILD = nil
22
22
 
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.2.0
4
+ version: 1.3.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-08-18 00:00:00.000000000 Z
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jbuilder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jsend_wrapper-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: pry-rails
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,8 +150,8 @@ dependencies:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
152
  version: '4.2'
125
- description: 'A Rails Engine to provide a basic RESTful interface for GTFS feeds.
126
- GTFS Spec: https://developers.google.com/transit/gtfs'
153
+ description: 'Reads and parses zip files conforming to Google''s GTFS spec. GTFS Spec:
154
+ https://developers.google.com/transit/gtfs'
127
155
  email: jon@ertt.ca
128
156
  executables:
129
157
  - rails
@@ -164,15 +192,15 @@ files:
164
192
  - app/models/gtfs_engine/stop_time.rb
165
193
  - app/models/gtfs_engine/transfer.rb
166
194
  - app/models/gtfs_engine/trip.rb
167
- - app/views/gtfs_engine/calendars/dates.json.jbuilder
168
- - app/views/gtfs_engine/data_sets/index.json.jbuilder
169
- - app/views/gtfs_engine/data_sets/show.json.jbuilder
170
- - app/views/gtfs_engine/gtfs/index.json.jbuilder
171
- - app/views/gtfs_engine/gtfs/show.json.jbuilder
172
- - app/views/gtfs_engine/transfers/from.json.jbuilder
173
- - app/views/gtfs_engine/transfers/from_to.json.jbuilder
174
- - app/views/gtfs_engine/transfers/to.json.jbuilder
175
- - app/views/gtfs_engine/trips/block.json.jbuilder
195
+ - app/views/gtfs_engine/calendars/dates.json.jsend
196
+ - app/views/gtfs_engine/data_sets/index.json.jsend
197
+ - app/views/gtfs_engine/data_sets/show.json.jsend
198
+ - app/views/gtfs_engine/gtfs/index.json.jsend
199
+ - app/views/gtfs_engine/gtfs/show.json.jsend
200
+ - app/views/gtfs_engine/transfers/from.json.jsend
201
+ - app/views/gtfs_engine/transfers/from_to.json.jsend
202
+ - app/views/gtfs_engine/transfers/to.json.jsend
203
+ - app/views/gtfs_engine/trips/block.json.jsend
176
204
  - bin/rails
177
205
  - config/initializers/extensions_loader.rb
178
206
  - config/routes.rb
@@ -1,26 +0,0 @@
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
- json.ignore_nil! true
16
-
17
- json.status 'success'
18
- json.data do
19
- @data_sets.each do |name, sets|
20
- json.set! name do
21
- json.array! sets do |set|
22
- json.extract! set, *%i(id name title url etag created_at)
23
- end
24
- end
25
- end
26
- end