Skip to content

Commit

Permalink
inital import
Browse files Browse the repository at this point in the history
  • Loading branch information
abradburne committed Apr 14, 2008
1 parent 94da53f commit 47992c0
Show file tree
Hide file tree
Showing 471 changed files with 23,821 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/apis/backend_api.rb
@@ -0,0 +1,2 @@
class BackendApi < ActionWebService::API::Base
end
36 changes: 36 additions & 0 deletions app/apis/blogger_api.rb
@@ -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
7 changes: 7 additions & 0 deletions app/apis/blogger_structs/blog.rb
@@ -0,0 +1,7 @@
module BloggerStructs
class Blog < ActionWebService::Struct
member :url, :string
member :blogId, :string
member :blogName, :string
end
end
8 changes: 8 additions & 0 deletions app/apis/blogger_structs/post.rb
@@ -0,0 +1,8 @@
module BloggerStructs
class Post < ActionWebService::Struct
member :userId, :string
member :postId, :string
member :dateCreated, :string
member :content, :string
end
end
8 changes: 8 additions & 0 deletions app/apis/blogger_structs/user.rb
@@ -0,0 +1,8 @@
module BloggerStructs
class User < ActionWebService::Struct
member :userId, :string
member :username, :string
member :email, :string
member :url, :string
end
end
22 changes: 22 additions & 0 deletions app/controllers/account_controller.rb
@@ -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
8 changes: 8 additions & 0 deletions app/controllers/application.rb
@@ -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
76 changes: 76 additions & 0 deletions app/controllers/articles_controller.rb
@@ -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
5 changes: 5 additions & 0 deletions app/controllers/backend_controller.rb
@@ -0,0 +1,5 @@
class BackendController < ApplicationController
web_service_scaffold 'invoke'
web_service_dispatching_mode :layered
web_service :blogger, BloggerService.new
end
70 changes: 70 additions & 0 deletions app/controllers/blogger_service.rb
@@ -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
10 changes: 10 additions & 0 deletions app/controllers/blogs_controller.rb
@@ -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
61 changes: 61 additions & 0 deletions app/controllers/categories_controller.rb
@@ -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
24 changes: 24 additions & 0 deletions app/controllers/comments_controller.rb
@@ -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

0 comments on commit 47992c0

Please sign in to comment.