user rails3.2 host xml-rpc server as a blog proxy

class MyController < ApplicationController
  protect_from_forgery :except => :xe_index 
  exposes_xmlrpc_methods :method_prefix => "metaWeblog."

  # This method will be exposed externally as "metaWeblog.newPost()"
  def newPost(blogid, username)
    return "hello word"
  end
  #exposes_xmlrpc_methods
  #add_method 'Container.method_name' do
  #  return 'Hello World'
  #end 
end

 

 

routes.rb

Rpc::Application.routes.draw do
  match 'api/xmlrpc' => 'my#xe_index'
  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id))(.:format)'
end

Gemfile

source 'https://rubygems.org'
gem 'therubyracer'
gem "rails-xmlrpc"
gem 'rails', '3.2.0'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

 

用来测试生成的xml-rpc服务是否可行

client2.rb

#encoding:utf-8
#! /usr/bin/env ruby
require 'xmlrpc/client'
server = XMLRPC::Client.new2("http://localhost:3000/api/xmlrpc")
puts server.call("metaWeblog.newPost","a","b")

 

xmlrpc服务是cross-language的

另外还可以使用base64编码后上传图片

有机会实现完整的本机blog proxy & backup,做为自己本地的备份存储

github 仓库

https://github.com/mlzboy/rpc

你可能感兴趣的:(server)