Class: RubyForge::Client

### Home Classes Methods

### In Files

- lib/rubyforge/client.rb

### Parent

Object

### Methods

- ::new
- #boundary_data_for
- #execute
- #get_content
- #post_content
- #query_string_for

### Files

- History.txt
- Manifest.txt
- README.txt

### Class/Module Index

Quicksearch

- Net
- Net::HTTP
- RubyForge
- RubyForge::Client
- Time

No matching classes.

# RubyForge::Client

### Attributes

agent_class[RW]
debug_dev[RW]
ssl_verify_mode[RW]

### Public Class Methods

new(proxy = nil) click to toggle source

    # File lib/rubyforge/client.rb, line 32
    def initialize(proxy = nil)
      @debug_dev       = nil
      @ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
      if proxy
        begin
          proxy_uri = URI.parse(proxy)
          @agent_class = Net::HTTP::Proxy(proxy_uri.host,proxy_uri.port)
        rescue URI::InvalidURIError
        end
      end
      @agent_class ||= Net::HTTP
    end

### Public Instance Methods

boundary_data_for(boundary, parameters) click to toggle source

    # File lib/rubyforge/client.rb, line 94
    def boundary_data_for(boundary, parameters)
      parameters.sort_by {|k,v| k.to_s }.map { |k,v|
        parameter = "--#{boundary}\r\nContent-Disposition: form-data; name=\"" +
            WEBrick::HTTPUtils.escape_form(k.to_s) + "\""

        if v.respond_to? :path
          parameter += "; filename=\"#{File.basename(v.path)}\"\r\n"
          parameter += "Content-Transfer-Encoding: binary\r\n"
          parameter += "Content-Type: text/plain"
        end
        parameter += "\r\n\r\n"

        if v.respond_to? :path
          parameter += v.read
        else
          parameter += v.to_s
        end

        parameter
      }.join("\r\n") + "\r\n--#{boundary}--\r\n"
    end

execute(request, uri, parameters = {}, headers = {}, userconfig = nil) click to toggle source

    # File lib/rubyforge/client.rb, line 57
    def execute(request, uri, parameters = {}, headers = {}, userconfig = nil)
      {
        'content-type' => 'application/x-www-form-urlencoded'
      }.merge(headers).each { |k,v| request[k] = v }

      http = agent_class.new( uri.host, uri.port )

      if uri.scheme == 'https' && uri.host !~ /localhost/
       http.use_ssl      = true
       http.verify_mode  = OpenSSL::SSL::VERIFY_NONE
      end

      request.basic_auth(userconfig["username"], userconfig["password"])

      request_data = case request['Content-Type']
                     when /boundary=(.*)$/
                       boundary_data_for($1, parameters)
                     else
                       query_string_for(parameters)
                     end
      request['Content-Length'] = request_data.length.to_s

      response = http.request(request, request_data)

      return response.body if response.class <= Net::HTTPSuccess

      if response.class <= Net::HTTPRedirection
        location = response['Location']
        unless location =~ /^http/
          location = "#{uri.scheme}://#{uri.host}#{location}"
        end
        uri = URI.parse(location)

        execute(agent_class::Get.new(uri.request_uri), uri)
      end
    end

get_content(uri, query = {}, headers = {}, userconfig = nil) click to toggle source

    # File lib/rubyforge/client.rb, line 51
    def get_content(uri, query = {}, headers = {}, userconfig = nil)
      uri = URI.parse(uri) unless uri.is_a?(URI)
      request = agent_class::Get.new(uri.request_uri)
      execute(request, uri, query, headers, userconfig)
    end

post_content(uri, form = {}, headers = {}, userconfig = nil) click to toggle source

    # File lib/rubyforge/client.rb, line 45
    def post_content(uri, form = {}, headers = {}, userconfig = nil)
      uri = URI.parse(uri) unless uri.is_a?(URI)
      request = agent_class::Post.new(uri.request_uri)
      execute(request, uri, form, headers, userconfig)
    end

query_string_for(parameters) click to toggle source

    # File lib/rubyforge/client.rb, line 116
    def query_string_for(parameters)
      parameters.sort_by {|k,v| k.to_s }.map { |k,v|
        k && [  WEBrick::HTTPUtils.escape_form(k.to_s),
                WEBrick::HTTPUtils.escape_form(v.to_s) ].join('=')
      }.compact.join('&')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.