forked from openSUSE/osem
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openSUSE#12 from ancorgs/master
JSON API for https://github.com/athanrous/suseconferenceclient
- Loading branch information
Showing
19 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Api::BaseController < ActionController::Base | ||
protect_from_forgery | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Api::V1::ConferencesController < Api::BaseController | ||
respond_to :json | ||
|
||
def index | ||
render :json => Conference.all, :serializer => ConferencesArraySerializer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# suseconferenceclient relies on a 'revision' attribute for caching and | ||
# doing some calculations. | ||
# | ||
# It should be incremented after any change in the conference or in any | ||
# associated models | ||
# | ||
# This observer updates the revision column in a non-intrusive way, | ||
# preventing validations, callbacks or exceptions to be triggered | ||
# | ||
# Relying on paper_trail could also be an option, but a 'revision' column | ||
# in table 'conferences' looks like a more simple and straightforward solution | ||
# | ||
class RevisionObserver < ActiveRecord::Observer | ||
observe :conference, :event, :room, :social_event, :track | ||
|
||
def after_save(model) | ||
begin | ||
conference = model.kind_of?(Conference) ? model : model.conference | ||
conference.reload.increment(:revision) | ||
conference.update_column(:revision, conference.revision) | ||
rescue | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class ConferenceSerializer < ActiveModel::Serializer | ||
attributes :guid, :name, :description, :year, :socialtag, :date_range, :url, :revision | ||
|
||
def name | ||
object.title | ||
end | ||
|
||
def year | ||
object.start_date.try(:year) | ||
end | ||
|
||
def socialtag | ||
object.social_tag | ||
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class RoomSerializer < ActiveModel::Serializer | ||
attributes :guid, :name, :description | ||
|
||
# FIXME: just giving suseconferenceclient something to play with | ||
def description | ||
"" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class TrackSerializer < ActiveModel::Serializer | ||
attributes :guid, :name, :color | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddRevisionToConference < ActiveRecord::Migration | ||
def change | ||
add_column :conferences, :revision, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters