Permalink
Browse files

Merge pull request #9 from mrloop/master

IOStream instead of String for post data

When posting a large file ~ 4MB to basecamp this error was thrown.

Timeout::Error
.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill'

Using an IOStream instead of a String for the post data solves this.
  • Loading branch information...
2 parents 1787a9b + 405b457 commit 64d966d4adabddc74d7d5f8c3d2a1c6928ac8b76 @anibalcucco committed Oct 6, 2011
Showing with 13 additions and 6 deletions.
  1. +8 −3 README.rdoc
  2. +5 −3 lib/basecamp/connection.rb
View
@@ -137,14 +137,19 @@ you want to delete. Example:
If the resource accepts file attachments, the +attachments+ parameter should
be an array of Basecamp::Attachment objects. Example:
- a1 = Basecamp::Attachment.create('primary', File.read('primary.doc'))
- a2 = Basecamp::Attachment.create('another', File.read('another.doc'))
+ f1 = File.open('primary.doc')
+ s1 = StringIO.new('a string')
+
+ a1 = Basecamp::Attachment.create('primary', f1)
+ a2 = Basecamp::Attachment.create('another', s1))
m = Basecamp::Message.new(:project_id => 1037)
...
m.attachments = [a1, a2]
m.save # => true
+ f1.close
+
=== Milestones
Is not implemented as an active resource, it uses the non-REST interface.
@@ -188,4 +193,4 @@ You can access other resources not included in this wrapper yet using "record" a
* jamesarosen
* defeated
* justinbarry
-* fmiopensource
+* fmiopensource
@@ -6,15 +6,17 @@ def initialize(master)
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE if master.use_ssl
end
- def post(path, body, headers = {})
+ def post(path, iostream, headers = {})
request = Net::HTTP::Post.new(path, headers.merge('Accept' => 'application/xml'))
request.basic_auth(@master.user, @master.password)
- @connection.request(request, body)
+ request.body_stream = iostream
+ request.content_length = iostream.size
+ @connection.request(request)
end
def get(path, headers = {})
request = Net::HTTP::Get.new(path, headers.merge('Accept' => 'application/xml'))
request.basic_auth(@master.user, @master.password)
@connection.request(request)
end
-end; end
+end; end

0 comments on commit 64d966d

Please sign in to comment.