aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2012-11-30 10:04:01 +0100
committerMarc Florisson2012-11-30 10:04:01 +0100
commita0bd6fc318e7ebe75e8c03949b9fc61e581de943 (patch)
tree1c465d9653b9abe4e1dba0378f468357f63f49f2
parenta018c33f2792033e5c0829252775f9831950b3ae (diff)
downloadchouette-core-a0bd6fc318e7ebe75e8c03949b9fc61e581de943.tar.bz2
add gem rabl
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock4
-rw-r--r--app/controllers/api/v1/chouette_controller.rb31
-rw-r--r--app/controllers/api/v1/lines_controller.rb17
-rw-r--r--app/controllers/api/v1/networks_controller.rb26
-rw-r--r--app/views/api/v1/lines/show.json.rabl11
-rw-r--r--app/views/api/v1/lines/show.xml.rabl10
-rw-r--r--config/routes.rb3
8 files changed, 78 insertions, 26 deletions
diff --git a/Gemfile b/Gemfile
index 4dcd84217..c4432fd5e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -54,6 +54,8 @@ gem 'coffee-script-source'
gem 'therubyrhino', :platform => :jruby
gem 'therubyracer', :platform => :ruby
+gem 'rabl'
+
# Gems used only for assets and not required
# in production environments by default.
group :assets do
diff --git a/Gemfile.lock b/Gemfile.lock
index da9f5dc21..509902435 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -241,6 +241,9 @@ GEM
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
+ rabl (0.7.8)
+ activesupport (>= 2.3.14)
+ multi_json (~> 1.0)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -388,6 +391,7 @@ DEPENDENCIES
modernizr-rails (~> 2.0.6)
ninoxe!
pg (~> 0.11.0)
+ rabl
rails (= 3.2.6)
ransack
rb-inotify
diff --git a/app/controllers/api/v1/chouette_controller.rb b/app/controllers/api/v1/chouette_controller.rb
new file mode 100644
index 000000000..401625da8
--- /dev/null
+++ b/app/controllers/api/v1/chouette_controller.rb
@@ -0,0 +1,31 @@
+module Api
+ module V1
+ class ChouetteController < ActionController::Base
+ respond_to :json, :xml
+ layout false
+ before_filter :restrict_access_and_switch
+
+ def referential
+ @referential ||= organisation.referentials.find_by_id @referential_id
+ end
+ def organisation
+ @organisation ||= Organisation.find_by_id @organisation_id
+ end
+
+private
+ def restrict_access_and_switch
+ authenticate_or_request_with_http_token do |token, options|
+ switch_referential if key_exists?( token)
+ end
+ end
+ def key_exists?( token)
+ @organisation_id, @referential_id = token.split('-')
+ organisation && referential
+ end
+ def switch_referential
+ Apartment::Database.switch(referential.slug)
+ end
+
+ end
+ end
+end
diff --git a/app/controllers/api/v1/lines_controller.rb b/app/controllers/api/v1/lines_controller.rb
new file mode 100644
index 000000000..2e22161d0
--- /dev/null
+++ b/app/controllers/api/v1/lines_controller.rb
@@ -0,0 +1,17 @@
+module Api
+ module V1
+ class LinesController < ChouetteController
+ inherit_resources
+
+ defaults :resource_class => Chouette::Line, :finder => :find_by_objectid!
+
+ protected
+
+ def collection
+ @lines ||= referential.lines
+ end
+ end
+ end
+end
+
+
diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb
index 2ecc23ed0..c9cb6345e 100644
--- a/app/controllers/api/v1/networks_controller.rb
+++ b/app/controllers/api/v1/networks_controller.rb
@@ -1,23 +1,12 @@
module Api
module V1
class NetworksController < ActionController::Base
- respond_to :json, :xml
- layout false
- before_filter :restrict_access_and_switch
-
- def referential
- @referential ||= organisation.referentials.find_by_id @referential_id
- end
- def organisation
- @organisation ||= Organisation.find_by_id @organisation_id
- end
def networks
@networks ||= referential.networks
end
def network
@network ||= networks.where( :objectid => params[:id])
end
-
def index
respond_to do |format|
@@ -31,21 +20,6 @@ module Api
format.xml { render :xml => network }
end
end
-
-private
- def restrict_access_and_switch
- authenticate_or_request_with_http_token do |token, options|
- switch_referential if key_exists?( token)
- end
- end
- def key_exists?( token)
- @organisation_id, @referential_id = token.split('-')
- organisation && referential
- end
- def switch_referential
- Apartment::Database.switch(referential.slug)
- end
-
end
end
end
diff --git a/app/views/api/v1/lines/show.json.rabl b/app/views/api/v1/lines/show.json.rabl
new file mode 100644
index 000000000..f9bf85dbd
--- /dev/null
+++ b/app/views/api/v1/lines/show.json.rabl
@@ -0,0 +1,11 @@
+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.xml.rabl b/app/views/api/v1/lines/show.xml.rabl
new file mode 100644
index 000000000..e1e165d30
--- /dev/null
+++ b/app/views/api/v1/lines/show.xml.rabl
@@ -0,0 +1,10 @@
+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
+
diff --git a/config/routes.rb b/config/routes.rb
index f711394b6..31aa9ac9a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -7,6 +7,9 @@ ChouetteIhm::Application.routes.draw do
namespace :api do
namespace :v1 do
resources :networks
+ resources :lines do
+ resources :routes
+ end
end
end