json API for suseconferenceclient
This commit is contained in:
parent
d648ab7cb5
commit
d95d8f234b
12 changed files with 159 additions and 8 deletions
|
|
@ -2,6 +2,6 @@ class Api::V1::ConferencesController < Api::BaseController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
respond_with Conference.all
|
render :json => Conference.all, :serializer => ConferencesArraySerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
11
app/controllers/api/v1/events_controller.rb
Normal file
11
app/controllers/api/v1/events_controller.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class Api::V1::EventsController < Api::BaseController
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
def index
|
||||||
|
events = Event.includes(:conference, :track, :room, :event_type, {:event_people => :person})
|
||||||
|
unless params[:conference_id].blank?
|
||||||
|
events = events.where("conferences.guid" => params[:conference_id])
|
||||||
|
end
|
||||||
|
respond_with events
|
||||||
|
end
|
||||||
|
end
|
||||||
13
app/controllers/api/v1/rooms_controller.rb
Normal file
13
app/controllers/api/v1/rooms_controller.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Api::V1::RoomsController < Api::BaseController
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
def index
|
||||||
|
if params[:conference_id].blank?
|
||||||
|
rooms = Room.all
|
||||||
|
else
|
||||||
|
conference = Conference.find_by_guid(params[:conference_id])
|
||||||
|
rooms = conference.rooms
|
||||||
|
end
|
||||||
|
respond_with rooms
|
||||||
|
end
|
||||||
|
end
|
||||||
14
app/controllers/api/v1/speakers_controller.rb
Normal file
14
app/controllers/api/v1/speakers_controller.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
class Api::V1::SpeakersController < Api::BaseController
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
def index
|
||||||
|
if params[:conference_id].blank?
|
||||||
|
people = Person.joins(:event_people)
|
||||||
|
else
|
||||||
|
people = Person.joins(:event_people => {:event => :conference})
|
||||||
|
people = people.where("conferences.guid" => params[:conference_id])
|
||||||
|
end
|
||||||
|
people = people.where("event_people.event_role" => "speaker")
|
||||||
|
render :json => people, :each_serializer => SpeakerSerializer
|
||||||
|
end
|
||||||
|
end
|
||||||
13
app/controllers/api/v1/tracks_controller.rb
Normal file
13
app/controllers/api/v1/tracks_controller.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Api::V1::TracksController < Api::BaseController
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
def index
|
||||||
|
if params[:conference_id].blank?
|
||||||
|
tracks = Track.all
|
||||||
|
else
|
||||||
|
tracks = Track.joins(:conference)
|
||||||
|
tracks = tracks.where("conferences.guid" => params[:conference_id])
|
||||||
|
end
|
||||||
|
respond_with tracks
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
class ConferenceSerializer < ActiveModel::Serializer
|
class ConferenceSerializer < ActiveModel::Serializer
|
||||||
attributes :guid, :name, :description, :year, :socialtag, :date_range#, :url, :revision
|
attributes :guid, :name, :description, :year, :socialtag, :date_range, :url, :revision
|
||||||
|
|
||||||
def name
|
def name
|
||||||
object.short_title
|
|
||||||
end
|
|
||||||
|
|
||||||
def description
|
|
||||||
object.title
|
object.title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -17,7 +13,23 @@ class ConferenceSerializer < ActiveModel::Serializer
|
||||||
object.social_tag
|
object.social_tag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def revision
|
||||||
|
object.revision || 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# FIXME: adjusting the format the DIRTY way, for oSC13.
|
||||||
|
# If you think this is ugly, don't look at the methods below
|
||||||
def date_range
|
def date_range
|
||||||
object.date_range_string
|
object.date_range_string.try(:split, ",").try(:first)
|
||||||
|
end
|
||||||
|
|
||||||
|
# FIXME: just giving suseconferenceclient something to play with
|
||||||
|
def description
|
||||||
|
"openSUSE Conference 2013 - Power to the Geeko"
|
||||||
|
end
|
||||||
|
|
||||||
|
# FIXME: same than the former
|
||||||
|
def url
|
||||||
|
"https://conference.opensuse.org/"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
10
app/serializers/conferences_array_serializer.rb
Normal file
10
app/serializers/conferences_array_serializer.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#
|
||||||
|
# Needed in order to add the API version number to the conferences array
|
||||||
|
#
|
||||||
|
class ConferencesArraySerializer < ActiveModel::ArraySerializer
|
||||||
|
|
||||||
|
def as_json(*args)
|
||||||
|
json = super
|
||||||
|
json.merge!(:version => 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
41
app/serializers/event_serializer.rb
Normal file
41
app/serializers/event_serializer.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
class EventSerializer < ActiveModel::Serializer
|
||||||
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
|
attributes :guid, :title, :length, :date, :language, :abstract,
|
||||||
|
:speaker_ids, :type, :room, :track
|
||||||
|
|
||||||
|
def date
|
||||||
|
object.start_time
|
||||||
|
end
|
||||||
|
|
||||||
|
def speaker_ids
|
||||||
|
speakers = object.event_people.select {|i| i.event_role == "speaker" }
|
||||||
|
speakers.map {|i| i.person.guid}
|
||||||
|
end
|
||||||
|
|
||||||
|
def type
|
||||||
|
object.event_type.try(:title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def room
|
||||||
|
object.room.try(:guid)
|
||||||
|
end
|
||||||
|
|
||||||
|
def track
|
||||||
|
object.track.try(:guid)
|
||||||
|
end
|
||||||
|
|
||||||
|
def abstract
|
||||||
|
# This should never happen
|
||||||
|
if object.abstract.blank?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
simple_format(object.abstract).gsub("\n", "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# FIXME: duplicated logic from Event#as_json
|
||||||
|
def length
|
||||||
|
object.event_type.try(:length) || 25
|
||||||
|
end
|
||||||
|
end
|
||||||
8
app/serializers/room_serializer.rb
Normal file
8
app/serializers/room_serializer.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
class RoomSerializer < ActiveModel::Serializer
|
||||||
|
attributes :guid, :name, :description
|
||||||
|
|
||||||
|
# FIXME: just giving suseconferenceclient something to play with
|
||||||
|
def description
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
17
app/serializers/speaker_serializer.rb
Normal file
17
app/serializers/speaker_serializer.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
class SpeakerSerializer < ActiveModel::Serializer
|
||||||
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
|
attributes :guid, :name, :company, :biography
|
||||||
|
|
||||||
|
def name
|
||||||
|
object.public_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def biography
|
||||||
|
if object.biography.blank?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
simple_format(object.biography).gsub("\n", "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/serializers/track_serializer.rb
Normal file
3
app/serializers/track_serializer.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
class TrackSerializer < ActiveModel::Serializer
|
||||||
|
attributes :guid, :name, :color
|
||||||
|
end
|
||||||
|
|
@ -56,7 +56,16 @@ Osem::Application.routes.draw do
|
||||||
|
|
||||||
namespace :api, defaults: {format: 'json'} do
|
namespace :api, defaults: {format: 'json'} do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :conferences, :only => :index
|
resources :conferences, :only => :index do
|
||||||
|
resources :rooms, :only => :index
|
||||||
|
resources :tracks, :only => :index
|
||||||
|
resources :speakers, :only => :index
|
||||||
|
resources :events, :only => :index
|
||||||
|
end
|
||||||
|
resources :rooms, :only => :index
|
||||||
|
resources :tracks, :only => :index
|
||||||
|
resources :speakers, :only => :index
|
||||||
|
resources :events, :only => :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue