diff options
| author | Marc Florisson | 2012-12-05 18:32:07 +0100 | 
|---|---|---|
| committer | Marc Florisson | 2012-12-05 18:32:07 +0100 | 
| commit | fdd87a8e14d3fcbf0f2fd91d6f2280e0128c73cf (patch) | |
| tree | 2dfc14269959e49f352fd84233ea88d635926ed8 /app | |
| parent | 2570573d472010249b753e404c6cad003a78ad39 (diff) | |
| download | chouette-core-fdd87a8e14d3fcbf0f2fd91d6f2280e0128c73cf.tar.bz2 | |
add more controllers in api/V1
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/api/v1/companies_controller.rb | 13 | ||||
| -rw-r--r-- | app/controllers/api/v1/connection_links_controller.rb | 13 | ||||
| -rw-r--r-- | app/controllers/api/v1/time_tables_controller.rb | 13 | ||||
| -rw-r--r-- | app/controllers/api/v1/vehicle_journeys_controller.rb | 17 | ||||
| -rw-r--r-- | app/models/api/v1/api_key.rb | 32 | ||||
| -rw-r--r-- | app/views/api/v1/lines/index.rabl | 4 | ||||
| -rw-r--r-- | app/views/api/v1/lines/show.json.rabl | 11 | ||||
| -rw-r--r-- | app/views/api/v1/lines/show.rabl | 12 | ||||
| -rw-r--r-- | app/views/api/v1/lines/show.xml.rabl | 10 | 
9 files changed, 104 insertions, 21 deletions
diff --git a/app/controllers/api/v1/companies_controller.rb b/app/controllers/api/v1/companies_controller.rb new file mode 100644 index 000000000..3f2cd2e7b --- /dev/null +++ b/app/controllers/api/v1/companies_controller.rb @@ -0,0 +1,13 @@ +class Api::V1::CompaniesController < Api::V1::ChouetteController +  inherit_resources + +  defaults :resource_class => Chouette::Company, :finder => :find_by_objectid! + +protected + +  def collection +    @companies ||= referential.companies +  end  + +end + diff --git a/app/controllers/api/v1/connection_links_controller.rb b/app/controllers/api/v1/connection_links_controller.rb new file mode 100644 index 000000000..7aa072cf3 --- /dev/null +++ b/app/controllers/api/v1/connection_links_controller.rb @@ -0,0 +1,13 @@ +class Api::V1::ConnectionLinksController < Api::V1::ChouetteController +  inherit_resources + +  defaults :resource_class => Chouette::ConnectionLink, :finder => :find_by_objectid! + +protected + +  def collection +    @connection_links ||= referential.connection_links +  end  + +end + diff --git a/app/controllers/api/v1/time_tables_controller.rb b/app/controllers/api/v1/time_tables_controller.rb new file mode 100644 index 000000000..53f564a52 --- /dev/null +++ b/app/controllers/api/v1/time_tables_controller.rb @@ -0,0 +1,13 @@ +class Api::V1::TimeTablesController < Api::V1::ChouetteController +  inherit_resources + +  defaults :resource_class => Chouette::TimeTable, :finder => :find_by_objectid! + +protected + +  def collection +    @time_tables ||= referential.time_tables +  end  + +end + diff --git a/app/controllers/api/v1/vehicle_journeys_controller.rb b/app/controllers/api/v1/vehicle_journeys_controller.rb new file mode 100644 index 000000000..2dd78cc19 --- /dev/null +++ b/app/controllers/api/v1/vehicle_journeys_controller.rb @@ -0,0 +1,17 @@ +class Api::V1::VehicleJourneysController < Api::V1::ChouetteController +  inherit_resources + +  defaults :resource_class => Chouette::VehicleJourney, :finder => :find_by_objectid! + +  belongs_to :line, :parent_class => Chouette::Line, :optional => true, :finder => :find_by_objectid!, :param => :line_id do +    belongs_to :route, :parent_class => Chouette::Route, :optional => true, :finder => :find_by_objectid!, :param => :route_id +  end +   +protected + +  def collection +    @vehicle_journeys ||= parent.vehicle_journeys +  end  + +end + diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb new file mode 100644 index 000000000..af029e5f7 --- /dev/null +++ b/app/models/api/v1/api_key.rb @@ -0,0 +1,32 @@ +module Api +  module V1 +    class ApiKey +      def initialize(token) +        @organisation_id, @referential_id = token.split('-') +      end +      def self.create( organisation, referential) +        ApiKey.new( "#{organisation.id}-#{referential.id}") +      end +      def token +        "#{@organisation_id}-#{@referential_id}" +      end +      def exists? +        organisation && referential +      end +      def referential_slug +        referential.slug +      end +      def referential +        @referential ||= organisation.referentials.find_by_id @referential_id +      end  +      def eql?(other) +        other.token == self.token +      end +    private +      def organisation +        @organisation ||= Organisation.find_by_id @organisation_id +      end  +    end +  end +end + diff --git a/app/views/api/v1/lines/index.rabl b/app/views/api/v1/lines/index.rabl new file mode 100644 index 000000000..6c3f73022 --- /dev/null +++ b/app/views/api/v1/lines/index.rabl @@ -0,0 +1,4 @@ +collection @lines + +extends "api/v1/lines/show" + diff --git a/app/views/api/v1/lines/show.json.rabl b/app/views/api/v1/lines/show.json.rabl deleted file mode 100644 index f9bf85dbd..000000000 --- a/app/views/api/v1/lines/show.json.rabl +++ /dev/null @@ -1,11 +0,0 @@ -object @line -attributes :objectid, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name -attributes :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs - -child :network do -  attributes :id, :name -  node(:aa) { |network| titi } -  node(:url) { |network| api_v1_network_url(:id => network.objectid) } -end - -  # attr_accessible :transport_mode, :network_id, :company_id, :objectid, :object_version diff --git a/app/views/api/v1/lines/show.rabl b/app/views/api/v1/lines/show.rabl new file mode 100644 index 000000000..1d65325cb --- /dev/null +++ b/app/views/api/v1/lines/show.rabl @@ -0,0 +1,12 @@ +object @line +attributes :objectid, :object_version, :creation_time, :creator_id +attributes :name, :number, :published_name, :transport_mode_name +attributes :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs + +child :network do +  attributes :objectid, :name, :description, :registration_number +end + +child :company do +  attributes :objectid, :name, :short_name, :registration_number +end diff --git a/app/views/api/v1/lines/show.xml.rabl b/app/views/api/v1/lines/show.xml.rabl deleted file mode 100644 index e1e165d30..000000000 --- a/app/views/api/v1/lines/show.xml.rabl +++ /dev/null @@ -1,10 +0,0 @@ -object @line -attributes :objectid, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name -attributes :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs - -child :network do -  attributes :id, :name -  node(:aa) { |network| titi } -  node(:url) { |network| api_v1_network_url(:id => network.objectid) } -end -  | 
