From 9b133ef2b79a9f603da7e95f9efaef4d4a541d26 Mon Sep 17 00:00:00 2001 From: Saher El-Neklawy Date: Sat, 1 Dec 2012 10:48:51 +0200 Subject: [PATCH] Initial typhoeus adapter implementation --- Gemfile | 2 ++ Gemfile.lock | 7 ++++++- lib/uber-s3/connection/typhoeus.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/uber-s3/connection/typhoeus.rb diff --git a/Gemfile b/Gemfile index 9d72db0..72d221d 100644 --- a/Gemfile +++ b/Gemfile @@ -12,3 +12,5 @@ group :development, :test do # gem 'nokogiri' end + +gem 'typhoeus', '~> 0.4.2' diff --git a/Gemfile.lock b/Gemfile.lock index 2c9f91d..b6b258f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,7 +19,7 @@ GIT PATH remote: . specs: - uber-s3 (0.2.3) + uber-s3 (0.2.4) mime-types (~> 1.17) GEM @@ -33,6 +33,7 @@ GEM eventmachine (>= 1.0.0.beta.4) eventmachine (1.0.0.beta.4) eventmachine (1.0.0.beta.4-java) + ffi (1.1.5) http_parser.rb (0.5.3) http_parser.rb (0.5.3-java) method_source (0.7.1) @@ -59,6 +60,9 @@ GEM rspec-mocks (2.7.0) slop (2.4.4) spoon (0.0.1) + typhoeus (0.4.2) + ffi (~> 1.0) + mime-types (~> 1.18) PLATFORMS java @@ -72,4 +76,5 @@ DEPENDENCIES pry-nav rake rspec (~> 2.7.0) + typhoeus (~> 0.4.2) uber-s3! diff --git a/lib/uber-s3/connection/typhoeus.rb b/lib/uber-s3/connection/typhoeus.rb new file mode 100644 index 0000000..2bb81d1 --- /dev/null +++ b/lib/uber-s3/connection/typhoeus.rb @@ -0,0 +1,28 @@ +require 'typhoeus' + +HYDRA = ::Typhoeus::Hydra.new + +module UberS3::Connection + class Typhoeus < Adapter + + def request(verb, url, headers={}, body=nil) + # TODO: see extra steps done in NET::HTTP adapter + params = {} + params[:headers] = headers + params[:method] = verb.to_sym + params[:body] = body if body + + r = ::Typhoeus::Request.new(url, params) + HYDRA.queue(r) + HYDRA.run + + UberS3::Response.new({ + :status => r.response.code, + :header => r.response.headers, + :body => r.response.body, + :raw => r.response + }) + end + + end +end