论坛首页 编程语言技术论坛

用Ruby on Rails 的 xmlrpc 来连接webservice

浏览 2333 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-03-12  
require "xmlrpc/client"
class SoapController < ApplicationController
  before_filter :get_XMLRPC_server
  
  def index
    @products_arr = get_products()
  end
  
  def rcp

    @result_1= @server.call("Bugzilla.version")
    @result_2= @server.call("Bugzilla.timezone")
    @result_3= @server.call("Bug.get",{:ids=>[1]})
   
    render :action=>'index'
  end
  
  def new_bug
    @product_name = params[:product_name]
  end
  
  def create_bug
    
    bug = {
        :product     => params[:p], 
        :component   => params[:component],
        :summary     => params[:summary],
        :version     => 'unspecified',
        :description => params[:description],
        :op_sys      => params[:op_sys],
        :platform    => params[:platform],   
        :priority    => params[:priority],
        :severity    => params[:severity]
    }
    
    @server.call("Bug.create",bug)
    
    redirect_to :action=>'index'
  end
  
private 

  def login_bugzilla(name,pass,is_remember)
    
     loginInfo= {
      :login=>name,
      :password => pass,
      :remember => is_remember 
    }
    
    return  @server.call("User.login",loginInfo)
  end
  
  def get_XMLRPC_server
    @server =  XMLRPC::Client.new( "192.168.1.37", "/bugzilla/xmlrpc.cgi")
    login_bugzilla('test1@a.com','111111',false)
  end
  
  def get_products
    ids = @server.call('Product.get_selectable_products')
    p = @server.call('Product.get',ids)
    return p["products"]
  end

end

 这里我用的是Bugzilla的webservice 做例子

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics