Skip to content
Browse files

testing curb

  • Loading branch information...
1 parent aceb4db commit 348e6c8995920ab67a335befbd6ecf8242309b12 @cice cice committed Jan 11, 2012
Showing with 56 additions and 19 deletions.
  1. +37 −0 lib/rapuncel/adapters/curb_adapter.rb
  2. +19 −19 lib/rapuncel/client.rb
View
37 lib/rapuncel/adapters/curb_adapter.rb
@@ -0,0 +1,37 @@
+require 'curb'
+
+module Rapuncel
+ module Adapters
+ module CurbAdapter
+ # Small response wrapper
+ class HttpResponse
+ def initialize body, code
+ @body, @code = body, code
+ end
+
+ def success?
+ !(@code =~ /^2/)
+ end
+
+ def body
+ @body
+ end
+
+ def code
+ @code
+ end
+ end
+
+ # Dispatch a XMLRPC via HTTP and return a response object.
+ def send_method_call str
+ @curb ||= Curb::Easy.new "#{connection.host}:#{connection.port}"
+
+ @curb.post_body = str
+ @curb.headers = @curb.headers.merge connection.headers
+ @curb.perform
+
+ HttpResponse.new @curb.body_str, @curb.response_code
+ end
+ end
+ end
+end
View
38 lib/rapuncel/client.rb
@@ -1,4 +1,4 @@
-require 'rapuncel/adapters/net_http_adapter'
+require 'rapuncel/adapters/curb_adapter'
require 'rapuncel/connection'
require 'rapuncel/xml_rpc/serializer'
require 'rapuncel/xml_rpc/deserializer'
@@ -12,23 +12,7 @@ class Client
attr_accessor :connection, :raise_on_fault, :raise_on_error
- include Adapters::NetHttpAdapter
-
- def proxy_for interface = nil
- if interface.nil?
- @default_proxy ||= Proxy.new self, nil
- else
- @proxies ||= Hash.new do |hash, key|
- hash[key] = Proxy.new self, key
- end
-
- @proxies[interface.to_s]
- end
- end
-
- def proxy
- proxy_for nil
- end
+ include Adapters::CurbAdapter
def initialize configuration = {}
@connection = Connection.new configuration.except(:raise_on, :serialization)
@@ -51,6 +35,22 @@ def initialize configuration = {}
end
end
+ def proxy_for interface = nil
+ if interface.nil?
+ @default_proxy ||= Proxy.new self, nil
+ else
+ @proxies ||= Hash.new do |hash, key|
+ hash[key] = Proxy.new self, key
+ end
+
+ @proxies[interface.to_s]
+ end
+ end
+
+ def proxy
+ proxy_for nil
+ end
+
# Dispatch a method call and return the response as Rapuncel::Response object.
def call name, *args
ActiveSupport::Deprecation.warn "Using #call is deprecated, please use #call_to_ruby instead.", caller
@@ -106,4 +106,4 @@ def raise_error response
raise(Response::Error, "HTTP Error: #{response.error.inspect}")
end
end
-end
+end

0 comments on commit 348e6c8

Please sign in to comment.
Something went wrong with that request. Please try again.