views:

126

answers:

1

I've been busy on a social networking site for developers for a while (like a mix of github and Facebook), and I want to implement a simple system to create repositories, like on github. For this, I want to create a command-line application in Ruby (not Rails), which will check if there were made any changes, then upload changed or new files. The social networking site is written in Ruby, using the Ruby on Rails Framework:

  DEVELOPER'S PC OR MAC                            SERVER
Command-line (Ruby, local) <-------> Social networking site (Rails, web)

For the Rails application, I currenly use the Paperclip plugin for a browser uploader. For the command-line uploader, what do you think is the best way for uploading? Sockets, a http-library, SSH, e-mail, FTP, something else? The uploading process should be fast, and the files are not really bigger than 200kb (unless it's Brainfuck, but that aside), since it are just source-code files.

A: 

Haven't used it myself but HTTPClient looks promising for this:

http://dev.ctor.org/doc/httpclient/

From their HTTPClient docs:

File.open('/tmp/post_data') do |file|
  body = { 'upload' => file, 'user' => 'nahi' }
  res = clnt.post(uri, body)
end

Also just noticed there are plenty of other options described in a previous stack overflow posting

mczepiel
Does this also work for binary files?
Time Machine
I see no reason why it wouldn't work. You're posting data much in the same way it's posted in a multipart form, and there's no need to specify the encoding of the file you're sending there. Should be pretty easy to wire up a test to confirm that.
mczepiel