#coding: utf-8 require 'rest_client' module Ns class Client def self.request(action = 'get', url = '', data_params = {}) #TODO 网路异常处理 #use RestClient now #get specific handle FIXME if action == 'get' ps = data_params[:data].dup ps.delete(:id) url = Util.params_query(url, ps) end Rails.logger.debug "====#{action} to #{url} with params: #{data_params.inspect}" puts "====#{action} to #{url} with params: #{data_params.inspect}" json_response = RestClient.send(action, url, data_params) result = JSON.parse(json_response) result end def self.config ServiceConfig end def self.url(key = '', params = {}) config.service_url(key, params) end #service request def self.service_request(service_key = '', params = {}, request_method = 'get') request(request_method, url(service_key, params[:data]), params) end #==service端统一从:data参数中接传来的额外请求数据 def self.get(key = '', params = {}) service_request(key, {:data=>params}, 'get') end def self.delete(key = '', params = {}) service_request(key, {:data=>params}, 'delete') end def self.post(key = '', params = {}) service_request(key, {:data=>params}, 'post') end def self.put(key = '', params = {}) service_request(key, {:data=>params}, 'put') end end end