WIP: first prototype of the JSON API.

* Tests not included, so I cannot prove that it works
This commit is contained in:
Ancor Gonzalez Sosa 2013-07-04 14:02:50 +02:00
parent 83b10447f4
commit 27017a4823
6 changed files with 44 additions and 0 deletions

View file

@ -50,4 +50,5 @@ gem 'acts_as_commentable_with_threading'
gem 'prawn' gem 'prawn'
gem 'prawn_rails' gem 'prawn_rails'
gem 'gravtastic' gem 'gravtastic'
gem 'active_model_serializers'

View file

@ -15,6 +15,8 @@ GEM
rack-cache (~> 1.2) rack-cache (~> 1.2)
rack-test (~> 0.6.1) rack-test (~> 0.6.1)
sprockets (~> 2.2.1) sprockets (~> 2.2.1)
active_model_serializers (0.8.1)
activemodel (>= 3.0)
activemodel (3.2.11) activemodel (3.2.11)
activesupport (= 3.2.11) activesupport (= 3.2.11)
builder (~> 3.0.0) builder (~> 3.0.0)
@ -213,6 +215,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
active_model_serializers
acts_as_commentable_with_threading acts_as_commentable_with_threading
bcrypt-ruby (~> 3.0.0) bcrypt-ruby (~> 3.0.0)
bootstrap-sass bootstrap-sass

View file

@ -0,0 +1,3 @@
class Api::BaseController < ActionController::Base
protect_from_forgery
end

View file

@ -0,0 +1,7 @@
class Api::V1::ConferencesController < Api::BaseController
respond_to :json
def index
respond_with Conference.all
end
end

View file

@ -0,0 +1,23 @@
class ConferenceSerializer < ActiveModel::Serializer
attributes :guid, :name, :description, :year, :socialtag, :date_range#, :url, :revision
def name
object.short_title
end
def description
object.title
end
def year
object.start_date.try(:year)
end
def socialtag
object.social_tag
end
def date_range
object.date_range_string
end
end

View file

@ -53,6 +53,13 @@ Osem::Application.routes.draw do
delete "/register" => "ConferenceRegistration#unregister" delete "/register" => "ConferenceRegistration#unregister"
end end
end end
namespace :api, defaults: {format: 'json'} do
namespace :v1 do
resources :conferences, :only => :index
end
end
match "/admin" => redirect("/admin/conference") match "/admin" => redirect("/admin/conference")
root :to => "home#index" root :to => "home#index"