Form Filler

Discussion in 'Ruby' started by eastcoastcoder@gmail.com, Feb 14, 2006.

  1. Guest

    Is there an equivalent in Ruby to the Perl modules which can "fill out
    an html/http form"?

    Given a hash, I'd like to either get the query string to append to the
    URL for GET's, or the POST contents to append for POST's, as if the
    hash was the form[field] = value. The routine should handle the url
    encoding and the like.

    Any luck?
    (If not, anyone up for a quick few lines of Ruby ninjahood?)
     
    , Feb 14, 2006
    #1
    1. Advertising

  2. Guest

    On Tue, 14 Feb 2006 wrote:

    > Is there an equivalent in Ruby to the Perl modules which can "fill out
    > an html/http form"?
    >
    > Given a hash, I'd like to either get the query string to append to the
    > URL for GET's, or the POST contents to append for POST's, as if the
    > hash was the form[field] = value. The routine should handle the url
    > encoding and the like.
    >
    > Any luck?
    > (If not, anyone up for a quick few lines of Ruby ninjahood?)


    harp:~ > cat a.rb
    require "cgi"

    class ::Hash
    def query() map{|k,v| [CGI::escape(k), CGI::escape(v)].join "="}.join "&" end
    end

    query = { "foo" => "< > &", "bar" => "http://b/a space" }

    puts query.query


    harp:~ > ruby a.rb
    foo=%3C+%3E+%26&bar=http%3A%2F%2Fb%2Fa+space


    hth.

    -a

    --
    judge your success by what you had to give up in order to get it.
    - h.h. the 14th dali lama
     
    , Feb 14, 2006
    #2
    1. Advertising

  3. Kev Jackson Guest


    >
    > harp:~ > cat a.rb
    > require "cgi"
    >
    > class ::Hash
    > def query() map{|k,v| [CGI::escape(k), CGI::escape(v)].join
    > "="}.join "&" end
    > end
    >
    > query = { "foo" => "< > &", "bar" => "http://b/a space" }
    >
    > puts query.query
    >
    >
    > harp:~ > ruby a.rb
    > foo=%3C+%3E+%26&bar=http%3A%2F%2Fb%2Fa+space
    >
    >

    6 minutes from post to solution - is that a record?

    Kev
     
    Kev Jackson, Feb 14, 2006
    #3
  4. Guest

    On Tue, 14 Feb 2006, Kev Jackson wrote:

    > 6 minutes from post to solution - is that a record?


    i think i got one in under 2 before... ;-)

    -a

    --
    judge your success by what you had to give up in order to get it.
    - h.h. the 14th dali lama
     
    , Feb 14, 2006
    #4
  5. D=C5=88a Utorok 14 Febru=C3=A1r 2006 05:19 Kev Jackson nap=C3=ADsal:
    > > harp:~ > cat a.rb
    > > require "cgi"
    > >
    > > class ::Hash
    > > def query() map{|k,v| [CGI::escape(k), CGI::escape(v)].join
    > > "=3D"}.join "&" end
    > > end
    > >
    > > query =3D { "foo" =3D> "< > &", "bar" =3D> "http://b/a space" }
    > >
    > > puts query.query
    > >
    > >
    > > harp:~ > ruby a.rb
    > > foo=3D%3C+%3E+%26&bar=3Dhttp%3A%2F%2Fb%2Fa+space

    >
    > 6 minutes from post to solution - is that a record?
    >
    > Kev


    Ara's time machine is almost as good as Guido's time machine, it seems.

    Oh, and someone apparently hacked up a Ruby WWW::Mechanize which is suppose=
    d=20
    to do this.

    David Vallner
     
    David Vallner, Feb 14, 2006
    #5
  6. Guest

    Excellent, most appreciated.

    Forgive my RFC ignorance, but is the same string appended to the URL
    for GETs and sent as the bod for POST's? Or is there a difference in
    the encoding somehow?
     
    , Feb 15, 2006
    #6
  7. Guest

    On Wed, 15 Feb 2006 wrote:

    > Excellent, most appreciated.
    >
    > Forgive my RFC ignorance, but is the same string appended to the URL
    > for GETs and sent as the bod for POST's? Or is there a difference in
    > the encoding somehow?


    it certainly is different. google around for more info. you'll need to use
    something like http-access2 for posting form data. check out my rubyforge
    script (on rubyforge no less) for a pretty complete example of posting
    including file uploads and redirects.

    regards.

    -a

    --
    judge your success by what you had to give up in order to get it.
    - h.h. the 14th dali lama
     
    , Feb 15, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dbuchanan
    Replies:
    2
    Views:
    2,623
    dbuchanan
    Dec 19, 2005
  2. Li Zhang
    Replies:
    4
    Views:
    6,108
    softip
    Feb 27, 2009
  3. Serial # 19781010
    Replies:
    1
    Views:
    520
    William Tasso
    Aug 10, 2003
  4. Andrey Tarasevich

    Bottom-filler DIV

    Andrey Tarasevich, Aug 26, 2007, in forum: HTML
    Replies:
    2
    Views:
    556
    Andrey Tarasevich
    Aug 26, 2007
  5. rob c
    Replies:
    4
    Views:
    345
    McKirahan
    Dec 30, 2005
Loading...

Share This Page