Sha256: 639635188edb5508a19e3dc77a287dbdc7ebc4e2358b053b8c3f4f27ac77ab47

Contents?: true

Size: 1 KB

Versions: 8

Compression:

Stored size: 1 KB

Contents

module S3Multipart
  class Http
    require 'net/http'

    attr_accessor :method, :path, :body, :headers, :response

    def initialize(method, path, options)
      @method = method
      @path = path
      @headers = options[:headers]
      @body = options[:body]
    end

    class << self
      def get(path, options={})
        new(:get, path, options).perform
      end

      def post(path, options={})
        new(:post, path, options).perform
      end

      def put(path, options={})
        new(:put, path, options).perform
      end
    end

    def perform
      request = request_class.new(path)
      headers.each do |key, val|
        request[key.to_s.split("_").map(&:capitalize).join("-")] = val
      end
      request.body = body if body
      
      @response = http.request(request)
    end

    private

      def http 
        Net::HTTP.new("#{Config.instance.bucket_name}.s3.amazonaws.com", 80)
      end

      def request_class
        Net::HTTP.const_get(method.to_s.capitalize)
      end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
s3_multipart-0.0.10.5 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.10.4 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.10.3 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.10.2 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.9 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.8 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.7 lib/s3_multipart/http/net_http.rb
s3_multipart-0.0.6 lib/s3_multipart/http/net_http.rb