WIP: first prototype of the JSON API.
* Tests not included, so I cannot prove that it works
This commit is contained in:
parent
83b10447f4
commit
27017a4823
6 changed files with 44 additions and 0 deletions
1
Gemfile
1
Gemfile
|
|
@ -50,4 +50,5 @@ gem 'acts_as_commentable_with_threading'
|
|||
gem 'prawn'
|
||||
gem 'prawn_rails'
|
||||
gem 'gravtastic'
|
||||
gem 'active_model_serializers'
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ GEM
|
|||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
active_model_serializers (0.8.1)
|
||||
activemodel (>= 3.0)
|
||||
activemodel (3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
builder (~> 3.0.0)
|
||||
|
|
@ -213,6 +215,7 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
active_model_serializers
|
||||
acts_as_commentable_with_threading
|
||||
bcrypt-ruby (~> 3.0.0)
|
||||
bootstrap-sass
|
||||
|
|
|
|||
3
app/controllers/api/base_controller.rb
Normal file
3
app/controllers/api/base_controller.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Api::BaseController < ActionController::Base
|
||||
protect_from_forgery
|
||||
end
|
||||
7
app/controllers/api/v1/conferences_controller.rb
Normal file
7
app/controllers/api/v1/conferences_controller.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Api::V1::ConferencesController < Api::BaseController
|
||||
respond_to :json
|
||||
|
||||
def index
|
||||
respond_with Conference.all
|
||||
end
|
||||
end
|
||||
23
app/serializers/conference_serializer.rb
Normal file
23
app/serializers/conference_serializer.rb
Normal 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
|
||||
|
|
@ -53,6 +53,13 @@ Osem::Application.routes.draw do
|
|||
delete "/register" => "ConferenceRegistration#unregister"
|
||||
end
|
||||
end
|
||||
|
||||
namespace :api, defaults: {format: 'json'} do
|
||||
namespace :v1 do
|
||||
resources :conferences, :only => :index
|
||||
end
|
||||
end
|
||||
|
||||
match "/admin" => redirect("/admin/conference")
|
||||
|
||||
root :to => "home#index"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue