Sha256: b5ff777008bf1666e502a003cd9e432583f66f618943bcad6d3447b37c5d8a88

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

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

1 entries across 1 versions & 1 rubygems

Version Path
s3_multipart-0.0.10.6 lib/s3_multipart/http/net_http.rb