Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94da53f
commit 47992c0
Showing
471 changed files
with
23,821 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class BackendApi < ActionWebService::API::Base | ||
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,36 @@ | ||
class BloggerAPI < ActionWebService::API::Base | ||
inflect_names false | ||
|
||
api_method :getUsersBlogs, | ||
:expects => [ {:appkey => :string}, {:username => :string}, | ||
{:password => :string} ], | ||
:returns => [[BloggerStructs::Blog]] | ||
|
||
api_method :getUserInfo, | ||
:expects => [ {:appkey => :string}, {:username => :string}, | ||
{:password => :string} ], | ||
:returns => [BloggerStructs::User] | ||
|
||
api_method :getPost, | ||
:expects => [ {:appkey => :string}, {:postid => :string}, | ||
{:username => :string}, {:password => :string} ], | ||
:returns => [BloggerStructs::Post] | ||
|
||
api_method :getRecentPosts, | ||
:expects => [ {:appkey => :string}, {:blogid => :string}, | ||
{:username => :string}, {:password => :string}, | ||
{:numberOfPosts => :integer} ], | ||
:returns => [[BloggerStructs::Post]] | ||
|
||
api_method :newPost, | ||
:expects => [ {:appkey => :string}, {:blogid => :string}, | ||
{:username => :string}, {:password => :string}, | ||
{:content => :string}, {:publish => :boolean} ], | ||
:returns => [:int] | ||
|
||
api_method :editPost, | ||
:expects => [ {:appkey => :string}, {:postid => :string}, | ||
{:username => :string}, {:password => :string}, | ||
{:content => :string}, {:publish => :boolean} ], | ||
:returns => [:boolean] | ||
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 @@ | ||
module BloggerStructs | ||
class Blog < ActionWebService::Struct | ||
member :url, :string | ||
member :blogId, :string | ||
member :blogName, :string | ||
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 @@ | ||
module BloggerStructs | ||
class Post < ActionWebService::Struct | ||
member :userId, :string | ||
member :postId, :string | ||
member :dateCreated, :string | ||
member :content, :string | ||
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 @@ | ||
module BloggerStructs | ||
class User < ActionWebService::Struct | ||
member :userId, :string | ||
member :username, :string | ||
member :email, :string | ||
member :url, :string | ||
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,22 @@ | ||
class AccountController < ApplicationController | ||
|
||
def authenticate | ||
self.logged_in_user = User.authenticate(params[:user][:username], | ||
params[:user][:password]) | ||
if is_logged_in? | ||
redirect_to index_url | ||
else | ||
flash[:error] = "I'm sorry, either your username or password was incorrect." | ||
redirect_to :action => 'login' | ||
end | ||
end | ||
|
||
def logout | ||
if request.post? | ||
reset_session | ||
flash[:notice] = "You have been logged out." | ||
end | ||
redirect_to index_url | ||
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 @@ | ||
# Filters added to this controller apply to all controllers in the application. | ||
# Likewise, all the methods added will be available for all controllers. | ||
|
||
class ApplicationController < ActionController::Base | ||
# Pick a unique cookie name to distinguish our session data from others' | ||
session :session_key => '_railscoders_session_id' | ||
include LoginSystem | ||
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,76 @@ | ||
class ArticlesController < ApplicationController | ||
before_filter :check_editor_role, :except => [:index, :show] | ||
|
||
def index | ||
if params[:category_id] | ||
@articles_pages, @articles = paginate(:articles, | ||
:include => :user, | ||
:order => 'published_at DESC', | ||
:conditions => "category_id=#{params[:category_id].to_i} AND published=true") | ||
else | ||
@articles = Article.find_all_by_published(true) | ||
@articles_pages, @articles = paginate(:articles, | ||
:include => :user, | ||
:order => 'published_at DESC', | ||
:conditions => "published = true") | ||
end | ||
respond_to do |wants| | ||
wants.html | ||
wants.xml { render :xml => @articles.to_xml } | ||
wants.rss { render :action => 'rss.rxml', :layout => false } | ||
wants.atom { render :action => 'atom.rxml', :layout => false } | ||
end | ||
end | ||
|
||
def show | ||
if is_logged_in? && @logged_in_user.has_role?('Editor') | ||
@article = Article.find(params[:id]) | ||
else | ||
@article = Article.find_by_id_and_published(params[:id], true) | ||
end | ||
respond_to do |wants| | ||
wants.html | ||
wants.xml { render :xml => @article.to_xml } | ||
end | ||
end | ||
|
||
def new | ||
@article = Article.new | ||
end | ||
|
||
def create | ||
@article = Article.create(params[:article]) | ||
@logged_in_user.articles << @article | ||
respond_to do |wants| | ||
wants.html { redirect_to admin_articles_url } | ||
wants.xml { render :xml => @article.to_xml } | ||
end | ||
end | ||
|
||
def edit | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
def update | ||
@article = Article.find(params[:id]) | ||
@article.update_attributes(params[:article]) | ||
respond_to do |wants| | ||
wants.html { redirect_to admin_articles_url } | ||
wants.xml { render :xml => @article.to_xml } | ||
end | ||
end | ||
|
||
def destroy | ||
@article = Article.find(params[:id]) | ||
@article.destroy | ||
respond_to do |wants| | ||
wants.html { redirect_to admin_articles_url } | ||
wants.xml { render :nothing => true } | ||
end | ||
end | ||
|
||
def admin | ||
@articles_pages, @articles = paginate(:articles, :order => 'published_at DESC') | ||
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,5 @@ | ||
class BackendController < ApplicationController | ||
web_service_scaffold 'invoke' | ||
web_service_dispatching_mode :layered | ||
web_service :blogger, BloggerService.new | ||
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,70 @@ | ||
class BloggerService < ActionWebService::Base | ||
web_service_api BloggerAPI | ||
|
||
def getUsersBlogs(appkey, username, password) | ||
if @user = User.authenticate(username, password) | ||
[BloggerStructs::Blog.new( | ||
:url => "http://localhost:3000/users/#{@user.id}/entries", | ||
:blogId => @user.id, | ||
:blogName => @user.blog_title ||= @user.username | ||
)] | ||
end | ||
end | ||
|
||
def getPost(appkey, postid, username, password) | ||
if @user = User.authenticate(username, password) | ||
entry = @user.entries.find(postid) | ||
BloggerStructs::Post.new( | ||
:userId => @user.id, | ||
:postId => entry.id, | ||
:dateCreated => entry.created_at.to_s(:db), | ||
:content => [entry.body] | ||
) | ||
end | ||
end | ||
|
||
def getRecentPosts(appkey, blogid, username, password, numberofposts) | ||
if @user = User.authenticate(username, password) | ||
@user.entries.find(:all, | ||
:order => 'created_at DESC', | ||
:limit => numberofposts).collect do |entry| | ||
BloggerStructs::Post.new( | ||
:userId => entry.user_id, | ||
:postId => entry.id, | ||
:dateCreated => entry.created_at.to_s(:db), | ||
:content => entry.body | ||
) | ||
end | ||
end | ||
end | ||
|
||
def getUserInfo(appkey, username, password) | ||
if @user = User.authenticate(username, password) | ||
BloggerStructs::User.new( | ||
:userId => @user.id, | ||
:username => @user.username, | ||
:url => "http://localhost:3000/users/#{@user.id}/entries" | ||
) | ||
end | ||
end | ||
|
||
def newPost(appkey, blogid, username, password, content, publish) | ||
if @user = User.authenticate(username, password) | ||
entry = Entry.new | ||
entry.title = "New entry" | ||
entry.body = content.to_s | ||
entry.user = @user | ||
entry.save | ||
return entry.id | ||
end | ||
end | ||
|
||
def editPost(appkey, postid, username, password, content, publish) | ||
if @user = User.authenticate(username, password) | ||
entry = @user.entries.find(postid) | ||
entry.body = content | ||
entry.save | ||
return true | ||
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,10 @@ | ||
class BlogsController < ApplicationController | ||
def index | ||
@entry_pages = Paginator.new(self, Entry.count, 10, params[:page]) | ||
@entries = Entry.find(:all, | ||
:limit => @entry_pages.items_per_page, | ||
:offset => @entry_pages.current.offset, | ||
:order => 'entries.created_at DESC', | ||
:include => :user) | ||
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,61 @@ | ||
class CategoriesController < ApplicationController | ||
before_filter :check_editor_role, :except => [:index, :show] | ||
|
||
def index | ||
@categories = Category.find(:all) | ||
respond_to do |wants| | ||
wants.html | ||
wants.xml { render :xml => @categories.to_xml } | ||
end | ||
end | ||
|
||
def show | ||
@category = Category.find(params[:id]) | ||
respond_to do |wants| | ||
wants.html { redirect_to category_articles_url(:category_id => @category.id) } | ||
wants.xml { render :xml => @category.to_xml } | ||
end | ||
end | ||
|
||
def new | ||
@category = Category.new | ||
end | ||
|
||
def create | ||
@category = Category.create(params[:category]) | ||
respond_to do |wants| | ||
wants.html { redirect_to admin_categories_url } | ||
wants.xml { render :xml => @category.to_xml } | ||
end | ||
end | ||
|
||
def edit | ||
@category = Category.find(params[:id]) | ||
end | ||
|
||
def update | ||
@category = Category.find(params[:id]) | ||
@category.update_attributes(params[:category]) | ||
respond_to do |wants| | ||
wants.html { redirect_to admin_categories_url } | ||
wants.xml { render :xml => @category.to_xml } | ||
end | ||
end | ||
|
||
def destroy | ||
@category = Category.find(params[:id]) | ||
@category.find(params[:id]).destroy | ||
respond_to do |wants| | ||
wants.html { redirect_to admin_categories_url } | ||
wants.xml { render :nothing => true } | ||
end | ||
end | ||
|
||
def admin | ||
@categories = Category.find(:all) | ||
respond_to do |wants| | ||
wants.html | ||
wants.xml { render :xml => @categories.to_xml } | ||
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,24 @@ | ||
class CommentsController < ApplicationController | ||
before_filter :login_required | ||
|
||
def create | ||
@entry = Entry.find_by_user_id_and_id(params[:user_id], params[:entry_id]) | ||
@comment = Comment.new(:user_id => @logged_in_user.id, :body => params[:comment][:body]) | ||
|
||
if @entry.comments << @comment | ||
flash[:notice] = 'Comment was successfully created.' | ||
Notifier.deliver_new_comment_notification(@comment) | ||
redirect_to entry_path(:user_id => @entry.user, :id => @entry) | ||
else | ||
render :controller => 'entries', :action => 'show', :user_id => @entry.user, :id => @entry | ||
end | ||
end | ||
|
||
def destroy | ||
@entry = Entry.find_by_user_id_and_id(@logged_in_user.id, params[:entry_id], :include => :user) | ||
@comment = @entry.comments.find(params[:id]) | ||
@comment.destroy | ||
|
||
redirect_to entry_path(:user_id => @entry.user.id, :id => @entry.id) | ||
end | ||
end |
Oops, something went wrong.