博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
user rails3.2 host xml-rpc server as a blog proxy
阅读量:6072 次
发布时间:2019-06-20

本文共 3119 字,大约阅读时间需要 10 分钟。

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

转载地址:http://yuigx.baihongyu.com/

你可能感兴趣的文章
SharePoint Wiki发布页面的“保存冲突”
查看>>
oracle 10g 数据库与客户端冲突导致实例创建无监听问题
查看>>
Delphi中读取文本文件的方法(实例一)
查看>>
Linux常用命令
查看>>
Android开源代码解读の使用TelephonyManager获取移动网络信息
查看>>
想说一点东西。。。。
查看>>
css知多少(8)——float上篇
查看>>
NLB网路负载均衡管理器详解
查看>>
水平添加滚动条
查看>>
PHP中”单例模式“实例讲解
查看>>
VS2008查看dll导出函数
查看>>
VM EBS R12迁移,启动APTier . AutoConfig错误
查看>>
atitit.细节决定成败的适合情形与缺点
查看>>
iOS - Library 库
查看>>
MATLAB 读取DICOM格式文件
查看>>
spring事务管理(Transaction)
查看>>
django.contrib.auth登陆注销学习
查看>>
js执行本地exe文件的3种方法
查看>>
理解B树索引
查看>>
vi编辑器的命令集合
查看>>