Skip to content

Commit

Permalink
importing existing from svn repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jeet committed Jul 23, 2008
1 parent a7fb853 commit c2c8912
Show file tree
Hide file tree
Showing 18 changed files with 704 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the white_list plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the white_list plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'WhiteList'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
7 changes: 7 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'action_web_service'
require 'plugin'

Dependencies.load_once_paths.delete File.dirname(__FILE__) + "/lib"



13 changes: 13 additions & 0 deletions lib/backend_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'meta_weblog_api'
require 'movable_type_api'
class BackendController < ApplicationController
session :off

web_service_dispatching_mode :layered
web_service(:metaWeblog) { MetaWeblogService.new(self) }
web_service(:mt) { MovableTypeService.new(self) }

alias xmlrpc api

cache_sweeper :article_sweeper, :assigned_section_sweeper, :comment_sweeper
end
31 changes: 31 additions & 0 deletions lib/meta_weblog_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class MetaWeblogApi < ActionWebService::API::Base
inflect_names false

api_method :getCategories,
:expects => [ {:blogid => :string}, {:username => :string}, {:password => :string} ],
:returns => [[:string]]

api_method :getPost,
:expects => [ {:postid => :string}, {:username => :string}, {:password => :string} ],
:returns => [MetaWeblogStructs::Article]

api_method :getRecentPosts,
:expects => [ {:blogid => :string}, {:username => :string}, {:password => :string}, {:numberOfPosts => :int} ],
:returns => [[MetaWeblogStructs::Article]]

api_method :deletePost,
:expects => [ {:appkey => :string}, {:postid => :string}, {:username => :string}, {:password => :string}, {:publish => :int} ],
:returns => [:bool]

api_method :editPost,
:expects => [ {:postid => :string}, {:username => :string}, {:password => :string}, {:struct => MetaWeblogStructs::Article}, {:publish => :int} ],
:returns => [:bool]

api_method :newPost,
:expects => [ {:blogid => :string}, {:username => :string}, {:password => :string}, {:struct => MetaWeblogStructs::Article}, {:publish => :int} ],
:returns => [:string]

api_method :newMediaObject,
:expects => [ {:blogid => :string}, {:username => :string}, {:password => :string}, {:data => MetaWeblogStructs::MediaObject} ],
:returns => [MetaWeblogStructs::Url]
end
91 changes: 91 additions & 0 deletions lib/meta_weblog_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class MetaWeblogService < XmlRpcService
web_service_api MetaWeblogApi
before_invocation :authenticate

def getCategories(blogid, username, password)
site.sections.find(:all, :order => 'id ASC').collect &:name
end

def getPost(postid, username, password)
article = @user.articles.find(postid)
article_dto_from(article)
end

def getRecentPosts(blogid, username, password, numberOfPosts)
@user.articles.find(:all, :order => "created_at DESC", :limit => numberOfPosts).collect{ |c| article_dto_from(c) }
end

def newPost(blogid, username, password, struct, publish)
article = @user.articles.build :site => site
post_it(article, username, password, struct, publish)
end

def editPost(postid, username, password, struct, publish)
article = @user.articles.find(postid)
post_it(article, username, password, struct, publish)
true
end

def deletePost(appkey, postid, username, password, publish)
article = @user.articles.find(postid)
article.destroy
true
end

def newMediaObject(blogid, username, password, data)
asset = site.assets.build \
:filename => data['name'],
:content_type => (data['type'] || guess_content_type_from(data['name'])),
:temp_data => Base64.decode64(data['bits'])
asset.save!
MetaWeblogStructs::Url.new("url" => asset.public_filename)
end

def article_dto_from(article)
MetaWeblogStructs::Article.new(
:description => article.body,
:title => article.title,
:postid => article.id.to_s,
:url => article_url(article).to_s,
:link => article_url(article).to_s,
:permaLink => article.permalink.to_s,
:categories => article.sections.collect { |c| c.name },
:mt_text_more => article.body.to_s,
:mt_excerpt => article.excerpt.to_s,
:mt_keywords => article.tag,
# :mt_allow_comments => article.allow_comments? ? 1 : 0,
# :mt_allow_pings => article.allow_pings? ? 1 : 0,
# :mt_convert_breaks => (article.text_filter.name.to_s rescue ''),
# :mt_tb_ping_urls => article.pings.collect { |p| p.url },
:dateCreated => (article.published_at rescue "")
)
end

protected
def article_url(article)
article.published? && article.full_permalink
end

