github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

taf2 / curb

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 183
    • 22
  • Source
  • Commits
  • Network (22)
  • Issues (5)
  • Downloads (7)
  • Wiki (3)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (4)
    • gh-pages
    • master ✓
    • more-ruby
    • ruby19
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby bindings for libcurl — Read more

  cancel

http://idle-hacking.com/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

ready for release 
Todd Fisher (author)
Sun Jan 31 09:10:12 -0800 2010
commit  ac0b465392429caaaec7ca2eadf98fe2c05603cb
tree    ab2a7fc652100f19683ddb0d14e610e79567658c
parent  502d0844fff6e9d0154e2f06de5e7826d4ff0bdc
curb /
name age
history
message
file .gitignore Fri Jun 19 16:47:39 -0700 2009 update version to 0.4.1 [Todd A. Fisher]
file LICENSE Tue Jul 15 08:33:01 -0700 2008 initial commit with multi handle support [taf2]
file README Loading commit data...
file README.markdown
file Rakefile
file curb.gemspec Fri Jan 29 14:08:13 -0800 2010 update version [Todd A. Fisher]
file doc.rb Sat Jul 18 05:39:07 -0700 2009 update's for rdoc [Todd Fisher]
directory ext/ Sun Jan 31 09:10:12 -0800 2010 ready for release [Todd Fisher]
file index.html Wed Jul 29 14:36:12 -0700 2009 update the website [Todd Fisher]
directory lib/ Tue Nov 24 06:18:21 -0800 2009 some minor formatting [Todd Fisher]
directory samples/
directory tests/ Sun Jan 31 09:09:18 -0800 2010 ext/ add an option to configure the default ti... [Todd Fisher]
README.markdown

Curb - Libcurl bindings for Ruby

  • rubyforge rdoc
  • rubyforge project
  • github project

Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the libcurl(3), a fully-featured client-side URL transfer library. cURL and libcurl live at http://curl.haxx.se/ .

Curb is a work-in-progress, and currently only supports libcurl's 'easy' and 'multi' modes.

License

Curb is copyright (c)2006 Ross Bamford, and released under the terms of the Ruby license. See the LICENSE file for the gory details.

You will need

  • A working Ruby installation (1.8+, tested with 1.8.6, 1.8.7, 1.9.1, and 1.9.2)
  • A working (lib)curl installation, with development stuff (7.5+, tested with 7.19.x)
  • A sane build environment (e.g. gcc, make)

Installation...

... will usually be as simple as:

$ gem install curb

Or, if you downloaded the archive:

$ rake install 

If you have a wierd setup, you might need extconf options. In this case, pass them like so:

$ rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever'

Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms. If you do use another platform and experience problems, or if you can expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues

Curb has fairly extensive RDoc comments in the source. You can build the documentation with:

$ rake doc

Examples

Simple fetch via HTTP:

c = Curl::Easy.perform("http://www.google.co.uk")
puts c.body_str

Same thing, more manual:

c = Curl::Easy.new("http://www.google.co.uk")
c.perform
puts c.body_str

Additional config:

Curl::Easy.perform("http://www.google.co.uk") do |curl| 
  curl.headers["User-Agent"] = "myapp-0.0"
  curl.verbose = true
end

Same thing, more manual:

c = Curl::Easy.new("http://www.google.co.uk") do |curl| 
  curl.headers["User-Agent"] = "myapp-0.0"
  curl.verbose = true
end

c.perform

Supplying custom handlers:

c = Curl::Easy.new("http://www.google.co.uk")

c.on_body { |data| print(data) }
c.on_header { |data| print(data) }

c.perform

Reusing Curls:

c = Curl::Easy.new

["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
  c.url = url
  c.perform
  c.body_str
end

HTTP POST form:

c = Curl::Easy.http_post("http://my.rails.box/thing/create",
                         Curl::PostField.content('thing[name]', 'box'),
                         Curl::PostField.content('thing[type]', 'storage'))

HTTP POST file upload:

c = Curl::Easy.new("http://my.rails.box/files/upload")
c.multipart_form_post = true
c.http_post(Curl::PostField.file('myfile.rb'))

Multi Interface (Basic HTTP GET):

# make multiple GET requests
easy_options = {:follow_location => true}
multi_options = {:pipeline => true}

Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
  # do something interesting with the easy response
  puts easy.last_effective_url
end

Multi Interface (Basic HTTP POST):

# make multiple POST requests
easy_options = {:follow_location => true, :multipart_form_post => true}
multi_options = {:pipeline => true}

url_fields = [
  { :url => 'url1', :post_fields => {'f1' => 'v1'} },
  { :url => 'url2', :post_fields => {'f1' => 'v1'} },
  { :url => 'url3', :post_fields => {'f1' => 'v1'} }
]

Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
  # do something interesting with the easy response
  puts easy.last_effective_url
end

Multi Interface (Advanced):

responses = {}
requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
m = Curl::Multi.new
# add a few easy handles
requests.each do |url|
  responses[url] = ""
  c = Curl::Easy.new(url) do|curl|
    curl.follow_location = true
    curl.on_body{|data| responses[url] << data; data.size }
  end
  m.add(c)
end

m.perform do
  puts "idling... can do some work here, including add new requests"
end

requests.each do|url|
  puts responses[url]
end
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server