diff options
| author | Marc Florisson | 2012-12-06 16:19:12 +0100 |
|---|---|---|
| committer | Marc Florisson | 2012-12-06 16:19:12 +0100 |
| commit | c57e39e2b2ef4152e35c1b886aaffc6536121fab (patch) | |
| tree | cb5643fc3082a111db24989dfe9b80e291950fba /app | |
| parent | fdd87a8e14d3fcbf0f2fd91d6f2280e0128c73cf (diff) | |
| download | chouette-core-c57e39e2b2ef4152e35c1b886aaffc6536121fab.tar.bz2 | |
define json and xml views for api/v1
Diffstat (limited to 'app')
20 files changed, 163 insertions, 29 deletions
diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb index c3d52348b..7443445df 100644 --- a/app/controllers/api/v1/networks_controller.rb +++ b/app/controllers/api/v1/networks_controller.rb @@ -1,25 +1,15 @@ module Api module V1 - class NetworksController < ChouetteController - def networks + class NetworksController < ChouetteController + inherit_resources + + defaults :resource_class => Chouette::Network, :finder => :find_by_objectid! + + protected + + def collection @networks ||= referential.networks end - def network - @network ||= networks.where( :objectid => params[:id]) - end - - def index - respond_to do |format| - format.json { render :json => networks } - format.xml { render :xml => networks } - end - end - def show - respond_to do |format| - format.json { render :json => network } - format.xml { render :xml => network } - end - end end end end diff --git a/app/views/api/v1/companies/index.rabl b/app/views/api/v1/companies/index.rabl new file mode 100644 index 000000000..ff94da999 --- /dev/null +++ b/app/views/api/v1/companies/index.rabl @@ -0,0 +1,4 @@ +collection @companies + +extends "api/v1/companies/show" + diff --git a/app/views/api/v1/companies/show.rabl b/app/views/api/v1/companies/show.rabl new file mode 100644 index 000000000..b7234081c --- /dev/null +++ b/app/views/api/v1/companies/show.rabl @@ -0,0 +1,5 @@ +object @company +extends "api/v1/trident_objects/show" +attributes :name, :short_name, :organizational_unit, :operating_department_name +attributes :code, :phone, :fax, :email, :registration_number + diff --git a/app/views/api/v1/connection_links/index.rabl b/app/views/api/v1/connection_links/index.rabl new file mode 100644 index 000000000..d17d2c149 --- /dev/null +++ b/app/views/api/v1/connection_links/index.rabl @@ -0,0 +1,4 @@ +collection @connection_links + +extends "api/v1/connection_links/show" + diff --git a/app/views/api/v1/connection_links/show.rabl b/app/views/api/v1/connection_links/show.rabl new file mode 100644 index 000000000..ad3fae7dd --- /dev/null +++ b/app/views/api/v1/connection_links/show.rabl @@ -0,0 +1,13 @@ +object @connection_link +extends "api/v1/trident_objects/show" + +attributes :connection_link_type, :name, :comment +attributes :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration +attributes :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs + +child :departure => :departure do + attributes :objectid, :name, :area_type, :longitude, :latitude, :long_lat_type +end +child :arrival => :arrival do + attributes :objectid, :name, :area_type, :longitude, :latitude, :long_lat_type +end diff --git a/app/views/api/v1/journey_patterns/index.rabl b/app/views/api/v1/journey_patterns/index.rabl new file mode 100644 index 000000000..4eb394669 --- /dev/null +++ b/app/views/api/v1/journey_patterns/index.rabl @@ -0,0 +1,4 @@ +collection @journey_patterns + +extends "api/v1/journey_patterns/show" + diff --git a/app/views/api/v1/journey_patterns/show.json.rabl b/app/views/api/v1/journey_patterns/show.json.rabl deleted file mode 100644 index bcde45ffd..000000000 --- a/app/views/api/v1/journey_patterns/show.json.rabl +++ /dev/null @@ -1,7 +0,0 @@ -object @journey_pattern -attributes :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :registration_number -attributes :published_name - -# :route_id, :departure_stop_point_id, :arrival_stop_point_id, :stop_point_ids, :stop_points - - diff --git a/app/views/api/v1/journey_patterns/show.rabl b/app/views/api/v1/journey_patterns/show.rabl new file mode 100644 index 000000000..60eed951c --- /dev/null +++ b/app/views/api/v1/journey_patterns/show.rabl @@ -0,0 +1,22 @@ +object @journey_pattern +extends "api/v1/trident_objects/show" + +attributes :name, :comment, :registration_number +attributes :published_name + +child :route do + attributes :objectid, :name, :published_name, :number, :direction, :wayback +end +child :vehicle_journeys do |vj| + attributes :objectid +end +child :stop_points => :stop_areas do |stop_point| + node(:stop_area) do |n| + { :objectid => n.stop_area.objectid, :name => n.stop_area.name, + :parent => n.stop_area.parent.objectid, + :area_type => n.stop_area.area_type, + :longitude => n.stop_area.longitude, :latitude => n.stop_area.latitude, + :long_lat_type => n.stop_area.long_lat_type} + end +end + diff --git a/app/views/api/v1/lines/show.rabl b/app/views/api/v1/lines/show.rabl index 1d65325cb..9c36d13b1 100644 --- a/app/views/api/v1/lines/show.rabl +++ b/app/views/api/v1/lines/show.rabl @@ -1,5 +1,5 @@ object @line -attributes :objectid, :object_version, :creation_time, :creator_id +extends "api/v1/trident_objects/show" attributes :name, :number, :published_name, :transport_mode_name attributes :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs diff --git a/app/views/api/v1/networks/index.html.erb b/app/views/api/v1/networks/index.html.erb deleted file mode 100644 index 93a634270..000000000 --- a/app/views/api/v1/networks/index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<p> - <%= @networks.map(&:name).join(',') %> -</p> diff --git a/app/views/api/v1/networks/index.rabl b/app/views/api/v1/networks/index.rabl new file mode 100644 index 000000000..124a65bee --- /dev/null +++ b/app/views/api/v1/networks/index.rabl @@ -0,0 +1,4 @@ +collection @networks + +extends "api/v1/networks/show" + diff --git a/app/views/api/v1/networks/show.rabl b/app/views/api/v1/networks/show.rabl new file mode 100644 index 000000000..7869ef7ec --- /dev/null +++ b/app/views/api/v1/networks/show.rabl @@ -0,0 +1,4 @@ +object @network +extends "api/v1/trident_objects/show" +attributes :version_date, :description, :name, :registration_number, :source_name +attributes :source_type, :source_identifier, :comment diff --git a/app/views/api/v1/routes/index.rabl b/app/views/api/v1/routes/index.rabl new file mode 100644 index 000000000..8f0eab32c --- /dev/null +++ b/app/views/api/v1/routes/index.rabl @@ -0,0 +1,3 @@ +collection @routes + +extends "api/v1/routes/show" diff --git a/app/views/api/v1/routes/show.rabl b/app/views/api/v1/routes/show.rabl new file mode 100644 index 000000000..2e481432d --- /dev/null +++ b/app/views/api/v1/routes/show.rabl @@ -0,0 +1,24 @@ +object @route +extends "api/v1/trident_objects/show" + +attributes :direction_code, :wayback_code, :name +attributes :comment, :opposite_route_id, :published_name, :number, :direction, :wayback + +child :line do + attributes :objectid, :name, :published_name, :number, :registration_number +end + +child :journey_patterns do |journey_pattern| + attributes :objectid, :name, :published_name, :registration_number +end + +child :vehicle_journeys do |vj| + attributes :objectid +end + +child :stop_areas do |stop_area| + attributes :objectid, :name, :area_type, :longitude, :latitude, :long_lat_type + glue stop_area.parent do + attributes :objectid => :parent + end +end diff --git a/app/views/api/v1/stop_areas/show.rabl b/app/views/api/v1/stop_areas/show.rabl new file mode 100644 index 000000000..032efe1a1 --- /dev/null +++ b/app/views/api/v1/stop_areas/show.rabl @@ -0,0 +1,21 @@ +object @stop_area +extends "api/v1/trident_objects/show" + +attributes :routing_stop_ids, :routing_line_ids +attributes :name, :comment, :area_type, :registration_number +attributes :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :x, :y, :projection_type +attributes :country_code, :street_name + +child :parent => :parent do + attributes :objectid, :name, :area_type, :longitude, :latitude, :long_lat_type +end + +child :children_in_depth => :children do |stop_area| + node(:stop_area) do |n| + { :objectid => n.stop_area.objectid, :name => n.stop_area.name, + :parent => n.stop_area.parent.objectid, + :area_type => n.stop_area.area_type, + :longitude => n.stop_area.longitude, :latitude => n.stop_area.latitude, + :long_lat_type => n.stop_area.long_lat_type} + end +end diff --git a/app/views/api/v1/time_tables/index.rabl b/app/views/api/v1/time_tables/index.rabl new file mode 100644 index 000000000..7f6371c88 --- /dev/null +++ b/app/views/api/v1/time_tables/index.rabl @@ -0,0 +1,3 @@ +collection @time_tables + +extends "api/v1/time_tables/show" diff --git a/app/views/api/v1/time_tables/show.rabl b/app/views/api/v1/time_tables/show.rabl new file mode 100644 index 000000000..90c5bc12c --- /dev/null +++ b/app/views/api/v1/time_tables/show.rabl @@ -0,0 +1,14 @@ +object @time_table +extends "api/v1/trident_objects/show" + +attributes :version, :comment +attributes :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday + +child :dates => :dates do |date| + attributes :date, :position +end + +child :periods => :periods do |period| + attributes :period_start, :period_end +end + diff --git a/app/views/api/v1/trident_objects/show.rabl b/app/views/api/v1/trident_objects/show.rabl new file mode 100644 index 000000000..4f28ac822 --- /dev/null +++ b/app/views/api/v1/trident_objects/show.rabl @@ -0,0 +1,2 @@ +attributes :objectid, :object_version, :creation_time, :creator_id + diff --git a/app/views/api/v1/vehicle_journeys/index.rabl b/app/views/api/v1/vehicle_journeys/index.rabl new file mode 100644 index 000000000..f7d25f3b9 --- /dev/null +++ b/app/views/api/v1/vehicle_journeys/index.rabl @@ -0,0 +1,3 @@ +collection @vehicle_journeys + +extends "api/v1/vehicle_journeys/show" diff --git a/app/views/api/v1/vehicle_journeys/show.rabl b/app/views/api/v1/vehicle_journeys/show.rabl new file mode 100644 index 000000000..488fb4766 --- /dev/null +++ b/app/views/api/v1/vehicle_journeys/show.rabl @@ -0,0 +1,24 @@ +object @vehicle_journey +extends "api/v1/trident_objects/show" + +attributes :comment, :status_value +attributes :transport_mode, :published_journey_name, :published_journey_identifier, :facility, :vehicle_type_identifier, :number + +child :route do + attributes :objectid, :name, :published_name, :number, :direction, :wayback +end + +child :journey_pattern do + attributes :objectid, :name, :published_name, :registration_number +end + +child :time_tables do + attributes :objectid +end + +child :vehicle_journey_at_stops do |vjas| + attributes :position, :connecting_service_id, :boarding_alighting_possibility, :arrival_time, :departure_time, :waiting_time, :elapse_duration, :headway_frequency + node(:stop_area) do |vjas| + {:objectid => vjas.stop_point.stop_area.objectid} + end +end |