def post_it(article, user, password, struct, publish)
# make sure publish is true if it's 1 if not leave it the way it is.
publish = publish == 1 || publish
# if no categories are supplied do not attempt to set any.
article.section_ids = Section.find(:all, :conditions => ['name IN (?)', struct['categories']]).collect(&:id) if struct['categories']
article.attributes = {:updater => @user, :body => struct['description'].to_s, :title => struct['title'].to_s, :excerpt => struct['mt_excerpt'].to_s}
# Keywords/Tags support
Tagging.set_on article, struct['mt_keywords'] if struct['mt_keywords'] # set/modify keywords _only_ if they are supplied. mt_keywords _overwrite_ not alter the ``tags''

utc_date = Time.utc(struct['dateCreated'].year, struct['dateCreated'].month, struct['dateCreated'].day, struct['dateCreated'].hour, struct['dateCreated'].sec, struct['dateCreated'].min) rescue article.published_at || Time.now.utc
article.published_at = publish == true ? utc_date : nil
article.save!
article.id
end

def guess_content_type_from(name)
if name =~ /(png|gif|jpe?g)/i
"image/#{$1 == 'jpg' ? 'jpeg' : $1}"
else
'application/octet-stream'
end
end
end
19 changes: 19 additions & 0 deletions lib/meta_weblog_structs/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module MetaWeblogStructs
class Article < ActionWebService::Struct
member :description, :string
member :title, :string
member :postid, :string
member :url, :string
member :link, :string
member :permaLink, :string
member :categories, [:string]
member :mt_text_more, :string
member :mt_excerpt, :string
member :mt_keywords, :string
member :mt_allow_comments, :int
member :mt_allow_pings, :int
member :mt_convert_breaks, :string
member :mt_tb_ping_urls, [:string]
member :dateCreated, :time
end
end
7 changes: 7 additions & 0 deletions lib/meta_weblog_structs/media_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MetaWeblogStructs
class MediaObject < ActionWebService::Struct
member :bits, :string
member :name, :string
member :type, :string
end
end
5 changes: 5 additions & 0 deletions lib/meta_weblog_structs/url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module MetaWeblogStructs
class Url < ActionWebService::Struct
member :url, :string
end
end
88 changes: 88 additions & 0 deletions lib/movable_type_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
class MovableTypeApi < ActionWebService::API::Base
inflect_names false

# Movable Type Programatic interface
# see: <http://www.movabletype.org/mt-static/docs/mtmanual_programmatic.html>
# supportedTextFilters has already been there!
# - Moritz Angermann
#
# mt.getRecentPostTitles
# Description: Returns a bandwidth-friendly list of the most recent posts in the system.
# Parameters: String blogid, String username, String password, int numberOfPosts
# Return value: on success, array of structs containing ISO.8601 dateCreated, String userid, String postid, String title; on failure, fault
# Notes: dateCreated is in the timezone of the weblog blogid
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetrecentposttitles.html>

#api_method :getRecentPostTitles,
# :expects => [ {:blogid => :string}, {:username => :string}, {:password => :string}, {:numberOfPosts => :int} ],
# :returns => [[MovableTypeStructs::Post]]

# mt.getCategoryList
# Description: Returns a list of all categories defined in the weblog.
# Parameters: String blogid, String username, String password
# Return value: on success, an array of structs containing String categoryId and String categoryName; on failure, fault.
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetcategorylist.html>
api_method :getCategoryList,
:expects => [ {:blogid => :string}, {:username => :string}, {:password => :string} ],
:returns => [[MovableTypeStructs::Category]]

# mt.getPostCategories
# Description: Returns a list of all categories to which the post is assigned.
# Parameters: String postid, String username, String password
# Return value: on success, an array of structs containing String categoryName, String categoryId, and boolean isPrimary; on failure, fault.
# Notes: isPrimary denotes whether a category is the post's primary category.
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetpostcategories.html>
api_method :getPostCategories,
:expects => [ {:postid => :string}, {:username => :string}, {:password => :string} ],
:returns => [[MovableTypeStructs::Category]]

# mt.setPostCategories
# Description: Sets the categories for a post.
# Parameters: String postid, String username, String password, array categories
# Return value: on success, boolean true value; on failure, fault
# Notes: the array categories is an array of structs containing String categoryId and boolean isPrimary. Using isPrimary to set the primary category is optional--in the absence of this flag, the first struct in the array will be assigned the primary category for the post.
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsetpostcategories.html>
api_method :setPostCategories,
:expects => [ {:postid => :string}, {:username => :string}, {:password => :string}, {:categories => [MovableTypeStructs::PostCategory]} ],
:returns => [:bool]

# mt.supportedMethods
# Description: Retrieve information about the XML-RPC methods supported by the server.
# Parameters: none
# Return value: an array of method names supported by the server.
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsupportedMethods.html>

api_method :supportedMethods,
:expects => [],
:returns => [[:string]]

