Sha256: 837bcb0f960cba5c5399ca1a3920cafa5cf04a1c61ba195eec7e3d2675b60298

Contents?: true

Size: 1.93 KB

Versions: 22

Compression:

Stored size: 1.93 KB

Contents

require 'net/http'
require 'uri'
module Mirage
  module Web
    class FileResponse
      attr_reader :response
      def initialize response
        @response = response
      end

      def save_as path
        @response.save_as(path)
      end
    end

    def http_put url, entity, options={}
      if options[:parameters]
        url << "?#{options[:parameters].to_a.collect{|pair|pair.join("=")}.join("&")}"
      end
      uri = URI.parse(url)
      request = Net::HTTP::Put.new(uri.request_uri)

      if entity.is_a? File
        request.body_stream=entity
        request.content_length=entity.lstat.size
      else
        request.body=entity
      end

      if options[:headers]
        options[:headers].each { |field, value| request.add_field(field, value) }
      end

      #if options[:parameters]
      #  request.set_form_data options[:parameters]
      #end

      Net::HTTP.new(uri.host, uri.port).request(request)
    end

    def http_get url, params={}, headers={}
      uri = URI.parse(url)
      request = Net::HTTP::Get.new(uri.request_uri)
      request.set_form_data params
      headers.each { |field, value| request.add_field(field, value) }
      Net::HTTP.new(uri.host, uri.port).request(request)
    end

    def http_post url, params={}, headers={}
      uri = URI.parse(url)
      request = Net::HTTP::Post.new(uri.request_uri)
      
      params.is_a?(Hash) ? request.set_form_data(params) : request.body = params
        
      headers.each { |field, value| request.add_field(field, value) }
      Net::HTTP.new(uri.host, uri.port).request(request)
    end

    def http_delete url, params={}, headers={}
      uri = URI.parse(url)
      request = Net::HTTP::Delete.new(uri.request_uri)
      params.is_a?(Hash) ? request.set_form_data(params) : request.body = params
      headers.each { |field, value| request.add_field(field, value) }
      Net::HTTP.new(uri.host, uri.port).request(request)
    end

  end
end
World(Mirage::Web)

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
mirage-3.0.4 features/support/web.rb
mirage-3.0.3 features/support/web.rb
mirage-3.0.2 features/support/web.rb
mirage-3.0.1 features/support/web.rb
mirage-3.0.0 features/support/web.rb
mirage-3.0.0.alpha.17 features/support/web.rb
mirage-3.0.0.alpha.16 features/support/web.rb
mirage-3.0.0.alpha.15 features/support/web.rb
mirage-3.0.0.alpha.14 features/support/web.rb
mirage-3.0.0.alpha.13 features/support/web.rb
mirage-3.0.0.alpha.12 features/support/web.rb
mirage-3.0.0.alpha.11 features/support/web.rb
mirage-3.0.0.alpha.10 features/support/web.rb
mirage-3.0.0.alpha.9 features/support/web.rb
mirage-3.0.0.alpha.8 features/support/web.rb
mirage-3.0.0.alpha.7 features/support/web.rb
mirage-3.0.0.alpha.6 features/support/web.rb
mirage-3.0.0.alpha.5 features/support/web.rb
mirage-3.0.0.alpha.4 features/support/web.rb
mirage-3.0.0.alpha.3 features/support/web.rb