# mt.supportedTextFilters
# Description: Retrieve information about the text formatting plugins supported by the server.
# Parameters: none
# Return value: an array of structs containing String key and String label. key is the unique string identifying a text formatting plugin, and label is the readable description to be displayed to a user. key is the value that should be passed in the mt_convert_breaks parameter to newPost and editPost.
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsupportedtextfilters.html>

api_method :supportedTextFilters,
:expects => [],
:returns => [[MovableTypeStructs::TextFilter]]

# mt.getTrackbackPings
# Description: Retrieve the list of TrackBack pings posted to a particular entry. This could be used to programmatically retrieve the list of pings for a particular entry, then iterate through each of those pings doing the same, until one has built up a graph of the web of entries referencing one another on a particular topic.
# Parameters: String postid
# Return value: an array of structs containing String pingTitle (the title of the entry sent in the ping), String pingURL (the URL of the entry), and String pingIP (the IP address of the host that sent the ping).
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgettrackbackpings.html>

# api_method :getTrackbackPings,
# :expects => [ {:postid => :string} ],
# :returns => [[MovableTypeStructs::Trackback]]

# mt.publishPost
# Description: Publish (rebuild) all of the static files related to an entry from your weblog. Equivalent to saving an entry in the system (but without the ping).
# Parameters: String postid, String username, String password
# Returns value: on success, boolean true value; on failure, fault
# Reference: <http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtpublishpost.html>

#api_method :publishPost,
# :expects => [ {:postid => :string}, {:username => :string}, {:password => :string} ],
# :returns => [:bool]
end
44 changes: 44 additions & 0 deletions lib/movable_type_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class MovableTypeService < XmlRpcService
web_service_api MovableTypeApi
before_invocation :authenticate, :except => [:supportedMethods, :supportedTextFilters]

#def getRecentPostTitles(blogid, username, password, numberOfPosts)
# # FIXME not implemented
#end

def getCategoryList(blogid, username, password)
site.sections.find(:all, :order => 'id ASC').collect { |c| MovableTypeStructs::Category.new(:categoryId => c.id, :categoryName => c.name) }
end

def getPostCategories(postid, username, password)
article = @user.articles.find(postid)
article.sections.collect { |c| MovableTypeStructs::Category.new(:categoryId => c.id, :categoryName => c.name) }
end

def setPostCategories(postid, username, password, categories)
article = @user.articles.find(postid)
article.section_ids= categories.collect { |c| c.categoryId }
article.save!
true
end

def supportedMethods
MetaWeblogService.public_instance_methods(false).collect { |m| "metaWeblog.{#m}" } \
+ MovableTypeService.public_instance_methods(false).collect { |m| "mt.{#m}" }
end

def supportedTextFilters
FilteredColumn.filters.collect { |(key, filter)| MovableTypeStructs::TextFilter.new(:key => key, :label => filter.filter_name) }
end

# def getTrackbackPings,
# ...
# end

#def publishPost(postid, username, password)
# article = @user.articles.find(postid)
# #article. hmmm now what?
# true
#end

end
6 changes: 6 additions & 0 deletions lib/movable_type_structs/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MovableTypeStructs
class Category < ActionWebService::Struct
member :categoryId, :string
member :categoryName, :string
end
end
8 changes: 8 additions & 0 deletions lib/movable_type_structs/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module MovableTypeStructs
class Post < ActionWebService::Struct
member :dateCreated, :time #ISO.8601
member :userid, :string
member :postid, :string
member :title, :string
end
end
7 changes: 7 additions & 0 deletions lib/movable_type_structs/post_category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MovableTypeStructs
class PostCategory < ActionWebService::Struct
member :categoryId, :string
member :categoryName, :string
member :isPrimary, :bool
end
end
6 changes: 6 additions & 0 deletions lib/movable_type_structs/text_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MovableTypeStructs
class TextFilter < ActionWebService::Struct
member :key, :string
member :label, :string
end
end
7 changes: 7 additions & 0 deletions lib/movable_type_structs/trackback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MovableTypeStructs
class Trackback < ActionWebService::Struct
member :pingTitle, :string
member :pingURL, :string
member :pingIP, :string
end
end
14 changes: 14 additions & 0 deletions lib/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Mephisto
module Plugins
class Mephisto < Mephisto::Plugin
author 'Ajay Maurya'
version '0.1'
notes " xmlrpc service for Mephisto , Port of Rick Olson's mephisto xmlrpc plugin for mephisto 0.8"

public_controller 'Backend'
add_route 'xmlrpc', :controller => 'backend', :action => 'xmlrpc'


end
end
end
Loading

0 comments on commit c2c8912

Please sign in to comment.